o
    Rh'                     @  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   S/home/air/sanwanet/backup_V2/venv/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]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&   r5   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   r7   d   r4   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   r4   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&   rA   r   r   r   copy{   s   z
Token.copyT)r   as_upstreammeta_serializerfilterdict_factoryrE   rF   &Callable[[dict[Any, Any]], Any] | NonerG   !Callable[[str, Any], bool] | NonerH   '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   rN   kv)rG   r   r   rP      s   $ r   Nc                 S  s   g | ]\}}||gqS r   r   rQ   r   r   r   
<listcomp>   s    z!Token.as_dict.<locals>.<listcomp>r   r   c              	     s    g | ]}|j  d qS ))r   rG   rH   rE   rF   )as_dict)rN   child)rE   r   rH   rG   rF   r   r   rT      s    )rB   fieldsr2   r;   )r&   r   rE   rF   rG   rH   mappingr   )rE   r   rH   rG   rF   r&   r   rU      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)rN   cclsr   r   rT      s    z#Token.from_dict.<locals>.<listcomp>Nr   )r   )r]   rY   tokenr   r\   r   rZ      s   zToken.from_dict)r	   r#   )r(   r   r	   r   )r	   r1   )r5   r6   r	   r#   )r(   r   r   r9   r	   r#   )r(   r   r	   r:   )r(   r   r   r   r	   r#   )rA   r   r	   r   )r   r    rE   r    rF   rI   rG   rJ   rH   rK   r	   rL   )rY   rL   r	   r   )__name__
__module____qualname____annotations__rB   fieldr   r   r   r   r   r   r   r   r   r!   r"   r'   r0   r3   r8   r7   r<   r@   rD   rU   classmethodrZ   r   r   r   r   r      sV   
 


	




/r   )r   r   r	   r   r   )
__future__r   collections.abcr   r   dataclassesrB   typingr   r   r*   markdown_it._compatr   r   	dataclassr   r   r   r   r   <module>   s    
