ó
Ð²Ebc           @` sv   d  Z  d d l m Z m Z m Z d d l m Z d d l m Z d d g Z	 i  Z
 d d „ Z d	 „  Z d
 „  Z d S(   u…  A collection of modules for iterating through different kinds of
tree, generating tokens identical to those produced by the tokenizer
module.

To create a tree walker for a new type of tree, you need to
implement a tree walker object (called TreeWalker by convention) that
implements a 'serialize' method which takes a tree as sole argument and
returns an iterator which generates tokens.
i    (   t   absolute_importt   divisiont   unicode_literalsi   (   t	   constants(   t   default_etreeu   getTreeWalkeru   pprintc         K` sð   |  j  ƒ  }  |  t k rã |  d k rD d d l m } | j t |  <qã |  d k rp d d l m } | j t |  <qã |  d k rœ d d l m } | j t |  <qã |  d k rã d d	 l m } | d
 k rÍ t	 } n  | j
 | |  j Sn  t j |  ƒ S(   u;  Get a TreeWalker class for various types of tree with built-in support

    :arg str treeType: the name of the tree type required (case-insensitive).
        Supported values are:

        * "dom": The xml.dom.minidom DOM implementation
        * "etree": A generic walker for tree implementations exposing an
          elementtree-like interface (known to work with ElementTree,
          cElementTree and lxml.etree).
        * "lxml": Optimized walker for lxml.etree
        * "genshi": a Genshi stream

    :arg implementation: A module implementing the tree type e.g.
        xml.etree.ElementTree or cElementTree (Currently applies to the "etree"
        tree type only).

    :arg kwargs: keyword arguments passed to the etree walker--for other
        walkers, this has no effect

    :returns: a TreeWalker class

    u   domi   (   t   domu   genshi(   t   genshiu   lxml(   t
   etree_lxmlu   etree(   t   etreeN(   t   lowert   treeWalkerCachet    R   t
   TreeWalkerR   R   R   t   NoneR   t   getETreeModulet   get(   t   treeTypet   implementationt   kwargsR   R   R   R   (    (    sF   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/__init__.pyt   getTreeWalker   s"    	c         c` sš   g  } xh |  D]` } | d } | d k r= | j  | d ƒ q | rh i d d 6d j | ƒ d 6Vg  } n  | Vq W| r– i d d 6d j | ƒ d 6Vn  d  S(   Nu   typeu
   Charactersu   SpaceCharactersu   datau    (   u
   Charactersu   SpaceCharacters(   t   appendt   join(   t   tokenst   pendingCharacterst   tokent   type(    (    sF   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/__init__.pyt   concatenateCharacterTokensA   s    
		c         C` s  g  } d } xét  |  ƒ D]Û} | d } | d k r~| d rž | d t j d k rž | d t j k r} t j | d } n
 | d } d | | d f } n
 | d } | j d	 d
 | | f ƒ | d 7} | d } xˆ t | j ƒ  ƒ D]t \ \ } }	 }
 | r:| t j k r!t j | } n | } d | |	 f } n |	 } | j d d
 | | |
 f ƒ qê W| d k rô| d 8} qôq | d k r—| d 8} q | d k rÅ| j d d
 | | d f ƒ q | d k r•| d rz| d r%| j d d
 | | d | d | d r| d n d f ƒ q’| d rX| j d d
 | | d | d f ƒ q’| j d d
 | | d f ƒ qô| j d d
 | f ƒ q | d k rÃ| j d d
 | | d f ƒ q | d k rät sôt d ƒ ‚ q t	 d | ƒ ‚ q Wd j
 | ƒ S(    u    Pretty printer for tree walkers

    Takes a TreeWalker instance and pretty prints the output of walking the tree.

    :arg walker: a TreeWalker instance

    i    u   typeu   StartTagu   EmptyTagu	   namespaceu   htmlu   %s %su   nameu   %s<%s>u    i   u   datau	   %s%s="%s"u   EndTagu   Commentu   %s<!-- %s -->u   Doctypeu   publicIdu   %s<!DOCTYPE %s "%s" "%s">u   systemIdu    u   %s<!DOCTYPE %s "" "%s">u   %s<!DOCTYPE %s>u   %s<!DOCTYPE >u
   Charactersu   %s"%s"u   SpaceCharactersuB   concatenateCharacterTokens should have got rid of all Space tokensu   Unknown token type, %su   
(   u   StartTagu   EmptyTag(   R   R   t
   namespacest   prefixesR   t   sortedt   itemst   Falset   AssertionErrort
   ValueErrorR   (   t   walkert   outputt   indentR   R   t   nst   namet   attrst	   namespacet	   localnamet   value(    (    sF   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/__init__.pyt   pprintP   sd    
!



%""

	"
	"N(   t   __doc__t
   __future__R    R   R   R   R   t   _utilsR   t   __all__R
   R   R   R   R+   (    (    (    sF   /tmp/pip-build-UPPWic/pip/pip/_vendor/html5lib/treewalkers/__init__.pyt   <module>	   s   ,	