3 ÝPfv6ã@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@s^eZdZdd„Zdd„Zdd„Zdd„Zdd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z 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)ÚnameÚparentÚvalueÚ attributesÚ childNodesZ_flags)Úselfr©rú/usr/lib/python3.6/base.pyÚ__init__s z Node.__init__cCs:djdd„|jjƒDƒƒ}|r,d|j|fSd|jSdS)Nú cSsg|]\}}d||f‘qS)z%s="%s"r)Ú.0rrrrrú +sz Node.__str__..z<%s %s>z<%s>)ÚjoinrÚitemsr)rZ attributesStrrrrÚ__str__*s  z Node.__str__cCs d|jS)Nz<%s>)r)rrrrÚ__repr__3sz Node.__repr__cCst‚dS)z3Insert node as a child of the current node N)ÚNotImplementedError)rÚnoderrrÚ appendChild6szNode.appendChildNcCst‚dS)zŒInsert 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!)rÚdataÚ insertBeforerrrÚ insertText;szNode.insertTextcCst‚dS)z¦Insert 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"ZrefNoderrrr%AszNode.insertBeforecCst‚dS)z:Remove node from the children of the current node N)r!)rr"rrrÚ removeChildGszNode.removeChildcCs$x|jD]}|j|ƒqWg|_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 N)rr#)rZ newParentZchildrrrÚreparentChildrenLs 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 N)r!)rrrrÚ cloneNodeVszNode.cloneNodecCst‚dS)zFReturn true if the node has children or text, false otherwise N)r!)rrrrÚ hasContent\szNode.hasContent)N) Ú__name__Ú __module__Ú __qualname__rrr r#r&r%r'r(r)r*rrrrrs   rc@seZdZdd„Zdd„ZdS)ÚActiveFormattingElementscCsfd}|tkrVxH|ddd…D]6}|tkr*P|j||ƒr>|d7}|dkr|j|ƒPqWtj||ƒdS)Nréééÿÿÿÿ)ÚMarkerÚ nodesEqualÚremoverÚappend)rr"Z equalCountÚelementrrrr5cs  zActiveFormattingElements.appendcCs$|j|jksdS|j|jks dSdS)NFT)Ú nameTupler)rZnode1Znode2rrrr3ps   z#ActiveFormattingElements.nodesEqualN)r+r,r-r5r3rrrrr.bs r.c@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|_|jƒdS)Nzhttp://www.w3.org/1999/xhtml)ÚdefaultNamespaceÚreset)rZnamespaceHTMLElementsrrrr’szTreeBuilder.__init__cCs.g|_tƒ|_d|_d|_d|_|jƒ|_dS)NF)Ú openElementsr.ÚactiveFormattingElementsZ headPointerZ formPointerÚinsertFromTableÚ documentClassÚdocument)rrrrr:™s zTreeBuilder.resetcCs~t|dƒ}|s$t|tƒr$td|f}t|\}}xHt|jƒD]:}|rP||krPdS| rd|j|krddS||j|kArs    zTreeBuilder.insertTextcCsvd}d}d}x(|jddd…D]}|jdkr|}PqW|rd|jrL|j}|}qn|j|jj|ƒd}n |jd}||fS)zsGet the foster parent element, and sibling to insert before (or None) when inserting a misnested table nodeNr/r rr1)r;rrÚindex)rZ lastTableZ fosterParentr%ZelmrrrrbMs  z)TreeBuilder.getTableMisnestedNodePositionc Cs8|jd j}|td ƒkr4||kr4|jjƒ|j|ƒdS) Nr/ÚddÚdtÚlirr ÚpÚrpÚrtr1)rdrerfrr rgrhri)r;rÚ frozensetrNÚgenerateImpliedEndTags)rÚexcluderrrrrkgs    z"TreeBuilder.generateImpliedEndTagscCs|jS)zReturn the final tree)r?)rrrrÚ getDocumentqszTreeBuilder.getDocumentcCs|jƒ}|jdj|ƒ|S)zReturn the final fragmentr)Ú fragmentClassr;r()rZfragmentrrrÚ getFragmentuszTreeBuilder.getFragmentcCst‚dS)zzSerialize the subtree of node in the format required by unit tests node - the node from which to start serializingN)r!)rr"rrrÚtestSerializer|szTreeBuilder.testSerializer)N)N)N)N)r+r,r-Ú__doc__r>r\rYrWrnrr:rFrMrOrQrTrXrZrRr^raÚpropertyr=r`r_r&rbrkrmrorprrrrr8zs6 .     r8)Z __future__rrrZpip._vendor.sixrZ constantsrrr r2rjÚsetrBÚobjectrrr.r8rrrrÚs    K