
bKc           @   s   d  d l  m Z m Z m Z y e Wn1 e k
 rW d  d l m Z d  d l m	 Z n Xd Z d e f d     YZ d e f d     YZ d S(	   i(   t   scopingElementst   tableInsertModeElementst
   namespaces(   t   Set(   t   ImmutableSett   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(   s8  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   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/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(   Nt    s   %s="%s"s   <%s %s>s   <%s>(   t   joinR
   t	   iteritemsR   (   R   R   R	   t   attributesStr(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   __unicode__!   s
    	2c         C   s   d |  j  S(   Ns   <%s>(   R   (   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   __repr__*   s    c         C   s
   t   d S(   s3   Insert node as a child of the current node
        N(   t   NotImplementedError(   R   t   node(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   appendChild-   s    c         C   s
   t   d S(   s   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(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt
   insertText2   s    c         C   s
   t   d S(   s   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(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyR   8   s    c         C   s
   t   d S(   s:   Remove node from the children of the current node
        N(   R   (   R   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   removeChild>   s    c         C   s.   x |  j  D] } | j |  q
 Wg  |  _  d S(   s   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(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   reparentChildrenC   s    c         C   s
   t   d S(   s   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   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt	   cloneNodeM   s    c         C   s
   t   d S(   sF   Return true if the node has children or text, false otherwise
        N(   R   (   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt
   hasContentT   s    N(   t   __name__t
   __module__R   R   R   R   R   R   R   R   R   R    R!   (    (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyR      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(   s  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(   Ns   http://www.w3.org/1999/xhtml(   t   defaultNamespaceR   t   reset(   R   t   namespaceHTMLElements(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyR   p   s    	c         C   s@   g  |  _  g  |  _ d  |  _ d  |  _ t |  _ |  j   |  _ d  S(   N(	   t   openElementst   activeFormattingElementsR   t   headPointert   formPointert   Falset   insertFromTablet   documentClasst   document(   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyR&   w   s    					c         C   s   i t  d  6t  t t d d f t d d f g  Bd 6t t d d f t d d f g  d 6} | | } x= t |  j  D], } | j | k r t S| j | k ry t	 Sqy Wt	 s t
  d  S(   Nt   htmlt   olt   ult   listt   table(   R    R   t   setR   t   reversedR(   R   t   Truet	   nameTupleR,   t   AssertionError(   R   t   targett   variantt   listElementsMapt   listElementsR   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/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    it   StartTagt   typeR   t	   namespaceR   (
   R)   t   lent   MarkerR(   R7   R    t   insertElementR   RA   R
   (   R   t   it   entryt   clonet   element(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt#   reconstructActiveFormattingElements   s.    	
	


c         C   s>   |  j  j   } x( |  j  r9 | t k r9 |  j  j   } q Wd  S(   N(   R)   t   popRC   (   R   RF   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/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(   s   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(   R)   RC   R   R,   (   R   R   t   item(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt!   elementInActiveFormattingElements   s    c         C   s3   |  j  |  } |  j j |  |  j j |  d  S(   N(   t   createElementR(   t   appendR/   R   (   R   t   tokenRH   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt
   insertRoot   s    c         C   sG   | d } | d } | d } |  j  | | |  } |  j j |  d  S(   NR   t   publicIdt   systemId(   t   doctypeClassR/   R   (   R   RP   R   RR   RS   t   doctype(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   insertDoctype   s
    


c         C   s:   | d  k r |  j d } n  | j |  j | d   d  S(   NiR   (   R   R(   R   t   commentClass(   R   RP   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   insertComment   s    c         C   sB   | d } | j  d |  j  } |  j | |  } | d | _ | S(   s.   Create an element but don't insert it anywhereR   RA   R   (   t   getR%   t   elementClassR
   (   R   RP   R   RA   RH   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyRN      s
    
c         C   s   |  j  S(   N(   t   _insertFromTable(   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   _getInsertFromTable   s    c         C   s.   | |  _  | r |  j |  _ n |  j |  _ d S(   ss   Switch the function used to insert an element from the
        normal one to the misnested table one and back againN(   R[   t   insertElementTableRD   t   insertElementNormal(   R   R	   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   _setInsertFromTable   s    	c         C   sf   | d } | j  d |  j  } |  j | |  } | d | _ |  j d j |  |  j j |  | S(   NR   RA   R   i(   RY   R%   RZ   R
   R(   R   RO   (   R   RP   R   RA   RH   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyR^      s    
c         C   s   |  j  |  } |  j d j t k r2 |  j |  S|  j   \ } } | d k r` | j |  n | j | |  |  j j	 |  | S(   s-   Create an element and insert it into the treeiN(
   RN   R(   R   R   R^   t   getTableMisnestedNodePositionR   R   R   RO   (   R   RP   RH   R   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/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(   s   Insert text data.iN(   R   R(   R-   R   R   R   R`   (   R   R   R   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/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(   ss   Get the foster parent element, and sibling to insert before
        (or None) when inserting a misnested table nodeNiR4   i   i    (   R   R(   R   R   t   index(   R   t	   lastTablet   fosterParentR   t   elm(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyR`   '  s    			c      	   C   sO   |  j  d j } | t d	  k rK | | k rK |  j  j   |  j |  n  d  S(
   Nit   ddt   dtt   lit   pt   tdt   tht   tr(   s   dds   dts   liRh   s   tds   ths   tr(   R(   R   t	   frozensetRJ   t   generateImpliedEndTags(   R   t   excludeR   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyRm   A  s
    c         C   s   |  j  S(   s   Return the final tree(   R/   (   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   getDocumentK  s    c         C   s$   |  j    } |  j d j |  | S(   s   Return the final fragmenti    (   t   fragmentClassR(   R   (   R   t   fragment(    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   getFragmentO  s    c         C   s
   t   d S(   sz   Serialize the subtree of node in the format required by unit tests
        node - the node from which to start serializingN(   R   (   R   R   (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   testSerializerV  s    N(   R"   R#   t   __doc__R   R.   RZ   RW   RT   Rp   R   R&   R>   RI   RK   RM   RQ   RV   RX   RN   R\   R_   t   propertyR-   R^   R]   R   R`   Rm   Ro   Rr   Rs   (    (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyR$   Y   s6   			.												
		N(   t   html5lib.constantsR    R   R   Rl   t	   NameErrort   setsR   R5   R   R   RC   t   objectR   R$   (    (    (    sZ   /home/sa3ruby/intertwingly.net/code/venus-bzr/planet/vendor/html5lib/treebuilders/_base.pyt   <module>   s   K