o
    Ù­j¶#  ã                   @  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                   @  sB   e Zd Zddd„Zedd
d„ƒZejddd„ƒZeddd„ƒZdS )Ú	StateBaseÚsrcÚstrÚmdr   Úenvr   c                 C  s   || _ || _|| _d S ©N)r   r   r   )Úselfr   r   r   © r   úN/var/www/html/CropPilot/venv/lib/python3.10/site-packages/markdown_it/ruler.pyÚ__init__!   s   
zStateBase.__init__Úreturnc                 C  s   | j S r   )Ú_src©r   r   r   r   r   &   s   zStateBase.srcÚvalueÚNonec                 C  s   || _ d | _d S r   )r   Ú_srcCharCode)r   r   r   r   r   r   *   s   
útuple[int, ...]c                 C  s6   t jdtdd� | jd u rtdd„ | jD ƒƒ| _| jS )Nz?StateBase.srcCharCode is deprecated. Use StateBase.src instead.é   )Ú
stacklevelc                 s  s   � | ]}t |ƒV  qd S r   )Úord)Ú.0Úcr   r   r   Ú	<genexpr>7   s   € z(StateBase.srcCharCode.<locals>.<genexpr>)ÚwarningsÚwarnÚDeprecationWarningr   Útupler   r   r   r   r   ÚsrcCharCode/   s   ý
zStateBase.srcCharCodeN)r   r   r   r   r   r   )r   r   )r   r   r   r   )r   r   )Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   Úsetterr(   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+   Ú__annotations__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)Úreprr3   Úfnr/   r0   N)r)   r*   r+   r1   r   r:   r   r   r   r   r5   C   s
   
 r5   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   r   c                 C  s   g | _ d | _d S r   )Ú	__rules__Ú	__cache__r   r   r   r   r   L   s   
zRuler.__init__r6   r   Úintc                 C  s*   t | jƒD ]\}}|j|kr|  S qdS )zFind rule index by nameéÿÿÿÿ)Ú	enumerater<   r6   )r   r6   Ú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)r<   r8   r0   Úaddr=   Úappendr:   )r   ÚchainsrB   r6   Úchainr   r   r   Ú__compile__[   s$   

ÿ

ûþzRuler.__compile__NÚruleNamer:   r3   Ú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: r0   N)rC   ÚKeyErrorr<   r:   Úgetr0   r=   )r   rJ   r:   rK   Ú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?   rM   Tr0   N©rC   rN   r<   Úinsertr5   r3   rO   r=   )r   rR   rJ   r:   rK   rP   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?   rM   r
   Tr0   NrS   )r   rV   rJ   r:   rK   rP   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).

        Tr0   N)r<   rF   r5   r3   rO   r=   )r   rJ   r:   rK   r   r   r   Úpush°   s   
ÿ
z
Ruler.pushFÚnamesústr | Iterable[str]ÚignoreInvalidr7   r/   c                 C  óp   t |tƒr|g}g }|D ]&}|  |¡}|dk r|rq|dk r'|s'td|› �ƒ‚d| j| _| |¡ qd| _|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   rC   rN   r<   r8   rF   r=   ©r   rY   r[   Úresultr6   Ú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
        :return: list of found rule names
        F)r_   r   r<   r8   rc   )r   rY   r[   rB   r   r   r   Ú
enableOnly×   s
   


zRuler.enableOnlyc                 C  r\   )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   r]   FNr^   r`   r   r   r   Údisableç   rd   zRuler.disablerD   Ú	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=   rI   rO   )r   rg   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   )r6   ©r!   Úrr   r   r   Ú
<listcomp>  s    z'Ruler.get_all_rules.<locals>.<listcomp>©r<   r   r   r   r   Úget_all_rules  ó   zRuler.get_all_rulesc                 C  rj   )zReturn the active rule names.c                 S  s   g | ]}|j r|j‘qS r   )r8   r6   rk   r   r   r   rm     s    z*Ruler.get_active_rules.<locals>.<listcomp>rn   r   r   r   r   Úget_active_rules  rp   zRuler.get_active_rules)r   r   )r6   r   r   r>   r   )rJ   r   r:   r3   rK   rL   r   r   )
rR   r   rJ   r   r:   r3   rK   rL   r   r   )
rV   r   rJ   r   r:   r3   rK   rL   r   r   )F)rY   rZ   r[   r7   r   r/   )rD   )rg   r   r   rh   )r   r/   )r)   r*   r+   r   rC   rI   rQ   rU   rW   rX   rc   re   rf   ri   ro   rq   r   r   r   r   r;   K   s*    


ÿûûÿÿÿÿ
r;   )Ú__doc__Ú
__future__r   Úcollections.abcr   Údataclassesr   r   Útypingr   r   r   r	   r$   Úutilsr   Úmarkdown_itr   r   r.   r3   r5   r;   r   r   r   r   Ú<module>   s     