python (3.11.7)

(root)/
lib/
python3.11/
idlelib/
__pycache__/
format.cpython-311.pyc

e=HdZddlZddlmZddlmZddlmZGddZe	dZ
d	Zd
ZdZ
dZd
ZejdZdZGddZGddZGddZedkrddlmZeddddSdS)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<eZdZdZdZedZdZddZdS)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 :-)
    c||_dSNeditwinselfrs  B/BuggyBox/python/3.11.7/bootstrap/lib/python3.11/idlelib/format.py__init__zFormatParagraph.__init__
cBtjddddd|_dS)N
extensionsrz	max-widthintH)typedefault)r	GetOption	max_width)clss rreloadzFormatParagraph.reload"s. *<9J+6UBPPP


rcd|_dSr	r
r
s rclosezFormatParagraph.close's
rNc||jn|}|jj}|j\}}|r(|r&|||}t|}n(t
||d\}}}}|rt|||}nt||}|
ddd||krk|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_startdeleter undo_block_stopsee)	r
eventlimitr%firstlastdatacomment_headernewdatas	         rformat_paragraph_eventz&FormatParagraph.format_paragraph_event*sd#(-U| l88::t	?T	?88E4((D/55NN#4H)=)=>>
.E4	6&tUNCCGG(u55Gue,,,d??MM(E***!!###KKt$$$KKw'''  """"MM(D)))wrr	)	__name__
__module____qualname____doc__rclassmethodrrr:rrrrsn PP[P$$$$$$rrc2tt|d\}}|d|zd|z}|d|zddrYt|rJ|dz}|d|zd|z}|d|zddrt|J|}t
|}t|}t
||krbt||dsK|dz}|d|zd|z}t
||krt||dKd|z}|dz
}|d|zd|z}|dkr{t
||krht||dsQ|dz
}|d|zd|z}|dkr*t
||krt||dQd|dzz}	|	||||	|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<r#Nr)maprsplitr'compareis_all_whiter(len)
r%marklinenocollinefirst_linenor8comment_header_lenr6r5s
          rr)r)Ss\c4::c??++KFC88FVOX%677D,,vU
3
3<T8J8J<!xxF):;;,,vU
3
3<T8J8J<L'--N^,,T
"
"N
2
2t$6$7$78993!xxF):;;T
"
"N
2
2t$6$7$78993F?DA
F88FVOX%677D
1** &&66t$6$7$78997!xxF):;;	1** &&66t$6$7$78997
fQhE$(=(===rcX|d}d}t|}||kr5t||r |dz}||krt|| ||kr|St||}|dz|kr1t||dzst||dz}n|}|d|}|}||krt||st	jd||}	tdt|	dD]}
|	|
}|s
t||z|kr/||kr)|||}||zdz}|
dzt|	kr|	|
dzdkr|dz}|dz}||krt|||||	||dd
|S)z3Return data reformatted to specified width (limit).
rrDNz(\s+) )rFrIrH
get_indentrerange
expandtabsappendrstripextendjoin)r7r4linesinindent1indent2newpartialwordsjwords            rr,r,xs+JJtE	AE

A
a%%Lq**%
aCa%%Lq**%Avvq""GsQww|E!A#J//wU1Q3Z((
)CG
a%%U1X..%58,,q#e**a((
	(
	(A8D
GdN..0011E99g%%

7>>++,,,!ns*GsSZZE!A#J#$5$5!C-
aCa%%U1X..%JJw~~   JJuQRRy99S>>rctdfd|dD}t|tz
d}t	||}|d}d}|dsd}|dd}dfd|D|zS)z?Return data reformatted to specified width with comment header.rQc3,K|]}|dVdSr	r@).0rMlcs  r	<genexpr>z#reformat_comment.<locals>.<genexpr>s+<<4T"##Y<<<<<<rNc3"K|]	}|zV
dSr	r@)rhrMr8s  rrjz#reformat_comment.<locals>.<genexpr>s(==T^D(======r)rIr[rFmaxr,)r7r4r8format_widthr9block_suffixris  `   @rr+r+s

^		B99<<<<4::d+;+;<<<<<Dus>222B77L |44GmmD!!G
L2;#2#,99====W=====LLrc0tjd|duS)z/Return True if line is empty or all whitespace.z^\s*$N)rUmatchrMs rrHrHs8Hd##4//rcPtjd|S)z/Return the initial space or tab indent of line.z	^([ \t]*)rUrsgrouprts rrTrTs 
8L$''--///rc^tjd|}|dS|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]*#*)NrlrDrv)rMms  rr(r(s.	&&Ay771::rz[ \t]*ct|}|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_rersr#rIrwrW)rMtabwidthrys   rget_line_indentr}sH	d##A5577C		,,X667777rcZeZdZdZdZdZdZd
dZd
dZd
dZ	d
d	Z
d
d
Zd
dZdZ
dS)FormatRegionzFormat selected text (region).c||_dSr	r
rs  rrzFormatRegion.__init__rrcr|jj}|j\}}|r3|r1||dz}||dz}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 +1crQ)rr%r&r*r'rF)r
r%r5r6headtailcharsr\s        r
get_regionzFormatRegion.get_regions| l88::t	4T	4::el233D::d%6677DD::011D::233Dt$$D!!T5%''rc|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.
        rQNr!r"r#r )rr%r[bellr-r.r/r0r r1tag_add)r
