ok

Mini Shell

Direktori : /opt/alt/python27/lib64/python2.7/idlelib/
Upload File :
Current File : //opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyc

�
�[
bc@s�dZddlZddlmZddd��YZd�Zd�Zd�Zd	�Zd
�Z	d�Z
edkr�ddlZej
d
ddde�ndS(s�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 :-)
i����N(tidleConftFormatParagraphcBs8eZddgfgZd�Zd�Zdd�ZRS(tformatsFormat Paragraphs<<format-paragraph>>cCs
||_dS(N(teditwin(tselfR((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyt__init__scCs
d|_dS(N(tNoneR(R((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pytclose sc	CsS|d
kr0tjddddddd�}n|jj}|jj�\}}|r~|r~|j||�}t|�}n$t||j	d��\}}}}|r�t
|||�}nt||�}|jd	d
d�||kr2|j
d|�|j�|j||�|j||�|j�n|j
d|�|jd�dS(s�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.
        t
extensionsRs	max-widthttypetinttdefaultiHtinserttsels1.0tendtbreakN(RRt	GetOptionRttexttget_selection_indicestgettget_comment_headertfind_paragraphtindextreformat_commenttreformat_paragrapht
tag_removetmark_settundo_block_starttdeleteRtundo_block_stoptsee(	RteventtlimitRtfirsttlasttdatatcomment_headertnewdata((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pytformat_paragraph_event#s.$


(sFormat Paragraphs<<format-paragraph>>N(t__name__t
__module__tmenudefsRRRR&(((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyRs
		c
Cs�tt|jd��\}}|jd|d|�}xM|jd|dd�r�t|�r�|d}|jd|d|�}q;W|}t|�}t|�}xKt|�|kr�t||�r�|d}|jd|d|�}q�Wd|}|d}|jd|d|�}xW|dkr{t|�|kr{t||�r{|d}|jd|d|�}q%Wd|d}	|	|||j|	|�fS(s�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.
    t.s%d.0s%d.endt<Rii(tmapR
tsplitRtcomparetis_all_whiteRtlen(
Rtmarktlinenotcoltlinetfirst_linenoR$tcomment_header_lenR"R!((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyRMs,(




cCs�|jd�}d}t|�}x*||krMt||�rM|d}q$W||kr^|St||�}|d|kr�t||d�r�t||d�}n|}|| }|}x||kr�t||�r�tjd||�}	x�tdt|	�d�D]�}
|	|
}|s+qnt||j��|kro||kro|j|j��|}n||d}|
dt|	�kr|	|
ddkr|d}qqW|d}q�W|j|j��|j	||�dj
|�S(s3Return data reformatted to specified width (limit).s
iis(\s+)it (R-R0R/t
get_indenttretranget
expandtabstappendtrstriptextendtjoin(R#R tlinestitntindent1tindent2tnewtpartialtwordstjtword((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyRrs<%
 
	*cs�t���dj�fd�|jd�D��}t|t��d�}t||�}|jd�}d}|ds�d}|d }ndj�fd�|D��|S(s?Return data reformatted to specified width with comment header.s
c3s|]}|�VqdS(N((t.0R4(tlc(s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pys	<genexpr>�siti����c3s|]}�|VqdS(N((RJR4(R$(s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pys	<genexpr>�s(R0R?R-tmaxR(R#R R$tformat_widthR%tblock_suffix((R$RKs</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyR�s(

cCstjd|�dk	S(s/Return True if line is empty or all whitespace.s^\s*$N(R9tmatchR(R4((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyR/�scCstjd|�j�S(s/Return the initial space or tab indent of line.s	^([ \t]*)(R9RPtgroup(R4((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyR8�scCs/tjd|�}|dkr"dS|jd�S(sReturn 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.
    s^([ \t]*#*)RLiN(R9RPRRQ(R4tm((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyR�st__main__s&idlelib.idle_test.test_formatparagrapht	verbosityitexit((t__doc__R9tidlelib.configHandlerRRRRRR/R8RR'tunittesttmaintFalse(((s</opt/alt/python27/lib64/python2.7/idlelib/FormatParagraph.pyt<module>s8	%	$				

Zerion Mini Shell 1.0