ó \STc@sdZdZddlZddlmZyddlmZWnddd„ƒYZnXyddlZeZWne k rŽddlZnXd„Z d „Z d „Z d „Z ed ƒ\ZZZd „Zd„Zd„Zd„Zddd„ƒYZdd„ZdS(s¼XML Canonicalization 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: 2003/01/25 11:41:21 $ by $Author: loewis $ s*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 iÿÿÿÿN(tNode(tXMLNSRcBseZdZdZRS(shttp://www.w3.org/2000/xmlns/s$http://www.w3.org/XML/1998/namespace(t__name__t __module__tBASEtXML(((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR-scCs|jr|jjƒpgS(N(t attributestvalues(tE((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyt6scCs |jp gS(N(t childNodes(R((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR 7scCs|jjdƒS(Ntxmlns(tnamet startswith(tn((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR 8scCs |jdkS(N(tunsuppressedPrefixestNone(R((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR 9sicCs2t|j|jƒ}|r|St|j|jƒS(sB_sorter(n1,n2) -> int Sorting predicate for non-NS attributes.(tcmpt namespaceURIt localName(tn1tn2ti((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyt_sorter@scCs=|ddkrdS|ddkr(dSt|d|dƒS(sY_sorter_ns((n,v),(n,v)) -> int "(an empty namespace URI is lexicographically least)."iR iÿÿÿÿi(R(RR((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyt _sorter_nsIs cCsš|jdƒr|d}n|jdƒr8|d}n|dkrS|jd ksn||jksn||krrdSx!|D]}||jkrydSqyWdS( s~_utilized(n, node, other_attrs, unsuppressedPrefixes) -> boolean Return true if that nodespace is utilized within the nodesxmlns:iR its#defaultiiN(s#defaultN(R tprefixR(Rtnodet other_attrsRtattr((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyt _utilizedQs   cCs|dkp||kS(N(R(tsubsetR((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR ast_implementationcBs­eZdZiZd„Zd„Zd„Zeeej list Scan ancestors of attribute and namespace context. Used only for single element node canonicalization, not for subset canonicalization.( tfiltert _IN_XML_NSt_attrst parentNodeR'RR*Rtappend(R3RtxmlattrsR5tparenttaR((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR/„s    cCs½t|_x­|jD]¢}|jtjkrMt|_|j|ƒt|_q|jtj kro|j |ƒq|jtj kr‘|j |ƒq|jtj kr¦qtt|ƒ‚qWdS(sË_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(t_LesserElementR,R R'RR*R+R.t_GreaterElementtPROCESSING_INSTRUCTION_NODEt_do_pit COMMENT_NODEt _do_commentR0R1R2(R3Rtchild((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR)™s    cCs‡t|j|ƒsdStj|jddƒ}tj|ddƒ}tj|ddƒ}tj|dd ƒ}|rƒ|j|ƒndS( s“_do_text(self, node) -> None Process a text or CDATA node. Render various special characters as their C14N entity representations.Nt&s&ts>s s (t _in_subsetRtstringtreplacetdataR$(R3Rts((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyt_do_text°scCs¢t|j|ƒsdS|j}|jtkr;|dƒn|dƒ||jƒ|j}|rx|dƒ||ƒn|dƒ|jtkrž|dƒndS(sÎ_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. Ns s(RIRR$R,R@tnodeNameRLR?(R3RtWRM((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyRB¾s        cCsˆt|j|ƒsdS|jr„|j}|jtkrD|dƒn|dƒ||jƒ|dƒ|jtkr„|dƒq„ndS(sÝ_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. Ns s(RIRR!R$R,R@RLR?(R3RRQ((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyRDÒs      cCs½|j}|dƒ||ƒ|dƒtj|ddƒ}tj|ddƒ}tj|ddƒ}tj|d d ƒ}tj|d d ƒ}tj|d dƒ}||ƒ|dƒdS(s;'_do_attr(self, node) -> None Process an attribute.ROs="RFs&RGs<t"s"s s s s s s N(R$RJRK(R3RtvalueRQRM((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyt_do_attrãs     c Csu|jd|jdjƒ|jdjƒ}}}|jƒ}i}|}t|j|ƒ} xÌt|ƒD]¾} | jtjkr³| j} | dkr£d} n| j || None Process an element (and its children).iiisxmlns:R RGRs xmlns:xmlR#s$http://www.w3.org/XML/1998/namespaceRHsN(s xmlns:xmlsxml(s$http://www.w3.org/XML/1998/namespace( R&tcopyRIRR9RRRRPt nodeValueRR-R;tupdateR$RtitemsR%RRtsortRRTR:textendRRRSt _childrenR thandlersR'(R3Rtinitial_other_attrst ns_parentt ns_renderedt xml_attrstns_localtxml_attrs_localRt in_subsetR>RRQR t ns_to_rendertvR&tc((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR.õsf 5   $   !!    "    (RRt__doc__R\R6R/R)RR(RNt TEXT_NODEtCDATA_SECTION_NODERBRARDRCRTR.R*(((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyR cs             YcKsU|r"tt||jf|ƒn/tjƒ}tt||jf|ƒ|jƒSdS(s™Canonicalize(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(tapplyR R$tStringIOtgetvalue(RtoutputR4RM((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyt CanonicalizeQs  (((Rgt _copyrightRJtxml.domRtxml.nsRt cStringIORkt ImportErrorR9R[R8R-trangeR?R+R@RRRRIR RRn(((sD/opt/freeware/lib64/python2.7/site-packages/_xmlplus/dom/ext/c14n.pyts.            î