\e[c @`sddlmZmZmZddlmZddlmZmZm Z ddddd d d d d g Z ej Z ej ZejZejZejZejZdZdje Z defdYZdefdYZdS(i(tabsolute_importtdivisiontunicode_literals(tNodei(t namespacest voidElementstspaceCharactersuDOCUMENTuDOCTYPEuTEXTuELEMENTuCOMMENTuENTITYuUNKNOWNu TreeWalkeruNonRecursiveTreeWalkeru <#UNKNOWN#>ut TreeWalkercB`szeZdZdZdZdZedZdZdZ dZ dZ d d d Z d Zd ZRS( u}Walks a tree yielding tokens Tokens are dicts that all have a ``type`` field specifying the type of the token. cC`s ||_dS(uCCreates a TreeWalker :arg tree: the tree to walk N(ttree(tselfR((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyt__init__scC`s tdS(N(tNotImplementedError(R ((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyt__iter__#scC`sidd6|d6S(uGenerates an error token with the given message :arg msg: the error message :returns: SerializeError token uSerializeErrorutypeudata((R tmsg((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyterror&scc`s<idd6|d6|d6|d6V|r8|jdVndS(urGenerates 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 uEmptyTagutypeunameu namespaceudatauVoid element has childrenN(R(R t namespacetnametattrst hasChildren((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytemptyTag0s  cC`s idd6|d6|d6|d6S(uGenerates 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 uStartTagutypeunameu namespaceudata((R RRR((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytstartTagEs cC`sidd6|d6|d6S(uGenerates an EndTag token :arg namespace: the namespace of the token--can be ``None`` :arg name: the name of the element :returns: EndTag token uEndTagutypeunameu namespace((R RR((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytendTagVs cc`s|}|jt}|t|t| }|rKidd6|d6Vn|}|jt}|t|}|ridd6|d6Vn|ridd6|d6VndS(utGenerates 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 uSpaceCharactersutypeudatau CharactersN(tlstripRtlentrstrip(R tdatatmiddletlefttright((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyttextdscC`sidd6|d6S(udGenerates a Comment token :arg data: the comment :returns: Comment token uCommentutypeudata((R R((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytcommentscC`s idd6|d6|d6|d6S(uGenerates a Doctype token :arg name: :arg publicId: :arg systemId: :returns: the Doctype token uDoctypeutypeunameupublicIdusystemId((R RtpublicIdtsystemId((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytdoctypes cC`sidd6|d6S(ujGenerates an Entity token :arg name: the entity name :returns: an Entity token uEntityutypeuname((R R((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytentityscC`s|jd|S(uHandles unknown node typesuUnknown node type: (R(R tnodeType((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytunknownsN(t__name__t __module__t__doc__R R RtFalseRRRRRtNoneR!R"R$(((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyRs      &  tNonRecursiveTreeWalkercB`s5eZdZdZdZdZdZRS(cC`s tdS(N(R (R tnode((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytgetNodeDetailsscC`s tdS(N(R (R R+((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyt getFirstChildscC`s tdS(N(R (R R+((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pytgetNextSiblingscC`s tdS(N(R (R R+((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyt getParentNodesc c`s|j}x|dk r|j|}|d|d}}t}|tkr_|j|Vn |tkrx|j|D] }|Vq{Wn|tkr|\}}}}| s|t dkr|t krx%|j ||||D] }|VqWt}q|j |||Vni|t kr7|j|dVnH|tkrX|j|dVn'|tkrmt}n|j|dV|r|j|} nd} | dk r| }q x|dk r|j|}|d|d}}|tkr<|\}}}}|r|t dks%|t kr<|j||Vq<n|j|krUd}Pn|j|} | dk rz| }Pq|j|}qWq WdS(Niiuhtml(RR)R,R(tDOCTYPER!tTEXTRtELEMENTRRRRtCOMMENTRtENTITYR"tDOCUMENTtTrueR$R-RR.R/( R t currentNodetdetailsttypeRttokenRRt attributest firstChildt nextSibling((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyR sZ     #          " (R%R&R,R-R.R/R (((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyR*s     N(t __future__RRRtxml.domRt constantsRRRt__all__t DOCUMENT_NODER5tDOCUMENT_TYPE_NODER0t TEXT_NODER1t ELEMENT_NODER2t COMMENT_NODER3t ENTITY_NODER4tUNKNOWNtjointobjectRR*(((sD/tmp/pip-install-0xiv62/pip/pip/_vendor/html5lib/treewalkers/base.pyts