U ��.e4� @s�ddlmZmZmZddlmZddlmZmZm Z ddddd d d d d g Z ej Z ej ZejZejZejZejZdZd�e �Z Gdd �d e�ZGdd �d e�ZdS)�)�absolute_import�division�unicode_literals)�Node�)� namespaces� voidElements�spaceCharacters�DOCUMENT�DOCTYPE�TEXT�ELEMENT�COMMENT�ENTITY�UNKNOWN� TreeWalker�NonRecursiveTreeWalkerz <#UNKNOWN#>�c@sleZdZdZdd�Zdd�Zdd�Zdd d �Zd d �Zd d�Z dd�Z dd�Z ddd�Z dd�Z dd�ZdS)rz}Walks a tree yielding tokens Tokens are dicts that all have a ``type`` field specifying the type of the token. cCs ||_dS)zCCreates a TreeWalker :arg tree: the tree to walk N)�tree)�selfr�r�I/usr/lib/python3.8/site-packages/pip/_vendor/html5lib/treewalkers/base.py�__init__szTreeWalker.__init__cCst�dS�N��NotImplementedError)rrrr�__iter__#szTreeWalker.__iter__cCs d|d�S)z�Generates an error token with the given message :arg msg: the error message :returns: SerializeError token ZSerializeError��type�datar)r�msgrrr�error&szTreeWalker.errorFccs$d|||d�V|r |�d�VdS)arGenerates 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 ZEmptyTag�r�name� namespacerzVoid element has childrenN�r!)rr$r#�attrs� hasChildrenrrr�emptyTag0s �zTreeWalker.emptyTagcCsd|||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 ZStartTagr"r)rr$r#r&rrr�startTagEs �zTreeWalker.startTagcCs 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 ZEndTag)rr#r$r)rr$r#rrr�endTagVs �zTreeWalker.endTagccsx|}|�t�}|dt|�t|��}|r6d|d�V|}|�t�}|t|�d�}|rdd|d�V|rtd|d�VdS)atGenerates 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 NZSpaceCharactersrZ Characters)�lstripr �len�rstrip)rrZmiddle�left�rightrrr�textds    zTreeWalker.textcCs d|d�S)zdGenerates a Comment token :arg data: the comment :returns: Comment token �Commentrr)rrrrr�comment�szTreeWalker.commentNcCsd|||d�S)z�Generates a Doctype token :arg name: :arg publicId: :arg systemId: :returns: the Doctype token ZDoctype)rr#�publicId�systemIdr)rr#r3r4rrr�doctype�s �zTreeWalker.doctypecCs d|d�S)zjGenerates an Entity token :arg name: the entity name :returns: an Entity token ZEntity)rr#r)rr#rrr�entity�szTreeWalker.entitycCs|�d|�S)zHandles unknown node typeszUnknown node type: r%)rZnodeTyperrr�unknown�szTreeWalker.unknown)F)NN)�__name__� __module__� __qualname__�__doc__rrr!r(r)r*r0r2r5r6r7rrrrrs &  c@s4eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd S) rcCst�dSrr�rZnoderrr�getNodeDetails�sz%NonRecursiveTreeWalker.getNodeDetailscCst�dSrrr<rrr� getFirstChild�sz$NonRecursiveTreeWalker.getFirstChildcCst�dSrrr<rrr�getNextSibling�sz%NonRecursiveTreeWalker.getNextSiblingcCst�dSrrr<rrr� getParentNode�sz$NonRecursiveTreeWalker.getParentNodec cs�|j}|dk �r�|�|�}|d|dd�}}d}|tkrJ|j|�Vn�|tkrj|j|�D] }|Vq\n�|tkr�|\}}}}|r�|tdkr�|tkr�|� ||||�D] }|Vq�d}n|� |||�VnV|t kr�|� |d�Vn<|t k�r|�|d�Vn |tk�rd}n|�|d�V|�r2|�|�} nd} | dk �rF| }q|dk r|�|�}|d|dd�}}|tk�r�|\}}}}|�r�|tdk�s�|tk�r�|�||�V|j|k�r�d}q|�|�} | dk �r�| }qn |�|�}�qFqdS)Nr�FZhtmlT)rr=r r5r r0r rrr(r)rr2rr6r r7r>r*r?r@) rZ currentNodeZdetailsrr'�tokenr$r#Z attributesZ firstChildZ nextSiblingrrrr�s\     �          zNonRecursiveTreeWalker.__iter__N)r8r9r:r=r>r?r@rrrrrr�s N)Z __future__rrrZxml.domrZ constantsrrr �__all__Z DOCUMENT_NODEr ZDOCUMENT_TYPE_NODEr Z TEXT_NODEr Z ELEMENT_NODEr Z COMMENT_NODErZ ENTITY_NODErr�join�objectrrrrrr�s" � !