rrrr\r%newcharss       r
set_regionzFormatRegion.set_regions| 99U##uIIKKKFue,,,

h%%%D$D(###UD(+++++rNcb|\}}}}tt|D]`}||}|rTt||jj\}}	|	|jjz}	|j|	||dz||<a|||||dS)z$Indent region by indentwidth spaces.Nr$)	rrVrIr}rr|indentwidth_make_blanksr
r
r3rrrr\posrMraw	effectives
          rindent_region_eventz FormatRegion.indent_region_events#'??#4#4 dE5U$$	O	OC:D
O!0t|7L!M!MY%(@@	!\66yAADJNc
dE5111wrc~|\}}}}tt|D]n}||}|rbt||jj\}}	t
|	|jjz
d}	|j|	||dz||<o|	||||dS)z$Dedent region by indentwidth spaces.rNr$)
rrVrIr}rr|rorrrrs
          rdedent_region_eventz FormatRegion.dedent_region_events#'??#4#4 dE5U$$	O	OC:D
O!0t|7L!M!MY	DL,D DaHH	!\66yAADJNc
dE5111wrc|\}}}}tt|dz
D]}||}d|z||<|||||dS)zrComment out each line in region.

        ## is appended to the beginning of each line to comment it out.
        rD##r$rrVrIrr
r3rrrr\rrMs        rcomment_region_eventz!FormatRegion.comment_region_event sr
$(??#4#4 dE5Ua((	%	%C:DE#JJdE5111wrc(|\}}}}tt|D]C}||}|s
|dddkr|dd}n|dddkr
|dd}|||<D|||||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.
        NrRrrD#r$rrs        runcomment_region_eventz#FormatRegion.uncomment_region_event,s$(??#4#4 dE5U$$		C:D
BQBx4ABBxbqbSABBxE#JJdE5111wrch|\}}}}|}|dStt|D]K}||}|r?t	||\}	}
t|
|\}}d|zd|zz||	dz||<L|||||dS)z@Convert leading spaces to tabs for each line in selected region.N	rSr$)r_asktabwidthrVrIr}divmodr)
r
r3rrrr\r|rrMrrntabsnspacess
             rtabify_region_eventz FormatRegion.tabify_region_event?s#'??#4#4 dE5$$&&FU$$	G	GC:D
G!0x!@!@Y!'	8!<!<w!E\C'M9DJFc
dE5111wrc|\}}}}|}|dStt|D] }|||||<!|||||dS)z.Expand tabs to spaces for each line in region.Nr$)rrrVrIrWr)r
r3rrrr\r|rs        runtabify_region_eventz"FormatRegion.untabify_region_eventNs#'??#4#4 dE5$$&&FU$$	9	9Cs..x88E#JJdE5111wrcTtdd|jj|jjddS)zReturn value for tab width.z	Tab widthzColumns per tab? (2-16)rRparentinitialvalueminvaluemaxvalue)rrr%rrs rrzFormatRegion._asktabwidthYs5%<$1
	rr	)r;r<r=r>rrrrrrrrrrr@rrrrs$$(((,,,,0











&



				rrc$eZdZdZdZdZdZdS)IndentszChange future indents.c||_dSr	r
rs  rrzIndents.__init__grrc|j}|j}tddd|zdzd|zdzdz|jr||_d	|_d
S)NzToggle tabsz
Turn tabs )onoffz?
Indent width )zwill bez
remains atz 8.z!
 Note: a tab is always 8 columns)rr$)rusetabsrr%r)r
r3rrs    rtoggle_tabs_eventzIndents.toggle_tabs_eventjs,/]733 !'0138933\
###
	$#*kGO#$Gwrc|j}tdd|j|jdd}|r||jkr|js||_dS)NzIndent widthz6New indent width (2-16)
(Always use 8 when using tabs)rRrrr$)rrr%rr)r
r3rras    rchange_indentwidth_eventz Indents.change_indentwidth_eventzs_, K &2
	&3'---go-"%GwrN)r;r<r=r>rrrr@rrrrdsG rrceZdZdZddZdS)Rstripc||_dSr	r
rs  rrzRstrip.__init__rrNc8|jj}|jj}|t	t|d}td|D]r}|d|zd|z}t|}t|
}||kr|d||fzd|zs|ddkrt|jdsy|d	d
kr`|ddkrG|d|d	d
kr|ddkG|
dS)Nr#rDz%i.0z%i.endz%i.%izend-2crQinterpzend-1cr"zend-3c)rr%undor/rfloatr*rVr'rIrYr0hasattrr1)	r
r3r%rend_linecurtxtrcuts	         r	do_rstripzRstrip.do_rstrips| | uTZZ..//00H%%	B	BC((6C<C88Cc((Ccjjll##CSyyGsCj0(S.AAAHHX$&&DL(33
'::h''%//xx))T11H%%%::h''%//xx))T11	
rr	)r;r<r=rrr@rrrrs7rr__main__)mainzidlelib.idle_test.test_formatrRF)	verbosityexit)r>rUtkinter.messageboxrtkinter.simpledialogridlelib.configrrrr)r,r+rHrTr(compiler{r}rrrr;unittestrr@rr<module>rs
			''''''++++++######@@@@@@@@F">">">J"""HMMM,000
000			"*Y''888MMMMMMMM`!!!!!!!!H@zD	(AEBBBBBBr