ó
ä™L]c        	   @` 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-sZz8gW/pip/pip/_vendor/html5lib/treewalkers/base.pyt   __init__   s    c         C` s
   t  ‚ d  S(   N(   t   NotImplementedError(   R	   (    (    sB   /tmp/pip-build-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/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-sZz8gW/pip/pip/_vendor/html5lib/treewalkers/base.pyt   getNodeDetailsµ   s    c         C` s
   t  ‚ d  S(   N(   R   (   R	   R+   (    (    sB   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treewalkers/base.pyt   getFirstChild¸   s    c         C` s
   t  ‚ d  S(   N(   R   (   R	   R+   (    (    sB   /tmp/pip-build-sZz8gW/pip/pip/_vendor/html5lib/treewalkers/base.pyt   getNextSibling»   s    c         C` s
   t  ‚ d  S(   N(   R   (   R	   R+   (    (    sB   /tmp/pip-build-sZz8gW/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-sZz8gW/pip/pip/_vendor/html5lib/treewalkers/base.pyR   Á   sZ    	#				"(   R%   R&   R,   R-   R.   R/   R   (    (    (    sB   /tmp/pip-build-sZz8gW/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-sZz8gW/pip/pip/_vendor/html5lib/treewalkers/base.pyt   <module>   s   						 