AlkantarClanX12

Your IP : 3.145.8.2


Current Path : /opt/alt/python35/lib64/python3.5/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/idlelib/__pycache__/FormatParagraph.cpython-35.opt-1.pyc



��Yfw�@s�dZddlZddlmZGdd�d�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
edkr�ddlZej
ddddd�dS)a�Extension to format a paragraph 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 :-)
�N)�idleConfc@sIeZdZddgfgZdd�Zdd�Zdd	d
�ZdS)�FormatParagraph�format�Format Paragraph�<<format-paragraph>>cCs
||_dS)N)�editwin)�selfr�r	�</opt/alt/python35/lib64/python3.5/idlelib/FormatParagraph.py�__init__szFormatParagraph.__init__cCs
d|_dS)N)r)rr	r	r
�close szFormatParagraph.closeNc	CsP|dkr-tjddddddd�}|jj}|jj�\}}|r{|r{|j||�}t|�}n$t||jd	��\}}}}|r�t	|||�}nt
||�}|jd
dd�||kr/|jd	|�|j
�|j||�|j||�|j�n|jd	|�|jd	�d
S)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�
extensionsrz	max-width�type�int�default�H�insertZselz1.0�end�break)rZ	GetOptionr�textZget_selection_indices�get�get_comment_header�find_paragraph�index�reformat_comment�reformat_paragraphZ
tag_removeZmark_setZundo_block_startZdeleterZundo_block_stopZsee)	rZevent�limitr�first�last�data�comment_header�newdatar	r	r
�format_paragraph_event#s.$


z&FormatParagraph.format_paragraph_event)rr)�__name__�
__module__�__qualname__Zmenudefsrrr"r	r	r	r
rs
rc
Cs�tt|jd��\}}|jd|d|�}xM|jd|dd�r�t|�r�|d}|jd|d|�}q;W|}t|�}t|�}xQt|�|kr�t||d��r�|d}|jd|d|�}q�Wd|}|d}|jd|d|�}x]|dkr�t|�|kr�t||d��r�|d}|jd|d|�}q+Wd|d}	|	|||j|	|�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_lenrrr	r	r
rMs,(




rcCs�|jd�}d}t|�}x*||krMt||�rM|d}q$W||kr^|St||�}|d|kr�t||d�r�t||d�}n|}|d|�}|}x�||kr�t||�r�tjd||�}	x�tdt|	�d�D]�}
|	|
}|s.qt||j��|kro||kro|j|j��|}||d}|
dt|	�kr|	|
ddkr|d}qW|d}q�W|j|j��|j	||d��dj
|�S)z3Return data reformatted to specified width (limit).�
rr(Nz(\s+)�� )r*r,r+�
get_indent�re�range�
expandtabs�append�rstrip�extend�join)rr�lines�i�nZindent1Zindent2�new�partialZwords�jZwordr	r	r
rrs<% 
*rcs�t���dj�fdd�|jd�D��}t|t��d�}t||�}|jd�}d}|d	s�d}|dd
�}dj�fdd�|D��|S)z?Return data reformatted to specified width with comment header.r0c3s|]}|�d�VqdS)Nr	)�.0r/)�lcr	r
�	<genexpr>�sz#reformat_comment.<locals>.<genexpr>��r(Nc3s|]}�|VqdS)Nr	)rAr/)r r	r
rC�s���rF)r,r:r*�maxr)rrr Zformat_widthr!Zblock_suffixr	)r rBr
r�s+
rcCstjd|�dk	S)z/Return True if line is empty or all whitespace.z^\s*$N)r4�match)r/r	r	r
r+�sr+cCstjd|�j�S)z/Return the initial space or tab indent of line.z	^([ \t]*))r4rH�group)r/r	r	r
r3�sr3cCs/tjd|�}|dkr"dS|jd�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]*#*)NrEr()r4rHrI)r/�mr	r	r
r�sr�__main__z&idlelib.idle_test.test_formatparagraph�	verbosityr1�exitF)�__doc__r4Zidlelib.configHandlerrrrrrr+r3rr#Zunittest�mainr	r	r	r
�<module>s8%$