
в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 d d d d	 d
 d d d g	 Z
 e j Z e j Z e j Z e j Z e j Z e j Z d Z d j e	  Z	 d e f d     YZ d e f d     YZ d S(   i    (   t   absolute_importt   divisiont   unicode_literals(   t   Nodei   (   t
   namespacest   voidElementst   spaceCharactersu   DOCUMENTu   DOCTYPEu   TEXTu   ELEMENTu   COMMENTu   ENTITYu   UNKNOWNu
   TreeWalkeru   NonRecursiveTreeWalkeru   <#UNKNOWN#>u    t
   TreeWalkerc           B` sz   e  Z d  Z d   Z d   Z d   Z e d  Z d   Z d   Z	 d   Z
 d   Z d d d	  Z d
   Z d   Z RS(   u}   Walks a tree yielding tokens

    Tokens are dicts that all have a ``type`` field specifying the type of the
    token.

    c         C` s   | |  _  d S(   uC   Creates a TreeWalker

        :arg tree: the tree to walk

        N(   t   tree(   t   selfR   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   __init__   s    c         C` s
   t   d  S(   N(   t   NotImplementedError(   R	   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   __iter__#   s    c         C` s   i d d 6| d 6S(   u   Generates an error token with the given message

        :arg msg: the error message

        :returns: SerializeError token

        u   SerializeErroru   typeu   data(    (   R	   t   msg(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   error&   s    c         c` s<   i d d 6| d 6| d 6| d 6V| r8 |  j  d  Vn  d S(   ur  Generates an EmptyTag token

        :arg namespace: the namespace of the token--can be ``None``

        :arg name: the name of the element

        :arg attrs: the attributes of the element as a dict

        :arg hasChildren: whether or not to yield a SerializationError because
            this tag shouldn't have children

        :returns: EmptyTag token

        u   EmptyTagu   typeu   nameu	   namespaceu   datau   Void element has childrenN(   R   (   R	   t	   namespacet   namet   attrst   hasChildren(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   emptyTag0   s
    	c         C` s    i d d 6| d 6| d 6| d 6S(   u   Generates a StartTag token

        :arg namespace: the namespace of the token--can be ``None``

        :arg name: the name of the element

        :arg attrs: the attributes of the element as a dict

        :returns: StartTag token

        u   StartTagu   typeu   nameu	   namespaceu   data(    (   R	   R   R   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   startTagE   s    
c         C` s   i d d 6| d 6| d 6S(   u   Generates an EndTag token

        :arg namespace: the namespace of the token--can be ``None``

        :arg name: the name of the element

        :returns: EndTag token

        u   EndTagu   typeu   nameu	   namespace(    (   R	   R   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   endTagV   s    

c         c` s   | } | j  t  } | t |  t |   } | rK i d d 6| d 6Vn  | } | j t  } | t |  } | r i d d 6| d 6Vn  | r i d d 6| d 6Vn  d S(   ut  Generates SpaceCharacters and Characters tokens

        Depending on what's in the data, this generates one or more
        ``SpaceCharacters`` and ``Characters`` tokens.

        For example:

            >>> from html5lib.treewalkers.base import TreeWalker
            >>> # Give it an empty tree just so it instantiates
            >>> walker = TreeWalker([])
            >>> list(walker.text(''))
            []
            >>> list(walker.text('  '))
            [{u'data': '  ', u'type': u'SpaceCharacters'}]
            >>> list(walker.text(' abc '))  # doctest: +NORMALIZE_WHITESPACE
            [{u'data': ' ', u'type': u'SpaceCharacters'},
            {u'data': u'abc', u'type': u'Characters'},
            {u'data': u' ', u'type': u'SpaceCharacters'}]

        :arg data: the text data

        :returns: one or more ``SpaceCharacters`` and ``Characters`` tokens

        u   SpaceCharactersu   typeu   datau
   CharactersN(   t   lstripR   t   lent   rstrip(   R	   t   datat   middlet   leftt   right(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   textd   s    c         C` s   i d d 6| d 6S(   ud   Generates a Comment token

        :arg data: the comment

        :returns: Comment token

        u   Commentu   typeu   data(    (   R	   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   comment   s    c         C` s    i d d 6| d 6| d 6| d 6S(   u   Generates a Doctype token

        :arg name:

        :arg publicId:

        :arg systemId:

        :returns: the Doctype token

        u   Doctypeu   typeu   nameu   publicIdu   systemId(    (   R	   R   t   publicIdt   systemId(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   doctype   s    
c         C` s   i d d 6| d 6S(   uj   Generates an Entity token

        :arg name: the entity name

        :returns: an Entity token

        u   Entityu   typeu   name(    (   R	   R   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   entity   s    c         C` s   |  j  d |  S(   u   Handles unknown node typesu   Unknown node type: (   R   (   R	   t   nodeType(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   unknown   s    N(   t   __name__t
   __module__t   __doc__R
   R   R   t   FalseR   R   R   R   R   t   NoneR!   R"   R$   (    (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyR      s   			
			&	
	
t   NonRecursiveTreeWalkerc           B` s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C` s
   t   d  S(   N(   R   (   R	   t   node(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   getNodeDetails   s    c         C` s
   t   d  S(   N(   R   (   R	   R+   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   getFirstChild   s    c         C` s
   t   d  S(   N(   R   (   R	   R+   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   getNextSibling   s    c         C` s
   t   d  S(   N(   R   (   R	   R+   (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   getParentNode   s    c         c` s  |  j  } x| d  k	 r|  j |  } | d | d } } t } | t k r_ |  j |   Vn | t k r x|  j |   D] } | Vq{ Wn | t k r| \ } } } } | s | t	 d k r | t
 k r x% |  j | | | |  D] } | Vq Wt } q|  j | | |  Vni | t k r7|  j | d  VnH | t k rX|  j | d  Vn' | t k rmt } n |  j | d  V| r|  j |  }	 n d  }	 |	 d  k	 r|	 } q x | d  k	 r|  j |  } | d | d } } | t k r<| \ } } } } | r| t	 d k s%| t
 k r<|  j | |  Vq<n  |  j  | k rUd  } Pn  |  j |  }
 |
 d  k	 rz|
 } Pq|  j |  } qWq Wd  S(   Ni    i   u   html(   R   R)   R,   R(   t   DOCTYPER!   t   TEXTR   t   ELEMENTR   R   R   R   t   COMMENTR   t   ENTITYR"   t   DOCUMENTt   TrueR$   R-   R   R.   R/   (   R	   t   currentNodet   detailst   typeR   t   tokenR   R   t
   attributest
   firstChildt   nextSibling(    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyR      sZ    	#				"(   R%   R&   R,   R-   R.   R/   R   (    (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyR*      s
   				N(   t
   __future__R    R   R   t   xml.domR   t	   constantsR   R   R   t   __all__t   DOCUMENT_NODER5   t   DOCUMENT_TYPE_NODER0   t	   TEXT_NODER1   t   ELEMENT_NODER2   t   COMMENT_NODER3   t   ENTITY_NODER4   t   UNKNOWNt   joint   objectR   R*   (    (    (    sB   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/base.pyt   <module>   s   						