ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python37/lib64/python3.7/idlelib/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib64/python3.7/idlelib/__pycache__/format.cpython-37.pyc

B

� f�=�@s�dZddlZddlmZddlmZddlmZGdd�d�Ze�	�dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Ze�d�Zdd�ZGdd�d�ZGdd�d�ZGdd�d�Zedkr�ddlmZedd 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@s6eZdZdZdd�Zedd��Zdd�Zdd	d
�ZdS)�FormatParagraphaFormat 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 :-)
    cCs
||_dS)N)�editwin)�selfr�r�3/opt/alt/python37/lib64/python3.7/idlelib/format.py�__init__szFormatParagraph.__init__cCstjdddddd�|_dS)N�
extensionsrz	max-width�int�H)�type�default)rZ	GetOption�	max_width)�clsrrr	�reload"szFormatParagraph.reloadcCs
d|_dS)N)r)rrrr	�close'szFormatParagraph.closeNc	Cs�|dkr|jn|}|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)rr�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�newdatarrr	�format_paragraph_event*s(



z&FormatParagraph.format_paragraph_event)N)	�__name__�
__module__�__qualname__�__doc__r
�classmethodrrr,rrrr	rs
rc
CsFtt|�d��\}}|�d|d|�}x:|�d|dd�rbt|�rb|d}|�d|d|�}q*W|}t|�}t|�}x<t|�|kr�t||d��s�|d}|�d|d|�}qzWd|}|d}|�d|d|�}xJ|dk�r$t|�|k�r$t||d���s$|d}|�d|d|�}q�Wd|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�splitrZcompare�is_all_whiter�len)
rZmark�lineno�col�lineZfirst_linenor*Zcomment_header_lenr(r'rrr	rSs,rcCs�|�d�}d}t|�}x ||kr6t||�r6|d}qW||krD|St||�}|d|kr~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}|
dt|	�kr�|	|
ddkr�|d}q�W|d}q�W|�|���|�	||d��d�
|�S)z3Return data reformatted to specified width (limit).�
rr4Nz(\s+)�� )r6r8r7�
get_indent�re�range�
expandtabs�append�rstrip�extend�join)r)r&�lines�i�nZindent1Zindent2�new�partialZwords�jZwordrrr	rxs<

 rcs�t���d��fdd�|�d�D��}t|t��d�}t||�}|�d�}d}|dshd}|dd�}d��fdd�|D��|S)	z?Return data reformatted to specified width with comment header.r<c3s|]}|�d�VqdS)Nr)�.0r;)�lcrr	�	<genexpr>�sz#reformat_comment.<locals>.<genexpr>�����Nc3s|]}�|VqdS)Nr)rMr;)r*rr	rO�s)r8rFr6�maxr)r)r&r*Zformat_widthr+Zblock_suffixr)r*rNr	r�s

rcCst�d|�dk	S)z/Return True if line is empty or all whitespace.z^\s*$N)r@�match)r;rrr	r7�sr7cCst�d|���S)z/Return the initial space or tab indent of line.z	^([ \t]*))r@rT�group)r;rrr	r?�sr?cCs"t�d|�}|dkrdS|�d�S)aReturn 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]*#*)NrQr4)r@rTrU)r;�mrrr	r�srz[ \t]*cCs$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_rerTrr8rUrB)r;�tabwidthrVrrr	�get_line_indent�s
rYc@sleZdZdZdd�Zdd�Zdd�Zdd	d
�Zddd�Zdd
d�Z	ddd�Z
ddd�Zddd�Zdd�Z
dS)�FormatRegionzFormat selected text (region).cCs
||_dS)N)r)rrrrr	r
�szFormatRegion.__init__cCsr|jj}|j��\}}|r<|r<|�|d�}|�|d�}n|�d�}|�d�}|�||�}|�d�}||||fS)aqReturn 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<)rrrrrr6)rrr'r(�head�tail�charsrGrrr	�
get_region�s



