U o aR@sZdZddlmZmZmZddlmZddlmZddgZ iZ d d dZ d d Z d dZ dS)aA 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 do implement a tree walker object (called TreeWalker by convention) that implements a 'serialize' method taking a tree as sole argument and returning an iterator generating tokens. )absolute_importdivisionunicode_literals) constants) default_etree getTreeWalkerpprintNcKs|}|tkr|dkr0ddlm}|jt|<np|dkrPddlm}|jt|<nP|dkrpddlm}|jt|<n0|dkrdd lm}|d krt}|j |f|jSt |S) a;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 dom)r genshi)r lxml) etree_lxmletree)rN) lowertreeWalkerCacher TreeWalkerr rrrgetETreeModuleget)treeTypeimplementationkwargsr r rrrjC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_vendor\html5lib\treewalkers\__init__.pyrs"       ccshg}|D]D}|d}|dkr,||dq|rFdd|dVg}|Vq|rddd|dVdS)Ntype) CharactersSpaceCharactersdatarr)rr)appendjoin)tokenspendingCharacterstokenrrrrconcatenateCharacterTokensAsr$c Csbg}d}t|D]D}|d}|dkr|drz|dtjdkrz|dtjkr`tj|d}n|d}d||df}n|d}|dd ||f|d 7}|d }t|D]T\\}} } |r|tjkrtj|}n|}d|| f}n| }|d d ||| fq|d krV|d 8}q|dkr2|d 8}q|dkrX|dd ||d fq|dkr |dr|dr|dd ||d|d|dr|dndfnF|dr|dd ||d|dfn|dd ||dfn|dd |fq|dkr0|dd ||d fq|dkrJdsVtdqtd|qd |S) zPretty printer for tree walkers Takes a TreeWalker instance and pretty prints the output of walking the tree. :arg walker: a TreeWalker instance rr)StartTagEmptyTag namespacehtmlz%s %snamez%s<%s> rrz %s%s="%s"r&EndTagCommentz %sDoctypepublicIdz%ssystemIdrz%sz%sz %srz%s"%s"rFzBconcatenateCharacterTokens should have got rid of all Space tokenszUnknown token type, %s ) r$r namespacesprefixesrsorteditemsAssertionError ValueErrorr ) walkeroutputindentr#rnsr)attrsr' localnamevaluerrrr Psn                )N)__doc__ __future__rrrrr_utilsr__all__rrr$r rrrrs    ,