o
    côj4&  ã                   @  sÊ   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	r4dd	lmZ G d
d„ dƒZG dd„ dedd�ZedƒZ	 edd�G dd„ de
e ƒƒZG d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                   @  s:   e Zd ZU ded< dZded< dd
d„Zeddd„ƒZdS )Ú	StateBaseÚstrÚsrcNz"tuple[str, tuple[int, ...]] | NoneÚ_src_char_codeÚmdr   Úenvr   c                 C  s   || _ || _|| _d S ©N)r   r   r   )Úselfr   r   r   © r   úb/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/markdown_it/ruler.pyÚ__init__)   s   
zStateBase.__init__Úreturnútuple[int, ...]c                 C  sP   t jdtdd� | jd u s| jd | jur#| jtdd„ | jD ƒƒf| _| jd S )Nz?StateBase.srcCharCode is deprecated. Use StateBase.src instead.é   )Ú
stacklevelr   c                 s  s   � | ]}t |ƒV  qd S r   )Úord)Ú.0Úcr   r   r   Ú	<genexpr>7   s   € z(StateBase.srcCharCode.<locals>.<genexpr>r
   )ÚwarningsÚwarnÚDeprecationWarningr   r   Útuple©r   r   r   r   ÚsrcCharCode.   s   ý
zStateBase.srcCharCode)r   r   r   r   r   r   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r   r   Úpropertyr%   r   r   r   r   r       s   
 
r   c                   @  s   e Zd ZU ded< dS )ÚRuleOptionsTypeú	list[str]ÚaltN)r&   r'   r(   r)   r   r   r   r   r+   ;   s   
 r+   F)ÚtotalÚ
RuleFuncTvT)Úslotsc                   @  s8   e Zd ZU ded< ded< edd�Zded< d	ed
< dS )ÚRuler   ÚnameÚboolÚenabledF)Úreprr/   Úfnr,   r-   N)r&   r'   r(   r)   r   r6   r   r   r   r   r1   C   s
   
 r1   c                   @  s¬   e Zd Zd1dd„Zd2dd	„Zd1d
d„Z	d3d4dd„Z	d3d5dd„Z	d3d6dd„Z	d3d4dd„Z		d7d8d"d#„Z
	d7d8d$d%„Z	d7d8d&d'„Zd9d:d+d,„Zd;d-d.„Zd;d/d0„ZdS )<ÚRulerr   ÚNonec                 C  s   g | _ d | _d S r   )Ú	__rules__Ú	__cache__r$   r   r   r   r   L   s   
zRuler.__init__r2   r   Úintc                 C  s*   t | jƒD ]\}}|j|kr|  S qdS )zFind rule index by nameéÿÿÿÿ)Ú	enumerater9   r2   )r   r2   ÚiÚruler   r   r   Ú__find__T   s
   
ÿzRuler.__find__c                 C  s„   dh}| j D ]}|jsq|jD ]}| |¡ qqi | _|D ]"}g | j|< | j D ]}|js-q'|r5||jvr5q'| j|  |j¡ q'qdS )zBuild rules lookup cacheÚ N)r9   r4   r-   Úaddr:   Úappendr6   )r   Zchainsr?   r2   Úchainr   r   r   Ú__compile__[   s$   

ÿ

ûþzRuler.__compile__NÚruleNamer6   r/   ÚoptionsúRuleOptionsType | Nonec                 C  sR   |   |¡}|pi }|dkrtd|› �ƒ‚|| j| _| dg ¡| j| _d| _dS )zöReplace 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
        r<   úParser rule not found: r-   N)r@   ÚKeyErrorr9   r6   Úgetr-   r:   )r   rF   r6   rG   Úindexr   r   r   Úatn   s   


zRuler.atÚ
beforeNamec                 C  sV   |   |¡}|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
        r<   rI   Tr-   N©r@   rJ   r9   Úinsertr1   r/   rK   r:   )r   rN   rF   r6   rG   rL   r   r   r   Úbefore€   s   
ÿ
zRuler.beforeÚ	afterNamec                 C  sZ   |   |¡}|pi }|dkrtd|› �ƒ‚| j |d 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
        r<   rI   r
   Tr-   NrO   )r   rR   rF   r6   rG   rL   r   r   r   Úafter˜   s   
ÿ
zRuler.afterc              
   C  s0   | j  tt |d||pi  dg ¡ƒ¡ d| _dS )zÒPush 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).

        Tr-   N)r9   rC   r1   r/   rK   r:   )r   rF   r6   rG   r   r   r   Úpush°   s   
ÿ
z
Ruler.pushFÚnamesústr | Iterable[str]ÚignoreInvalidr3   r,   c                 C  ó|   t |tƒr|g}g }z/|D ]&}|  |¡}|dk r|rq|dk r(|s(td|› �ƒ‚d| j| _| |¡ qW d| _|S d| _w )aJ  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
            (the rules named before it are still enabled)
        :return: list of found rule names
        r   ú!Rules manager: invalid rule name TN©Ú
isinstancer   r@   rJ   r9   r4   rC   r:   ©r   rU   rW   Úresultr2   Úidxr   r   r   Úenable¿   ó    

ù	ÿzRuler.enablec                 C  s.   t |tƒr|g}| jD ]}d|_q|  ||¡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
            (all rules are still disabled, and the rules named before it enabled)
        :return: list of found rule names
        F)r[   r   r9   r4   r_   )r   rU   rW   r?   r   r   r   Ú
enableOnlyÚ   s
   

zRuler.enableOnlyc                 C  rX   )aL  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
            (the rules named before it are still disabled)
        :return: list of found rule names
        r   rY   FNrZ   r\   r   r   r   Údisableë   r`   zRuler.disablerA   Ú	chainNameúlist[RuleFuncTv]c                 C  s2   | j du r|  ¡  | j dus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.

        N)r:   rE   rK   )r   rc   r   r   r   ÚgetRules  s   
zRuler.getRulesc                 C  ó   dd„ | j D ƒS )z Return all available rule names.c                 S  s   g | ]}|j ‘qS r   )r2   ©r   Úrr   r   r   Ú
<listcomp>  s    z'Ruler.get_all_rules.<locals>.<listcomp>©r9   r$   r   r   r   Úget_all_rules  ó   zRuler.get_all_rulesc                 C  rf   )zReturn the active rule names.c                 S  s   g | ]}|j r|j‘qS r   )r4   r2   rg   r   r   r   ri     s    z*Ruler.get_active_rules.<locals>.<listcomp>rj   r$   r   r   r   Úget_active_rules  rl   zRuler.get_active_rules)r   r8   )r2   r   r   r;   r   )rF   r   r6   r/   rG   rH   r   r8   )
rN   r   rF   r   r6   r/   rG   rH   r   r8   )
rR   r   rF   r   r6   r/   rG   rH   r   r8   )F)rU   rV   rW   r3   r   r,   )rA   )rc   r   r   rd   )r   r,   )r&   r'   r(   r   r@   rE   rM   rQ   rS   rT   r_   ra   rb   re   rk   rm   r   r   r   r   r7   K   s*    


ÿûûÿÿÿÿ
r7   )Ú__doc__Ú
__future__r   Úcollections.abcr   Údataclassesr   r   Útypingr   r   r   r	   r    Úutilsr   Úmarkdown_itr   r   r+   r/   r1   r7   r   r   r   r   Ú<module>   s     