zFormatRegion.get_regioncCsz|jj}d�|�}||kr&|��dS|�ddd�|�d|�|��|�||�|�||�|�	�|�
d|d�dS)aaReplace 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<Nrz1.0rr)rrrFZbellr r!r"r#rr$Ztag_add)rr[r\r]rGr�newcharsrrr	�
set_region�s
zFormatRegion.set_regionNc
Cs�|��\}}}}xZtt|��D]J}||}|rt||jj�\}}	|	|jj}	|j�|	�||d�||<qW|�||||�dS)z$Indent region by indentwidth spaces.Nr)	r^rAr8rYrrX�indentwidth�_make_blanksr`)
rr%r[r\r]rG�posr;�raw�	effectiverrr	�indent_region_events z FormatRegion.indent_region_eventc
Cs�|��\}}}}x`tt|��D]P}||}|rt||jj�\}}	t|	|jjd�}	|j�|	�||d�||<qW|�	||||�dS)z$Dedent region by indentwidth spaces.rNr)
r^rAr8rYrrXrSrarbr`)
rr%r[r\r]rGrcr;rdrerrr	�dedent_region_events z FormatRegion.dedent_region_eventcCsR|��\}}}}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.
        r4z##r)r^rAr8r`)rr%r[r\r]rGrcr;rrr	�comment_region_event sz!FormatRegion.comment_region_eventcCs�|��\}}}}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^rAr8r`)rr%r[r\r]rGrcr;rrr	�uncomment_region_event,sz#FormatRegion.uncomment_region_eventc
Cs�|��\}}}}|��}|dkr$dSx\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^�_asktabwidthrAr8rY�divmodr`)
rr%r[r\r]rGrXrcr;rdreZntabsZnspacesrrr	�tabify_region_event?s$z FormatRegion.tabify_region_eventcCs`|��\}}}}|��}|dkr$dSx&tt|��D]}||�|�||<q2W|�||||�dS)z.Expand tabs to spaces for each line in region.Nr)r^rlrAr8rBr`)rr%r[r\r]rGrXrcrrr	�untabify_region_eventNsz"FormatRegion.untabify_region_eventcCstdd|jj|jjddd�S)zReturn value for tab width.z	Tab widthzColumns per tab? (2-16)r=�)�parent�initialvalue�minvalue�maxvalue)rrrra)rrrr	rlYszFormatRegion._asktabwidth)N)N)N)N)N)N)r-r.r/r0r
r^r`rfrgrhrjrnrorlrrrr	rZ�s





rZc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�IndentszChange future indents.cCs
||_dS)N)r)rrrrr	r
gszIndents.__init__cCsJ|j}|j}tddd|dd|dd|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�usetabsrrra)rr%rrwrrr	�toggle_tabs_eventjs
zIndents.toggle_tabs_eventcCs<|j}tdd|j|jddd�}|r8||jkr8|js8||_dS)NzIndent widthz6New indent width (2-16)
(Always use 8 when using tabs)r=rp)rqrrrsrtr)rrrrarw)rr%rrJrrr	�change_indentwidth_eventzsz Indents.change_indentwidth_eventN)r-r.r/r0r
rxryrrrr	rudsruc@seZdZdd�Zddd�ZdS)�RstripcCs
||_dS)N)r)rrrrr	r
�szRstrip.__init__Nc	Cs�|jj}|jj}|��tt|�d���}xZtd|�D]L}|�d|d|�}t	|�}t	|�
��}||kr6|�d||fd|�q6W|�d�dkr�t|jd�s�x*|�d	�d
kr�|�d�dkr�|�d�q�W|�
�dS)Nrr4z%i.0z%i.endz%i.%izend-2cr<Zinterpzend-1cz1.0zend-3c)rr�undor"r�floatrrArr8rDr#�hasattrr$)	rr%rr{Zend_lineZcurZtxtrdZcutrrr	�	do_rstrip�s zRstrip.do_rstrip)N)r-r.r/r
r~rrrr	rz�srz�__main__)�mainzidlelib.idle_test.test_formatr=F)�	verbosity�exit)r0r@Ztkinter.messageboxrZtkinter.simpledialogrZidlelib.configrrrrrrr7r?r�compilerWrYrZrurzr-Zunittestr�rrrr	�<module>s*C%$

$ 

Zerion Mini Shell 1.0