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