Edit File: grep.cpython-37.pyc
B ����r}�c7������������������@���s����d�Z�ddlZddlZddlZddlmZmZ�ddlmZ�ddl m Z �ddlmZ�ddd�Z d d ��Zdd��ZG�d d��de �Zdd��Zedkr�ddlmZ�edddd��ddlmZ�ee��dS�)z�Grep dialog for Find in Files functionality. Inherits from SearchDialogBase for GUI and uses searchengine to prepare search pattern. �����N)� StringVar� BooleanVar)�Checkbutton)�SearchDialogBase)�searchenginec�������������C���sN���|�����}t�|�}t|d�s*t|||�|_|j}|��dd�}|�|�||��dS�)a���Open the Find in Files dialog. Module-level function to access the singleton GrepDialog instance and open the dialog. If text is selected, it is used as the search phrase; otherwise, the previous entry is used. Args: text: Text widget that contains the selected text for default search phrase. io: iomenu.IOBinding instance with default path to search. flist: filelist.FileList instance for OutputWindow parent. �_grepdialogz sel.firstzsel.lastN)Z_rootr����get�hasattr� GrepDialogr����open)�text�io�flist�root�engineZdialog�searchphrase��r����1/opt/alt/python37/lib64/python3.7/idlelib/grep.py�grep���s���� r���c�������������C���s���t�|���dS�)zHandle os.walk error.N)�print)�msgr���r���r���� walk_error+���s����r���c�������������#���sB���x<t�j|�td�D�]*\��}}���fdd�|D��E�dH��|sP�qW�dS�)z�Generate file names in dir that match pattern. Args: folder: Root directory to search. pattern: File pattern to match. recursive: True to include subdirectories. )�onerrorc�������������3���s(���|�] }t���|��rtj���|�V��qd�S�)N)�fnmatch�os�path�join)�.0�name)�dirpath�patternr���r���� <genexpr>9���s���zfindfiles.<locals>.<genexpr>N)r����walkr���)�folderr ���� recursive�_� filenamesr���)r���r ���r���� findfiles0���s ����r'���c�������������������s`���e�Zd�ZdZdZdZdZ��fdd�Zddd �Zd d��Z dd ��Z dd��Zddd�Zdd��Z ���ZS�)r ���z$Dialog for searching multiple files.zFind in Files DialogZGrepr���c����������������s,���t����||��||�_t|�|�_t|�|�_dS�)a-��Create search dialog for searching for a phrase in the file system. Uses SearchDialogBase as the basis for the GUI and a searchengine instance to prepare the search. Attributes: flist: filelist.Filelist instance for OutputWindow parent. globvar: String value of Entry widget for path to search. globent: Entry widget for globvar. Created in create_entries(). recvar: Boolean value of Checkbutton widget for traversing through subdirectories. N)�super�__init__r���r����globvarr����recvar)�selfr���r���r���)� __class__r���r���r)���G���s���� zGrepDialog.__init__Nc������� ������C���sh���t��|�||��|r|jpd}nd}tj�|�\}}tj�|�\}}|sJd}|�j�tj� |d|����dS�)a_��Make dialog visible on top of others and ready to use. Extend the SearchDialogBase open() to set the initial value for globvar. Args: text: Multicall object containing the text information. searchphrase: String phrase to search. io: iomenu.IOBinding instance containing file path. ��z.py�*N) r���r����filenamer���r����split�splitextr*����setr���) r,���r���r���r ���r����dir�base�head�tailr���r���r���r���Z���s����zGrepDialog.openc�������������C���s"���t��|���|��d|�j�d�|�_dS�)z9Create base entry widgets and add widget for search path.z In files:r���N)r����create_entriesZ make_entryr*���Zglobent)r,���r���r���r���r8���p���s���� zGrepDialog.create_entriesc�������������C���s*���t�|����d�|�jdd�}|jddd��dS�)z0Add check button to recurse down subdirectories.r���zRecurse down subdirectories)Zvariabler����topZboth)ZsideZfillN)r���Z make_framer+����pack)r,���Zbtnr���r���r����create_other_buttonsu���s����zGrepDialog.create_other_buttonsc�������������C���s ���t��|���|�jd|�jdd��dS�)z<Create base command buttons and add button for Search Files.zSearch FilesT)ZisdefN)r����create_command_buttonsZmake_button�default_command)r,���r���r���r���r<���|���s���� z!GrepDialog.create_command_buttonsc�������������C���sj���|�j����}|sdS�|�j���}|s.|�j����dS�ddlm}�tj }z||�j �t_ |��||��W�d|t_ X�dS�)a ��Grep for search pattern in file path. The default command is bound to <Return>. If entry values are populated, set OutputWindow as stdout and perform search. The search dialog is closed automatically when the search begins. Nr���)�OutputWindow)r���Zgetprogr*���r���r9���ZbellZidlelib.outwinr>����sys�stdoutr����grep_it)r,���Zevent�progr���r>���Zsaver���r���r���r=�������s���� zGrepDialog.default_commandc������� ������C���sR��t�j�|�\}}|st�j}tt|||�j�����}|�����|�j � ��}td|�d|��d���d}y�x�|D�]�}y�t|dd��j} xbt | d�D�]T\} }|dd ��d kr�|d d��}|�|�r�tj�|��d| ��d|��d ���|d7�}q�W�W�d Q�R�X�W�qd�tk �r�}�zt|��W�d d }~X�Y�qdX�qdW�t|�r.d|��d �nd��W�n�tk �rL���Y�nX�d S�)a���Search for prog within the lines of the files in path. For the each file in the path directory, open the file and search each line for the matching pattern. If the pattern is found, write the file and line information to stdout (which is an OutputWindow). Args: prog: The compiled, cooked search pattern. path: String containing the search path. z Searching z in z ...r����replace)�errors�������N� z: zHits found: z' (Hint: right-click to open locations.)zNo hits.)r���r���r1����curdir�sortedr'���r+���r����closer���Zgetpatr���r���� enumerate�searchr?���r@����write�OSError�AttributeError) r,���rB���r���r#���ZfilepatZfilelistZpat�hits�fn�f�lineno�liner���r���r���r���rA�������s0���� zGrepDialog.grep_it)N)N)�__name__� __module__�__qualname__�__doc__�titleZiconZneedwrapbuttonr)���r���r8���r;���r<���r=���rA���� __classcell__r���r���)r-���r���r ���@���s��� r ���c����������������s����ddl�m}m}m�m���ddlm}m}�ddlm }�||��}|� d��tt|�� ���d�dd����\}}|� d|��d|d������||��||�} | ����|| d d ������������fdd�} || d | d�}|����d�S�)Nr���)�Toplevel�Text�SEL�END)�Frame�Button)�PyShellFileListzTest GrepDialog�+rE�����������)Zheightc������������������s,�������d����t��d�����d����d�S�)Nz1.0)r���)Ztag_addr���Z tag_remover���)r^���r]���r���r���r���r����show_grep_dialog����s����z&_grep_dialog.<locals>.show_grep_dialogzShow GrepDialog)r���Zcommand)�tkinterr[���r\���r]���r^����tkinter.ttkr_���r`���Zidlelib.pyshellra���rY����map�intZgeometryr1���r:���)�parentr[���r\���r_���r`���ra���r9����x�y�framere���Zbuttonr���)r^���r]���r���r���r����_grep_dialog����s���� rn����__main__)�mainzidlelib.idle_test.test_grep����F)� verbosity�exit)�run)NN)rX���r���r���r?���rf���r���r���rg���r���Zidlelib.searchbaser���Zidlelibr���r���r���r'���r ���rn���rU���Zunittestrp���Zidlelib.idle_test.htestrt���r���r���r���r����<module>���s$��� �