ó
ä™L]c           @` sh  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 i e e ƒ e f d 6e e e e	 d d f g ƒ Bƒ e f d 6e e e e	 d d f e	 d d f g ƒ Bƒ e f d	 6e e	 d d f e	 d d
 f g ƒ e f d
 6e e	 d d f e	 d d f g ƒ e f d 6Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   i    (   t   absolute_importt   divisiont   unicode_literals(   t	   text_typei   (   t   scopingElementst   tableInsertModeElementst
   namespacesu   htmlu   buttonu   olu   ulu   listu   tableu   optgroupu   optionu   selectt   Nodec           B` sk   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z RS(   u   Represents an item in the treec         C` s:   | |  _  d |  _ d |  _ i  |  _ g  |  _ g  |  _ d S(   uR   Creates a Node

        :arg name: The tag name associated with the node

        N(   t   namet   Nonet   parentt   valuet
   attributest
   childNodest   _flags(   t   selfR   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   __init__   s    					c         C` sa   d j  g  |  j j ƒ  D] \ } } d | | f ^ q ƒ } | rR d |  j | f Sd |  j Sd  S(   Nu    u   %s="%s"u   <%s %s>u   <%s>(   t   joinR   t   itemsR   (   R   R   R   t   attributesStr(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   __str__-   s
    	2c         C` s   d |  j  S(   Nu   <%s>(   R   (   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   __repr__6   s    c         C` s
   t  ‚ d S(   u[   Insert node as a child of the current node

        :arg node: the node to insert

        N(   t   NotImplementedError(   R   t   node(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   appendChild9   s    c         C` s
   t  ‚ d S(   uB  Insert 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

        N(   R   (   R   t   datat   insertBefore(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt
   insertTextA   s    
c         C` s
   t  ‚ d S(   u  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 node

        :arg node: the node to insert

        :arg refNode: the child node to insert the node before

        N(   R   (   R   R   t   refNode(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR   M   s    
c         C` s
   t  ‚ d S(   uh   Remove node from the children of the current node

        :arg node: the child node to remove

        N(   R   (   R   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   removeChildY   s    c         C` s.   x |  j  D] } | j | ƒ q
 Wg  |  _  d S(   uô   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(   R   R   (   R   t	   newParentt   child(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   reparentChildrena   s    	c         C` s
   t  ‚ d S(   uŠ   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   (   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt	   cloneNoden   s    c         C` s
   t  ‚ d S(   uF   Return true if the node has children or text, false otherwise
        N(   R   (   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt
   hasContentt   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R	   R   R   R   R    R!   R"   (    (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR      s   									t   ActiveFormattingElementsc           B` s   e  Z d  „  Z d „  Z RS(   c         C` s“   d } | t  k r xj |  d  d  d … D]R } | t  k r< Pn  |  j | | ƒ r[ | d 7} n  | d k r& |  j | ƒ Pq& q& Wn  t j |  | ƒ d  S(   Ni    iÿÿÿÿi   i   (   t   Markert
   nodesEqualt   removet   listt   append(   R   R   t
   equalCountt   element(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR+   {   s    c         C` s0   | j  | j  k s t S| j | j k s, t St S(   N(   t	   nameTuplet   FalseR   t   True(   R   t   node1t   node2(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR(   ˆ   s
    (   R#   R$   R+   R(   (    (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR&   z   s   	t   TreeBuilderc           B` sû   e  Z d  Z d Z d Z d Z d Z d Z d „  Z	 d „  Z
 d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d	 „ Z d
 „  Z d „  Z d „  Z e e e ƒ Z d „  Z d „  Z d d „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   u  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

    c         C` s)   | r d |  _  n	 d |  _  |  j ƒ  d S(   um   Create a TreeBuilder

        :arg namespaceHTMLElements: whether or not to namespace HTML elements

        u   http://www.w3.org/1999/xhtmlN(   t   defaultNamespaceR	   t   reset(   R   t   namespaceHTMLElements(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR   ¬   s    	c         C` sC   g  |  _  t ƒ  |  _ d  |  _ d  |  _ t |  _ |  j ƒ  |  _	 d  S(   N(
   t   openElementsR&   t   activeFormattingElementsR	   t   headPointert   formPointerR/   t   insertFromTablet   documentClasst   document(   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR5   ¸   s    				c         C` sÐ   t  | d ƒ } | sO t | t ƒ r7 t d | f } n  t | t ƒ sO t ‚ n  t | \ } } x^ t |  j ƒ D]M } | r‹ | | k r‹ t	 S| r¥ | j
 | k r¥ t	 S| | j
 | k Aro t Sqo Wt sÌ t ‚ d  S(   Nu	   nameTupleu   html(   t   hasattrt
   isinstanceR   R   t   tuplet   AssertionErrort   listElementsMapt   reversedR7   R0   R.   R/   (   R   t   targett   variantt	   exactNodet   listElementst   invertR   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   elementInScopeÄ   s    c         C` s'  |  j  s d  St |  j  ƒ d } |  j  | } | t k sH | |  j k rL d  SxL | t k rš | |  j k rš | d k r€ d } Pn  | d 8} |  j  | } qO Wx… t r"| d 7} |  j  | } | j ƒ  } |  j i d d 6| j d 6| j d 6| j	 d 6ƒ } | |  j  | <| |  j  d k rž Pqž qž Wd  S(	   Ni   i    iÿÿÿÿu   StartTagu   typeu   nameu	   namespaceu   data(
   R8   t   lenR'   R7   R0   R!   t   insertElementR   t	   namespaceR   (   R   t   it   entryt   cloneR-   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt#   reconstructActiveFormattingElementsÚ   s.    	
	


c         C` s>   |  j  j ƒ  } x( |  j  r9 | t k r9 |  j  j ƒ  } q Wd  S(   N(   R8   t   popR'   (   R   RN   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   clearActiveFormattingElements  s    c         C` sH   xA |  j  d d d … D]) } | t k r- Pq | j | k r | Sq Wt S(   uš   Check if an element exists between the end of the active
        formatting elements and the last marker. If it does, return it, else
        return falseNiÿÿÿÿ(   R8   R'   R   R/   (   R   R   t   item(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt!   elementInActiveFormattingElements  s    c         C` s3   |  j  | ƒ } |  j j | ƒ |  j j | ƒ d  S(   N(   t   createElementR7   R+   R=   R   (   R   t   tokenR-   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt
   insertRoot  s    c         C` sG   | d } | d } | d } |  j  | | | ƒ } |  j j | ƒ d  S(   Nu   nameu   publicIdu   systemId(   t   doctypeClassR=   R   (   R   RV   R   t   publicIdt   systemIdt   doctype(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   insertDoctype   s
    


c         C` s:   | d  k r |  j d } n  | j |  j | d ƒ ƒ d  S(   Niÿÿÿÿu   data(   R	   R7   R   t   commentClass(   R   RV   R
   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   insertComment(  s    c         C` sB   | d } | j  d |  j ƒ } |  j | | ƒ } | d | _ | S(   u.   Create an element but don't insert it anywhereu   nameu	   namespaceu   data(   t   getR4   t   elementClassR   (   R   RV   R   RL   R-   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyRU   -  s
    
c         C` s   |  j  S(   N(   t   _insertFromTable(   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   _getInsertFromTable5  s    c         C` s.   | |  _  | r |  j |  _ n |  j |  _ d S(   us   Switch the function used to insert an element from the
        normal one to the misnested table one and back againN(   Ra   t   insertElementTableRK   t   insertElementNormal(   R   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   _setInsertFromTable8  s    	c         C` s…   | d } t  | t ƒ s) t d | ƒ ‚ | j d |  j ƒ } |  j | | ƒ } | d | _ |  j d j | ƒ |  j j	 | ƒ | S(   Nu   nameu   Element %s not unicodeu	   namespaceu   dataiÿÿÿÿ(
   R?   R   RA   R_   R4   R`   R   R7   R   R+   (   R   RV   R   RL   R-   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyRd   C  s    
c         C` s„   |  j  | ƒ } |  j d j t k r2 |  j | ƒ S|  j ƒ  \ } } | d k r` | j | ƒ n | j | | ƒ |  j j	 | ƒ | S(   u-   Create an element and insert it into the treeiÿÿÿÿN(
   RU   R7   R   R   Rd   t   getTableMisnestedNodePositionR	   R   R   R+   (   R   RV   R-   R
   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyRc   M  s    c         C` s{   | d k r |  j d } n  |  j sE |  j rU |  j d j t k rU | j | ƒ n" |  j ƒ  \ } } | j | | ƒ d S(   u   Insert text data.iÿÿÿÿN(   R	   R7   R;   R   R   R   Rf   (   R   R   R
   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR   ]  s    	c         C` s¤   d } d } d } x7 |  j d d d … D] } | j d k r) | } Pq) q) W| r� | j rm | j } | } qš |  j |  j j | ƒ d } n |  j d } | | f S(   us   Get the foster parent element, and sibling to insert before
        (or None) when inserting a misnested table nodeNiÿÿÿÿu   tablei   i    (   R	   R7   R   R
   t   index(   R   t	   lastTablet   fosterParentR   t   elm(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyRf   l  s    			c      
   C` sO   |  j  d j } | t d
 ƒ k rK | | k rK |  j  j ƒ  |  j | ƒ n  d  S(   Niÿÿÿÿu   ddu   dtu   liu   optionu   optgroupu   pu   rpu   rt(   u   ddu   dtu   liu   optionu   optgroupu   pu   rpu   rt(   R7   R   t	   frozensetRQ   t   generateImpliedEndTags(   R   t   excludeR   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyRl   †  s
    c         C` s   |  j  S(   u   Return the final tree(   R=   (   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   getDocument�  s    c         C` s$   |  j  ƒ  } |  j d j | ƒ | S(   u   Return the final fragmenti    (   t   fragmentClassR7   R    (   R   t   fragment(    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   getFragment”  s    c         C` s
   t  ‚ d S(   u‰   Serialize the subtree of node in the format required by unit tests

        :arg node: the node from which to start serializing

        N(   R   (   R   R   (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   testSerializer›  s    N(   R#   R$   R%   R	   R<   R`   R]   RX   Ro   R   R5   RI   RP   RR   RT   RW   R\   R^   RU   Rb   Re   t   propertyR;   Rd   Rc   R   Rf   Rl   Rn   Rq   Rr   (    (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyR3   ’   s6   			.									
		
		N(   t
   __future__R    R   R   t   pip._vendor.sixR   t	   constantsR   R   R   R	   R'   Rk   R/   t   setR0   RB   t   objectR   R*   R&   R3   (    (    (    sC   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treebuilders/base.pyt   <module>   s   *! c