
    eh#                    4   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZ ddlZddlmZ e	rdd	lmZ  G d
 d          Z G d ded          Z ed          Z	  ed           G d de
e                               Z G d de
e                   ZdS )a  
class Ruler

Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and
[[MarkdownIt#inline]] to manage sequences of functions (rules):

- keep rules in defined order
- assign the name to each rule
- enable/disable rules
- add/replace rules
- allow assign rules to additional named chains (in the same)
- caching lists of active rules

You will not need use this class directly until write plugins. For simple
rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and
[[MarkdownIt.use]].
    )annotations)Iterable)	dataclassfield)TYPE_CHECKINGGeneric	TypedDictTypeVarN   )EnvType)
MarkdownItc                  h    e Zd ZddZedd	            Zej        dd            Zedd            ZdS )	StateBasesrcstrmdr   envr   c                0    || _         || _        || _        d S N)r   r   r   )selfr   r   r   s       a/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/markdown_it/ruler.py__init__zStateBase.__init__!   s        returnc                    | j         S r   )_srcr   s    r   r   zStateBase.src&   s
    yr   valueNonec                "    || _         d | _        d S r   )r   _srcCharCode)r   r   s     r   r   zStateBase.src*   s    	48r   tuple[int, ...]c                    t          j        dt          d           | j        #t	          d | j        D                       | _        | j        S )Nz?StateBase.srcCharCode is deprecated. Use StateBase.src instead.   )
stacklevelc              3  4   K   | ]}t          |          V  d S r   )ord).0cs     r   	<genexpr>z(StateBase.srcCharCode.<locals>.<genexpr>7   s(      %@%@c!ff%@%@%@%@%@%@r   )warningswarnDeprecationWarningr!   tupler   r   s    r   srcCharCodezStateBase.srcCharCode/   sY    M	
 	
 	
 	

 $ %%@%@di%@%@%@ @ @D  r   N)r   r   r   r   r   r   )r   r   )r   r   r   r   )r   r"   )__name__
__module____qualname__r   propertyr   setterr/    r   r   r   r       s           
    X 	Z9 9 9 Z9 ! ! ! X! ! !r   r   c                      e Zd ZU ded<   dS )RuleOptionsType	list[str]altN)r0   r1   r2   __annotations__r5   r   r   r7   r7   ;   s         NNNNNr   r7   F)total
RuleFuncTvT)slotsc                  P    e Zd ZU ded<   ded<    ed          Zded<   d	ed
<   dS )Ruler   nameboolenabledF)reprr<   fnr8   r9   N)r0   r1   r2   r:   r   rD   r5   r   r   r?   r?   C   sI         IIIMMMU&&&B&&&&NNNNNr   r?   c                      e Zd Zd$dZd%dZd$dZ	 d&d'dZ	 d&d(dZ	 d&d)dZ	 d&d'dZ		 d*d+dZ
	 d*d+dZ	 d*d+dZd,d-d!Zd.d"Zd.d#Zd	S )/Rulerr   r   c                "    g | _         d | _        d S r   )	__rules__	__cache__r   s    r   r   zRuler.__init__L   s    13 >Br   r@   r   intc                X    t          | j                  D ]\  }}|j        |k    r|c S dS )zFind rule index by name)	enumeraterH   r@   )r   r@   irules       r   __find__zRuler.__find__T   s?     00 	 	GAtyD   !rr   c                    dh}| j         D ])}|j        s
|j        D ]}|                    |           *i | _        |D ]O}g | j        |<   | j         D ];}|j        s
|r
||j        vr| j        |                             |j                   <PdS )zBuild rules lookup cache N)rH   rB   r9   addrI   appendrD   )r   chainsrO   r@   chains        r   __compile__zRuler.__compile__[   s    N 	! 	!D<  ! !

4    ! 	6 	6E$&DN5! 6 6|  e4833u%,,TW55556	6 	6r   NruleNamerD   r<   optionsRuleOptionsType | Nonec                    |                      |          }|pi }|dk    rt          d|           || j        |         _        |                    dg           | j        |         _        d| _        dS )zReplace rule by name with new function & options.

        :param ruleName: rule name to replace.
        :param fn: new rule function.
        :param options: new rule options (not mandatory).
        :raises: KeyError if name not found
        rL   Parser rule not found: r9   N)rP   KeyErrorrH   rD   getr9   rI   )r   rX   rD   rY   indexs        r   atzRuler.atn   su     h''-RB;;?X??@@@#%u $+KKr$:$:u!r   
beforeNamec                
   |                      |          }|pi }|dk    rt          d|           | j                            |t	          t
                   |d||                    dg                                d| _        dS )aK  Add new rule to chain before one with given name.

        :param beforeName: new rule will be added before this one.
        :param ruleName: new rule will be added before this one.
        :param fn: new rule function.
        :param options: new rule options (not mandatory).
        :raises: KeyError if name not found
        rL   r\   Tr9   NrP   r]   rH   insertr?   r<   r^   rI   )r   ra   rX   rD   rY   r_   s         r   beforezRuler.before   s     j))-RB;;AZAABBB4
