£Á°èZ¨Ä…–K§‚«“ô4“ÒÙ´dîfUÙÃÅ WKbyÊ¦•êŽ…È®FÒ¿ÊÎóCozá¬S@6{Í:›œêZÌ:Š•_%:¢¾¾~;‘Ã~èŠ©ÊÇí`ÔÑ©úë™µ'5I¿fš×WO%ø9¾«¾DK|€ùÍD”Ýs]nHÕ¶ê×Ó¼ãžªéUWŸÈË%DÒÕ¬ï‘]/Åcx  ‰ï2ß]ä6G[]S£ÔÏ¯rs{úëóµmÒï#UQxo·õÞCe]"±/aÙ&Eã4ú9Jé_ÞåëdãöKë)AÞ                  ¯¹ægƒÛowÐø^d™ý½ßB7áyMä9ÜÖUã
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<html>
3
Pfv6                 @   s   d dl mZmZmZ d dlmZ ddlmZmZm	Z	 dZ
eedfeeee	d dfgB dfeeee	d d	fe	d d
fgB dfee	d dfe	d dfgdfee	d dfe	d dfgdfdZG dd deZG dd deZG dd deZdS )    )absolute_importdivisionunicode_literals)	text_type   )scopingElementstableInsertModeElements
namespacesNFhtmlbuttonZolZultableoptgroupoptionT)Nr   listr   Zselectc               @   s^   e Zd Zdd Zdd Zdd Zdd Zdd
dZdd Zdd Z	dd Z
dd Zdd Zd	S )Nodec             C   s(   || _ d| _d| _i | _g | _g | _dS )a6  Node 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__c             C   s:   dj dd | jj D }|r,d| j|f S d| j S d S )N c             S   s   g | ]\}}d ||f qS )z%s="%s"r   ).0r   r   r   r   r   
<listcomp>+   s   z Node.__str__.<locals>.<listcomp>z<%s %s>z<%s>)joinr   itemsr   )r   ZattributesStrr   r   r   __str__*   s
    
zNode.__str__c             C   s
   d| j  S )Nz<%s>)r   )r   r   r   r   __repr__3   s    zNode.__repr__c             C   s   t dS )z3Insert node as a child of the current node
        N)NotImplementedError)r   noder   r   r   appendChild6   s    zNode.appendChildNc             C   s   t dS )zInsert 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insertBeforer   r   r   
insertText;   s    zNode.insertTextc             C   s   t dS )zInsert 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!   )r   r"   ZrefNoder   r   r   r%   A   s    zNode.insertBeforec             C   s   t dS )z:Remove node from the children of the current node
        N)r!   )r   r"   r   r   r   removeChildG   s    zNode.removeChildc             C   s$   x| j D ]}|j| qW g | _ dS )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
        N)r   r#   )r   Z	newParentZchildr   r   r   reparentChildrenL   s    zNode.reparentChildrenc             C   s   t dS )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
        N)r!   )r   r   r   r   	cloneNodeV   s    zNode.cloneNodec             C   s   t dS )zFReturn true if the node has children or text, false otherwise
        N)r!   )r   r   r   r   
hasContent\   s    zNode.hasContent)N)__name__
__module____qualname__r   r   r    r#   r&   r%   r'   r(   r)   r*   r   r   r   r   r      s   	

r   c               @   s   e Zd Zdd Zdd ZdS )ActiveFormattingElementsc             C   sf   d}|t krVxH| d d d D ]6}|t kr*P | j||r>|d7 }|dkr| j| P qW tj| | d S )Nr         )Marker
nodesEqualremover   append)r   r"   Z
equalCountelementr   r   r   r5   c   s    
zActiveFormattingElements.appendc             C   s$   |j |j ksdS |j|jks dS dS )NFT)	nameTupler   )r   Znode1Znode2r   r   r   r3   p   s
    z#ActiveFormattingElements.nodesEqualN)r+   r,   r-   r5   r3   r   r   r   r   r.   b   s   r.   c               @   s   e Zd ZdZdZdZdZdZdZdd Z	dd Z
d+ddZd	d
 Zdd Zdd Zdd Zdd Zd,ddZdd Zdd Zdd ZeeeZdd Zdd Zd-dd Zd!d" Zd.d#d$Zd%d& Zd'd( Zd)d* ZdS )/TreeBuildera  Base 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
    Nc             C   s   |rd| _ nd | _ | j  d S )Nzhttp://www.w3.org/1999/xhtml)defaultNamespacereset)r   ZnamespaceHTMLElementsr   r   r   r      s    zTreeBuilder.__init__c             C   s.   g | _ t | _d | _d | _d| _| j | _d S )NF)openElementsr.   activeFormattingElementsZheadPointerZformPointerinsertFromTabledocumentClassdocument)r   r   r   r   r:      s    zTreeBuilder.resetc             C   s~   t |d}|s$t|tr$td |f}t| \}}xHt| jD ]:}|rP||krPdS | rd|j|krddS ||j|kA r<dS q<W d S )Nr7   r
   TF)hasattr
isinstancer   r	   listElementsMapreversedr;   r7   )r   targetZvariantZ	exactNodeZlistElementsinvertr"   r   r   r   elementInScope   s    

zTreeBuilder.elementInScopec             C   s   | j s
d S t| j d }| j | }|tks4|| jkr8d S x6|tkrn|| jkrn|dkrZd}P |d8 }| j | }q:W xR|d7 }| j | }|j }| jd|j|j|jd}|| j |< || j d krrP qrW d S )Nr/   r   ZStartTag)typer   	namespacer$   r1   r1   )	r<   lenr2   r;   r)   insertElementr   rH   r   )r   ientryZcloner6   r   r   r   #reconstructActiveFormattingElements   s.    


z/TreeBuilder.reconstructActiveFormattingElementsc             C   s,   | j j }x| j r&|tkr&| j j }qW d S )N)r<   popr2   )r   rL   r   r   r   clearActiveFormattingElements   s    
z)TreeBuilder.clearActiveFormattingElementsc             C   s8   x2| j ddd D ]}|tkr"P q|j|kr|S qW dS )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/   Fr1   )r<   r2   r   )r   r   itemr   r   r   !elementInActiveFormattingElements   s    
z-TreeBuilder.elementInActiveFormattingElementsc             C   s&   | j |}| jj| | jj| d S )N)createElementr;   r5   r?   r#   )r   tokenr6   r   r   r   
insertRoot   s    
zTreeBuilder.insertRootc             C   s6   |d }|d }|d }| j |||}| jj| d S )Nr   publicIdsystemId)doctypeClassr?   r#   )r   rS   r   rU   rV   Zdoctyper   r   r   insertDoctype  s
    zTreeBuilder.insertDoctypec             C   s*   |d kr| j d }|j| j|d  d S )Nr/   r$   r1   )r;   r#   commentClass)r   rS   r   r   r   r   insertComment	  s    
zTreeBuilder.insertCommentc             C   s0   |d }|j d| j}| j||}|d |_|S )z.Create an element but don't insert it anywherer   rH   r$   )getr9   elementClassr   )r   rS   r   rH   r6   r   r   r   rR     s
    
zTreeBuilder.createElementc             C   s   | j S )N)_insertFromTable)r   r   r   r   _getInsertFromTable  s    zTreeBuilder._getInsertFromTablec             C   s    || _ |r| j| _n| j| _dS )zsSwitch the function used to insert an element from the
        normal one to the misnested table one and back againN)r]   insertElementTablerJ   insertElementNormal)r   r   r   r   r   _setInsertFromTable  s    
zTreeBuilder._setInsertFromTablec             C   sL   |d }|j d| j}| j||}|d |_| jd j| | jj| |S )Nr   rH   r$   r/   r1   )r[   r9   r\   r   r;   r#   r5   )r   rS   r   rH   r6   r   r   r   r`   $  s    
zTreeBuilder.insertElementNormalc             C   s`   | j |}| jd jtkr$| j|S | j \}}|dkrD|j| n|j|| | jj| |S )z-Create an element and insert it into the treer/   Nr1   )	rR   r;   r   r   r`   getTableMisnestedNodePositionr#   r%   r5   )r   rS   r6   r   r%   r   r   r   r_   .  s    

zTreeBuilder.insertElementTablec             C   sX   |dkr| j d }| j s0| jr<| j d jtkr<|j| n| j \}}|j|| dS )zInsert text data.Nr/   r1   r1   )r;   r=   r   r   r&   rb   )r   r$   r   r%   r   r   r   r&   >  s    

