ó
^†êWc           @` 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` se   e  Z d  „  Z d „  Z d „  Z d „  Z d
 d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(   c         C` s:   | |  _  d |  _ d |  _ i  |  _ g  |  _ g  |  _ d S(   u6  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(   t   namet   Nonet   parentt   valuet
   attributest
   childNodest   _flags(   t   selfR   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   __str__*   s
    	2c         C` s   d |  j  S(   Nu   <%s>(   R   (   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   __repr__3   s    c         C` s
   t  ‚ d S(   u3   Insert node as a child of the current node
        N(   t   NotImplementedError(   R   t   node(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   appendChild6   s    c         C` s
   t  ‚ d S(   uŒ   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   t   datat   insertBefore(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt
   insertText;   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 nodeN(   R   (   R   R   t   refNode(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyR   A   s    c         C` s
   t  ‚ d S(   u:   Remove node from the children of the current node
        N(   R   (   R   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   removeChildG   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
        N(   R   R   (   R   t	   newParentt   child(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   reparentChildrenL   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   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt	   cloneNodeV   s    c         C` s
   t  ‚ d S(   uF   Return true if the node has children or text, false otherwise
        N(   R   (   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt
   hasContent\   s    N(   t   __name__t
   __module__R   R   R   R   R	   R   R   R   R    R!   R"   (    (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyR*   c   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(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyR'   p   s
    (   R#   R$   R*   R'   (    (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyR%   b   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(   Nu   http://www.w3.org/1999/xhtml(   t   defaultNamespaceR	   t   reset(   R   t   namespaceHTMLElements(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyR4   ˜   s    				c         C` sŒ   t  | d ƒ } t | \ } } xZ t |  j ƒ D]I } | j | k rK | s] | | k ra | ra t S| | j | k Ar/ t Sq/ Wt sˆ t ‚ d  S(   Nu	   nameTuple(	   t   hasattrt   listElementsMapt   reversedR6   R   R/   R-   R.   t   AssertionError(   R   t   targett   variantt	   exactNodet   listElementst   invertR   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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(
   R7   t   lenR&   R6   R/   R!   t   insertElementR   t	   namespaceR   (   R   t   it   entryt   cloneR,   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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(   R7   t   popR&   (   R   RK   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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ÿÿÿÿ(   R7   R&   R   R.   (   R   R   t   item(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt!   elementInActiveFormattingElementsè   s    c         C` s3   |  j  | ƒ } |  j j | ƒ |  j j | ƒ d  S(   N(   t   createElementR6   R*   R<   R   (   R   t   tokenR,   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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   RS   R   t   publicIdt   systemIdt   doctype(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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	   R6   R   t   commentClass(   R   RS   R
   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/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   getR3   t   elementClassR   (   R   RS   R   RI   R,   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyRR     s
    
c         C` s   |  j  S(   N(   t   _insertFromTable(   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   _getInsertFromTable  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(   R^   t   insertElementTableRH   t   insertElementNormal(   R   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   _setInsertFromTable  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ÿÿÿÿ(
   t
   isinstanceR   R@   R\   R3   R]   R   R6   R   R*   (   R   RS   R   RI   R,   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyRa     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(
   RR   R6   R   R   Ra   t   getTableMisnestedNodePositionR	   R   R   R*   (   R   RS   R,   R
   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyR`   (  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	   R6   R:   R   R   R   Rd   (   R   R   R
   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyR   8  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	   R6   R   R
   t   index(   R   t	   lastTablet   fosterParentR   t   elm(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyRd   G  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(   R6   R   t	   frozensetRN   t   generateImpliedEndTags(   R   t   excludeR   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyRj   a  s
    c         C` s   |  j  S(   u   Return the final tree(   R<   (   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   getDocumentk  s    c         C` s$   |  j  ƒ  } |  j d j | ƒ | S(   u   Return the final fragmenti    (   t   fragmentClassR6   R    (   R   t   fragment(    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   getFragmento  s    c         C` s
   t  ‚ d S(   uz   Serialize the subtree of node in the format required by unit tests
        node - the node from which to start serializingN(   R   (   R   R   (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   testSerializerv  s    N(   R#   R$   t   __doc__R	   R;   R]   RZ   RU   Rm   R   R4   RF   RM   RO   RQ   RT   RY   R[   RR   R_   Rb   t   propertyR:   Ra   R`   R   Rd   Rj   Rl   Ro   Rp   (    (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyR2   z   s6   			.									
		
		N(   t
   __future__R    R   R   t   pip._vendor.sixR   t	   constantsR   R   R   R	   R&   Ri   R.   t   setR/   R>   t   objectR   R)   R%   R2   (    (    (    sx   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/treebuilders/_base.pyt   <module>   s   *! K