HEX
Server: Apache
System: Linux sg2plmcpnl492417.prod.sin2.secureserver.net 4.18.0-553.58.1.lve.el8.x86_64 #1 SMP Fri Jul 4 12:07:06 UTC 2025 x86_64
User: nyiet8349bzl (9207396)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //proc/self/root/opt/python38/lib/python3.8/idlelib/__pycache__/colorizer.cpython-38.pyc
U

�i�_�2�@s�ddlZddlZddlZddlZddlmZddlmZdZdd�Z	dd�Z
e�e
�ej�Z
e�d	ej�Zd
d�ZGdd
�d
e�Zdd�Zedkr�ddlmZedddd�ddlmZee�dS)�N)�idleConf)�	DelegatorFcCsd|d�|�dS)z9Return a named group pattern matching list of alternates.z(?P<%s>�|�))�join)�nameZ
alternates�r�0/opt/python38/lib/python3.8/idlelib/colorizer.py�anysr
c
Cs�dtdtj�d}dd�tt�D�}dtd|�d}tddg�}d	}|d
}|d}|d}|d
}td||||g�}	|d|d|d|	dtddg�S)Nz\b�KEYWORDcSs(g|] }|�d�s|tjkrt|��qS)�_)�
startswith�keyword�kwlist�str)�.0rrrr	�
<listcomp>s

