o
    Zh'                     @  st   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
Zejdi eG dd dZdS )    )annotations)CallableMutableMappingN)AnyLiteral)DATACLASS_KWARGSvaluer   returnc                 C  s   | si S t | trt| S | S )zConvert Token.attrs set as ``None`` or ``[[key, value], ...]`` to a dict.

    This improves compatibility with upstream markdown-it.
    )
isinstancelistdict)r    r   H/var/www/html/lang_env/lib/python3.10/site-packages/markdown_it/token.pyconvert_attrs   s
   
r   c                   @  s>  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< 	 dEddZdFd d!ZdGd#d$ZdHd'd(ZdId+d,ZdJd.d/ZdKd0d1ZdLd4d5Zd6d6d	d	ed7dMd@dAZedNdCdDZd	S )O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hiddenr	   Nonec                 C  s   t | j| _d S N)r   r   selfr   r   r   __post_init__O   s   zToken.__post_init__namec                 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.attrIndex#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[      zToken.attrItemsattrDatatuple[str, str | int | float]c                 C  s   |\}}|  || dS )zAAdd `[ name, value ]` attribute to list. Init attrs if necessary.N)attrSet)r%   r4   r'   r   r   r   r   attrPush_   s   zToken.attrPushr   str | int | floatc                 C  s   || j |< dS )z>Set `name` attribute to `value`. Override old value if exists.N)r   )r%   r'   r   r   r   r   r6   d   r3   zToken.attrSet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   r3   zToken.attrGetc                 C  sX   || j v r%| j | }t|tstd| j |  | d| | j |< dS || j |< dS )zJoin 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.attrJoin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_factoryrD   rE   &Callable[[dict[Any, Any]], Any] | NonerF   !Callable[[str, Any], bool] | NonerG   'Callable[..., MutableMapping[str, Any]]MutableMapping[str, Any]c                  s   fddt D }rfdd| D } r6d|v r6|d s)dn
dd |d  D |d< rDd|v rD|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>   s     z Token.as_dict.<locals>.<genexpr>c                 3  s&    | ]\}} ||r||fV  qd S r#   r   rM   kv)rF   r   r   rO      s   $ r   Nc                 S  s   g | ]\}}||gqS r   r   rP   r   r   r   
<listcomp>   s    z!Token.as_dict.<locals>.<listcomp>r   r   c              	     s    g | ]}|j  d qS ))r   rF   rG   rD   rE   )as_dict)rM   child)rD   r   rG   rF   rE   r   r   rS      s    )rA   fieldsr1   r:   )r%   r   rD   rE   rF   rG   mappingr   )rD   r   rG   rF   rE   r%   r   rT      s   

zToken.as_dictdctc                   s.    di |}|j r fdd|j D |_ |S )zConvert a dict to a Token.c                   s   g | ]}  |qS r   )	from_dict)rM   cclsr   r   rS      s    z#Token.from_dict.<locals>.<listcomp>Nr   )r   )r\   rX   tokenr   r[   r   rY      s   zToken.from_dict)r	   r"   )r'   r   r	   r   )r	   r0   )r4   r5   r	   r"   )r'   r   r   r8   r	   r"   )r'   r   r	   r9   )r'   r   r   r   r	   r"   )r@   r   r	   r   )r   r   rD   r   rE   rH   rF   rI   rG   rJ   r	   rK   )rX   rK   r	   r   )__name__
__module____qualname____annotations__rA   fieldr   r   r   r   r   r   r   r   r   r    r!   r&   r/   r2   r7   r6   r;   r?   rC   rT   classmethodrY   r   r   r   r   r      sV   
 


	




/r   )r   r   r	   r   r   )
__future__r   collections.abcr   r   dataclassesrA   typingr   r   r)   Zmarkdown_it._compatr   r   	dataclassr   r   r   r   r   <module>   s    
