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

Nj2@sddlZddlZddlZddlZddlmZddlmZdZddZ	ddZ
ee
ejZ
ed	ejZd
dZGdd
d
eZddZedkrddlmZeddddddlmZeedS)N)idleConf)	DelegatorFcCsd|d|dS)z9Return a named group pattern matching list of alternates.z(?P<%s>|))join)nameZ
alternatesr6/opt/alt/python37/lib64/python3.7/idlelib/colorizer.pyanysr
c
Csdtdtjd}ddttD}dtd|d}tddg}d	}|d
}|d}|d}|d
}td||||g}	|d|d|d|	dtddgS)Nz\bKEYWORDcSs(g|] }|ds|tjkrt|qS)_)
startswithkeywordkwliststr).0rrrr	
<listcomp>s
zmake_pat.<locals>.<listcomp>z([^.'\"\\#]\b|^)BUILTINCOMMENTz#[^\n]*z(?i:r|u|f|fr|rf|b|br|rb)?z'[^'\\\n]*(\\.[^'\\\n]*)*'?z"[^"\\\n]*(\\.[^"\\\n]*)*"?z''''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?z'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?STRINGrSYNCz\n)r
rrdirbuiltins)
kwZbuiltinlistbuiltincommentZstringprefixZsqstringZdqstringZ	sq3stringZ	dq3stringstringrrr	make_patsrz\s+(\w+)cCs^t}t|d}t|dd}t|d}|j|d|d||d|d|dddS)zcSet color options of Text widget.

    If ColorDelegator is used, this should be called first.
    ZnormalZcursor
foregroundZhilite
background)rrZinsertbackgroundZselectforegroundZselectbackgroundZinactiveselectbackgroundN)rCurrentThemeGetHighlightZconfig)textthemeZ
normal_colorsZcursor_colorZ
select_colorsrrr	color_config"sr$c@seZdZdZddZddZddZdd	Zd
dZdd
dZ	dddZ
dddZddZd ddZ
ddZddZddZdS)!ColorDelegatora-Delegator for syntax highlighting (text coloring).

    Instance variables:
        delegate: Delegator below this one in the stack, meaning the
                one this one delegates to.

        Used to track state:
        after_id: Identifier for scheduled after event, which is a
                timer for colorizing the text.
        allow_colorizing: Boolean toggle for applying colorizing.
        colorizing: Boolean flag when colorizing is in process.
        stop_colorizing: Boolean flag to end an active colorizing
                process.
    cCs*t||t|_t|_|dS)N)r__init__
init_stateprogidprogLoadTagDefs)selfrrr	r&Gs

zColorDelegator.__init__cCsd|_d|_d|_d|_dS)z1Initialize variables that track colorizing state.NTF)after_idallow_colorizingstop_colorizing
colorizing)r+rrr	r'NszColorDelegator.init_statecCs\|jdk	r|dt|||dk	rL||d|j|ddnd|_d|_	dS)aSet the delegate for this instance.

        A delegate is an instance of a Delegator class and each
        delegate points to the next delegator in the stack.  This
        allows multiple delegators to be chained together for a
        widget.  The bottom delegate for a colorizer is a Text
        widget.

        If there is a delegate, also start the colorizing process.
        Nz<<toggle-auto-coloring>>z1.0endTF)
delegateZunbindrsetdelegate
config_colorsZbindtoggle_colorize_eventnotify_ranger.r-)r+r1rrr	r2Us

zColorDelegator.setdelegatecCs4x$|jD]\}}|j|f|qW|ddS)z4Configure text widget tags with colors from tagdefs.ZselN)tagdefsitemsZ
tag_configureZ	tag_raise)r+tagZcnfrrr	r3lszColorDelegator.config_colorscCszt}t|dt|dt|dt|dt|dddddddt|dt|d	d
	|_trvtd|jdS)z.Create dictionary of tag names to text colors.rrrrZ
definitionN)rrerrorhit)	rrrr
DEFINITIONrTODOZERRORr:r6)rr r!r6DEBUGprint)r+r#rrr	r*rs





zColorDelegator.LoadTagDefsNcCs6||}|j||||||dt|dS)z:Insert chars into widget at index and mark for colorizing.z+%dcN)indexr1insertr5len)r+r?charsZtagsrrr	r@s
zColorDelegator.insertcCs&||}|j||||dS)z5Delete chars between indexes and mark for colorizing.N)r?r1deleter5)r+index1index2rrr	rCs
zColorDelegator.deletecCsb|d|||jr$tr tddS|jr<d|_tr<td|jr^trNtd|d|j|_dS)zCMark text changes for processing and restart colorizing, if active.r<zcolorizing already scheduledNTzstop colorizingzschedule colorizing)	tag_addr,r=r>r/r.r-after
recolorize)r+rDrErrr	r5szColorDelegator.notify_rangecCs8|jr(|j}d|_trtd||d|_d|_dS)Nzcancel scheduled recolorizerFT)r,r=r>after_cancelr-r.)r+r,rrr	closes
zColorDelegator.closecCs|jr(|j}d|_trtd|||jrF|jrFtr@tdd|_|j|_|jrl|jsl|d|j|_trtd|jr~dpdd	S)
zToggle colorizing on and off.

        When toggling off, if colorizing is scheduled or is in
        process, it will be cancelled and/or stopped.

        When toggling on, colorizing will be scheduled.
        Nzcancel scheduled recolorizerzstop colorizingTrFzauto colorizing turnedZonZoffbreak)	r,r=r>rJr-r/r.rHrI)r+Zeventr,rrr	r4s"

z$ColorDelegator.toggle_colorize_eventcCsd|_|jstrtddS|js2tr.tddS|jrHtrDtddSzHd|_d|_trbtdt}|	t}trtd||Wdd|_X|jr|
d	d
rtrtd|d|j|_dS)
aSTimer event (every 1ms) to colorize text.

        Colorizing is only attempted when the text widget exists,
        when colorizing is toggled on, and when the colorizing
        process is not already running.

        After colorizing is complete, some cleanup is done to
        make sure that all the text has been colorized.
        Nzno delegatezauto colorizing is offzalready colorizingFTz
colorizing...z%.3f secondsr<z1.0zreschedule colorizingrF)
r,r1r=r>r-r/r.timeZperf_counterrecolorize_main
tag_nextrangerHrI)r+Zt0Zt1rrr	rIs8
zColorDelegator.recolorizecCsd}x|d|}|sP|\}}|d|||d|}|rJ|d}nd}d}|}d}d}x|s|}||d|}t|dd	}d||d
k}|||}	|	sdSx|jD]}
||
||qW||	}|j	|}x|rx|
D]~\}}
|
r||\}}|
||d||d||
d
kr|j||}|r|d\}}|
d|d||d|qW|j	||}qWd||d
kr|}d}nd}|s|
d|||jrbtrtddSqbWqWdS)z(Evaluate text and apply colorizing tags.z1.0r<rrFFz+%d lines linestartdz-1cNz+%dc)defclassr;zcolorizing stopped)rO
tag_removeZ
tag_prevranger?minZ	tag_namesgetr6r(search	groupdictr7spanrGr)matchr0updater.r=r>)r+nextitemheadtailrBZlines_to_getokZmarkliner8mkeyvalueabZm1rrr	rNsl




zColorDelegator.recolorize_maincCs"x|jD]}||ddqWdS)zRemove all colorizing tags.z1.0r0N)r6rU)r+r8rrr	removecolors#szColorDelegator.removecolors)N)N)N)N)__name__
__module____qualname____doc__r&r'r2r3r*r@rCr5rKr4rIrNrhrrrr	r%7s


	
"Br%cCsddlm}m}ddlm}||}|dtt|	ddd\}}|d|d|d	fd
}||dd}|j
dd
d|d||t
|||}	t}
|	|
dS)Nr)ToplevelText)
PercolatorzTest ColorDelegator+rFz
700x250+%d+%dabif True: int ('1') # keyword, builtin, string, comment
elif False: print(0)
else: float(None)
if iF + If + IF: 'keyword matching must respect case'
if'': x or''  # valid string-keyword no-space combinations
async def f(): await g()
# All valid prefixes for unicode and byte strings should be colored.
'x', '''x''', "x", """x"""
r'x', u'x', R'x', U'x', f'x', F'x'
fr'x', Fr'x', fR'x', FR'x', rf'x', rF'x', Rf'x', RF'x'
b'x',B'x', br'x',Br'x',bR'x',BR'x', rb'x', rB'x',Rb'x',RB'x'
# Invalid combinations of legal characters should be half colored.
ur'x', ru'x', uf'x', fu'x', UR'x', ufr'x', rfu'x', xf'x', fx'x'
Zwhite)rZboth)expandZfillr@)ZtkinterrmrnZidlelib.percolatorrotitlemapintZgeometrysplitZpackr@Z	focus_setr$r%Zinsertfilter)parentrmrnrotopxysourcer"pdrrr	_color_delegator)s
 r__main__)mainz idlelib.idle_test.test_colorizerrQ)	verbosityexit)run)rrrerMZidlelib.configrZidlelib.delegatorrr=r
rcompileSr(r)r$r%rriZunittestrZidlelib.idle_test.htestrrrrr	<module>s&s"