U ÀÒ.eó8ã@súddlmZmZmZddlmZddlmZmZm Z dZ e eƒdfe ee e ddfgƒBƒdfe ee e dd fe dd fgƒBƒdfe e ddfe dd fgƒdfe e dd fe dd fgƒdfdœZ Gdd„deƒZGdd„deƒZGdd„deƒZdS)é)Úabsolute_importÚdivisionÚunicode_literals)Ú text_typeé)ÚscopingElementsÚtableInsertModeElementsÚ namespacesNFÚhtmlÚbuttonZolZulÚtableÚoptgroupÚoptionT)Nr Úlistr Zselectc@sbeZdZdZdd„Zdd„Zdd„Zdd „Zdd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z 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)ÚnameÚparentÚvalueÚ attributesÚ childNodesZ_flags)Úselfr©rúJ/usr/lib/python3.8/site-packages/pip/_vendor/html5lib/treebuilders/base.pyÚ__init__s z Node.__init__cCs:d dd„|j ¡Dƒ¡}|r,d|j|fSd|jSdS)Nú cSsg|]\}}d||f‘qS)z%s="%s"r)Ú.0rrrrrÚ .sÿz Node.__str__..z<%s %s>ú<%s>)ÚjoinrÚitemsr)rZ attributesStrrrrÚ__str__-s  þz Node.__str__cCs d|jS)Nr)r©rrrrÚ__repr__6sz Node.__repr__cCst‚dS)z[Insert node as a child of the current node :arg node: the node to insert N©ÚNotImplementedError©rÚnoderrrÚ appendChild9szNode.appendChildNcCst‚dS)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#)rÚdataÚ insertBeforerrrÚ insertTextAs zNode.insertTextcCst‚dS)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&ZrefNoderrrr)Ms zNode.insertBeforecCst‚dS)zhRemove node from the children of the current node :arg node: the child node to remove Nr#r%rrrÚ removeChildYszNode.removeChildcCs |jD]}| |¡qg|_dS)zôMove 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')rZ newParentZchildrrrÚreparentChildrenas  zNode.reparentChildrencCst‚dS)zŠReturn 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.cloneNodecCst‚dS)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)r+r,r-r.rrrrrs    rc@seZdZdd„Zdd„ZdS)ÚActiveFormattingElementscCsfd}|tkrV|ddd…D]:}|tkr*qV| ||¡r>|d7}|dkr| |¡qVqt ||¡dS)Nréÿÿÿÿéé)ÚMarkerÚ nodesEqualÚremoverÚappend)rr&Z equalCountÚelementrrrr:{s  zActiveFormattingElements.appendcCs$|j|jksdS|j|jks dSdS)NFT)Ú nameTupler)rZnode1Znode2rrrr8ˆs   z#ActiveFormattingElements.nodesEqualN)r/r0r1r:r8rrrrr3zs r3c@sÖeZdZdZdZdZdZdZdZdd„Z dd„Z d+dd„Z d d „Z d d „Z d d„Zdd„Zdd„Zd,dd„Zdd„Zdd„Zdd„ZeeeƒZdd„Zdd„Zd-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)ÚdefaultNamespaceÚreset)rZnamespaceHTMLElementsrrrr¬szTreeBuilder.__init__cCs.g|_tƒ|_d|_d|_d|_| ¡|_dS)NF)Ú openElementsr3ÚactiveFormattingElementsZ headPointerZ formPointerÚinsertFromTableÚ documentClassÚdocumentr!rrrr?¸s zTreeBuilder.resetcCs~t|dƒ}|s$t|tƒr$td|f}t|\}}t|jƒD]>}|rP||krPdS|sd|j|krddS||j|kAr:dSq:dS)Nr<r TF)ÚhasattrÚ isinstancerr ÚlistElementsMapÚreversedr@r<)rÚtargetZvariantZ exactNodeZ listElementsÚinvertr&rrrÚelementInScopeÄs     zTreeBuilder.elementInScopecCsÀ|js dSt|jƒd}|j|}|tks4||jkr8dS|tkrl||jkrl|dkrXd}ql|d8}|j|}q8|d7}|j|}| ¡}| d|j|j|jdœ¡}||j|<||jdkrlq¼qldS)Nr5rr4ZStartTag)ÚtyperÚ namespacer() rAÚlenr7r@r-Ú insertElementrrMr)rÚiÚentryZcloner;rrrÚ#reconstructActiveFormattingElementsÚs.   ý z/TreeBuilder.reconstructActiveFormattingElementscCs(|j ¡}|jr$|tkr$|j ¡}q dS©N)rAÚpopr7)rrQrrrÚclearActiveFormattingElementss z)TreeBuilder.clearActiveFormattingElementscCs:|jddd…D]$}|tkr"q6q|j|kr|SqdS)zšCheck if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return falseNr4F)rAr7r)rrÚitemrrrÚ!elementInActiveFormattingElements s   z-TreeBuilder.elementInActiveFormattingElementscCs&| |¡}|j |¡|j |¡dSrS)Ú createElementr@r:rDr')rÚtokenr;rrrÚ insertRoots  zTreeBuilder.insertRootcCs6|d}|d}|d}| |||¡}|j |¡dS)NrÚpublicIdÚsystemId)Ú doctypeClassrDr')rrYrr[r\ZdoctyperrrÚ insertDoctype s zTreeBuilder.insertDoctypecCs*|dkr|jd}| | |d¡¡dS)Nr4r()r@r'Ú commentClass)rrYrrrrÚ insertComment(s zTreeBuilder.insertCommentcCs0|d}| d|j¡}| ||¡}|d|_|S)z.Create an element but don't insert it anywhererrMr()Úgetr>Ú elementClassr©rrYrrMr;rrrrX-s   zTreeBuilder.createElementcCs|jSrS)Ú_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)rdÚinsertElementTablerOÚinsertElementNormal)rrrrrÚ_setInsertFromTable8s zTreeBuilder._setInsertFromTablecCsL|d}| d|j¡}| ||¡}|d|_|jd |¡|j |¡|S)NrrMr(r4)rar>rbrr@r'r:rcrrrrgCs   zTreeBuilder.insertElementNormalcCs`| |¡}|jdjtkr$| |¡S| ¡\}}|dkrD| |¡n | ||¡|j |¡|S)z-Create an element and insert it into the treer4N) rXr@rrrgÚgetTableMisnestedNodePositionr'r)r:)rrYr;rr)rrrrfMs      zTreeBuilder.insertElementTablecCsV|dkr|jd}|jr.|jr:|jdjtkr:| |¡n| ¡\}}| ||¡dS)zInsert text data.Nr4)r@rBrrr*ri)rr(rr)rrrr*]s   ÿÿ  zTreeBuilder.insertTextcCstd}d}d}|jddd…D]}|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 nodeNr4r r5r)r@rrÚindex)rZ lastTableZ fosterParentr)Zelmrrrrils  ÿ z)TreeBuilder.getTableMisnestedNodePositioncCs8|jdj}|tdƒkr4||kr4|j ¡| |¡dS)Nr4)ZddZdtZlirr ÚpZrpZrt)r@rÚ frozensetrTÚgenerateImpliedEndTags)rÚexcluderrrrrm†s   ÿ z"TreeBuilder.generateImpliedEndTagscCs|jS)zReturn the final tree)rDr!rrrÚ getDocument�szTreeBuilder.getDocumentcCs| ¡}|jd |¡|S)zReturn the final fragmentr)Ú fragmentClassr@r,)rZfragmentrrrÚ getFragment”szTreeBuilder.getFragmentcCst‚dS)z‰Serialize the subtree of node in the format required by unit tests :arg node: the node from which to start serializing Nr#r%rrrÚtestSerializer›szTreeBuilder.testSerializer)N)N)N)N)r/r0r1r2rCrbr_r]rprr?rKrRrUrWrZr^r`rXrerhÚpropertyrBrgrfr*rirmrorqrrrrrrr=’s6   .     r=)Z __future__rrrZpip._vendor.sixrZ constantsrrr r7rlÚsetrGÚobjectrrr3r=rrrrÚs0   ÿÿ  ÿÿ  ÿÿù c