a
    'ñ»j'  ã                   @  sz   d dl mZ d dlmZmZ d dlZd dlmZm	Z	 d dl
Z
d dlmZ dddœdd	„Zejf i e¤ŽG d
d„ dƒƒZdS )é    )Úannotations)ÚCallableÚMutableMappingN)ÚAnyÚLiteral)ÚDATACLASS_KWARGSr   )ÚvalueÚreturnc                 C  s   | si S t | tƒrt| ƒS | S )zŠConvert Token.attrs set as ``None`` or ``[[key, value], ...]`` to a dict.

    This improves compatibility with upstream markdown-it.
    )Ú
isinstanceÚlistÚdict)r   © r   ú7E:\soccer\ml_env\Lib\site-packages\markdown_it/token.pyÚconvert_attrs   s
    
r   c                   @  sh  e Zd ZU ded< ded< ded< ejed�Zded< d	Zd
ed< dZ	ded< d	Z
ded< dZded< dZded< dZded< ejed�Zded< dZded< dZded< ddœdd„Zdddœd d!„Zd"dœd#d$„Zd%dd&œd'd(„Zdd)dd*œd+d,„Zdd-dœd.d/„Zdddd*œd0d1„Zd2d d3œd4d5„Zd6d6d	d	ed7œddd8d9d:d;d<œd=d>„Zed;d d?œd@dA„ƒZd	S )BÚTokenÚstrÚtypeÚtagzLiteral[-1, 0, 1]Znesting)Údefault_factoryzdict[str, str | int | float]ÚattrsNzlist[int] | NoneÚmapr   ÚintÚlevelzlist[Token] | NoneÚchildrenÚ ÚcontentÚmarkupÚinfozdict[Any, Any]ÚmetaFÚboolÚblockÚhiddenÚNone)r	   c                 C  s   t | jƒ| _d S ©N)r   r   ©Úselfr   r   r   Ú__post_init__O   s    zToken.__post_init__)Únamer	   c                 C  s.   t  dt¡ || jvrdS t| j ¡ ƒ |¡S )NzEToken.attrIndex should not be used, since Token.attrs is a dictionaryéÿÿÿÿ)ÚwarningsÚwarnÚUserWarningr   r   ÚkeysÚindex©r%   r'   r   r   r   Ú	attrIndexR   s    þ
zToken.attrIndexz#list[tuple[str, str | int | float]]c                 C  s   t | j ¡ ƒS )zGet (key, value) list of attrs.)r   r   Úitemsr$   r   r   r   Ú	attrItems[   s    zToken.attrItemsztuple[str, str | int | float])ÚattrDatar	   c                 C  s   |\}}|   ||¡ dS )zAAdd `[ name, value ]` attribute to list. Init attrs if necessary.N)ÚattrSet)r%   r2   r'   r   r   r   r   ÚattrPush_   s    zToken.attrPushzstr | int | float)r'   r   r	   c                 C  s   || j |< dS )z>Set `name` attribute to `value`. Override old value if exists.N)r   )r%   r'   r   r   r   r   r3   d   s    zToken.attrSetzNone | str | int | floatc                 C  s   | j  |d¡S )z@Get the value of attribute `name`, or null if it does not exist.N)r   Úgetr.   r   r   r   ÚattrGeth   s    zToken.attrGetc                 C  sV   || j v rH| j | }t|tƒs2td| j | › �ƒ‚|› d|› �| j |< n
|| j |< dS )z‘Join value to existing attribute via space.
        Or create new attribute if not exists.
        Useful to operate with token classes.
        z#existing attr 'name' is not a str: ú N)r   r
   r   Ú	TypeError)r%   r'   r   Úcurrentr   r   r   ÚattrJoinl   s    


ÿzToken.attrJoinr   )Úchangesr	   c                 K  s   t j| fi |¤ŽS )z&Return a shallow copy of the instance.)ÚdcÚreplace)r%   r;   r   r   r   Úcopy{   s    z
Token.copyT)r   Úas_upstreamÚmeta_serializerÚfilterÚdict_factoryz&Callable[[dict[Any, Any]], Any] | Nonez!Callable[[str, Any], bool] | Nonez'Callable[..., MutableMapping[str, Any]]zMutableMapping[str, Any])r   r?   r@   rA   rB   r	   c                  s¾   ˆ‡fdd„t  ˆ¡D ƒƒ}ˆr:ˆ‡fdd„| ¡ D ƒƒ}ˆ rld|v rl|d sRdndd„ |d  ¡ D ƒ|d< ˆrˆd|v rˆˆ|d ƒ|d< ˆrº| d	d¡rº‡ ‡‡‡‡fd
d„|d	 D ƒ|d	< |S )aê  Return the token as a dictionary.

        :param children: Also convert children to dicts
        :param as_upstream: Ensure the output dictionary is equal to that created by markdown-it
            For example, attrs are converted to null or lists
        :param meta_serializer: hook for serializing ``Token.meta``
        :param filter: A callable whose return code determines whether an
            attribute or element is included (``True``) or dropped (``False``).
            Is called with the (key, value) pair.
        :param dict_factory: A callable to produce dictionaries from.
            For example, to produce ordered dictionaries instead of normal Python
            dictionaries, pass in ``collections.OrderedDict``.

        c                 3  s    | ]}|j tˆ |j ƒfV  qd S r#   )r'   Úgetattr)Ú.0Úfr$   r   r   Ú	<genexpr>–   ó    z Token.as_dict.<locals>.<genexpr>c                 3  s$   | ]\}}ˆ ||ƒr||fV  qd S r#   r   ©rD   ÚkÚv)rA   r   r   rF   ˜   rG   r   Nc                 S  s   g | ]\}}||g‘qS r   r   rH   r   r   r   Ú
<listcomp>�   rG   z!Token.as_dict.<locals>.<listcomp>r   r   c              	     s    g | ]}|j ˆˆˆˆ ˆd �‘qS ))r   rA   rB   r?   r@   )Úas_dict)rD   Úchild)r?   r   rB   rA   r@   r   r   rK   ¢   s   ùû)r<   Úfieldsr0   r5   )r%   r   r?   r@   rA   rB   Úmappingr   )r?   r   rB   rA   r@   r%   r   rL      s    ÿýø

zToken.as_dict)Údctr	   c                   s.   ˆ f i |¤Ž}|j r*‡ fdd„|j D ƒ|_ |S )zConvert a dict to a Token.c                   s   g | ]}ˆ   |¡‘qS r   )Ú	from_dict)rD   Úc©Úclsr   r   rK   ³   rG   z#Token.from_dict.<locals>.<listcomp>)r   )rT   rP   Útokenr   rS   r   rQ   ®   s    zToken.from_dict)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r<   Úfieldr   r   r   r   r   r   r   r   r   r    r!   r&   r/   r1   r4   r3   r6   r:   r>   rL   ÚclassmethodrQ   r   r   r   r   r      s:   
	ù/r   )Ú
__future__r   Úcollections.abcr   r   Údataclassesr<   Útypingr   r   r)   Zmarkdown_it._compatr   r   Ú	dataclassr   r   r   r   r   Ú<module>   s   