Current File : //lib/python3.9/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/base.cpython-39.pyc
a

[��f�8�@s�ddlmZmZmZddlmZddlmZmZm	Z	dZ
ee�dfeee	ddfhB�dfeee	dd	fe	dd
fhB�dfee	ddfe	ddfg�dfee	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	�Zddd�Zd
d�Z	dd�Z
dd�Zdd�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.9/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�
<listcomp>.s�z Node.__str__.<locals>.<listcomp>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	newParent�childrrr�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)rZnode1Znode2rrrr9�s
z#ActiveFormattingElements.nodesEqualN)r0r1r2r;r9rrrrr4zs
r4c@s�eZdZdZdZdZdZdZdZdd�Z	dd�Z
d+dd�Zd	d
�Zdd�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)�openElementsr4�activeFormattingElementsZheadPointerZformPointer�insertFromTable�
documentClass�documentr!rrrr@�szTreeBuilder.resetcCs�t|d�}|s2t|t�r$td|f}t|t�s2J�t|\}}t|j�D]>}|r^||kr^dS|sr|j|krrdS||j|vArHdSqHds�J�dS)Nr=r
TF)	�hasattr�
isinstancerr	�tuple�listElementsMap�reversedrAr=)r�targetZvariantZ	exactNodeZlistElements�invertr&rrr�elementInScope�s

zTreeBuilder.elementInScopecCs�|js
dSt|j�d}|j|}|tks4||jvr8dS|tkrl||jvrl|dkrXd}ql|d8}|j|}q8|d7}|j|}|��}|�d|j|j|jd��}||j|<||jdkrlq�qldS)Nr6rr5ZStartTag)�typer�	namespacer()	rB�lenr8rAr.�
insertElementrrOr)r�i�entryZcloner<rrr�#reconstructActiveFormattingElements�s.

�
z/TreeBuilder.reconstructActiveFormattingElementscCs(|j��}|jr$|tkr$|j��}q
dS�N)rB�popr8)rrSrrr�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 falseNr5F)rBr8r)rr�itemrrr�!elementInActiveFormattingElements
s

z-TreeBuilder.elementInActiveFormattingElementscCs&|�|�}|j�|�|j�|�dSrU)�
createElementrAr;rEr')r�tokenr<rrr�
insertRoots
zTreeBuilder.insertRootcCs6|d}|d}|d}|�|||�}|j�|�dS)Nr�publicId�systemId)�doctypeClassrEr')rr[rr]r^Zdoctyperrr�
insertDoctype s
zTreeBuilder.insertDoctypecCs*|dur|jd}|�|�|d��dS)Nr5r()rAr'�commentClass)rr[rrrr�
insertComment(s
zTreeBuilder.insertCommentcCs0|d}|�d|j�}|�||�}|d|_|S)z.Create an element but don't insert it anywhererrOr()�getr?�elementClassr�rr[rrOr<rrrrZ-s

zTreeBuilder.createElementcCs|jSrU)�_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)rf�insertElementTablerQ�insertElementNormal)rrrrr�_setInsertFromTable8s
zTreeBuilder._setInsertFromTablecCsb|d}t|t�sJd|��|�d|j�}|�||�}|d|_|jd�|�|j�|�|S)NrzElement %s not unicoderOr(r5)	rGrrcr?rdrrAr'r;rerrrriCs
zTreeBuilder.insertElementNormalcCs`|�|�}|jdjtvr$|�|�S|��\}}|durD|�|�n|�||�|j�|�|S)z-Create an element and insert it into the treer5N)	rZrArrri�getTableMisnestedNodePositionr'r)r;)rr[r<rr)rrrrhMs

zTreeBuilder.insertElementTablecCsV|dur|jd}|jr.|jr:|jdjtvr:|�|�n|��\}}|�||�dS)zInsert text data.Nr5)rArCrrr*rk)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 nodeNr5rr6r)rArr�index)rZ	lastTableZfosterParentr)Zelmrrrrkls 
�
z)TreeBuilder.getTableMisnestedNodePositioncCs8|jdj}|td�vr4||kr4|j��|�|�dS)Nr5)�ddZdtZlirr
�pZrpZrt)rAr�	frozensetrV�generateImpliedEndTags)rZexcluderrrrrp�s�
z"TreeBuilder.generateImpliedEndTagscCs|jS)zReturn the final tree)rEr!rrr�getDocument�szTreeBuilder.getDocumentcCs|��}|jd�|�|S)zReturn the final fragmentr)�
fragmentClassrAr-)r�fragmentrrr�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)r0r1r2r3rDrdrar_rrrr@rMrTrWrYr\r`rbrZrgrj�propertyrCrirhr*rkrprqrtrurrrrr>�s6
.
	




r>)Z
__future__rrrZpip._vendor.sixrZ	constantsrrr	r8rorI�objectrrr4r>rrrr�<module>s0

��
��
���c