PK!33)__pycache__/__init__.cpython-36.opt-1.pycnu[3 B;W@sbdZddlmZmZmZddlmZddlmZdddd d d gZ iZ dd dZ ddZ ddZ d S)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 getTreeWalkerpprintdometreegenshi etree_lxmlNcKs|j}|tkr|dkr0ddlm}|jt|<np|dkrPddlm}|jt|<nP|dkrpddlm}|jt|<n0|dkrdd lm}|d krt}|j |f|jStj |S) aGet a TreeWalker class for various types of tree with built-in support Args: treeType (str): 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 Implementation: A module implementing the tree type e.g. xml.etree.ElementTree or cElementTree (Currently applies to the "etree" tree type only). r )r r )r Zlxml)r r )r N) lowertreeWalkerCacher Z TreeWalkerr r r rZgetETreeModuleget)ZtreeTypeimplementationkwargsr r r r r/usr/lib/python3.6/__init__.pyrs"       ccslg}xL|D]D}|d}|dkr.|j|dq |rHddj|dVg}|Vq W|rhddj|dVdS)Ntype CharactersSpaceCharactersdatar)rr)rr)appendjoin)tokensZpendingCharacterstokenrrrrconcatenateCharacterTokens<s  rc Cs^g}d}xHt|D]:}|d}|dkr&|dr~|dtjdkr~|dtjkrdtj|d}n|d}d||df}n|d}|jd d ||f|d 7}|d }xdt|jD]T\\}} } |r|tjkrtj|}n|}d|| f}n| }|jd d ||| fqW|dkrP|d 8}q|dkr:|d 8}q|dkr`|jdd ||d fq|dkr|dr|dr|jdd ||d|d|dr|dndfnF|dr|jdd ||d|dfn|jdd ||dfn|jdd |fq|dkr8|jdd ||d fq|dkrDqtd|qWdj|S)zPretty printer for tree walkersrrStartTagEmptyTag namespaceZhtmlz%s %snamez%s<%s> rrz %s%s="%s"ZEndTagCommentz %sZDoctypeZpublicIdz%sZsystemIdrz%sz%sz %srz%s"%s"rzUnknown token type, %s )r r!) rrZ namespacesprefixesrsorteditems ValueErrorr) Zwalkeroutputindentrrnsr#Zattrsr"Z localnamevaluerrrr Ksd               )N)__doc__Z __future__rrrrrZ_utilsr__all__rrrr rrrr s   'PK!=L#__pycache__/__init__.cpython-36.pycnu[3 B;W@sbdZddlmZmZmZddlmZddlmZdddd d d gZ iZ dd dZ ddZ ddZ d S)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 getTreeWalkerpprintdometreegenshi etree_lxmlNcKs|j}|tkr|dkr0ddlm}|jt|<np|dkrPddlm}|jt|<nP|dkrpddlm}|jt|<n0|dkrdd lm}|d krt}|j |f|jStj |S) aGet a TreeWalker class for various types of tree with built-in support Args: treeType (str): 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 Implementation: A module implementing the tree type e.g. xml.etree.ElementTree or cElementTree (Currently applies to the "etree" tree type only). r )r r )r Zlxml)r r )r N) lowertreeWalkerCacher Z TreeWalkerr r r rZgetETreeModuleget)ZtreeTypeimplementationkwargsr r r r r/usr/lib/python3.6/__init__.pyrs"       ccslg}xL|D]D}|d}|dkr.|j|dq |rHddj|dVg}|Vq W|rhddj|dVdS)Ntype CharactersSpaceCharactersdatar)rr)rr)appendjoin)tokensZpendingCharacterstokenrrrrconcatenateCharacterTokens<s  rc Cslg}d}xVt|D]H}|d}|d kr&|dr~|dtjdkr~|dtjkrdtj|d}n|d}d||df}n|d}|jd d ||f|d 7}|d }xdt|jD]T\\}} } |r|tjkrtj|}n|}d|| f}n| }|jd d ||| fqW|dkr^|d 8}q|dkr:|d 8}q|dkr`|jdd ||d fq|dkr|dr|dr|jdd ||d|d|dr|dndfnF|dr|jdd ||d|dfn|jdd ||dfn|jdd |fq|dkr8|jdd ||d fq|dkrRds^tdqtd|qWdj |S)!zPretty printer for tree walkersrrStartTagEmptyTag namespaceZhtmlz%s %snamez%s<%s> rrz %s%s="%s"ZEndTagCommentz %sZDoctypeZpublicIdz%sZsystemIdrz%sz%sz %srz%s"%s"rFzBconcatenateCharacterTokens should have got rid of all Space tokenszUnknown token type, %s )r r!) rrZ namespacesprefixesrsorteditemsAssertionError ValueErrorr) Zwalkeroutputindentrrnsr#Zattrsr"Z localnamevaluerrrr Ksd               )N)__doc__Z __future__rrrrrZ_utilsr__all__rrrr rrrr s   'PK!P4j%__pycache__/base.cpython-36.opt-1.pycnu[3 B;WK @sddlmZmZmZddlmZddlmZmZm Z ddddd d d d d g Z ej Z ej ZejZejZejZejZdZdje Z Gdd d eZGdd d eZdS))absolute_importdivisionunicode_literals)Node) namespaces voidElementsspaceCharactersDOCUMENTDOCTYPETEXTELEMENTCOMMENTENTITYUNKNOWN TreeWalkerNonRecursiveTreeWalkerz <#UNKNOWN#>c@sheZdZddZddZddZddd Zd d Zd d ZddZ ddZ dddZ ddZ ddZ dS)rcCs ||_dS)N)tree)selfrr/usr/lib/python3.6/base.py__init__szTreeWalker.__init__cCstdS)N)NotImplementedError)rrrr__iter__szTreeWalker.__iter__cCs d|dS)NZSerializeError)typedatar)rmsgrrrerrorszTreeWalker.errorFccs$d|||dV|r |jdVdS)NZEmptyTag)rname namespacerzVoid element has children)r)rr rattrs hasChildrenrrremptyTags  zTreeWalker.emptyTagcCsd|||dS)NZStartTag)rrr rr)rr rr!rrrstartTag%szTreeWalker.startTagcCs d||dS)NZEndTag)rrr r)rr rrrrendTag+szTreeWalker.endTagccsx|}|jt}|dt|t|}|r6d|dV|}|jt}|t|d}|rdd|dV|rtd|dVdS)NZSpaceCharacters)rrZ Characters)lstripr lenrstrip)rrZmiddleleftrightrrrtext0s    zTreeWalker.textcCs d|dS)NComment)rrr)rrrrrcomment>szTreeWalker.commentNcCsd|||dS)NZDoctype)rrpublicIdsystemIdr)rrr.r/rrrdoctypeAszTreeWalker.doctypecCs d|dS)NZEntity)rrr)rrrrrentityGszTreeWalker.entitycCs|jd|S)NzUnknown node type: )r)rZnodeTyperrrunknownJszTreeWalker.unknown)F)NN)__name__ __module__ __qualname__rrrr#r$r%r+r-r0r1r2rrrrrs  c@s4eZdZddZddZddZddZd d Zd S) rcCstdS)N)r)rnoderrrgetNodeDetailsOsz%NonRecursiveTreeWalker.getNodeDetailscCstdS)N)r)rr6rrr getFirstChildRsz$NonRecursiveTreeWalker.getFirstChildcCstdS)N)r)rr6rrrgetNextSiblingUsz%NonRecursiveTreeWalker.getNextSiblingcCstdS)N)r)rr6rrr getParentNodeXsz$NonRecursiveTreeWalker.getParentNodec cs|j}x|dk r|j|}|d|dd}}d}|tkrN|j|Vn|tkrrx|j|D] }|VqbWn|tkr|\}}}}| s|tdkr|tkrx|j ||||D] }|VqWd}n|j |||VnV|t kr|j |dVn<|t kr|j|dVn |tkrd}n|j|dV|r@|j|} nd} | dk rT| }q x|dk r|j|}|d|dd}}|tkr|\}}}}|r|tdks|tkr|j||V|j|krd}P|j|} | dk r| }Pn |j|}qVWq WdS)NrFZhtmlT)rr7r r0r r+r rrr#r$rr-rr1r r2r8r%r9r:) rZ currentNodeZdetailsrr"tokenr rZ attributesZ firstChildZ nextSiblingrrrr[sZ                 zNonRecursiveTreeWalker.__iter__N)r3r4r5r7r8r9r:rrrrrrNs N)Z __future__rrrZxml.domrZ constantsrrr __all__Z DOCUMENT_NODEr ZDOCUMENT_TYPE_NODEr Z TEXT_NODEr Z ELEMENT_NODEr Z COMMENT_NODErZ ENTITY_NODErrjoinobjectrrrrrrs  :PK!P4j__pycache__/base.cpython-36.pycnu[3 B;WK @sddlmZmZmZddlmZddlmZmZm Z ddddd d d d d g Z ej Z ej ZejZejZejZejZdZdje Z Gdd d eZGdd d eZdS))absolute_importdivisionunicode_literals)Node) namespaces voidElementsspaceCharactersDOCUMENTDOCTYPETEXTELEMENTCOMMENTENTITYUNKNOWN TreeWalkerNonRecursiveTreeWalkerz <#UNKNOWN#>c@sheZdZddZddZddZddd Zd d Zd d ZddZ ddZ dddZ ddZ ddZ dS)rcCs ||_dS)N)tree)selfrr/usr/lib/python3.6/base.py__init__szTreeWalker.__init__cCstdS)N)NotImplementedError)rrrr__iter__szTreeWalker.__iter__cCs d|dS)NZSerializeError)typedatar)rmsgrrrerrorszTreeWalker.errorFccs$d|||dV|r |jdVdS)NZEmptyTag)rname namespacerzVoid element has children)r)rr rattrs hasChildrenrrremptyTags  zTreeWalker.emptyTagcCsd|||dS)NZStartTag)rrr rr)rr rr!rrrstartTag%szTreeWalker.startTagcCs d||dS)NZEndTag)rrr r)rr rrrrendTag+szTreeWalker.endTagccsx|}|jt}|dt|t|}|r6d|dV|}|jt}|t|d}|rdd|dV|rtd|dVdS)NZSpaceCharacters)rrZ Characters)lstripr lenrstrip)rrZmiddleleftrightrrrtext0s    zTreeWalker.textcCs d|dS)NComment)rrr)rrrrrcomment>szTreeWalker.commentNcCsd|||dS)NZDoctype)rrpublicIdsystemIdr)rrr.r/rrrdoctypeAszTreeWalker.doctypecCs d|dS)NZEntity)rrr)rrrrrentityGszTreeWalker.entitycCs|jd|S)NzUnknown node type: )r)rZnodeTyperrrunknownJszTreeWalker.unknown)F)NN)__name__ __module__ __qualname__rrrr#r$r%r+r-r0r1r2rrrrrs  c@s4eZdZddZddZddZddZd d Zd S) rcCstdS)N)r)rnoderrrgetNodeDetailsOsz%NonRecursiveTreeWalker.getNodeDetailscCstdS)N)r)rr6rrr getFirstChildRsz$NonRecursiveTreeWalker.getFirstChildcCstdS)N)r)rr6rrrgetNextSiblingUsz%NonRecursiveTreeWalker.getNextSiblingcCstdS)N)r)rr6rrr getParentNodeXsz$NonRecursiveTreeWalker.getParentNodec cs|j}x|dk r|j|}|d|dd}}d}|tkrN|j|Vn|tkrrx|j|D] }|VqbWn|tkr|\}}}}| s|tdkr|tkrx|j ||||D] }|VqWd}n|j |||VnV|t kr|j |dVn<|t kr|j|dVn |tkrd}n|j|dV|r@|j|} nd} | dk rT| }q x|dk r|j|}|d|dd}}|tkr|\}}}}|r|tdks|tkr|j||V|j|krd}P|j|} | dk r| }Pn |j|}qVWq WdS)NrFZhtmlT)rr7r r0r r+r rrr#r$rr-rr1r r2r8r%r9r:) rZ currentNodeZdetailsrr"tokenr rZ attributesZ firstChildZ nextSiblingrrrr[sZ                 zNonRecursiveTreeWalker.__iter__N)r3r4r5r7r8r9r:rrrrrrNs N)Z __future__rrrZxml.domrZ constantsrrr __all__Z DOCUMENT_NODEr ZDOCUMENT_TYPE_NODEr Z TEXT_NODEr Z ELEMENT_NODEr Z COMMENT_NODErZ ENTITY_NODErrjoinobjectrrrrrrs  :PK! G__$__pycache__/dom.cpython-36.opt-1.pycnu[3 B;W@sBddlmZmZmZddlmZddlmZGdddejZ dS))absolute_importdivisionunicode_literals)Node)basec@s,eZdZddZddZddZddZd S) TreeWalkercCs|jtjkr tj|j|j|jfS|jtjtj fkr>tj |j fS|jtj kri}xJt |jjD]8}|j|}|jr|j||j|jf<q^|j|d|jf<q^Wtj|j|j||jfS|jtjkrtj|j fS|jtjtjfkrtjfStj|jfSdS)N)ZnodeTyperZDOCUMENT_TYPE_NODErZDOCTYPEnameZpublicIdZsystemIdZ TEXT_NODEZCDATA_SECTION_NODEZTEXTZ nodeValueZ ELEMENT_NODElistZ attributeskeysZgetAttributeNodeZ namespaceURIvalueZ localNameZELEMENTZnodeNameZ hasChildNodesZ COMMENT_NODECOMMENTZ DOCUMENT_NODEZDOCUMENT_FRAGMENT_NODEZDOCUMENTZUNKNOWN)selfnodeZattrsattrr/usr/lib/python3.6/dom.pygetNodeDetails s$        zTreeWalker.getNodeDetailscCs|jS)N)Z firstChild)rrrrr getFirstChild$szTreeWalker.getFirstChildcCs|jS)N)Z nextSibling)rrrrrgetNextSibling'szTreeWalker.getNextSiblingcCs|jS)N)Z parentNode)rrrrr getParentNode*szTreeWalker.getParentNodeN)__name__ __module__ __qualname__rrrrrrrrrsrN) Z __future__rrrZxml.domrrZNonRecursiveTreeWalkerrrrrrs  PK! G____pycache__/dom.cpython-36.pycnu[3 B;W@sBddlmZmZmZddlmZddlmZGdddejZ dS))absolute_importdivisionunicode_literals)Node)basec@s,eZdZddZddZddZddZd S) TreeWalkercCs|jtjkr tj|j|j|jfS|jtjtj fkr>tj |j fS|jtj kri}xJt |jjD]8}|j|}|jr|j||j|jf<q^|j|d|jf<q^Wtj|j|j||jfS|jtjkrtj|j fS|jtjtjfkrtjfStj|jfSdS)N)ZnodeTyperZDOCUMENT_TYPE_NODErZDOCTYPEnameZpublicIdZsystemIdZ TEXT_NODEZCDATA_SECTION_NODEZTEXTZ nodeValueZ ELEMENT_NODElistZ attributeskeysZgetAttributeNodeZ namespaceURIvalueZ localNameZELEMENTZnodeNameZ hasChildNodesZ COMMENT_NODECOMMENTZ DOCUMENT_NODEZDOCUMENT_FRAGMENT_NODEZDOCUMENTZUNKNOWN)selfnodeZattrsattrr/usr/lib/python3.6/dom.pygetNodeDetails s$        zTreeWalker.getNodeDetailscCs|jS)N)Z firstChild)rrrrr getFirstChild$szTreeWalker.getFirstChildcCs|jS)N)Z nextSibling)rrrrrgetNextSibling'szTreeWalker.getNextSiblingcCs|jS)N)Z parentNode)rrrrr getParentNode*szTreeWalker.getParentNodeN)__name__ __module__ __qualname__rrrrrrrrrsrN) Z __future__rrrZxml.domrrZNonRecursiveTreeWalkerrrrrrs  PK! &__pycache__/etree.cpython-36.opt-1.pycnu[3 B;W@@sddlmZmZmZyddlmZWn>ek rbyddlmZWnek r\eZYnXYnXddl Z ddl m Z ddl m Z ddlmZe jd Zd d ZeeZdS) )absolute_importdivisionunicode_literals) OrderedDictN) string_types)base)moduleFactoryFactoryz {([^}]*)}(.*)cs,|}|jdjGfdddtj}tS)NZasdcs4eZdZdZfddZddZddZdd Zd S) z#getETreeBuilder..TreeWalkeraGiven the particular ElementTree representation, this implementation, to avoid using recursion, returns "nodes" as tuples with the following content: 1. The current element 2. The index of the element relative to its parent 3. A stack of ancestor elements 4. A flag "text", "tail" or None to indicate if the current node is a text node; either the text or tail of the current element (1) c s2t|tr2|\}}}}|d kr.tjt||fS|}t|dsD|j}|jd krVtjfS|jdkr|tj |j |j d|j dfS|jkrtj |j fSt j|j}|r|j\}}n d}|j}t}xPt|jjD]>\} } t j| }|r| ||jd |jd f<q| |d| f<qWtj|||t|p*|j fSdS) Ntexttailtag DOCUMENT_ROOTDOCUMENT_FRAGMENTz ZpublicIdZsystemIdrr )r r )rr) isinstancetuplerZTEXTgetattrhasattrZgetrootr ZDOCUMENTZDOCTYPEr getCOMMENT tag_regexpmatchgroupsrlistZattribitemsgroupZELEMENTlen) selfnodeZelt_flagr namespacer Zattrsnamevalue)ElementTreeCommentType/usr/lib/python3.6/etree.pygetNodeDetails's6         z2getETreeBuilder..TreeWalker.getNodeDetailscSstt|tr|\}}}}n|dgdf\}}}}|dkr8dS|jrJ|||dfSt|rl|j||dd|dfSdSdS)Nr r r)r r )rrr rappend)rrelementkeyparentsr r%r%r& getFirstChildOs   z1getETreeBuilder..TreeWalker.getFirstChildcSst|tr|\}}}}ndS|dkrLt|rF|j||dd|dfSdSnN|jrf|dkrf|||dfS|t|ddkr|d|d|d|dfSdSdS)Nr rr rr-)rrrr(r )rrr)r*r+r r%r%r&getNextSibling`s   z2getETreeBuilder..TreeWalker.getNextSiblingcSsht|tr|\}}}}ndS|dkr:|s,|S|||dfSn*|j}|sJ|S|t|dj||dfSdS)Nr rr-)rrpoprindex)rrr)r*r+r parentr%r%r& getParentNodets z1getETreeBuilder..TreeWalker.getParentNodeN)__name__ __module__ __qualname____doc__r'r,r.r2r%)r$r%r& TreeWalkers   (r7)Commentr rZNonRecursiveTreeWalkerlocals)ZElementTreeImplementationZ ElementTreer7r%)r$r&getETreeBuilders nr:)Z __future__rrr collectionsr ImportErrorZ ordereddictdictreZsixrrZ_utilsr compilerr:ZgetETreeModuler%r%r%r&s    tPK!۰I __pycache__/etree.cpython-36.pycnu[3 B;W@@sddlmZmZmZyddlmZWn>ek rbyddlmZWnek r\eZYnXYnXddl Z ddl m Z ddl m Z ddlmZe jd Zd d ZeeZdS) )absolute_importdivisionunicode_literals) OrderedDictN) string_types)base)moduleFactoryFactoryz {([^}]*)}(.*)cs,|}|jdjGfdddtj}tS)NZasdcs4eZdZdZfddZddZddZdd Zd S) z#getETreeBuilder..TreeWalkeraGiven the particular ElementTree representation, this implementation, to avoid using recursion, returns "nodes" as tuples with the following content: 1. The current element 2. The index of the element relative to its parent 3. A stack of ancestor elements 4. A flag "text", "tail" or None to indicate if the current node is a text node; either the text or tail of the current element (1) c sLt|tr2|\}}}}|d kr.tjt||fS|}t|dsD|j}|jd krVtjfS|jdkr|tj |j |j d|j dfS|jkrtj |j fSt|jt stt|jtj|j}|r|j\}}n d}|j}t}xPt|jjD]>\} } tj| }|r| ||jd |jd f<q| |d| f<qWtj|||t|pD|j fSdS) Ntexttailtag DOCUMENT_ROOTDOCUMENT_FRAGMENTz ZpublicIdZsystemIdrr )r r )rr) isinstancetuplerZTEXTgetattrhasattrZgetrootr ZDOCUMENTZDOCTYPEr getCOMMENTrAssertionErrortype tag_regexpmatchgroupsrlistZattribitemsgroupZELEMENTlen) selfnodeZelt_flagr namespacer Zattrsnamevalue)ElementTreeCommentType/usr/lib/python3.6/etree.pygetNodeDetails's8         z2getETreeBuilder..TreeWalker.getNodeDetailscSstt|tr|\}}}}n|dgdf\}}}}|dkr8dS|jrJ|||dfSt|rl|j||dd|dfSdSdS)Nr r r)r r )rrr rappend)rr elementkeyparentsr"r'r'r( getFirstChildOs   z1getETreeBuilder..TreeWalker.getFirstChildcSst|tr|\}}}}ndS|dkrLt|rF|j||dd|dfSdSnN|jrf|dkrf|||dfS|t|ddkr|d|d|d|dfSdSdS)Nr rr rr/)rrrr*r )rr r+r,r-r"r'r'r(getNextSibling`s   z2getETreeBuilder..TreeWalker.getNextSiblingcSst|tr|\}}}}ndS|dkr:|s,|S|||dfSnD|j}|sJ|St|dj|dksdt|t|dj||dfSdS)Nr rr/r/)rrpoprcountrindex)rr r+r,r-r"parentr'r'r( getParentNodets z1getETreeBuilder..TreeWalker.getParentNodeN)__name__ __module__ __qualname____doc__r)r.r0r5r')r&r'r( TreeWalkers   (r:)Commentr rZNonRecursiveTreeWalkerlocals)ZElementTreeImplementationZ ElementTreer:r')r&r(getETreeBuilders nr=)Z __future__rrr collectionsr ImportErrorZ ordereddictdictreZsixrrZ_utilsr compilerr=ZgetETreeModuler'r'r'r(s    tPK!+__pycache__/etree_lxml.cpython-36.opt-1.pycnu[3 B;W@sddlmZmZmZddlmZddlmZddlm Z ddl m Z ddl m Z d d Z Gd d d eZGd ddeZGdddeZGdddeZGddde jZdS))absolute_importdivisionunicode_literals) text_type)etree) tag_regexp)base) _ihatexmlcCs*|dkr dSt|tr|S|jddSdS)Nasciistrict) isinstancerdecode)sr /usr/lib/python3.6/etree_lxml.py ensure_str s  rc@s,eZdZddZddZddZddZd S) RootcCs||_g|_y:|jjrD|jjt|t|jjt|jjt|jj Wnt k rZYnXy |j }Wnt k r|}YnXx|j dk r|j }qWx |dk r|jj||j }qWd|_d|_dS)N)Z elementtreechildrenZdocinfoZ internalDTDappendDoctyperZ root_name public_idZ system_urlAttributeErrorZgetrootZ getpreviousgetnexttexttail)selfZetnoderrr__init__s*         z Root.__init__cCs |j|S)N)r)rkeyrrr __getitem__1szRoot.__getitem__cCsdS)Nr)rrrrr4sz Root.getnextcCsdS)Nr r)rrrr__len__7sz Root.__len__N)__name__ __module__ __qualname__rr!rr"rrrrrsrc@seZdZddZddZdS)rcCs(||_||_||_||_d|_d|_dS)N) root_nodenamer system_idrr)rr&r'rr(rrrr<s zDoctype.__init__cCs |jjdS)Nr )r&r)rrrrrEszDoctype.getnextN)r#r$r%rrrrrrr;s rc@seZdZddZddZdS) FragmentRootcs$fdd|D_d__dS)Ncsg|]}t|qSr)FragmentWrapper).0Zchild)rrr Ksz)FragmentRoot.__init__..)rrr)rrr)rrrJszFragmentRoot.__init__cCsdS)Nr)rrrrrNszFragmentRoot.getnextN)r#r$r%rrrrrrr)Isr)c@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)r*cCsT||_||_t|jdr(t|jj|_nd|_t|jdrJt|jj|_nd|_dS)Nrr)r&objhasattrrrr)rZ fragment_rootr-rrrrSs  zFragmentWrapper.__init__cCs t|j|S)N)getattrr-)rr'rrr __getattr___szFragmentWrapper.__getattr__cCs6|jj}|j|}|t|dkr.||dSdSdS)Nr )r&rindexlen)rZsiblingsidxrrrrbs   zFragmentWrapper.getnextcCs |j|S)N)r-)rr rrrr!jszFragmentWrapper.__getitem__cCs t|jS)N)boolr-)rrrr__bool__mszFragmentWrapper.__bool__cCsdS)Nr)rrrr getparentpszFragmentWrapper.getparentcCs t|jS)N)strr-)rrrr__str__sszFragmentWrapper.__str__cCs t|jS)N)r7r-)rrrr __unicode__vszFragmentWrapper.__unicode__cCs t|jS)N)r2r-)rrrrr"yszFragmentWrapper.__len__N) r#r$r%rr0rr!r5r6r8r9r"rrrrr*Rs r*c@s4eZdZddZddZddZddZd d Zd S) TreeWalkercCsJt|trt||_t|}nt|_t|}tjj||t j |_ dS)N) rlistsetfragmentChildrenr)rr NonRecursiveTreeWalkerrr Z InfosetFilterfilter)rZtreerrrr~s   zTreeWalker.__init__c Cst|tr&|\}}tjtt||fSt|tr8tjfSt|trVtj |j |j |j fSt|t r|t|d r|tjt|jfS|jtjkrtjt|jfS|jtjkrtjt|jddfStjt|j}|r|j\}}nd}t|j}i}xbt|jjD]P\}}t|}t|}tj|}|rB|||jd|jdf<n ||d|f<qWtj||jj ||t!|dkpx|jfSdS)Ntagr rr)"rtupler ZTEXTrr/rZDOCUMENTrZDOCTYPEr'rr(r*r.r-r@rCommentCOMMENTrZEntityZENTITYrmatchgroupsr;ZattribitemsgroupZELEMENTr?Z fromXmlNamer2) rrr rE namespacer@Zattrsr'valuerrrgetNodeDetailss8       zTreeWalker.getNodeDetailscCs|jr|dfS|dSdS)Nrr)r)rrrrr getFirstChildszTreeWalker.getFirstChildcCsNt|tr8|\}}|dkr0t|r*|dSdSn|jS|jrF|dfS|jS)Nrrr)rrBr2rr)rrr rrrgetNextSiblings zTreeWalker.getNextSiblingcCs6t|tr |\}}|dkr.|Sn||jkr.dS|jS)Nr)rrBr=r6)rrr rrr getParentNodes  zTreeWalker.getParentNodeN)r#r$r%rrKrLrMrNrrrrr:}s  ) r:N)Z __future__rrrZsixrZlxmlrZtreebuilders.etreerr r robjectrrr)r*r>r:rrrrs      & +PK!G=%__pycache__/etree_lxml.cpython-36.pycnu[3 B;W@sddlmZmZmZddlmZddlmZddlm Z ddl m Z ddl m Z d d Z Gd d d eZGd ddeZGdddeZGdddeZGddde jZdS))absolute_importdivisionunicode_literals) text_type)etree) tag_regexp)base) _ihatexmlcCs*|dkr dSt|tr|S|jddSdS)Nasciistrict) isinstancerdecode)sr /usr/lib/python3.6/etree_lxml.py ensure_str s  rc@s,eZdZddZddZddZddZd S) RootcCs||_g|_y:|jjrD|jjt|t|jjt|jjt|jj Wnt k rZYnXy |j }Wnt k r|}YnXx|j dk r|j }qWx |dk r|jj||j }qWd|_d|_dS)N)Z elementtreechildrenZdocinfoZ internalDTDappendDoctyperZ root_name public_idZ system_urlAttributeErrorZgetrootZ getpreviousgetnexttexttail)selfZetnoderrr__init__s*         z Root.__init__cCs |j|S)N)r)rkeyrrr __getitem__1szRoot.__getitem__cCsdS)Nr)rrrrr4sz Root.getnextcCsdS)Nr r)rrrr__len__7sz Root.__len__N)__name__ __module__ __qualname__rr!rr"rrrrrsrc@seZdZddZddZdS)rcCs(||_||_||_||_d|_d|_dS)N) root_nodenamer system_idrr)rr&r'rr(rrrr<s zDoctype.__init__cCs |jjdS)Nr )r&r)rrrrrEszDoctype.getnextN)r#r$r%rrrrrrr;s rc@seZdZddZddZdS) FragmentRootcs$fdd|D_d__dS)Ncsg|]}t|qSr)FragmentWrapper).0Zchild)rrr Ksz)FragmentRoot.__init__..)rrr)rrr)rrrJszFragmentRoot.__init__cCsdS)Nr)rrrrrNszFragmentRoot.getnextN)r#r$r%rrrrrrr)Isr)c@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)r*cCsT||_||_t|jdr(t|jj|_nd|_t|jdrJt|jj|_nd|_dS)Nrr)r&objhasattrrrr)rZ fragment_rootr-rrrrSs  zFragmentWrapper.__init__cCs t|j|S)N)getattrr-)rr'rrr __getattr___szFragmentWrapper.__getattr__cCs6|jj}|j|}|t|dkr.||dSdSdS)Nr )r&rindexlen)rZsiblingsidxrrrrbs   zFragmentWrapper.getnextcCs |j|S)N)r-)rr rrrr!jszFragmentWrapper.__getitem__cCs t|jS)N)boolr-)rrrr__bool__mszFragmentWrapper.__bool__cCsdS)Nr)rrrr getparentpszFragmentWrapper.getparentcCs t|jS)N)strr-)rrrr__str__sszFragmentWrapper.__str__cCs t|jS)N)r7r-)rrrr __unicode__vszFragmentWrapper.__unicode__cCs t|jS)N)r2r-)rrrrr"yszFragmentWrapper.__len__N) r#r$r%rr0rr!r5r6r8r9r"rrrrr*Rs r*c@s4eZdZddZddZddZddZd d Zd S) TreeWalkercCsJt|trt||_t|}nt|_t|}tjj||t j |_ dS)N) rlistsetfragmentChildrenr)rr NonRecursiveTreeWalkerrr Z InfosetFilterfilter)rZtreerrrr~s   zTreeWalker.__init__c Cst|tr:|\}}|dks&td|tjtt||fSt|trLtjfSt|t rjtj |j |j |j fSt|trt|d rtjt|jfS|jtjkrtjt|jfS|jtjkrtjt|jdd fStjt|j}|r|j\}}nd}t|j}i}xbt|jjD]P\}}t|}t|}tj|}|rX|||jd|jdf<n ||d|f<qWtj||j j!||t"|dkp|jfSdS) Nrrz%Text nodes are text or tail, found %stagr rr)rr)#rtupleAssertionErrorr ZTEXTrr/rZDOCUMENTrZDOCTYPEr'rr(r*r.r-r@rCommentCOMMENTrZEntityZENTITYrmatchgroupsr;ZattribitemsgroupZELEMENTr?Z fromXmlNamer2) rrr rF namespacer@Zattrsr'valuerrrgetNodeDetailss:       zTreeWalker.getNodeDetailscCsDt|t stdt|s*|js*td|jr8|dfS|dSdS)NzText nodes have no childrenzNode has no childrenrr)rrBrCr2r)rrrrr getFirstChilds zTreeWalker.getFirstChildcCsbt|trL|\}}|dks&td||dkrDt|r>|dSdSn|jS|jrZ|dfS|jS)Nrrz%Text nodes are text or tail, found %sr)rr)rrBrCr2rr)rrr rrrgetNextSiblings zTreeWalker.getNextSiblingcCsJt|tr4|\}}|dks&td||dkrB|Sn||jkrBdS|jS)Nrrz%Text nodes are text or tail, found %s)rr)rrBrCr=r6)rrr rrr getParentNodes  zTreeWalker.getParentNodeN)r#r$r%rrLrMrNrOrrrrr:}s  ) r:N)Z __future__rrrZsixrZlxmlrZtreebuilders.etreerr r robjectrrr)r*r>r:rrrrs      & +PK!.  '__pycache__/genshi.cpython-36.opt-1.pycnu[3 B;W @sddlmZmZmZddlmZddlmZmZmZm Z m Z ddlm Z m Z m Z mZmZmZddlmZddlmZmZGd d d ejZd S) )absolute_importdivisionunicode_literals)QName)STARTEND XML_NAMESPACEDOCTYPETEXT)START_NSEND_NS START_CDATA END_CDATAPICOMMENT)base) voidElements namespacesc@seZdZddZddZdS) TreeWalkerccsdd}x6|jD],}|dk r4x|j||D] }|Vq&W|}q W|dk r`x|j|dD] }|VqRWdS)N)Ztreetokens)selfZpreviouseventtokenr/usr/lib/python3.6/genshi.py__iter__ s  zTreeWalker.__iter__ccs|\}}}|tkr|\}}|j}|j} i} x8|D]0\} } t| trT| | | j| jf<q0| | d| f<q0W| tdkr|tkrxJ|j| || | p|dtkp|d|kD] } | VqWn|j | || Vn|tkr|j}|j} | tdks|tkr|j | |Vn~|t kr|j |Vnf|t kr>xZ|j|D] } | Vq,Wn>|tkrV|j|Vn&|tttttttfkrpn |j|VdS)NZhtmlrr)rZ localname namespace isinstancerrrZemptyTagrZstartTagZendTagrZcommentr textr Zdoctyperr r r rrunknown)rrnextZkinddata_tagZattribsnamerZconverted_attribskvrrrrrs@        zTreeWalker.tokensN)__name__ __module__ __qualname__rrrrrrr srN)Z __future__rrrZ genshi.corerrrrr r r r r rrrrZ constantsrrrrrrrs    PK!.  !__pycache__/genshi.cpython-36.pycnu[3 B;W @sddlmZmZmZddlmZddlmZmZmZm Z m Z ddlm Z m Z m Z mZmZmZddlmZddlmZmZGd d d ejZd S) )absolute_importdivisionunicode_literals)QName)STARTEND XML_NAMESPACEDOCTYPETEXT)START_NSEND_NS START_CDATA END_CDATAPICOMMENT)base) voidElements namespacesc@seZdZddZddZdS) TreeWalkerccsdd}x6|jD],}|dk r4x|j||D] }|Vq&W|}q W|dk r`x|j|dD] }|VqRWdS)N)Ztreetokens)selfZpreviouseventtokenr/usr/lib/python3.6/genshi.py__iter__ s  zTreeWalker.__iter__ccs|\}}}|tkr|\}}|j}|j} i} x8|D]0\} } t| trT| | | j| jf<q0| | d| f<q0W| tdkr|tkrxJ|j| || | p|dtkp|d|kD] } | VqWn|j | || Vn|tkr|j}|j} | tdks|tkr|j | |Vn~|t kr|j |Vnf|t kr>xZ|j|D] } | Vq,Wn>|tkrV|j|Vn&|tttttttfkrpn |j|VdS)NZhtmlrr)rZ localname namespace isinstancerrrZemptyTagrZstartTagZendTagrZcommentr textr Zdoctyperr r r rrunknown)rrnextZkinddata_tagZattribsnamerZconverted_attribskvrrrrrs@        zTreeWalker.tokensN)__name__ __module__ __qualname__rrrrrrr srN)Z __future__rrrZ genshi.corerrrrr r r r r rrrrZ constantsrrrrrrrs    PK!sD! __init__.pynu["""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 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. """ from __future__ import absolute_import, division, unicode_literals from .. import constants from .._utils import default_etree __all__ = ["getTreeWalker", "pprint", "dom", "etree", "genshi", "etree_lxml"] treeWalkerCache = {} def getTreeWalker(treeType, implementation=None, **kwargs): """Get a TreeWalker class for various types of tree with built-in support Args: treeType (str): 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 Implementation: A module implementing the tree type e.g. xml.etree.ElementTree or cElementTree (Currently applies to the "etree" tree type only). """ treeType = treeType.lower() if treeType not in treeWalkerCache: if treeType == "dom": from . import dom treeWalkerCache[treeType] = dom.TreeWalker elif treeType == "genshi": from . import genshi treeWalkerCache[treeType] = genshi.TreeWalker elif treeType == "lxml": from . import etree_lxml treeWalkerCache[treeType] = etree_lxml.TreeWalker elif treeType == "etree": from . import etree if implementation is None: implementation = default_etree # XXX: NEVER cache here, caching is done in the etree submodule return etree.getETreeModule(implementation, **kwargs).TreeWalker return treeWalkerCache.get(treeType) def concatenateCharacterTokens(tokens): pendingCharacters = [] for token in tokens: type = token["type"] if type in ("Characters", "SpaceCharacters"): pendingCharacters.append(token["data"]) else: if pendingCharacters: yield {"type": "Characters", "data": "".join(pendingCharacters)} pendingCharacters = [] yield token if pendingCharacters: yield {"type": "Characters", "data": "".join(pendingCharacters)} def pprint(walker): """Pretty printer for tree walkers""" output = [] indent = 0 for token in concatenateCharacterTokens(walker): type = token["type"] if type in ("StartTag", "EmptyTag"): # tag name if token["namespace"] and token["namespace"] != constants.namespaces["html"]: if token["namespace"] in constants.prefixes: ns = constants.prefixes[token["namespace"]] else: ns = token["namespace"] name = "%s %s" % (ns, token["name"]) else: name = token["name"] output.append("%s<%s>" % (" " * indent, name)) indent += 2 # attributes (sorted for consistent ordering) attrs = token["data"] for (namespace, localname), value in sorted(attrs.items()): if namespace: if namespace in constants.prefixes: ns = constants.prefixes[namespace] else: ns = namespace name = "%s %s" % (ns, localname) else: name = localname output.append("%s%s=\"%s\"" % (" " * indent, name, value)) # self-closing if type == "EmptyTag": indent -= 2 elif type == "EndTag": indent -= 2 elif type == "Comment": output.append("%s" % (" " * indent, token["data"])) elif type == "Doctype": if token["name"]: if token["publicId"]: output.append("""%s""" % (" " * indent, token["name"], token["publicId"], token["systemId"] if token["systemId"] else "")) elif token["systemId"]: output.append("""%s""" % (" " * indent, token["name"], token["systemId"])) else: output.append("%s" % (" " * indent, token["name"])) else: output.append("%s" % (" " * indent,)) elif type == "Characters": output.append("%s\"%s\"" % (" " * indent, token["data"])) elif type == "SpaceCharacters": assert False, "concatenateCharacterTokens should have got rid of all Space tokens" else: raise ValueError("Unknown token type, %s" % type) return "\n".join(output) PK!M#KKbase.pynu[from __future__ import absolute_import, division, unicode_literals from xml.dom import Node from ..constants import namespaces, voidElements, spaceCharacters __all__ = ["DOCUMENT", "DOCTYPE", "TEXT", "ELEMENT", "COMMENT", "ENTITY", "UNKNOWN", "TreeWalker", "NonRecursiveTreeWalker"] DOCUMENT = Node.DOCUMENT_NODE DOCTYPE = Node.DOCUMENT_TYPE_NODE TEXT = Node.TEXT_NODE ELEMENT = Node.ELEMENT_NODE COMMENT = Node.COMMENT_NODE ENTITY = Node.ENTITY_NODE UNKNOWN = "<#UNKNOWN#>" spaceCharacters = "".join(spaceCharacters) class TreeWalker(object): def __init__(self, tree): self.tree = tree def __iter__(self): raise NotImplementedError def error(self, msg): return {"type": "SerializeError", "data": msg} def emptyTag(self, namespace, name, attrs, hasChildren=False): yield {"type": "EmptyTag", "name": name, "namespace": namespace, "data": attrs} if hasChildren: yield self.error("Void element has children") def startTag(self, namespace, name, attrs): return {"type": "StartTag", "name": name, "namespace": namespace, "data": attrs} def endTag(self, namespace, name): return {"type": "EndTag", "name": name, "namespace": namespace} def text(self, data): data = data middle = data.lstrip(spaceCharacters) left = data[:len(data) - len(middle)] if left: yield {"type": "SpaceCharacters", "data": left} data = middle middle = data.rstrip(spaceCharacters) right = data[len(middle):] if middle: yield {"type": "Characters", "data": middle} if right: yield {"type": "SpaceCharacters", "data": right} def comment(self, data): return {"type": "Comment", "data": data} def doctype(self, name, publicId=None, systemId=None): return {"type": "Doctype", "name": name, "publicId": publicId, "systemId": systemId} def entity(self, name): return {"type": "Entity", "name": name} def unknown(self, nodeType): return self.error("Unknown node type: " + nodeType) class NonRecursiveTreeWalker(TreeWalker): def getNodeDetails(self, node): raise NotImplementedError def getFirstChild(self, node): raise NotImplementedError def getNextSibling(self, node): raise NotImplementedError def getParentNode(self, node): raise NotImplementedError def __iter__(self): currentNode = self.tree while currentNode is not None: details = self.getNodeDetails(currentNode) type, details = details[0], details[1:] hasChildren = False if type == DOCTYPE: yield self.doctype(*details) elif type == TEXT: for token in self.text(*details): yield token elif type == ELEMENT: namespace, name, attributes, hasChildren = details if (not namespace or namespace == namespaces["html"]) and name in voidElements: for token in self.emptyTag(namespace, name, attributes, hasChildren): yield token hasChildren = False else: yield self.startTag(namespace, name, attributes) elif type == COMMENT: yield self.comment(details[0]) elif type == ENTITY: yield self.entity(details[0]) elif type == DOCUMENT: hasChildren = True else: yield self.unknown(details[0]) if hasChildren: firstChild = self.getFirstChild(currentNode) else: firstChild = None if firstChild is not None: currentNode = firstChild else: while currentNode is not None: details = self.getNodeDetails(currentNode) type, details = details[0], details[1:] if type == ELEMENT: namespace, name, attributes, hasChildren = details if (namespace and namespace != namespaces["html"]) or name not in voidElements: yield self.endTag(namespace, name) if self.tree is currentNode: currentNode = None break nextSibling = self.getNextSibling(currentNode) if nextSibling is not None: currentNode = nextSibling break else: currentNode = self.getParentNode(currentNode) PK!eodom.pynu[from __future__ import absolute_import, division, unicode_literals from xml.dom import Node from . import base class TreeWalker(base.NonRecursiveTreeWalker): def getNodeDetails(self, node): if node.nodeType == Node.DOCUMENT_TYPE_NODE: return base.DOCTYPE, node.name, node.publicId, node.systemId elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE): return base.TEXT, node.nodeValue elif node.nodeType == Node.ELEMENT_NODE: attrs = {} for attr in list(node.attributes.keys()): attr = node.getAttributeNode(attr) if attr.namespaceURI: attrs[(attr.namespaceURI, attr.localName)] = attr.value else: attrs[(None, attr.name)] = attr.value return (base.ELEMENT, node.namespaceURI, node.nodeName, attrs, node.hasChildNodes()) elif node.nodeType == Node.COMMENT_NODE: return base.COMMENT, node.nodeValue elif node.nodeType in (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE): return (base.DOCUMENT,) else: return base.UNKNOWN, node.nodeType def getFirstChild(self, node): return node.firstChild def getNextSibling(self, node): return node.nextSibling def getParentNode(self, node): return node.parentNode PK!\@@etree.pynu[from __future__ import absolute_import, division, unicode_literals try: from collections import OrderedDict except ImportError: try: from ordereddict import OrderedDict except ImportError: OrderedDict = dict import re from six import string_types from . import base from .._utils import moduleFactoryFactory tag_regexp = re.compile("{([^}]*)}(.*)") def getETreeBuilder(ElementTreeImplementation): ElementTree = ElementTreeImplementation ElementTreeCommentType = ElementTree.Comment("asd").tag class TreeWalker(base.NonRecursiveTreeWalker): # pylint:disable=unused-variable """Given the particular ElementTree representation, this implementation, to avoid using recursion, returns "nodes" as tuples with the following content: 1. The current element 2. The index of the element relative to its parent 3. A stack of ancestor elements 4. A flag "text", "tail" or None to indicate if the current node is a text node; either the text or tail of the current element (1) """ def getNodeDetails(self, node): if isinstance(node, tuple): # It might be the root Element elt, _, _, flag = node if flag in ("text", "tail"): return base.TEXT, getattr(elt, flag) else: node = elt if not(hasattr(node, "tag")): node = node.getroot() if node.tag in ("DOCUMENT_ROOT", "DOCUMENT_FRAGMENT"): return (base.DOCUMENT,) elif node.tag == "": return (base.DOCTYPE, node.text, node.get("publicId"), node.get("systemId")) elif node.tag == ElementTreeCommentType: return base.COMMENT, node.text else: assert isinstance(node.tag, string_types), type(node.tag) # This is assumed to be an ordinary element match = tag_regexp.match(node.tag) if match: namespace, tag = match.groups() else: namespace = None tag = node.tag attrs = OrderedDict() for name, value in list(node.attrib.items()): match = tag_regexp.match(name) if match: attrs[(match.group(1), match.group(2))] = value else: attrs[(None, name)] = value return (base.ELEMENT, namespace, tag, attrs, len(node) or node.text) def getFirstChild(self, node): if isinstance(node, tuple): element, key, parents, flag = node else: element, key, parents, flag = node, None, [], None if flag in ("text", "tail"): return None else: if element.text: return element, key, parents, "text" elif len(element): parents.append(element) return element[0], 0, parents, None else: return None def getNextSibling(self, node): if isinstance(node, tuple): element, key, parents, flag = node else: return None if flag == "text": if len(element): parents.append(element) return element[0], 0, parents, None else: return None else: if element.tail and flag != "tail": return element, key, parents, "tail" elif key < len(parents[-1]) - 1: return parents[-1][key + 1], key + 1, parents, None else: return None def getParentNode(self, node): if isinstance(node, tuple): element, key, parents, flag = node else: return None if flag == "text": if not parents: return element else: return element, key, parents, None else: parent = parents.pop() if not parents: return parent else: assert list(parents[-1]).count(parent) == 1 return parent, list(parents[-1]).index(parent), parents, None return locals() getETreeModule = moduleFactoryFactory(getETreeBuilder) PK!ơ etree_lxml.pynu[from __future__ import absolute_import, division, unicode_literals from six import text_type from lxml import etree from ..treebuilders.etree import tag_regexp from . import base from .. import _ihatexml def ensure_str(s): if s is None: return None elif isinstance(s, text_type): return s else: return s.decode("ascii", "strict") class Root(object): def __init__(self, et): self.elementtree = et self.children = [] try: if et.docinfo.internalDTD: self.children.append(Doctype(self, ensure_str(et.docinfo.root_name), ensure_str(et.docinfo.public_id), ensure_str(et.docinfo.system_url))) except AttributeError: pass try: node = et.getroot() except AttributeError: node = et while node.getprevious() is not None: node = node.getprevious() while node is not None: self.children.append(node) node = node.getnext() self.text = None self.tail = None def __getitem__(self, key): return self.children[key] def getnext(self): return None def __len__(self): return 1 class Doctype(object): def __init__(self, root_node, name, public_id, system_id): self.root_node = root_node self.name = name self.public_id = public_id self.system_id = system_id self.text = None self.tail = None def getnext(self): return self.root_node.children[1] class FragmentRoot(Root): def __init__(self, children): self.children = [FragmentWrapper(self, child) for child in children] self.text = self.tail = None def getnext(self): return None class FragmentWrapper(object): def __init__(self, fragment_root, obj): self.root_node = fragment_root self.obj = obj if hasattr(self.obj, 'text'): self.text = ensure_str(self.obj.text) else: self.text = None if hasattr(self.obj, 'tail'): self.tail = ensure_str(self.obj.tail) else: self.tail = None def __getattr__(self, name): return getattr(self.obj, name) def getnext(self): siblings = self.root_node.children idx = siblings.index(self) if idx < len(siblings) - 1: return siblings[idx + 1] else: return None def __getitem__(self, key): return self.obj[key] def __bool__(self): return bool(self.obj) def getparent(self): return None def __str__(self): return str(self.obj) def __unicode__(self): return str(self.obj) def __len__(self): return len(self.obj) class TreeWalker(base.NonRecursiveTreeWalker): def __init__(self, tree): # pylint:disable=redefined-variable-type if isinstance(tree, list): self.fragmentChildren = set(tree) tree = FragmentRoot(tree) else: self.fragmentChildren = set() tree = Root(tree) base.NonRecursiveTreeWalker.__init__(self, tree) self.filter = _ihatexml.InfosetFilter() def getNodeDetails(self, node): if isinstance(node, tuple): # Text node node, key = node assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key return base.TEXT, ensure_str(getattr(node, key)) elif isinstance(node, Root): return (base.DOCUMENT,) elif isinstance(node, Doctype): return base.DOCTYPE, node.name, node.public_id, node.system_id elif isinstance(node, FragmentWrapper) and not hasattr(node, "tag"): return base.TEXT, ensure_str(node.obj) elif node.tag == etree.Comment: return base.COMMENT, ensure_str(node.text) elif node.tag == etree.Entity: return base.ENTITY, ensure_str(node.text)[1:-1] # strip &; else: # This is assumed to be an ordinary element match = tag_regexp.match(ensure_str(node.tag)) if match: namespace, tag = match.groups() else: namespace = None tag = ensure_str(node.tag) attrs = {} for name, value in list(node.attrib.items()): name = ensure_str(name) value = ensure_str(value) match = tag_regexp.match(name) if match: attrs[(match.group(1), match.group(2))] = value else: attrs[(None, name)] = value return (base.ELEMENT, namespace, self.filter.fromXmlName(tag), attrs, len(node) > 0 or node.text) def getFirstChild(self, node): assert not isinstance(node, tuple), "Text nodes have no children" assert len(node) or node.text, "Node has no children" if node.text: return (node, "text") else: return node[0] def getNextSibling(self, node): if isinstance(node, tuple): # Text node node, key = node assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key if key == "text": # XXX: we cannot use a "bool(node) and node[0] or None" construct here # because node[0] might evaluate to False if it has no child element if len(node): return node[0] else: return None else: # tail return node.getnext() return (node, "tail") if node.tail else node.getnext() def getParentNode(self, node): if isinstance(node, tuple): # Text node node, key = node assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key if key == "text": return node # else: fallback to "normal" processing elif node in self.fragmentChildren: return None return node.getparent() PK!_m  genshi.pynu[from __future__ import absolute_import, division, unicode_literals from genshi.core import QName from genshi.core import START, END, XML_NAMESPACE, DOCTYPE, TEXT from genshi.core import START_NS, END_NS, START_CDATA, END_CDATA, PI, COMMENT from . import base from ..constants import voidElements, namespaces class TreeWalker(base.TreeWalker): def __iter__(self): # Buffer the events so we can pass in the following one previous = None for event in self.tree: if previous is not None: for token in self.tokens(previous, event): yield token previous = event # Don't forget the final event! if previous is not None: for token in self.tokens(previous, None): yield token def tokens(self, event, next): kind, data, _ = event if kind == START: tag, attribs = data name = tag.localname namespace = tag.namespace converted_attribs = {} for k, v in attribs: if isinstance(k, QName): converted_attribs[(k.namespace, k.localname)] = v else: converted_attribs[(None, k)] = v if namespace == namespaces["html"] and name in voidElements: for token in self.emptyTag(namespace, name, converted_attribs, not next or next[0] != END or next[1] != tag): yield token else: yield self.startTag(namespace, name, converted_attribs) elif kind == END: name = data.localname namespace = data.namespace if namespace != namespaces["html"] or name not in voidElements: yield self.endTag(namespace, name) elif kind == COMMENT: yield self.comment(data) elif kind == TEXT: for token in self.text(data): yield token elif kind == DOCTYPE: yield self.doctype(*data) elif kind in (XML_NAMESPACE, DOCTYPE, START_NS, END_NS, START_CDATA, END_CDATA, PI): pass else: yield self.unknown(kind) PK!33)__pycache__/__init__.cpython-36.opt-1.pycnu[PK!=L#__pycache__/__init__.cpython-36.pycnu[PK!P4j%u__pycache__/base.cpython-36.opt-1.pycnu[PK!P4jT/__pycache__/base.cpython-36.pycnu[PK! G__$-A__pycache__/dom.cpython-36.opt-1.pycnu[PK! G__G__pycache__/dom.cpython-36.pycnu[PK! &N__pycache__/etree.cpython-36.opt-1.pycnu[PK!۰I t\__pycache__/etree.cpython-36.pycnu[PK!+j__pycache__/etree_lxml.cpython-36.opt-1.pycnu[PK!G=%3__pycache__/etree_lxml.cpython-36.pycnu[PK!.  '"__pycache__/genshi.cpython-36.opt-1.pycnu[PK!.  !__pycache__/genshi.cpython-36.pycnu[PK!sD! __init__.pynu[PK!M#KKbase.pynu[PK!eoIdom.pynu[PK!\@@etree.pynu[PK!ơ |etree_lxml.pynu[PK!_m  Rgenshi.pynu[PKf