#HdBE28N8NOO	
 	
 	
 r   	afterNamec                   |                      |          }|pi }|dk    rt          d|           | j                            |dz   t	          t
                   |d||                    dg                                d| _        dS )aG  Add new rule to chain after one with given name.

        :param afterName: new rule will be added after this one.
        :param ruleName: new rule will be added after this one.
        :param fn: new rule function.
        :param options: new rule options (not mandatory).
        :raises: KeyError if name not found
        rL   r\   r   Tr9   Nrc   )r   rf   rX   rD   rY   r_   s         r   afterzRuler.after   s     i((-RB;;@Y@@AAAAItJ'$GKKr<R<RSS	
 	
 	
 r   c                    | j                             t          t                   |d||pi                     dg                                d| _        dS )zPush new rule to the end of chain.

        :param ruleName: new rule will be added to the end of chain.
        :param fn: new rule function.
        :param options: new rule options (not mandatory).

        Tr9   N)rH   rT   r?   r<   r^   rI   )r   rX   rD   rY   s       r   pushz
Ruler.push   sU     	XtR'-R1D1DUB1O1OPP	
 	
 	
 r   Fnamesstr | Iterable[str]ignoreInvalidrA   r8   c                   t          |t                    r|g}g }|D ]a}|                     |          }|dk     r|r |dk     r|st          d|           d| j        |         _        |                    |           bd| _        |S )a  Enable rules with given names.

        :param names: name or list of rule names to enable.
        :param ignoreInvalid: ignore errors when rule not found
        :raises: KeyError if name not found and not ignoreInvalid
        :return: list of found rule names
        r   !Rules manager: invalid rule name TN
isinstancer   rP   r]   rH   rB   rT   rI   r   rk   rm   resultr@   idxs         r   enablezRuler.enable   s     eS!! 	GE 	  	 D--%%Ca]aI4IIJJJ*.DN3'MM$r   c                    t          |t                    r|g}| j        D ]	}d|_        
|                     ||          S )a-  Enable rules with given names, and disable everything else.

        :param names: name or list of rule names to enable.
        :param ignoreInvalid: ignore errors when rule not found
        :raises: KeyError if name not found and not ignoreInvalid
        :return: list of found rule names
        F)rq   r   rH   rB   ru   )r   rk   rm   rO   s       r   
enableOnlyzRuler.enableOnly   sK     eS!! 	GEN 	! 	!D DLL{{5-000r   c                   t          |t                    r|g}g }|D ]a}|                     |          }|dk     r|r |dk     r|st          d|           d| j        |         _        |                    |           bd| _        |S )a  Disable rules with given names.

        :param names: name or list of rule names to enable.
        :param ignoreInvalid: ignore errors when rule not found
        :raises: KeyError if name not found and not ignoreInvalid
        :return: list of found rule names
        r   ro   FNrp   rr   s         r   disablezRuler.disable   s     eS!! 	GE 	  	 D--%%Ca]aI4IIJJJ*/DN3'MM$r   rR   	chainNamelist[RuleFuncTv]c                    | j         |                                  | j         J | j                             |g           pg S )a=  Return array of active functions (rules) for given chain name.
        It analyzes rules configuration, compiles caches if not exists and returns result.

        Default chain name is `''` (empty string). It can't be skipped.
        That's done intentionally, to keep signature monomorphic for high speed.

        )rI   rW   r^   )r   rz   s     r   getRuleszRuler.getRules   sI     >!>---~!!)R006B6r   c                $    d | j         D             S )z Return all available rule names.c                    g | ]	}|j         
S r5   )r@   r(   rs     r   
<listcomp>z'Ruler.get_all_rules.<locals>.<listcomp>  s    ///1///r   rH   r   s    r   get_all_ruleszRuler.get_all_rules  s    //////r   c                $    d | j         D             S )zReturn the active rule names.c                *    g | ]}|j         	|j        S r5   )rB   r@   r   s     r   r   z*Ruler.get_active_rules.<locals>.<listcomp>  s!    <<<1!)<<<<r   r   r   s    r   get_active_ruleszRuler.get_active_rules  s    <<<<<<r   )r   r   )r@   r   r   rJ   r   )rX   r   rD   r<   rY   rZ   r   r   )
ra   r   rX   r   rD   r<   rY   rZ   r   r   )
rf   r   rX   r   rD   r<   rY   rZ   r   r   )F)rk   rl   rm   rA   r   r8   )rR   )rz   r   r   r{   )r   r8   )r0   r1   r2   r   rP   rW   r`   re   rh   rj   ru   rw   ry   r}   r   r   r5   r   r   rF   rF   K   sq       B B B B   6 6 6 6( PT    . +/    : +/    2 PT      AF    2 AF1 1 1 1 1" AF    07 7 7 7 70 0 0 0= = = = = =r   rF   )__doc__
__future__r   collections.abcr   dataclassesr   r   typingr   r   r	   r
   r+   utilsr   markdown_itr   r   r7   r<   r?   rF   r5   r   r   <module>r      s   $ # " " " " " $ $ $ $ $ $ ( ( ( ( ( ( ( ( = = = = = = = = = = = =        '&&&&&&! ! ! ! ! ! ! !6    iu     W\""
 F     7:   H= H= H= H= H=GJ H= H= H= H= H=r   