Re4 @sddlmZmZmZddlmZddlmZmZm Z ddddd d d d d g Z ej Z ej ZejZejZejZejZdZdje Z Gdd d eZGdd d eZdS))absolute_importdivisionunicode_literals)Node) namespaces voidElementsspaceCharactersDOCUMENTDOCTYPETEXTELEMENTCOMMENTENTITYUNKNOWN TreeWalkerNonRecursiveTreeWalkerz <#UNKNOWN#>c@seZdZdZddZddZddZdd d Zd d Zd dZ ddZ ddZ ddddZ ddZ ddZdS)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)selfrr/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/html5lib/treewalkers/base.py__init__szTreeWalker.__init__cCs tdS)N)NotImplementedError)rrrr__iter__#szTreeWalker.__iter__cCsddd|iS)zGenerates an error token with the given message :arg msg: the error message :returns: SerializeError token typeSerializeErrordatar)rmsgrrrerror&szTreeWalker.errorFccs5ddd|d|d|iV|r1|jdVdS)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 rEmptyTagname namespacerzVoid element has childrenN)r)rr"r!attrs hasChildrenrrremptyTag0s   zTreeWalker.emptyTagcCsddd|d|d|iS)zGenerates 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 rStartTagr!r"rr)rr"r!r#rrrstartTagEs zTreeWalker.startTagcCsddd|d|iS)zGenerates an EndTag token :arg namespace: the namespace of the token--can be ``None`` :arg name: the name of the element :returns: EndTag token rEndTagr!r"r)rr"r!rrrendTagVs zTreeWalker.endTagccs|}|jt}|dt|t|}|rLddd|iV|}|jt}|t|d}|rddd|iV|rddd|iVdS)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 NrSpaceCharactersr Characters)lstripr lenrstrip)rrZmiddleleftrightrrrtextds zTreeWalker.textcCsddd|iS)zdGenerates a Comment token :arg data: the comment :returns: Comment token rCommentrr)rrrrrcommentszTreeWalker.commentNcCsddd|d|d|iS)zGenerates a Doctype token :arg name: :arg publicId: :arg systemId: :returns: the Doctype token rDoctyper!publicIdsystemIdr)rr!r5r6rrrdoctypes zTreeWalker.doctypecCsddd|iS)zjGenerates an Entity token :arg name: the entity name :returns: an Entity token rEntityr!r)rr!rrrentityszTreeWalker.entitycCs|jd|S)zHandles unknown node typeszUnknown node type: )r)rZnodeTyperrrunknownszTreeWalker.unknown)__name__ __module__ __qualname____doc__rrrr%r'r)r1r3r7r9r:rrrrrs       &  c@sLeZdZddZddZddZddZd d Zd S) rcCs tdS)N)r)rnoderrrgetNodeDetailssz%NonRecursiveTreeWalker.getNodeDetailscCs tdS)N)r)rr?rrr getFirstChildsz$NonRecursiveTreeWalker.getFirstChildcCs tdS)N)r)rr?rrrgetNextSiblingsz%NonRecursiveTreeWalker.getNextSiblingcCs tdS)N)r)rr?rrr getParentNodesz$NonRecursiveTreeWalker.getParentNodec cs|j}x|dk r|j|}|d|dd}}d}|tkre|j|Vn |tkrx|j|D] }|VqWn|tkr|\}}}}| s|tdkr|tkrx%|j ||||D] }|VqWd}q|j |||Vni|t kr=|j |dVnH|t kr^|j|dVn'|tkrsd}n|j|dV|r|j|} nd} | dk r| }q x|dk r|j|}|d|dd}}|tkrB|\}}}}|r%|tdks1|tkrB|j||V|j|krXd}P|j|} | dk r}| }Pq|j|}qWq WdS)NrFhtmlT)rr@r r7r r1r rrr%r'rr3rr9r r:rAr)rBrC) r currentNodedetailsrr$tokenr"r! attributesZ firstChildZ nextSiblingrrrrsZ     #          " zNonRecursiveTreeWalker.__iter__N)r;r<r=r@rArBrCrrrrrrs     N) __future__rrrxml.domr constantsrrr __all__Z DOCUMENT_NODEr ZDOCUMENT_TYPE_NODEr Z TEXT_NODEr Z ELEMENT_NODEr Z COMMENT_NODErZ ENTITY_NODErrjoinobjectrrrrrrs