OwlCyberSecurity - MANAGER
Edit File: format.cpython-37.pyc
B ����� f�=������������������@���s����d�Z�ddlZddlmZ�ddlmZ�ddlmZ�G�dd��d�Ze� ���dd ��Z d d��Zdd ��Zdd��Z dd��Zdd��Ze�d�Zdd��ZG�dd��d�ZG�dd��d�ZG�dd��d�Zedkr�ddlmZ�edd d!d"��dS�)#z�Format all or a selected region (line slice) of text. Region formatting options: paragraph, comment block, indent, deindent, comment, uncomment, tabify, and untabify. File renamed from paragraph.py with functions added from editor.py. �����N)�askyesno)� askinteger)�idleConfc���������������@���s6���e�Zd�ZdZdd��Zedd���Zdd��Zdd d �ZdS�)�FormatParagrapha��Format a paragraph, comment block, or selection to a max width. Does basic, standard text formatting, and also understands Python comment blocks. Thus, for editing Python source code, this extension is really only suitable for reformatting these comment blocks or triple-quoted strings. Known problems with comment reformatting: * If there is a selection marked, and the first line of the selection is not complete, the block will probably not be detected as comments, and will have the normal "text formatting" rules applied. * If a comment block has leading whitespace that mixes tabs and spaces, they will not be considered part of the same block. * Fancy comments, like this bulleted list, aren't handled :-) c�������������C���s ���||�_�d�S�)N)�editwin)�selfr�����r����3/opt/alt/python37/lib64/python3.7/idlelib/format.py�__init__���s����zFormatParagraph.__init__c�������������C���s���t�jdddddd�|�_d�S�)N� extensionsr���z max-width�int�H���)�type�default)r���Z GetOption� max_width)�clsr���r���r ����reload"���s����zFormatParagraph.reloadc�������������C���s ���d�|�_�d�S�)N)r���)r���r���r���r ����close'���s����zFormatParagraph.closeNc������� ������C���s����|dkr|�j�n|}|�jj}|�j���\}}|rF|rF|�||�}t|�}nt||�d��\}}}}|rpt|||�}n t ||�}|� ddd��||kr�|�d|��|����|� ||��|�||��|����n|�d|��|�d��dS�)a���Formats paragraph to a max width specified in idleConf. If text is selected, format_paragraph_event will start breaking lines at the max width, starting from the beginning selection. If no text is selected, format_paragraph_event uses the current cursor location to determine the paragraph (lines of text surrounded by blank lines) and formats it. The length limit parameter is for testing with a known value. N�insert�selz1.0�end�break)r���r����text�get_selection_indices�get�get_comment_header�find_paragraph�index�reformat_comment�reformat_paragraph� tag_remove�mark_set�undo_block_start�deleter����undo_block_stopZsee) r����event�limitr����first�last�data�comment_header�newdatar���r���r ����format_paragraph_event*���s(���� z&FormatParagraph.format_paragraph_event)N) �__name__� __module__�__qualname__�__doc__r ����classmethodr���r���r,���r���r���r���r ���r������s ���r���c������� ������C���sF��t�t|�d��\}}|��d|�d|��}x:|��d|�dd�rbt|�rb|d�}|��d|�d|��}q*W�|}t|�}t|�}x<t|�|kr�t||d���s�|d�}|��d|�d|��}qzW�d|�}|d�}|��d|�d|��}xJ|dk�r$t|�|k�r$t||d����s$|d�}|��d|�d|��}q�W�d|d��} | |||��| |�fS�) z�Returns the start/stop indices enclosing the paragraph that mark is in. Also returns the comment format string, if any, and paragraph of text between the start/stop indices. �.z%d.0z%d.end�<r�������Nr���)�mapr����splitr���Zcompare�is_all_whiter����len) r���Zmark�lineno�col�lineZfirst_linenor*���Zcomment_header_lenr(���r'���r���r���r ���r���S���s,����r���c�������������C���s���|���d�}d}t|�}x ||k�r6t||��r6|d�}qW�||krD|�S�t||��}|d�|k�r~t||d���s~t||d���}n|}|d|��}|}x�||k��rTt||���sTt��d||��} x�tdt| �d�D�]x} | | �}|s�q�t||�����|k�r||k�r|�|�����|}||�d�}| d�t| �k�r�| | d��dkr�|d�}q�W�|d�}q�W�|�|�����|� ||d����d� |�S�)z3Return data reformatted to specified width (limit).� r���r4���Nz(\s+)����� )r6���r8���r7���� get_indent�re�range� expandtabs�append�rstrip�extend�join)r)���r&����lines�i�nZindent1Zindent2�new�partialZwords�jZwordr���r���r ���r���x���s<���� r���c����������������s����t�����d��fdd�|��d�D���}�t|t�����d�}t|�|�}|�d�}d}|d�shd}|dd��}d���fdd�|D���|�S�) z?Return data reformatted to specified width with comment header.r<���c�������������3���s���|�]}|��d���V��qd�S�)Nr���)�.0r;���)�lcr���r ���� <genexpr>����s����z#reformat_comment.<locals>.<genexpr>���������Nc�������������3���s���|�]}��|�V��qd�S�)Nr���)rM���r;���)r*���r���r ���rO�������s����)r8���rF���r6����maxr���)r)���r&���r*���Zformat_widthr+���Zblock_suffixr���)r*���rN���r ���r�������s���� r���c�������������C���s���t��d|��dk S�)z/Return True if line is empty or all whitespace.z^\s*$N)r@����match)r;���r���r���r ���r7�������s����r7���c�������������C���s���t��d|�����S�)z/Return the initial space or tab indent of line.z ^([ \t]*))r@���rT����group)r;���r���r���r ���r?�������s����r?���c�������������C���s"���t��d|��}|dkrdS�|�d�S�)a��Return string with leading whitespace and '#' from line or ''. A null return indicates that the line is not a comment line. A non- null return, such as ' #', will be used to find the other lines of a comment block with the same indent. z^([ \t]*#*)NrQ���r4���)r@���rT���rU���)r;����mr���r���r ���r�������s�����r���z[ \t]*c�������������C���s$���t��|��}|���t|����|��fS�)z�Return a line's indentation as (# chars, effective # of spaces). The effective # of spaces is the length after properly "expanding" the tabs into spaces, as done by str.expandtabs(tabwidth). )�_line_indent_rerT���r���r8���rU���rB���)r;����tabwidthrV���r���r���r ����get_line_indent����s���� rY���c���������������@���sl���e�Zd�ZdZdd��Zdd��Zdd��Zdd d �Zddd�Zdd d�Z ddd�Z ddd�Zddd�Zdd��Z dS�)�FormatRegionzFormat selected text (region).c�������������C���s ���||�_�d�S�)N)r���)r���r���r���r���r ���r �������s����zFormatRegion.__init__c�������������C���sr���|�j�j}|�j����\}}|r<|r<|�|d��}|�|d��}n|�d�}|�d�}|�||�}|�d�}||||fS�)aq��Return line information about the selected text region. If text is selected, the first and last indices will be for the selection. If there is no text selected, the indices will be the current cursor location. Return a tuple containing (first index, last index, string representation of text, list of text lines). z linestartz-1c lineend +1czinsert linestartzinsert lineend +1cr<���)r���r���r���r���r���r6���)r���r���r'���r(����head�tail�charsrG���r���r���r ���� get_region����s���� zFormatRegion.get_regionc�������������C���sz���|�j�j}d�|�}||kr&|����dS�|�ddd��|�d|��|����|�||��|�||��|� ���|� d|d��dS�)aa��Replace the text between the given indices. Args: head: Starting index of text to replace. tail: Ending index of text to replace. chars: Expected to be string of current text between head and tail. lines: List of new lines to insert between head and tail. r<���Nr���z1.0r���r���)r���r���rF���Zbellr ���r!���r"���r#���r���r$���Ztag_add)r���r[���r\���r]���rG���r����newcharsr���r���r ���� set_region����s���� zFormatRegion.set_regionNc������� ������C���s����|�����\}}}}xZtt|��D�]J}||�}|rt||�jj�\}} | |�jj�} |�j�| �||d���||<�qW�|��||||��dS�)z$Indent region by indentwidth spaces.Nr���) r^���rA���r8���rY���r���rX����indentwidth�_make_blanksr`���) r���r%���r[���r\���r]���rG����posr;����raw� effectiver���r���r ����indent_region_event��s���� z FormatRegion.indent_region_eventc������� ������C���s����|�����\}}}}x`tt|��D�]P}||�}|rt||�jj�\}} t| |�jj�d�} |�j�| �||d���||<�qW�|�� ||||��dS�)z$Dedent region by indentwidth spaces.r���Nr���) r^���rA���r8���rY���r���rX���rS���ra���rb���r`���) r���r%���r[���r\���r]���rG���rc���r;���rd���re���r���r���r ����dedent_region_event��s���� z FormatRegion.dedent_region_eventc�������������C���sR���|�����\}}}}x,tt|�d��D�]}||�}d|�||<�q"W�|��||||��dS�)zrComment out each line in region. ## is appended to the beginning of each line to comment it out. r4���z##r���)r^���rA���r8���r`���)r���r%���r[���r\���r]���rG���rc���r;���r���r���r ����comment_region_event ��s����z!FormatRegion.comment_region_eventc�������������C���s����|�����\}}}}xdtt|��D�]T}||�}|s0q|dd��dkrN|dd��}n|dd��dkrj|dd��}|||<�qW�|��||||��dS�)z�Uncomment each line in region. Remove ## or # in the first positions of a line. If the comment is not in the beginning position, this command will have no effect. Nr=���z##r4����#r���)r^���rA���r8���r`���)r���r%���r[���r\���r]���rG���rc���r;���r���r���r ����uncomment_region_event,��s����z#FormatRegion.uncomment_region_eventc������� ������C���s����|�����\}}}}|����}|dkr$dS�x\tt|��D�]L}||�}|r2t||�\} } t| |�\}}d|�d|��|| d���||<�q2W�|��||||��dS�)z@Convert leading spaces to tabs for each line in selected region.N� r>���r���)r^����_asktabwidthrA���r8���rY����divmodr`���) r���r%���r[���r\���r]���rG���rX���rc���r;���rd���re���ZntabsZnspacesr���r���r ����tabify_region_event?��s����$z FormatRegion.tabify_region_eventc�������������C���s`���|�����\}}}}|����}|dkr$dS�x&tt|��D�]}||��|�||<�q2W�|��||||��dS�)z.Expand tabs to spaces for each line in region.Nr���)r^���rl���rA���r8���rB���r`���)r���r%���r[���r\���r]���rG���rX���rc���r���r���r ����untabify_region_eventN��s����z"FormatRegion.untabify_region_eventc�������������C���s���t�dd|�jj|�jjddd�S�)zReturn value for tab width.z Tab widthzColumns per tab? (2-16)r=�������)�parent�initialvalue�minvalue�maxvalue)r���r���r���ra���)r���r���r���r ���rl���Y��s����zFormatRegion._asktabwidth)N)N)N)N)N)N)r-���r.���r/���r0���r ���r^���r`���rf���rg���rh���rj���rn���ro���rl���r���r���r���r ���rZ�������s��� rZ���c���������������@���s(���e�Zd�ZdZdd��Zdd��Zdd��ZdS�) �IndentszChange future indents.c�������������C���s ���||�_�d�S�)N)r���)r���r���r���r���r ���r ���g��s����zIndents.__init__c�������������C���sJ���|�j�}|j}tddd|��d�d|��d�d�|jd�rF|�|_d |_d S�)NzToggle tabsz Turn tabs )ZonZoffz? Indent width )zwill bez remains atz 8.z! Note: a tab is always 8 columns)rq�������r���)r����usetabsr���r���ra���)r���r%���r���rw���r���r���r ����toggle_tabs_eventj��s���� zIndents.toggle_tabs_eventc�������������C���s<���|�j�}tdd|j|jddd�}|r8||jkr8|js8||_dS�)NzIndent widthz6New indent width (2-16) (Always use 8 when using tabs)r=���rp���)rq���rr���rs���rt���r���)r���r���r���ra���rw���)r���r%���r���rJ���r���r���r ����change_indentwidth_eventz��s����z Indents.change_indentwidth_eventN)r-���r.���r/���r0���r ���rx���ry���r���r���r���r ���ru���d��s���ru���c���������������@���s���e�Zd�Zdd��Zddd�ZdS�)�Rstripc�������������C���s ���||�_�d�S�)N)r���)r���r���r���r���r ���r ������s����zRstrip.__init__Nc������� ������C���s����|�j�j}|�j�j}|����tt|�d���}xZtd|�D�]L}|�d|�d|��}t |�}t |� ���}||k�r6|�d||f�d|���q6W�|�d�dkr�t|�j�d�s�x*|�d �d kr�|�d�dkr�|�d��q�W�|� ���d�S�)Nr���r4���z%i.0z%i.endz%i.%izend-2cr<���Zinterpzend-1cz1.0zend-3c)r���r����undor"���r����floatr���rA���r���r8���rD���r#����hasattrr$���) r���r%���r���r{���Zend_lineZcurZtxtrd���Zcutr���r���r ���� do_rstrip���s ����zRstrip.do_rstrip)N)r-���r.���r/���r ���r~���r���r���r���r ���rz������s���rz����__main__)�mainzidlelib.idle_test.test_formatr=���F)� verbosity�exit)r0���r@���Ztkinter.messageboxr���Ztkinter.simpledialogr���Zidlelib.configr���r���r���r���r���r���r7���r?���r����compilerW���rY���rZ���ru���rz���r-���Zunittestr����r���r���r���r ����<module>���s*���C%$ �$