0{Y5@shddlmZmZmZddlmZddlmZmZm Z dZ ie edfd6e ee e ddfgBdfd6e ee e dd fe dd fgBdfd 6e e ddfe dd fgdfd 6e e dd fe ddfgdfd6Z GdddeZGdddeZGdddeZdS))absolute_importdivisionunicode_literals) text_type)scopingElementstableInsertModeElements namespacesNFhtmlbuttonolullisttableoptgroupoptionTselectc@seZdZddZddZddZddZd d d Zd d ZddZ ddZ ddZ ddZ d S)NodecCs:||_d|_d|_i|_g|_g|_dS)a6Node representing an item in the tree. name - The tag name associated with the node parent - The parent of the current node (or None for the document node) value - The value of the current node (applies to text nodes and comments attributes - a dict holding name, value pairs for attributes of the node childNodes - a list of child nodes of the current node. This must include all elements but not necessarily other node types _flags - A list of miscellaneous flags that can be set on the node N)nameparentvalue attributes childNodes_flags)selfrrB/tmp/pip-ok8sy_ze-build/pip/_vendor/html5lib/treebuilders/_base.py__init__s     z Node.__init__cCsKdjdd|jjD}|r<d|j|fSd|jSdS)N cSs&g|]\}}d||fqS)z%s="%s"r).0rrrrr +s z Node.__str__..z<%s %s>z<%s>)joinritemsr)r attributesStrrrr__str__*s z Node.__str__cCs d|jS)Nz<%s>)r)rrrr__repr__3sz Node.__repr__cCs tdS)z3Insert node as a child of the current node N)NotImplementedError)rnoderrr appendChild6szNode.appendChildNcCs tdS)zInsert data as text in the current node, positioned before the start of node insertBefore or to the end of the node's text. N)r&)rdata insertBeforerrr insertText;szNode.insertTextcCs tdS)zInsert node as a child of the current node, before refNode in the list of child nodes. Raises ValueError if refNode is not a child of the current nodeN)r&)rr'refNoderrrr*AszNode.insertBeforecCs tdS)z:Remove node from the children of the current node N)r&)rr'rrr removeChildGszNode.removeChildcCs.x|jD]}|j|q Wg|_dS)zMove all the children of the current node to newParent. This is needed so that trees that don't store text as nodes move the text in the correct way N)rr()r newParentchildrrrreparentChildrenLszNode.reparentChildrencCs tdS)zReturn a shallow copy of the current node i.e. a node with the same name and attributes but with no parent or child nodes N)r&)rrrr cloneNodeVszNode.cloneNodecCs tdS)zFReturn true if the node has children or text, false otherwise N)r&)rrrr hasContent\szNode.hasContent) __name__ __module__ __qualname__rr$r%r(r+r*r-r0r1r2rrrrrs       rc@s(eZdZddZddZdS)ActiveFormattingElementscCsd}|tkrxj|dddD]R}|tkr<Pn|j||r[|d7}n|dkr&|j|Pq&q&Wntj||dS)Nr)Marker nodesEqualremoverappend)rr' equalCountelementrrrr=cs      zActiveFormattingElements.appendcCs0|j|jksdS|j|jks,dSdS)NFT) nameTupler)rnode1node2rrrr;ps z#ActiveFormattingElements.nodesEqualN)r3r4r5r=r;rrrrr6bs  r6c@s?eZdZdZdZdZdZdZdZddZ ddZ dddZ d d Z d d Z d dZddZddZdddZddZddZddZeeeZddZddZddd Zd!d"Zdd#d$Zd%d&Zd'd(Zd)d*ZdS)+ TreeBuilderaBase treebuilder implementation documentClass - the class to use for the bottommost node of a document elementClass - the class to use for HTML Elements commentClass - the class to use for comments doctypeClass - the class to use for doctypes NcCs)|rd|_n d|_|jdS)Nzhttp://www.w3.org/1999/xhtml)defaultNamespacereset)rnamespaceHTMLElementsrrrrs  zTreeBuilder.__init__cCsCg|_t|_d|_d|_d|_|j|_dS)NF) openElementsr6activeFormattingElements headPointer formPointerinsertFromTable documentClassdocument)rrrrrEs      zTreeBuilder.resetcCst|d}t|\}}xZt|jD]I}|j|krK| s]||kra|radS||j|kAr/dSq/WdstdS)Nr@TF)hasattrlistElementsMapreversedrGrr@AssertionError)rtargetvariant exactNode listElementsinvertr'rrrelementInScopeszTreeBuilder.elementInScopecCs!|js dSt|jd}|j|}|tksH||jkrLdSxL|tkr||jkr|dkrd}Pn|d8}|j|}qOWx|d7}|j|}|j}|jidd6|jd6|jd6|jd6}||j|<||jd krPqqWdS) Nr7rStartTagtyper namespacer)r9r9) rHlenr:rGr1 insertElementrrZr)rientrycloner?rrr#reconstructActiveFormattingElementss.          z/TreeBuilder.reconstructActiveFormattingElementscCs>|jj}x(|jr9|tkr9|jj}qWdS)N)rHpopr:)rr^rrrclearActiveFormattingElementssz)TreeBuilder.clearActiveFormattingElementscCsHxA|jdddD])}|tkr-Pq|j|kr|SqWdS)zCheck if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return falseNr7Fr9)rHr:r)rritemrrr!elementInActiveFormattingElementss  z-TreeBuilder.elementInActiveFormattingElementscCs3|j|}|jj||jj|dS)N) createElementrGr=rMr()rtokenr?rrr insertRootszTreeBuilder.insertRootcCsG|d}|d}|d}|j|||}|jj|dS)NrpublicIdsystemId) doctypeClassrMr()rrfrrhridoctyperrr insertDoctypes    zTreeBuilder.insertDoctypecCs:|dkr|jd}n|j|j|ddS)Nr7r)r9)rGr( commentClass)rrfrrrr insertComments zTreeBuilder.insertCommentcCsB|d}|jd|j}|j||}|d|_|S)z.Create an element but don't insert it anywhererrZr))getrD elementClassr)rrfrrZr?rrrres   zTreeBuilder.createElementcCs|jS)N)_insertFromTable)rrrr_getInsertFromTableszTreeBuilder._getInsertFromTablecCs.||_|r|j|_n |j|_dS)zsSwitch the function used to insert an element from the normal one to the misnested table one and back againN)rqinsertElementTabler\insertElementNormal)rrrrr_setInsertFromTables zTreeBuilder._setInsertFromTablecCs|d}t|ts)td||jd|j}|j||}|d|_|jdj||jj ||S)NrzElement %s not unicoderZr)r7r9) isinstancerrQrorDrprrGr(r=)rrfrrZr?rrrrts  zTreeBuilder.insertElementNormalcCs|j|}|jdjtkr2|j|S|j\}}|dkr`|j|n|j|||jj||S)z-Create an element and insert it into the treer7Nr9) rerGrrrtgetTableMisnestedNodePositionr(r*r=)rrfr?rr*rrrrs(s  zTreeBuilder.insertElementTablecCs{|dkr|jd}n|j sE|jrU|jdjtkrU|j|n"|j\}}|j||dS)zInsert text data.Nr7r9r9)rGrKrrr+rw)rr)rr*rrrr+8s   zTreeBuilder.insertTextcCsd}d}d}x7|jdddD]}|jdkr)|}Pq)q)W|r|jrm|j}|}q|j|jj|d}n |jd}||fS)zsGet the foster parent element, and sibling to insert before (or None) when inserting a misnested table nodeNr7rrr9)rGrrindex)r lastTable fosterParentr*elmrrrrwGs    z)TreeBuilder.getTableMisnestedNodePositionc CsO|jd j}|td krK||krK|jj|j|ndS) Nr7dddtlirrprprtr9)zddzdtzlizoptionzoptgrouprzrpzrt)rGr frozensetragenerateImpliedEndTags)rexcluderrrrras   z"TreeBuilder.generateImpliedEndTagscCs|jS)zReturn the final tree)rM)rrrr getDocumentkszTreeBuilder.getDocumentcCs$|j}|jdj||S)zReturn the final fragmentr) fragmentClassrGr0)rfragmentrrr getFragmentos zTreeBuilder.getFragmentcCs tdS)zzSerialize the subtree of node in the format required by unit tests node - the node from which to start serializingN)r&)rr'rrrtestSerializervszTreeBuilder.testSerializer)r3r4r5__doc__rLrprmrjrrrErWr`rbrdrgrlrnrerrrupropertyrKrtrsr+rwrrrrrrrrrCzs6    .           rC) __future__rrrZpip._vendor.sixr constantsrrr r:rsetrOobjectrrr6rCrrrrs*! K