/$ZL@dZdZddlZddlmZ ddlmZn#GddZYnxYw ddlZeZn#e $rddlZYnwxYwdZ d Z d Z d Z ed \ZZZd ZdZdZdZdZGddZddZdS)aXML Canonicalization Patches Applied to xml.dom.ext.c14n: http://sourceforge.net/projects/pyxml/ [ 1444526 ] c14n.py: http://www.w3.org/TR/xml-exc-c14n/ fix -- includes [ 829905 ] c14n.py fix for bug #825115, Date Submitted: 2003-10-24 23:43 -- include dependent namespace declarations declared in ancestor nodes (checking attributes and tags), -- handle InclusiveNamespaces PrefixList parameter This module generates canonical XML of a document or element. http://www.w3.org/TR/2001/REC-xml-c14n-20010315 and includes a prototype of exclusive canonicalization http://www.w3.org/Signature/Drafts/xml-exc-c14n Requires PyXML 0.7.0 or later. Known issues if using Ft.Lib.pDomlette: 1. Unicode 2. does not white space normalize attributes of type NMTOKEN and ID? 3. seems to be include " " after importing external entities? Note, this version processes a DOM tree, and consequently it processes namespace nodes as attributes, not from a node's namespace axis. This permits simple document and element canonicalization without XPath. When XPath is used, the XPath result node list is passed and used to determine if the node is in the XPath result list, but little else. Authors: "Joseph M. Reagle Jr." "Rich Salz" $Date: 2006-03-30 23:47:16 +0000 (Thu, 30 Mar 2006) $ by $Author: boverhof $ a*Copyright 2001, Zolera Systems Inc. All Rights Reserved. Copyright 2001, MIT. All Rights Reserved. Distributed under the terms of: Python 2.0 License or later. http://www.python.org/2.0.1/license.html or W3C Software License http://www.w3.org/Consortium/Legal/copyright-software-19980720 N)Node)XMLNSceZdZdZdZdS)rzhttp://www.w3.org/2000/xmlns/$http://www.w3.org/XML/1998/namespaceN)__name__ __module__ __qualname__BASEXML3/usr/lib/python3/dist-packages/pysimplesoap/c14n.pyrr7s.4r rcF|jr|jpgSN) attributesvaluesEs rr@s AL:Q\%8%8%:%:Arr c|jpgSr) childNodesrs rrrAs al(br c6|jdS)Nxmlns)name startswithns rrrBsqv((11r c|jdkSr)unsuppressedPrefixesrs rrrCsq-5r crt|j|j}|r|St|j|jS)zB_sorter(n1,n2) -> int Sorting predicate for non-NS attributes.)cmp namespaceURI localName)n1n2is r_sorterr(Js4 BOR_--AN( r|R\ * **r cr|ddkrdS|ddkrdSt|d|dS)zY_sorter_ns((n,v),(n,v)) -> int "(an empty namespace URI is lexicographically least)."rr)r")r%r&s r _sorter_nsr,SsB !u !u r!ube  r c.|dr |dd}n|dr |dd}|dkr |jdvs||jks||vrdS|D]}||jkrdS| t|D]}||jkrdSd S) z~_utilized(n, node, other_attrs, unsuppressedPrefixes) -> boolean Return true if that nodespace is utilized within the nodexmlns:Nr)z#defaultNr+r)rprefix_attrs)rnode other_attrsrattrs r _utilizedr7[s ||H abbE g   abbE 2$+!333 T[A!5551&&   AAA '4LL * *DDK 1r cg}|jr d|jzg}ndg}t|D]A}|jds|js$|d|jzBi}|D]}|j}||vr||#|dr"|dd|vr||Z|dr"|dd|vr|||j|vr|||dr |j||<||fS)zhttp://www.w3.org/TR/xml-exc-c14n/ InclusiveNamespaces PrefixList parameter, which lists namespace prefixes that are handled in the manner described by the Canonical XML Recommendationxmlns:%srr.r/Nr0)r2r3nodeNamerappendvalue) r4contextr inclusive usedPrefixesaunused_namespace_dictr6rs r_inclusiveNamespacePrefixesrBosI {!"DK/0 y D\\22 :  ) )CC8J01111 2 2 M $ $ $   T " " " " \\( # # 2!""1E(E(E   T " " " " \\' " " 2qu0D'D'D   T " " " " ]l * *   T " " " " \\( # # 2'+z !! $ + ++r c|dup||vSrr )subsetr4s rrrs&D."BDFNr ceZdZdZiZdZdZdZeeej <dZ e eej <e eej <dZ e eej<dZeeej<dZgd fd Zeeej<d S) _implementationzImplementation class for C14N. This accompanies a node during it's processing and includes the parameters and processing state.c &||_|d|_|dd|_|d|_|dt jt jd}|ddiiif|_|j tj kr| |d S|j tj krt|_t!|sFt#||||j\}}|||| d S||}|||d S|j tjkrd St+t-|) z"Create and run the implementation.rDcommentsrrnsdict)xmlrrJr1)unusedN)writegetrDrHrrr r statenodeTyper DOCUMENT_NODE _do_document ELEMENT_NODE_Element documentOrder _inclusiverB_inherit_context _do_elementDOCUMENT_TYPE_NODE TypeErrorstr)selfr4rLkwrI inheritedrKs r__init__z_implementation.__init__ss ffX&& z1-- $&FF+A$B$B!59uz"K"KLLuRj"b1 =D. . .   d # # # # # ]d/ / /!)D d## 2#>tTEZEZ[_E`E` $ 9$;$; &  y @@@@@ 11$77   y11111 ]d5 5 5 DCII&& &r czttt|}g|j}}|r|jt jkrxttt|D]7}|j}||vr*||||8|j}|r|jt jkx|S)z_inherit_context(self, node) -> list Scan ancestors of attribute and namespace context. Used only for single element node canonicalization, not for subset canonicalization.) filter _IN_XML_NSr3 parentNoderOrrRr$r;)r[r4xmlattrsr]parentr@rs rrVz _implementation._inherit_contexts*fTll336  'D,===Jv77 ( (KH$$OOA&&&$$Q'''&F  'D,===r ct|_|jD]}|jtjkr.t |_||t|_E|jtj kr| |p|jtj kr| ||jtj krtt|dS)z_do_document(self, node) -> None Process a document node. documentOrder holds whether the document element has been encountered such that PIs/comments can be written as specified.N)_LesserElementrTrrOrrRrSrW_GreaterElementPROCESSING_INSTRUCTION_NODE_do_pi COMMENT_NODE _do_commentrXrYrZ)r[r4childs rrQz_implementation._do_documents ,_ , ,E~!222%-"  '''%4""4#CCC E""""4#444  ''''4#:::E +++ , ,r c t|j|sdStj|jdd}tj|dd}tj|dd}tj|dd }|r||dSdS) z_do_text(self, node) -> None Process a text or CDATA node. Render various special characters as their C14N entity representations.N&&<<>z> z ) _in_subsetrDstringreplacedatarL)r[r4ss r_do_textz_implementation._do_texts$+t,,4ff N49c7 3 3 N1c6 * * N1c6 * * N1fg . . djjmmmmmr c<t|j|sdS|j}|jtkr |d|d||j|j}|r|d|||d|jtkr |ddSdS)z_do_pi(self, node) -> None Process a PI node. Render a leading or trailing #xA if the document order of the PI is greater or lesser (respectively) than the document element. N z)rtrDrLrTrgr:rwrf)r[r4Wrxs rriz_implementation._do_pis $+t,,4ff J   0 0!!D''' $ $- I   AcFFF AaDDD $   / /4 / /r ct|j|sdS|jre|j}|jt kr |d|d||j|d|jtkr|ddSdSdS)z_do_comment(self, node) -> None Process a comment node. Render a leading or trailing #xA if the document order of the comment is greater or lesser (respectively) than the document element. Nr{z)rtrDrHrLrTrgrwrf)r[r4r}s rrkz_implementation._do_comments $+t,,4ff = = A!_44aaggg AfIII AdiLLL AeHHH!^33QQtWWWWW  = = 43r c|j}|d|||dtj|dd}tj|dd}tj|dd}tj|d d }tj|d d }tj|d d}|||ddS)z;'_do_attr(self, node) -> None Process an attribute.r|z="rnrorprq"z" z r{z rsz N)rLrurv)r[rr<r}rxs r_do_attrz_implementation._do_attrs J # ! $ N5#w / / N1c6 * * N1c8 , , N1ff - - N1ff - - N1ff - - ! #r Nc|jd|jd|jd}}}|}||jd}|}t|} i} g} t|j|} |t |zD]} | jtjkr| j }|dkrd}| j ||<nc| jtj kr$| s| rt|j| r | | | j <n*t|j| r| | | | |jd}}| r7|j }| sv|j d|jz}nd}||sM||s8||st#d |d |||||<||=|d ||g}|D]\}}|dkr5|tjd fvr%|dtjd dfvr@|d vr|dvrI||f|vr8| st)||| |jr| ||f| s|||<|t.|D] \}}||||||<!| rt|j|jr(| | n'| || t8| D]"} || j | j#|d|j||||fc}|_t=|D]"}t?j |j!||#||_|r|d|zdSdS)zu_do_element(self, node, initial_other_attrs = [], unused = {}) -> None Process an element (and its children).rr+Nr r.rr9z*For exclusive c14n, unable to map prefix "z" in rpr1)z xmlns:xmlrJ)rrrz)"rNcopyrUrtrDr3r#rr r: nodeValuer r;updaterLr2has_key RuntimeErroritemsrMr7rsortr,rrbextendrr(r< _childrenrFhandlersrO)r[r4initial_other_attrsrK ns_parent ns_rendered xml_attrsns_unused_inheritedns_localr>xml_attrs_localr5 in_subsetr@rr}rr2 ns_to_rendervrNcs rrWz_implementation._do_element%s 1 tz!}1133TZ]5G5G5I5I!*; % >"&*Q-"4"4"6"6 >>##t$$  t{D11 $vd||3 . .A~++J==g!k 59,,44 4;0J0J423OAJ/t{A..*&&q)))   _ - - - -*d4 > =D 4;*'4FF$F"**62248;K;KF;S;S4.66v>>+*l"FFDD*+++(;6'BHV$+F3 AcFFF AdGGGL~~'' 3 3!<"""""""r )rrr __doc__rr^rVrQrrPry TEXT_NODECDATA_SECTION_NODErirhrkrjrrWrRr r rrFrFsDDH'''8*,,,($0HT      (HT^(0HT $%999"28HT -. = = =#.HT $794t#t#t#t#j#.HT r rFc |rtt||jf|dStj}tt||jf||S)aCanonicalize(node, output=None, **kw) -> UTF-8 Canonicalize a DOM document/element node and all descendents. Return the text; if output is specified then output.write will be called to output the text and None will be returned Keyword parameters: nsdict: a dictionary of prefix:uri namespace entries assumed to exist in the surrounding context comments: keep comments if non-zero (default is 0) subset: Canonical XML subsetting resulting from XPath (default is []) unsuppressedPrefixes: do exclusive C14N, and this specifies the prefixes that should be inherited. N)applyrFrLStringIOgetvalue)r4outputr\rxs r Canonicalizers_ ofl3R88888     oag333zz||r r)r _copyrightruxml.domrxml.nsr cStringIOr ImportErrorr3rrarUrangerfrSrgr(r,r7rBrtrFrr r rrs##J   555555555555HHOOOOO B A ( ( 1 1 5 5 -2E!HH)/+++   (,,,>C B I.I.I.I.I.I.I.I.Xs(3 ??