• File: format.cpython-37.opt-1.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib64/python3.7/idlelib/__pycache__/format.cpython-37.opt-1.pyc
  • Date Modified: 10/26/2026 8:08 PM
  • File size: 13.13 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

Nj=@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
||_dS)N)editwin)selfrr3/opt/alt/python37/lib64/python3.7/idlelib/format.py__init__szFormatParagraph.__init__cCstjdddddd|_dS)N
extensionsrz	max-widthintH)typedefault)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||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.
        Ninsertselz1.0endbreak)rrtextget_selection_indicesgetget_comment_headerfind_paragraphindexreformat_commentreformat_paragraph
tag_removemark_setundo_block_startdeleterundo_block_stopZsee)	reventlimitrfirstlastdatacomment_headernewdatarrr	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|ddrbt|rb|d}|d|d|}q*W|}t|}t|}x<t||krt||ds|d}|d|d|}qzWd|}|d}|d|d|}xJ|dkr$t||kr$t||ds$|d}|d|d|}qWd|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)maprsplitrZcompareis_all_whiterlen)
rZmarklinenocollineZfirst_linenor*Zcomment_header_lenr(r'rrr	rSs,rcCs|d}d}t|}x ||kr6t||r6|d}qW||krD|St||}|d|kr~t||ds~t||d}n|}|d|}|}x||krTt||sTtd||}	xtdt|	dD]x}
|	|
}|sqt|||kr||kr|||}||d}|
dt|	kr|	|
ddkr|d}qW|d}qW|||	||dd
|S)z3Return data reformatted to specified width (limit).
rr4Nz(\s+) )r6r8r7
get_indentrerange
expandtabsappendrstripextendjoin)r)r&linesinZindent1Zindent2newpartialZwordsjZwordrrr	rxs<

 rcstdfdd|dD}t|td}t||}|d}d}|dshd}|dd}dfdd|D|S)	z?Return data reformatted to specified width with comment header.r<c3s|]}|dVqdS)Nr).0r;)lcrr		<genexpr>sz#reformat_comment.<locals>.<genexpr>Nc3s|]}|VqdS)Nr)rMr;)r*rr	rOs)r8rFr6maxr)r)r&r*Zformat_widthr+Zblock_suffixr)r*rNr	rs

rcCstd|dk	S)z/Return True if line is empty or all whitespace.z^\s*$N)r@match)r;rrr	r7sr7cCstd|S)z/Return the initial space or tab indent of line.z	^([ \t]*))r@rTgroup)r;rrr	r?sr?cCs"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]*#*)NrQr4)r@rTrU)r;mrrr	rsrz[ \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_rerTrr8rUrB)r;tabwidthrVrrr	get_line_indents
rYc@sleZdZdZddZddZddZdd	d
ZdddZdd
dZ	dddZ
dddZdddZddZ
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(headtailcharsrGrrr	
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.
        r<Nrz1.0rr)rrrFZbellr r!r"r#rr$Ztag_add)rr[r\r]rGrnewcharsrrr	
set_regions
zFormatRegion.set_regionNc
Cs|\}}}}xZtt|D]J}||}|rt||jj\}}	|	|jj}	|j|	||d||<qW|||||dS)z$Indent region by indentwidth spaces.Nr)	r^rAr8rYrrXindentwidth_make_blanksr`)
rr%r[r\r]rGposr;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|dD]}||}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|dddkrN|dd}n|dddkrj|dd}|||<qW|||||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.
        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^_asktabwidthrAr8rYdivmodr`)
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|jjdddS)zReturn value for tab width.z	Tab widthzColumns per tab? (2-16)r=)parentinitialvalueminvaluemaxvalue)rrrra)rrrr	rlYszFormatRegion._asktabwidth)N)N)N)N)N)N)r-r.r/r0r
r^r`rfrgrhrjrnrorlrrrr	rZs





rZc@s(eZdZdZddZddZddZdS)	IndentszChange future indents.cCs
||_dS)N)r)rrrrr	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)rqr)rusetabsrrra)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@seZdZddZdddZdS)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|ddkrt|jdsx*|d	d
kr|ddkr|dqW|
dS)Nrr4z%i.0z%i.endz%i.%izend-2cr<Zinterpzend-1cz1.0zend-3c)rrundor"rfloatrrArr8rDr#hasattrr$)	rr%rr{Zend_lineZcurZtxtrdZcutrrr		do_rstrips zRstrip.do_rstrip)N)r-r.r/r
r~rrrr	rzsrz__main__)mainzidlelib.idle_test.test_formatr=F)	verbosityexit)r0r@Ztkinter.messageboxrZtkinter.simpledialogrZidlelib.configrrrrrrr7r?rcompilerWrYrZrurzr-Zunittestrrrrr	<module>s*C%$

$