t_8 @sWddlmZmZmZddlmZddlmZmZm Z dZ de edfde ee ddfhBdfd e ee dd fe dd fhBdfd e e ddfe dd fgdfd e e ddfe ddfgdfiZ Gddde ZGdddeZGddde ZdS))absolute_importdivisionunicode_literals) text_type)scopingElementstableInsertModeElements namespacesNFbuttonhtmllistolultableselectoptgroupoptionTc@seZdZdZddZddZddZdd Zd d d Zd dZ ddZ ddZ ddZ ddZ d S)NodezRepresents an item in the treecCs:||_d|_d|_i|_g|_g|_dS)zRCreates a Node :arg name: The tag name associated with the node N)nameparentvalue attributes childNodes_flags)selfrr/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-1.el7.x86_64/opt/alt/python35/lib/python3.5/site-packages/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__6sz Node.__repr__cCs tdS)z[Insert node as a child of the current node :arg node: the node to insert N)NotImplementedError)rnoderrr appendChild9szNode.appendChildNcCs tdS)aBInsert data as text in the current node, positioned before the start of node insertBefore or to the end of the node's text. :arg data: the data to insert :arg insertBefore: True if you want to insert the text before the node and False if you want to insert it after the node N)r&)rdata insertBeforerrr insertTextAs zNode.insertTextcCs tdS)aInsert 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 node :arg node: the node to insert :arg refNode: the child node to insert the node before N)r&)rr'refNoderrrr*Ms zNode.insertBeforecCs tdS)zhRemove node from the children of the current node :arg node: the child node to remove N)r&)rr'rrr removeChildYszNode.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 :arg newParent: the node to move all this node's children to N)rr()r newParentchildrrrreparentChildrenas zNode.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 cloneNodenszNode.cloneNodecCs tdS)zFReturn true if the node has children or text, false otherwise N)r&)rrrr hasContenttszNode.hasContent)__name__ __module__ __qualname____doc__rr$r%r(r+r*r-r0r1r2rrrrrs      rc@s(eZdZddZddZdS)ActiveFormattingElementscCsd}|tkrsx^|dddD]I}|tkr9P|j||rU|d7}|dkr&|j|Pq&Wtj||dS)Nr)Marker nodesEqualremover append)rr' equalCountelementrrrr>{s     zActiveFormattingElements.appendcCs0|j|jksdS|j|jks,dSdS)NFT) nameTupler)rnode1node2rrrr<s z#ActiveFormattingElements.nodesEqualN)r3r4r5r>r<rrrrr7zs  r7c@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)zmCreate a TreeBuilder :arg namespaceHTMLElements: whether or not to namespace HTML elements zhttp://www.w3.org/1999/xhtmlN)defaultNamespacereset)rnamespaceHTMLElementsrrrrs  zTreeBuilder.__init__cCsCg|_t|_d|_d|_d|_|j|_dS)NF) openElementsr7activeFormattingElements headPointer formPointerinsertFromTable documentClassdocument)rrrrrFs      zTreeBuilder.resetcCst|d}|sIt|tr4td|f}t|tsItt|\}}x^t|jD]M}|r||krdS| r|j |krdS||j |kAridSqiWdstdS)NrAr TF) hasattr isinstancerr tupleAssertionErrorlistElementsMapreversedrHrA)rtargetvariant exactNode listElementsinvertr'rrrelementInScopeszTreeBuilder.elementInScopec Cs|js dSt|jd}|j|}|tksH||jkrLdSxI|tkr||jkr|dkr}d}P|d8}|j|}qOWxx|d7}|j|}|j}|jddd|jd|jd|ji}||j|<||jd krPqWdS) Nr8rtypeStartTagr namespacer)r:r:) rIlenr;rHr1 insertElementrr]r)rientrycloner@rrr#reconstructActiveFormattingElementss.           z/TreeBuilder.reconstructActiveFormattingElementscCs>|jj}x(|jr9|tkr9|jj}qWdS)N)rIpopr;)rrarrrclearActiveFormattingElementssz)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 falseNr8Fr:)rIr;r)rritemrrr!elementInActiveFormattingElements s  z-TreeBuilder.elementInActiveFormattingElementscCs3|j|}|jj||jj|dS)N) createElementrHr>rNr()rtokenr@rrr insertRootszTreeBuilder.insertRootcCsG|d}|d}|d}|j|||}|jj|dS)NrpublicIdsystemId) doctypeClassrNr()rrirrkrldoctyperrr insertDoctype s    zTreeBuilder.insertDoctypecCs7|dkr|jd}|j|j|ddS)Nr8r)r:)rHr( commentClass)rrirrrr insertComment(s  zTreeBuilder.insertCommentcCsB|d}|jd|j}|j||}|d|_|S)z.Create an element but don't insert it anywhererr]r))getrE elementClassr)rrirr]r@rrrrh-s   zTreeBuilder.createElementcCs|jS)N)_insertFromTable)rrrr_getInsertFromTable5szTreeBuilder._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)rtinsertElementTabler_insertElementNormal)rrrrr_setInsertFromTable8s zTreeBuilder._setInsertFromTablecCs|d}t|ts)td||jd|j}|j||}|d|_|jdj||jj ||S)NrzElement %s not unicoder]r)r8r:) rPrrRrrrErsrrHr(r>)rrirr]r@rrrrwCs  zTreeBuilder.insertElementNormalcCs|j|}|jdjtkr2|j|S|j\}}|dkr`|j|n|j|||jj||S)z-Create an element and insert it into the treer8Nr:) rhrHrrrwgetTableMisnestedNodePositionr(r*r>)rrir@rr*rrrrvMs  zTreeBuilder.insertElementTablecCsx|dkr|jd}|j sB|jrR|jdjtkrR|j|n"|j\}}|j||dS)zInsert text data.Nr8r:r:)rHrLrrr+ry)rr)rr*rrrr+]s    zTreeBuilder.insertTextcCsd}d}d}x4|jdddD]}|jdkr)|}Pq)W|r|jrj|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 nodeNr8rrr:)rHrrindex)r lastTable fosterParentr*elmrrrryls    z)TreeBuilder.getTableMisnestedNodePositionc CsL|jd j}|td krH||krH|jj|j|dS) Nr8dddtlirrprprtr:)r~rrrrrrr)rHr frozensetrdgenerateImpliedEndTags)rexcluderrrrrs   z"TreeBuilder.generateImpliedEndTagscCs|jS)zReturn the final tree)rN)rrrr getDocumentszTreeBuilder.getDocumentcCs$|j}|jdj||S)zReturn the final fragmentr) fragmentClassrHr0)rfragmentrrr getFragments zTreeBuilder.getFragmentcCs tdS)zSerialize the subtree of node in the format required by unit tests :arg node: the node from which to start serializing N)r&)rr'rrrtestSerializerszTreeBuilder.testSerializer)r3r4r5r6rMrsrprmrrrFrZrcrergrjrorqrhrurxpropertyrLrwrvr+ryrrrrrrrrrDs6   .           rD) __future__rrrZpip._vendor.sixr constantsrrr r;rrSobjectrr r7rDrrrrs#c