o 7]h8@sddlmZmZmZddlmZddlmZmZm Z dZ e edfe ee ddfhBdfe ee dd fe dd fhBdfe e ddfe dd fgdfe e dd fe dd fgdfdZ Gddde ZGdddeZGddde ZdS))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)selfrrH/usr/lib/python3/dist-packages/pip/_vendor/html5lib/treebuilders/base.py__init__s  z Node.__init__cCs6ddd|jD}|rd|j|fSd|jS)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__6s z Node.__repr__cCt)z[Insert node as a child of the current node :arg node: the node to insert NotImplementedErrorrnoderrr appendChild9zNode.appendChildNcCr()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 r))rdata insertBeforerrr insertTextA zNode.insertTextcCr()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 r))rr,refNoderrrr0Mr2zNode.insertBeforecCr()zhRemove node from the children of the current node :arg node: the child node to remove r)r+rrr removeChildYr.zNode.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.reparentChildrencCr()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 r)r&rrr cloneNodenszNode.cloneNodecCr()zFReturn true if the node has children or text, false otherwise r)r&rrr hasContenttszNode.hasContentN)__name__ __module__ __qualname____doc__rr%r'r-r1r0r4r7r8r9rrrrrs     rc@seZdZddZddZdS)ActiveFormattingElementscCsfd}|tkr+|dddD]}|tkrn|||r|d7}|dkr*||nq t||dS)Nr)Marker nodesEqualremoverappend)rr, equalCountelementrrrrF{s  zActiveFormattingElements.appendcCs$|j|jksdS|j|jksdSdS)NFT) nameTupler)rnode1node2rrrrDs  z#ActiveFormattingElements.nodesEqualN)r;r<r=rFrDrrrrr?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|rd|_nd|_|dS)zmCreate a TreeBuilder :arg namespaceHTMLElements: whether or not to namespace HTML elements zhttp://www.w3.org/1999/xhtmlN)defaultNamespacereset)rnamespaceHTMLElementsrrrrs zTreeBuilder.__init__cCs.g|_t|_d|_d|_d|_||_dS)NF) openElementsr?activeFormattingElements headPointer formPointerinsertFromTable documentClassdocumentr&rrrrNs zTreeBuilder.resetcCst|d}|st|trtd|f}t|tsJt|\}}t|jD]}|r/||kr/dS|s9|j|kr9dS||j|vArCdSq$J)NrIr TF) hasattr isinstancerr tuplelistElementsMapreversedrPrI)rtargetvariant exactNode listElementsinvertr,rrrelementInScopes     zTreeBuilder.elementInScopecCs|jsdSt|jd}|j|}|tks||jvrdS|tkr>||jvr>|dkr,d}n|d8}|j|}|tkr>||jvs% |d7}|j|}|}|d|j|j|jd}||j|<||jdkrgdSq?)NrArr@TStartTag)typer namespacer/) rQlenrCrPr8 insertElementrrdr)rientryclonerHrrr#reconstructActiveFormattingElementss4     z/TreeBuilder.reconstructActiveFormattingElementscCs@|j}|jr|tkr|j}|jr|tks dSdSdSdSr:)rQpoprC)rrhrrrclearActiveFormattingElementss  z)TreeBuilder.clearActiveFormattingElementscCs:|jdddD]}|tkrdS|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)rQrCr)rritemrrr!elementInActiveFormattingElements s z-TreeBuilder.elementInActiveFormattingElementscCs&||}|j||j|dSr:) createElementrPrFrVr-)rtokenrHrrr insertRoots  zTreeBuilder.insertRootcCs6|d}|d}|d}||||}|j|dS)NrpublicIdsystemId) doctypeClassrVr-)rrprrrrsdoctyperrr insertDoctype s zTreeBuilder.insertDoctypecCs*|dur |jd}|||ddS)Nr@r/)rPr- commentClass)rrprrrr insertComment(s zTreeBuilder.insertCommentcCs0|d}|d|j}|||}|d|_|S)z.Create an element but don't insert it anywhererrdr/)getrM elementClassrrrprrdrHrrrro-s   zTreeBuilder.createElementcC|jSr:)_insertFromTabler&rrr_getInsertFromTable5szTreeBuilder._getInsertFromTablecCs"||_|r |j|_dS|j|_dS)zsSwitch the function used to insert an element from the normal one to the misnested table one and back againN)r}insertElementTablerfinsertElementNormal)rrrrr_setInsertFromTable8s  zTreeBuilder._setInsertFromTablecCsb|d}t|tsJd||d|j}|||}|d|_|jd||j||S)NrzElement %s not unicoderdr/r@) rXrryrMrzrrPr-rFr{rrrrCs   zTreeBuilder.insertElementNormalcCs`||}|jdjtvr||S|\}}|dur"||n||||j||S)z-Create an element and insert it into the treer@N) rorPrrrgetTableMisnestedNodePositionr-r0rF)rrprHrr0rrrrMs      zTreeBuilder.insertElementTablecCsX|dur |jd}|jr|jr|jdjtvr||dS|\}}|||dS)zInsert text data.Nr@)rPrTrrr1r)rr/rr0rrrr1]s    zTreeBuilder.insertTextcCsd}d}d}|jdddD] }|jdkr|}nq|r7|jr(|j}|}||fS|j|j|d}||fS|jd}||fS)zsGet the foster parent element, and sibling to insert before (or None) when inserting a misnested table nodeNr@rrAr)rPrrindex)r lastTable fosterParentr0elmrrrrls&  z)TreeBuilder.getTableMisnestedNodePositioncCs@|jdj}|tdvr||kr|j||dSdSdS)Nr@)dddtlirrprprt)rPr frozensetrkgenerateImpliedEndTags)rexcluderrrrrs   z"TreeBuilder.generateImpliedEndTagscCr|)zReturn the final tree)rVr&rrr getDocumentszTreeBuilder.getDocumentcCs|}|jd||S)zReturn the final fragmentr) fragmentClassrPr7)rfragmentrrr getFragmentszTreeBuilder.getFragmentcCr()zSerialize the subtree of node in the format required by unit tests :arg node: the node from which to start serializing r)r+rrrtestSerializerr.zTreeBuilder.testSerializerr:)r;r<r=r>rUrzrwrtrrrNrarjrlrnrqrvrxror~rpropertyrTrrr1rrrrrrrrrrLs8  .      rL) __future__rrrpip._vendor.sixr constantsrrr rCrrZobjectrrr?rLrrrrs2        c