%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python3.8/idlelib/__pycache__/
Upload File :
Create Path :
Current File : //usr/local/lib/python3.8/idlelib/__pycache__/format.cpython-38.pyc

U

qa=@sdZddlZddlmZddlmZddlmZGdddZe	dd	Z
d
dZdd
ZddZ
ddZddZedZddZGdddZGdddZGdddZedkrddlmZedd d!d"dS)#zFormat 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@s6eZdZdZddZeddZddZdd	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
||_dSNeditwinselfrr*/usr/local/lib/python3.8/idlelib/format.py__init__szFormatParagraph.__init__cCstjdddddd|_dS)N
extensionsrz	max-widthintH)typedefault)rZ	GetOption	max_width)clsrrrreload"s
zFormatParagraph.reloadcCs
d|_dSrrr
rrrclose'szFormatParagraph.closeNc	Cs|dkr|jn|}|jj}|j\}}|rF|rF|||}t|}nt||d\}}}}|rpt|||}n
t	||}|
ddd||kr|d|||
||||||n|d||ddS)aFormats 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.
        Ninsertsel1.0endbreak)rrtextget_selection_indicesgetget_comment_headerfind_paragraphindexreformat_commentreformat_paragraph
tag_removemark_setundo_block_startdeleterundo_block_stopZsee)	r
eventlimitrfirstlastdatacomment_headernewdatarrrformat_paragraph_event*s*




z&FormatParagraph.format_paragraph_event)N)	__name__
__module____qualname____doc__r
classmethodrrr1rrrrrs
rc
Cs:tt|d\}}|d|d|}|d|ddr`t|r`|d}|d|d|}q(|}t|}t|}t||krt||ds|d}|d|d|}qtd|}|d}|d|d|}|dkrt||krt||ds|d}|d|d|}qd|d}	|	||||	|fS)	zReturns 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<rNr)maprsplitrZcompareis_all_whiter len)
rZmarklinenocollineZfirst_linenor/Zcomment_header_lenr-r,rrrr!Ss2

r!cCst|d}d}t|}||kr4t||r4|d}q||kr@|St||}|d|krzt||dszt||d}n|}|d|}|}||krJt||sJtd||}	tdt|	dD]x}
|	|
}|sqt|||kr
||kr
|||}||d}|
dt|	kr|	|
ddkr|d}q|d}q|||	||dd
|S)z3Return data reformatted to specified width (limit).
rr9Nz(\s+) )r;r=r<
get_indentrerange
expandtabsappendrstripextendjoin)r.r+linesinZindent1Zindent2newpartialZwordsjZwordrrrr$xs>

 

r$cstdfdd|dD}t|td}t||}|d}d}|dshd}|dd}dfdd|D|S)	z?Return data reformatted to specified width with comment header.rAc3s|]}|dVqdSrr.0r@)lcrr	<genexpr>sz#reformat_comment.<locals>.<genexpr>Nc3s|]}|VqdSrrrR)r/rrrUs)r=rKr;maxr$)r.r+r/Zformat_widthr0Zblock_suffixr)r/rTrr#s

r#cCstd|dk	S)z/Return True if line is empty or all whitespace.z^\s*$N)rEmatchr@rrrr<sr<cCstd|S)z/Return the initial space or tab indent of line.z	^([ \t]*)rErZgroupr[rrrrDsrDcCs"td|}|dkrdS|dS)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]*#*)NrWr9r\)r@mrrrr sr z[ \t]*cCs$t|}|t||fS)zReturn 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_rerZrr=r]rG)r@tabwidthr^rrrget_line_indents
rac@sleZdZdZddZddZddZdd	d
ZdddZdd
dZ	dddZ
dddZdddZddZ
dS)FormatRegionzFormat selected text (region).cCs
||_dSrrr	rrr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 +1crA)rrrr"rr;)r
rr,r-headtailcharsrLrrr
get_regions



zFormatRegion.get_regioncCsz|jj}d|}||kr&|dS|ddd|d|||||||||	|
d|ddS)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.
        rANrrrr)rrrKZbellr%r&r'r(rr)Ztag_add)r