�zmake_pat.<locals>.<listcomp>z([^.'\"\\#]\b|^)�BUILTIN�COMMENTz#[^\n]*z(?i:r|u|f|fr|rf|b|br|rb)?z'[^'\\\n]*(\\.[^'\\\n]*)*'?z"[^"\\\n]*(\\.[^"\\\n]*)*"?z''''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?z'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?�STRINGr�SYNCz\n)r
rr�dir�builtins)
�kwZbuiltinlist�builtin�commentZstringprefixZsqstringZdqstringZ	sq3stringZ	dq3string�stringrrr	�make_pats�
�rz\s+(\w+)cCs^t��}t�|d�}t�|d�d}t�|d�}|j|d|d||d|d|dd�dS)zcSet color options of Text widget.

    If ColorDelegator is used, this should be called first.
    ZnormalZcursor�
foregroundZhilite�
background)rrZinsertbackgroundZselectforegroundZselectbackgroundZinactiveselectbackgroundN)r�CurrentTheme�GetHighlightZconfig)�text�themeZ
normal_colorsZcursor_colorZ
select_colorsrrr	�color_config"s�r$c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
d�Z	ddd�Z
ddd�Zdd�Zd dd�Z
dd�Zdd�Zdd�Zd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_state�prog�idprog�LoadTagDefs��selfrrr	r&Gs

zColorDelegator.__init__cCsd|_d|_d|_d|_dS)z1Initialize variables that track colorizing state.NTF)�after_id�allow_colorizing�stop_colorizing�
colorizingr+rrr	r'NszColorDelegator.init_statecCs\|jdk	r|�d�t�||�|dk	rL|��|�d|j�|�dd�nd|_d|_	dS)a�Set 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>>�1.0�endTF)
�delegateZunbindr�setdelegate�
config_colors�bind�toggle_colorize_event�notify_ranger/r.)r,r3rrr	r4Us

zColorDelegator.setdelegatecCs0|j��D]\}}|j|f|�q
|�d�dS)z4Configure text widget tags with colors from tagdefs.ZselN)�tagdefs�itemsZ
tag_configureZ	tag_raise)r,�tagZcnfrrr	r5lszColorDelegator.config_colorscCszt��}t�|d�t�|d�t�|d�t�|d�t�|d�ddd�ddd�t�|d�t�|d	�d
�	|_trvtd|j�dS)z.Create dictionary of tag names to text colors.rrrrZ
definitionN)rr�error�hit)	rrrr�
DEFINITIONr�TODO�ERRORr=r9)rr r!r9�DEBUG�print)r,r#rrr	r*rs






�
zColorDelegator.LoadTagDefsNcCs6|�|�}|j�|||�|�||dt|��dS)z:Insert chars into widget at index and mark for colorizing.�+%dcN)�indexr3�insertr8�len)r,rD�charsZtagsrrr	rE�s
zColorDelegator.insertcCs&|�|�}|j�||�|�|�dS)z5Delete chars between indexes and mark for colorizing.N)rDr3�deleter8�r,Zindex1Zindex2rrr	rH�s
zColorDelegator.deletecCsb|�d||�|jr$tr td�dS|jr<d|_tr<td�|jr^trNtd�|�d|j�|_dS)zCMark text changes for processing and restart colorizing, if active.r?zcolorizing already scheduledNT�stop colorizingzschedule colorizing�)	�tag_addr-rArBr0r/r.�after�
recolorizerIrrr	r8�szColorDelegator.notify_rangecCs8|jr(|j}d|_trtd�|�|�d|_d|_dS)N�cancel scheduled recolorizerFT)r-rArB�after_cancelr.r/)r,r-rrr	�close�s
zColorDelegator.closecCs�|jr(|j}d|_trtd�|�|�|jrF|jrFtr@td�d|_|j|_|jrl|jsl|�d|j�|_tr�td|jr~dp�d�d	S)
z�Toggle 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.
        NrOrJTrKzauto colorizing turnedZonZoff�break)	r-rArBrPr.r0r/rMrN)r,�eventr-rrr	r7�s$

�z$ColorDelegator.toggle_colorize_eventcCs�d|_|jstrtd�dS|js2tr.td�dS|jrHtrDtd�dSzHd|_d|_trbtd�t��}|�	�t��}tr�td||�W5d|_X|jr�|�
d	d
�r�tr�td�|�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?r1zreschedule colorizingrK)
r-r3rArBr.r0r/�time�perf_counter�recolorize_main�
tag_nextrangerMrN)r,�t0�t1rrr	rN�s8
zColorDelegator.recolorizecCs�d}|�d|�}|s�q�|\}}|�d||�|�d|�}|rH|d}nd}d}|}d}d}|s|}|�|d|�}t|dd	�}d|�|d
�k}|�||�}	|	s�dS|jD]}
|�|
||�q�||	}|j�	|�}|�r~|�
���D]~\}}
|
r�|�|�\}}|�
||d||d|�|
d
kr�|j�||�}|r�|�d�\}}|�
d|d||d|�q�|j�	||���}q�d|�|d
�k�r�|}d}nd}|�s�|�
d|�|��|jr\t�r�td�dSq\qdS)z(Evaluate text and apply colorizing tags.r1r?rrK�Fz+%d lines linestart��dz-1cNrC)�def�classr>zcolorizing stopped)rW�
tag_removeZ
tag_prevrangerD�minZ	tag_names�getr9r(�search�	groupdictr:�spanrLr)�matchr2�updater/rArB)r,�next�item�head�tailrGZlines_to_get�okZmark�liner;�m�key�value�a�bZm1rrr	rV�sp
�


�

�zColorDelegator.recolorize_maincCs|jD]}|�|dd�qdS)zRemove all colorizing tags.r1r2N)r9r_)r,r;rrr	�removecolors#s
zColorDelegator.removecolors)N)N)N)N)�__name__�
__module__�__qualname__�__doc__r&r'r4r5r*rErHr8rQr7rNrVrrrrrr	r%7s


	
"Br%cCs�ddlm}m}ddlm}||�}|�d�tt|���	d�dd��\}}|�d|d|d	f�d
}||dd�}|j
dd
d�|�d|�|��t
|�||�}	t�}
|	�|
�dS)Nr)�Toplevel�Text)�
PercolatorzTest ColorDelegator�+rKz
700x250+%d+%d��abif 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)�expand�fillrE)�tkinterrwrxZidlelib.percolatorry�title�map�intZgeometry�split�packrEZ	focus_setr$r%Zinsertfilter)�parentrwrxry�top�x�y�sourcer"�p�drrr	�_color_delegator)s 
 �r��__main__)�mainz idlelib.idle_test.test_colorizerr[)�	verbosity�exit)�run)rr�rerTZidlelib.configrZidlelib.delegatorrrAr
r�compile�Sr(r)r$r%r�rsZunittestr�Zidlelib.idle_test.htestr�rrrr	�<module>s&s"