o
    Ëý°j4  ã                   @   s’   d dl mZmZmZ d dlmZ ddlmZmZm	Z	 g d¢Z
ejZejZejZejZejZejZdZd e	¡Z	G dd	„ d	eƒZG d
d„ deƒZdS )é    )Úabsolute_importÚdivisionÚunicode_literals)ÚNodeé   )Ú
namespacesÚvoidElementsÚspaceCharacters)	ÚDOCUMENTÚDOCTYPEÚTEXTÚELEMENTÚCOMMENTÚENTITYÚUNKNOWNÚ
TreeWalkerÚNonRecursiveTreeWalkerz<#UNKNOWN#>Ú c                   @   sl   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	d
„Zdd„ Zdd„ Z	dd„ Z
dd„ Zddd„Zdd„ Zdd„ ZdS )r   z}Walks a tree yielding tokens

    Tokens are dicts that all have a ``type`` field specifying the type of the
    token.

    c                 C   s
   || _ dS )zCCreates a TreeWalker

        :arg tree: the tree to walk

        N)Útree)Úselfr   © r   ú˜/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/base.pyÚ__init__   s   
zTreeWalker.__init__c                 C   ó   t ‚©N©ÚNotImplementedError)r   r   r   r   Ú__iter__#   ó   zTreeWalker.__iter__c                 C   ó
   d|dœS )z†Generates an error token with the given message

        :arg msg: the error message

        :returns: SerializeError token

        ÚSerializeError©ÚtypeÚdatar   )r   Úmsgr   r   r   Úerror&   ó   
zTreeWalker.errorFc                 c   s*   � d|||dœV  |r|   d¡V  dS dS )ar  Generates an EmptyTag token

        :arg namespace: the namespace of the token--can be ``None``

        :arg name: the name of the element

        :arg attrs: the attributes of the element as a dict

        :arg hasChildren: whether or not to yield a SerializationError because
            this tag shouldn't have children

        :returns: EmptyTag token

        ÚEmptyTag©r"   ÚnameÚ	namespacer#   zVoid element has childrenN©r%   )r   r*   r)   ÚattrsÚhasChildrenr   r   r   ÚemptyTag0   s   €þÿzTreeWalker.emptyTagc                 C   s   d|||dœS )zôGenerates a StartTag token

        :arg namespace: the namespace of the token--can be ``None``

        :arg name: the name of the element

        :arg attrs: the attributes of the element as a dict

        :returns: StartTag token

        ÚStartTagr(   r   )r   r*   r)   r,   r   r   r   ÚstartTagE   ó
   ýzTreeWalker.startTagc                 C   s   d||dœS )z´Generates an EndTag token

        :arg namespace: the namespace of the token--can be ``None``

        :arg name: the name of the element

        :returns: EndTag token

        ÚEndTag)r"   r)   r*   r   )r   r*   r)   r   r   r   ÚendTagV   s   
þzTreeWalker.endTagc                 c   s~   � |}|  t¡}|dt|ƒt|ƒ … }|rd|dœV  |}| t¡}|t|ƒd… }|r3d|dœV  |r=d|dœV  dS dS )at  Generates SpaceCharacters and Characters tokens

        Depending on what's in the data, this generates one or more
        ``SpaceCharacters`` and ``Characters`` tokens.

        For example:

            >>> from html5lib.treewalkers.base import TreeWalker
            >>> # Give it an empty tree just so it instantiates
            >>> walker = TreeWalker([])
            >>> list(walker.text(''))
            []
            >>> list(walker.text('  '))
            [{u'data': '  ', u'type': u'SpaceCharacters'}]
            >>> list(walker.text(' abc '))  # doctest: +NORMALIZE_WHITESPACE
            [{u'data': ' ', u'type': u'SpaceCharacters'},
            {u'data': u'abc', u'type': u'Characters'},
            {u'data': u' ', u'type': u'SpaceCharacters'}]

        :arg data: the text data

        :returns: one or more ``SpaceCharacters`` and ``Characters`` tokens

        NÚSpaceCharactersr!   Ú
Characters)Úlstripr	   ÚlenÚrstrip)r   r#   ÚmiddleÚleftÚrightr   r   r   Útextd   s   €

ÿzTreeWalker.textc                 C   r   )zdGenerates a Comment token

        :arg data: the comment

        :returns: Comment token

        ÚCommentr!   r   )r   r#   r   r   r   ÚcommentŠ   r&   zTreeWalker.commentNc                 C   s   d|||dœS )zŒGenerates a Doctype token

        :arg name:

        :arg publicId:

        :arg systemId:

        :returns: the Doctype token

        ÚDoctype)r"   r)   ÚpublicIdÚsystemIdr   )r   r)   r@   rA   r   r   r   Údoctype”   r1   zTreeWalker.doctypec                 C   r   )zjGenerates an Entity token

        :arg name: the entity name

        :returns: an Entity token

        ÚEntity)r"   r)   r   )r   r)   r   r   r   Úentity¥   r&   zTreeWalker.entityc                 C   s   |   d| ¡S )zHandles unknown node typeszUnknown node type: r+   )r   ÚnodeTyper   r   r   Úunknown¯   s   zTreeWalker.unknown)F)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r%   r.   r0   r3   r<   r>   rB   rD   rF   r   r   r   r   r      s    

&


r   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )r   c                 C   r   r   r   ©r   Únoder   r   r   ÚgetNodeDetailsµ   r   z%NonRecursiveTreeWalker.getNodeDetailsc                 C   r   r   r   rK   r   r   r   ÚgetFirstChild¸   r   z$NonRecursiveTreeWalker.getFirstChildc                 C   r   r   r   rK   r   r   r   ÚgetNextSibling»   r   z%NonRecursiveTreeWalker.getNextSiblingc                 C   r   r   r   rK   r   r   r   ÚgetParentNode¾   r   z$NonRecursiveTreeWalker.getParentNodec                 c   sê  � | j }|d uró|  |¡}|d |dd … }}d}|tkr%| j|Ž V  ni|tkr5| j|Ž D ]}|V  q.nY|tkre|\}}}}|rG|td kr\|tv r\|  	||||¡D ]}|V  qSd}n2|  
|||¡V  n)|tkrr|  |d ¡V  n|tkr|  |d ¡V  n|tkr†d}n|  |d ¡V  |r–|  |¡}	nd }	|	d urŸ|	}nN|d urí|  |¡}|d |dd … }}|tkrÐ|\}}}}|rÅ|td ksÉ|tvrÐ|  ||¡V  | j |u rØd }n|  |¡}
|
d urä|
}n	|  |¡}|d us£|d usd S d S )Nr   é   FÚhtmlT)r   rM   r   rB   r   r<   r   r   r   r.   r0   r   r>   r   rD   r
   rF   rN   r3   rO   rP   )r   ÚcurrentNodeÚdetailsr"   r-   Útokenr*   r)   Ú
attributesÚ
firstChildÚnextSiblingr   r   r   r   Á   sd   €
ÿ
ÿ



ñÖzNonRecursiveTreeWalker.__iter__N)rG   rH   rI   rM   rN   rO   rP   r   r   r   r   r   r   ´   s    r   N)Ú
__future__r   r   r   Úxml.domr   Ú	constantsr   r   r	   Ú__all__ÚDOCUMENT_NODEr
   ÚDOCUMENT_TYPE_NODEr   Ú	TEXT_NODEr   ÚELEMENT_NODEr   ÚCOMMENT_NODEr   ÚENTITY_NODEr   r   ÚjoinÚobjectr   r   r   r   r   r   Ú<module>   s    
 !