rcrdrerLrnewcharsrrr
set_regions
zFormatRegion.set_regionNc
Cs||\}}}}tt|D]J}||}|rt||jj\}}	|	|jj}	|j|	||d||<q|||||dS)z$Indent region by indentwidth spaces.Nr)	rfrFr=rarr`indentwidth_make_blanksrh
r
r*rcrdrerLposr@raw	effectiverrrindent_region_eventsz FormatRegion.indent_region_eventc
Cs|\}}}}tt|D]P}||}|rt||jj\}}	t|	|jjd}	|j|	||d||<q|	||||dS)z$Dedent region by indentwidth spaces.rNr)
rfrFr=rarr`rYrirjrhrkrrrdedent_region_eventsz FormatRegion.dedent_region_eventcCsN|\}}}}tt|dD]}||}d|||<q |||||dS)zrComment out each line in region.

        ## is appended to the beginning of each line to comment it out.
        r9##rrfrFr=rhr
r*rcrdrerLrlr@rrrcomment_region_event sz!FormatRegion.comment_region_eventcCs|\}}}}tt|D]T}||}|s.q|dddkrL|dd}n|dddkrh|dd}|||<q|||||dS)zUncomment 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.
        NrBrqr9#rrrrsrrruncomment_region_event,s
z#FormatRegion.uncomment_region_eventc
Cs|\}}}}|}|dkr$dStt|D]L}||}|r0t||\}	}
t|
|\}}d|d|||	d||<q0|||||dS)z@Convert leading spaces to tabs for each line in selected region.N	rCr)rf_asktabwidthrFr=radivmodrh)
r
r*rcrdrerLr`rlr@rmrnZntabsZnspacesrrrtabify_region_event?s"z FormatRegion.tabify_region_eventcCs\|\}}}}|}|dkr$dStt|D]}|||||<q0|||||dS)z.Expand tabs to spaces for each line in region.Nr)rfrxrFr=rGrh)r
r*rcrdrerLr`rlrrruntabify_region_eventNsz"FormatRegion.untabify_region_eventcCstdd|jj|jjdddS)zReturn value for tab width.z	Tab widthzColumns per tab? (2-16)rBparentZinitialvalueZminvaluemaxvalue)rrrrirrrrrxYszFormatRegion._asktabwidth)N)N)N)N)N)N)r2r3r4r5r
rfrhrorprtrvrzr{rxrrrrrbs





rbc@s(eZdZdZddZddZddZdS)	IndentszChange future indents.cCs
||_dSrrr	rrrr
gszIndents.__init__cCsJ|j}|j}tddd|dd|dd|jdrF||_d	|_d
S)NzToggle tabsz
Turn tabs )ZonZoffz?
Indent width )zwill bez
remains atz 8.z!
 Note: a tab is always 8 columns)r~r)rusetabsrrri)r
r*rrrrr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)rBr|r}r)rrrrir)r
r*rrOrrrchange_indentwidth_eventzsz Indents.change_indentwidth_eventN)r2r3r4r5r
rrrrrrrdsrc@seZdZddZdddZdS)RstripcCs
||_dSrrr	rrrr
szRstrip.__init__Nc	Cs|jj}|jj}|tt|d}td|D]L}|d|d|}t	|}t	|
}||kr4|d||fd|q4|ddkrt|jds|d	d
kr|ddkr|dq|
dS)Nrr9z%i.0z%i.endz%i.%izend-2crAZinterpzend-1crzend-3c)rrundor'rfloatr"rFrr=rIr(hasattrr))	r
r*rrZend_lineZcurZtxtrmZcutrrr	do_rstrips$
zRstrip.do_rstrip)N)r2r3r4r
rrrrrrsr__main__)mainzidlelib.idle_test.test_formatrBF)	verbosityexit)r5rEZtkinter.messageboxrZtkinter.simpledialogrZidlelib.configrrrr!r$r#r<rDr compiler_rarbrrr2Zunittestrrrrr<module>s*C%$

$ 

Zerion Mini Shell 1.0