
вEbc           @` 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 i e e  e f d 6e e e	 d d f h B e f d 6e e e	 d d f e	 d d f h 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-UPPWic/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-UPPWic/pip/pip/_vendor/html5lib/treebuilders/base.pyt   __str__-   s
    	2c         C` s   d |  j  S(   Nu   <%s>(   R   (   R   (    (    sC   /tmp/pip-build-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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    ii   i   (   t   Markert
   nodesEqualt   removet   listt   append(   R   R   t
   equalCountt   element(    (    sC   /tmp/pip-build-UPPWic/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-UPPWic/pip/pip/_vendor/html5lib/treebuilders/base.pyR(      s
    (   R#   R$   R+   R(   (    (    (    sC   /tmp/pip-build-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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    iu   StartTagu   typeu   nameu	   namespaceu   data(
   R8   t   lenR'   R7   R0   R!   t   insertElementR   t	   namespaceR   (   R   t   it   entryt   cloneR-   (    (    sC   /tmp/pip-build-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/pip/pip/_vendor/html5lib/treebuilders/base.pyt   insertDoctype   s
    


c         C` s:   | d  k r |  j d } n  | j |  j | d   d  S(   Niu   data(   R	   R7   R   t   commentClass(   R   RV   R
   (    (    sC   /tmp/pip-build-UPPWic/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-UPPWic/pip/pip/_vendor/html5lib/treebuilders/base.pyRU   -  s
    
c         C` s   |  j  S(   N(   t   _insertFromTable(   R   (    (    sC   /tmp/pip-build-UPPWic/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-UPPWic/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-UPPWic/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 treeiN(
   RU   R7   R   R   Rd   t   getTableMisnestedNodePositionR	   R   R   R+   (   R   RV   R-   R
   R   (    (    sC   /tmp/pip-build-UPPWic/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.iN(   R	   R7   R;   R   R   R   Rf   (   R   R   R
   R   (    (    sC   /tmp/pip-build-UPPWic/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 nodeNiu   tablei   i    (   R	   R7   R   R
   t   index(   R   t	   lastTablet   fosterParentR   t   elm(    (    sC   /tmp/pip-build-UPPWic/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(   Niu   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-UPPWic/pip/pip/_vendor/html5lib/treebuilders/base.pyRl     s
    c         C` s   |  j  S(   u   Return the final tree(   R=   (   R   (    (    sC   /tmp/pip-build-UPPWic/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-UPPWic/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-UPPWic/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-UPPWic/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/   R0   RB   t   objectR   R*   R&   R3   (    (    (    sC   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treebuilders/base.pyt   <module>   s   $ c