o 7]h4@sddlmZmZmZddlmZddlmZmZm Z gdZ ej Z ej ZejZejZejZejZdZde Z Gdd d eZGd d d eZd S) )absolute_importdivisionunicode_literals)Node) namespaces voidElementsspaceCharacters) DOCUMENTDOCTYPETEXTELEMENTCOMMENTENTITYUNKNOWN TreeWalkerNonRecursiveTreeWalkerz <#UNKNOWN#>c@sleZdZdZddZddZddZdd d Zd d Zd dZ ddZ ddZ dddZ 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)selfrrG/usr/lib/python3/dist-packages/pip/_vendor/html5lib/treewalkers/base.py__init__s zTreeWalker.__init__cCtNNotImplementedError)rrrr__iter__#zTreeWalker.__iter__cC d|dS)zGenerates an error token with the given message :arg msg: the error message :returns: SerializeError token SerializeErrortypedatar)rmsgrrrerror& zTreeWalker.errorFccs*d|||dV|r|dVdSdS)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 EmptyTagr"name namespacer#zVoid element has childrenNr%)rr*r)attrs hasChildrenrrremptyTag0szTreeWalker.emptyTagcCsd|||dS)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 StartTagr(r)rr*r)r,rrrstartTagE  zTreeWalker.startTagcCs d||dS)zGenerates 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)rr*r)rrrendTagVs zTreeWalker.endTagccs~|}|t}|dt|t|}|rd|dV|}|t}|t|d}|r3d|dV|r=d|dVdSdS)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 NSpaceCharactersr! Characters)lstripr lenrstrip)rr#middleleftrightrrrtextds    zTreeWalker.textcCr)zdGenerates a Comment token :arg data: the comment :returns: Comment token Commentr!r)rr#rrrcommentr&zTreeWalker.commentNcCsd|||dS)zGenerates a Doctype token :arg name: :arg publicId: :arg systemId: :returns: the Doctype token Doctype)r"r)publicIdsystemIdr)rr)r@rArrrdoctyper1zTreeWalker.doctypecCr)zjGenerates an Entity token :arg name: the entity name :returns: an Entity token Entity)r"r)r)rr)rrrentityr&zTreeWalker.entitycCs|d|S)zHandles unknown node typeszUnknown node type: r+)rnodeTyperrrunknownszTreeWalker.unknown)F)NN)__name__ __module__ __qualname____doc__rrr%r.r0r3r<r>rBrDrFrrrrrs &  rc@s4eZdZddZddZddZddZd d Zd S) rcCrrrrnoderrrgetNodeDetailsrz%NonRecursiveTreeWalker.getNodeDetailscCrrrrKrrr getFirstChildrz$NonRecursiveTreeWalker.getFirstChildcCrrrrKrrrgetNextSiblingrz%NonRecursiveTreeWalker.getNextSiblingcCrrrrKrrr getParentNoderz$NonRecursiveTreeWalker.getParentNodec cs|j}|dur||}|d|dd}}d}|tkr%|j|Vni|tkr5|j|D]}|Vq.nY|tkre|\}}}}|rG|tdkr\|tvr\| ||||D]}|VqSd}n2| |||Vn)|t krr| |dVn|t kr||dVn|tkrd}n||dV|r||} nd} | dur| }nN|dur||}|d|dd}}|tkr|\}}}}|r|tdks|tvr|||V|j|urd}n||} | dur| }n ||}|dus|dusdSdS)NrFhtmlT)rrMr rBr r<r rrr.r0rr>rrDr rFrNr3rOrP) r currentNodedetailsr"r-tokenr*r) attributes firstChild nextSiblingrrrrsd         zNonRecursiveTreeWalker.__iter__N)rGrHrIrMrNrOrPrrrrrrs  rN) __future__rrrxml.domr constantsrrr __all__ DOCUMENT_NODEr DOCUMENT_TYPE_NODEr TEXT_NODEr ELEMENT_NODEr COMMENT_NODEr ENTITY_NODErrjoinobjectrrrrrrs  !