U o a8@sddlmZmZmZddlmZddlmZmZm Z dZ e edfe ee e ddfgBdfe ee e dd fe dd fgBdfe e ddfe dd fgdfe e dd fe dd fgdfdZ GdddeZGdddeZGdddeZdS))absolute_importdivisionunicode_literals) text_type)scopingElementstableInsertModeElements namespacesNFhtmlbuttonolultableoptgroupoptionT)Nr listrselectc@sbeZdZdZddZddZddZdd Zdd 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)selfrrgC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_vendor\html5lib\treebuilders\base.py__init__s z Node.__init__cCs:ddd|jD}|r,d|j|fSd|jSdS)N cSsg|]\}}d||fqS)z%s="%s"r).0rrrrr .sz Node.__str__..z<%s %s><%s>)joinritemsr)r attributesStrrrr__str__-s  z Node.__str__cCs d|jS)Nr!)rrrrr__repr__6sz Node.__repr__cCstdS)z[Insert node as a child of the current node :arg node: the node to insert NNotImplementedErrorrnoderrr appendChild9szNode.appendChildNcCstdS)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 Nr()rdata insertBeforerrr insertTextAs zNode.insertTextcCstdS)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 Nr()rr+refNoderrrr.Ms zNode.insertBeforecCstdS)zhRemove node from the children of the current node :arg node: the child node to remove Nr(r*rrr removeChildYszNode.removeChildcCs |jD]}||qg|_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.reparentChildrencCstdS)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 Nr(r&rrr cloneNodenszNode.cloneNodecCstdS)zFReturn true if the node has children or text, false otherwise Nr(r&rrr hasContenttszNode.hasContent)N)__name__ __module__ __qualname____doc__rr%r'r,r/r.r1r4r5r6rrrrrs    rc@seZdZddZddZdS)ActiveFormattingElementscCsfd}|tkrV|dddD]:}|tkr*qV|||r>|d7}|dkr||qVqt||dS)Nr)Marker nodesEqualremoverappend)rr+ equalCountelementrrrrB{s  zActiveFormattingElements.appendcCs$|j|jksdS|j|jks dSdS)NFT) nameTupler)rnode1node2rrrr@s   z#ActiveFormattingElements.nodesEqualN)r7r8r9rBr@rrrrr;zs r;c@seZdZdZdZdZdZdZdZddZ ddZ d+ddZ d d Z d d Z d dZddZddZd,ddZddZddZddZeeeZddZddZd-dd Zd!d"Zd.d#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|r d|_nd|_|dS)zmCreate a TreeBuilder :arg namespaceHTMLElements: whether or not to namespace HTML elements zhttp://www.w3.org/1999/xhtmlN)defaultNamespacereset)rnamespaceHTMLElementsrrrrszTreeBuilder.__init__cCs.g|_t|_d|_d|_d|_||_dS)NF) openElementsr;activeFormattingElements headPointer formPointerinsertFromTable documentClassdocumentr&rrrrJs zTreeBuilder.resetcCst|d}|s2t|tr$td|f}t|ts2tt|\}}t|jD]>}|r^||kr^dS|sr|j |krrdS||j |kArHdSqHdstdS)NrEr TF) hasattr isinstancerr tupleAssertionErrorlistElementsMapreversedrLrE)rtargetvariant exactNode listElementsinvertr+rrrelementInScopes     zTreeBuilder.elementInScopecCs|js dSt|jd}|j|}|tks4||jkr8dS|tkrl||jkrl|dkrXd}ql|d8}|j|}q8|d7}|j|}|}|d|j|j|jd}||j|<||jdkrlqqldS)Nr=rr<StartTag)typer namespacer-) rMlenr?rLr5 insertElementrrar)rientryclonerDrrr#reconstructActiveFormattingElementss.    z/TreeBuilder.reconstructActiveFormattingElementscCs(|j}|jr$|tkr$|j}q dSN)rMpopr?)rrerrrclearActiveFormattingElementss z)TreeBuilder.clearActiveFormattingElementscCs:|jdddD]$}|tkr"q6q|j|kr|SqdS)zCheck if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return falseNr<F)rMr?r)rritemrrr!elementInActiveFormattingElements s   z-TreeBuilder.elementInActiveFormattingElementscCs&||}|j||j|dSrh) createElementrLrBrRr,)rtokenrDrrr insertRoots  zTreeBuilder.insertRootcCs6|d}|d}|d}||||}|j|dS)NrpublicIdsystemId) doctypeClassrRr,)rrnrrprqdoctyperrr insertDoctype s zTreeBuilder.insertDoctypecCs*|dkr|jd}|||ddS)Nr<r-)rLr, commentClass)rrnrrrr insertComment(s zTreeBuilder.insertCommentcCs0|d}|d|j}|||}|d|_|S)z.Create an element but don't insert it anywhererrar-)getrI elementClassrrrnrrarDrrrrm-s   zTreeBuilder.createElementcCs|jSrh)_insertFromTabler&rrr_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)rzinsertElementTablercinsertElementNormal)rrrrr_setInsertFromTable8s zTreeBuilder._setInsertFromTablecCsb|d}t|tstd||d|j}|||}|d|_|jd||j ||S)NrzElement %s not unicoderar-r<) rTrrVrwrIrxrrLr,rBryrrrr}Cs   zTreeBuilder.insertElementNormalcCs`||}|jdjtkr$||S|\}}|dkrD||n ||||j||S)z-Create an element and insert it into the treer<N) rmrLrrr}getTableMisnestedNodePositionr,r.rB)rrnrDrr.rrrr|Ms      zTreeBuilder.insertElementTablecCsV|dkr|jd}|jr.|jr:|jdjtkr:||n|\}}|||dS)zInsert text data.Nr<)rLrPrrr/r)rr-rr.rrrr/]s     zTreeBuilder.insertTextcCstd}d}d}|jdddD]}|jdkr|}q4q|rb|jrJ|j}|}ql|j|j|d}n |jd}||fS)zsGet the foster parent element, and sibling to insert before (or None) when inserting a misnested table nodeNr<rr=r)rLrrindex)r lastTable fosterParentr.elmrrrrls   z)TreeBuilder.getTableMisnestedNodePositioncCs8|jdj}|tdkr4||kr4|j||dS)Nr<)dddtlirrprprt)rLr frozensetrigenerateImpliedEndTags)rexcluderrrrrs    z"TreeBuilder.generateImpliedEndTagscCs|jS)zReturn the final tree)rRr&rrr getDocumentszTreeBuilder.getDocumentcCs|}|jd||S)zReturn the final fragmentr) fragmentClassrLr4)rfragmentrrr getFragmentszTreeBuilder.getFragmentcCstdS)zSerialize the subtree of node in the format required by unit tests :arg node: the node from which to start serializing Nr(r*rrrtestSerializerszTreeBuilder.testSerializer)N)N)N)N)r7r8r9r:rQrxrurrrrrJr^rgrjrlrortrvrmr{r~propertyrPr}r|r/rrrrrrrrrrHs6   .     rH) __future__rrrZpip._vendor.sixr constantsrrr r?rsetrWobjectrrr;rHrrrrs0        c