zTreeBuilder.insertTextc             C   sv   d}d}d}x(| j ddd D ]}|jdkr|}P qW |rd|jrL|j}|}qn| j | j j|d  }n
| j d }||fS )zsGet the foster parent element, and sibling to insert before
        (or None) when inserting a misnested table nodeNr/   r   r   r1   )r;   r   r   index)r   Z	lastTableZfosterParentr%   Zelmr   r   r   rb   M  s    

z)TreeBuilder.getTableMisnestedNodePositionc          
   C   s8   | j d
 j}|tdkr4||kr4| j j  | j| d S )Nr/   dddtlir   r   prprtr1   )rd   re   rf   r   r   rg   rh   ri   )r;   r   	frozensetrN   generateImpliedEndTags)r   excluder   r   r   r   rk   g  s
    
z"TreeBuilder.generateImpliedEndTagsc             C   s   | j S )zReturn the final tree)r?   )r   r   r   r   getDocumentq  s    zTreeBuilder.getDocumentc             C   s   | j  }| jd j| |S )zReturn the final fragmentr   )fragmentClassr;   r(   )r   Zfragmentr   r   r   getFragmentu  s    zTreeBuilder.getFragmentc             C   s   t dS )zzSerialize the subtree of node in the format required by unit tests
        node - the node from which to start serializingN)r!   )r   r"   r   r   r   testSerializer|  s    zTreeBuilder.testSerializer)N)N)N)N)r+   r,   r-   __doc__r>   r\   rY   rW   rn   r   r:   rF   rM   rO   rQ   rT   rX   rZ   rR   r^   ra   propertyr=   r`   r_   r&   rb   rk   rm   ro   rp   r   r   r   r   r8   z   s6   
.
	




r8   )Z
__future__r   r   r   Zpip._vendor.sixr   Z	constantsr   r   r	   r2   rj   setrB   objectr   r   r.   r8   r   r   r   r   <module>   s   
K