o
    Ù­jí  ã                   @  sd   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d	„Zejd
d�G dd„ dƒƒZdS )é    )Úannotations)ÚCallableÚMutableMappingN)ÚAnyÚLiteralÚvaluer   Ú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   úN/var/www/html/CropPilot/venv/lib/python3.10/site-packages/markdown_it/token.pyÚconvert_attrs	   s
   
r   T)Úslotsc                   @  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__M   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   Ú	attrIndexP   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   Ú	attrItemsY   ó   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   b   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   ÚattrGetf   r4   zToken.attrGetc                 C  sX   || j v r%| j | }t|tƒstd| j | › �ƒ‚|› d|› �| j |< dS || 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   ÚattrJoinj   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   Úcopyy   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   )Ú
__future__r   Úcollections.abcr   r   ÚdataclassesrB   Útypingr   r   r*   r   Ú	dataclassr   r   r   r   r   Ú<module>   s    

