/$ZWdZddlmZddlZejdkreZeZddlZddl Z ddl Z ddl Z ddl mZmZmZmZddlmZmZmZmZmZmZmZejeZGdd eZdS) zSimple XML manipulation)unicode_literalsN3) __author__ __copyright__ __license__ __version__)TYPE_MAPTYPE_MARSHAL_FNTYPE_UNMARSHAL_FNREVERSE_TYPE_MAPStructDateDecimalcHeZdZdZdddddidfdZd(dZdZdZd Zd)d Z e j d krd Z nd Z dZ dZdZdZdZdZdZdZdZ d*dZdZdZdZdZdZdZdZe j d kreZndZd Zd!Z e!d"Z"d+d#Z#d$Z$ d,d%Z%d&Z&d(d'Z'dS)-SimpleXMLElementz#Simple XML manipulation (simil PHP)NFc||_d|}tjd|z|_||_||_||_|_ tj j ||_ n #t|xYw|j jg|_dS||_||_ dS)z :param namespaces_map: How to map our namespace prefix to that given by the client; {prefix: received_prefix} |z ^(%s):.*$N)!_SimpleXMLElement__namespaces_mapjoinkeysrecompile_SimpleXMLElement__ns_rx_SimpleXMLElement__ns_SimpleXMLElement__prefix_SimpleXMLElement__jettyxmldomminidom parseString_SimpleXMLElement__documentlogerrordocumentElement_SimpleXMLElement__elements) selftextelementsdocument namespaceprefixnamespaces_mapjetty_rxs 8/usr/lib/python3/dist-packages/pysimplesoap/simplexml.py__init__zSimpleXMLElement.__init__'s !/hh~**,,--z,"455      "%'/"="=d"C"C  $#>?DOOO&DO&DOOOs #)B B*Tc |r |jdur|j|}nt|tr3|j|}|r|d|nR|jr+|j|j|jd|}n |j|j|}|t|tj j j r3| |j |jn-| |j||j |t#|g|j|j|j|j|jS)zAdding a child tag to a nodeFxmlns:Nr)r*r+r,r.r-)rr" createElement isinstance basestring setAttributercreateElementNSrrr CDATASection appendChildcreateCDATASectiondatacreateTextNode_elementrrr)r'namer(nselements r0 add_childzSimpleXMLElement.add_childAs KTY%''o33D99GG"j)) K/77==6(("555 K/99$)PTP]P]P]_c_cEdee/99$)TJJ  $ <== J##DO$F$Fty$Q$QRRRR##DO$B$B4$H$HIII !!'***Y_i=,0     c|drt|||dS|||dS)z$Add text child tag node (short form)_N) startswithobject __setattr__rD)r'tagr(s r0rJzSimpleXMLElement.__setattr__`sP >>#   &   tS$ / / / / / NN3 % % % % %rEcpd|jjD}|D]}|j|dS)z#Remove a child tag (non recursive!)c2g|]}|j|jk|SnodeType ELEMENT_NODE.0_SimpleXMLElement__elements r0 z0SimpleXMLElement.__delattr__..j5EEE) )Y-CCCCCCrEN)r@ childNodes removeChild)r'rKr)rCs r0 __delattr__zSimpleXMLElement.__delattr__hs[EEt}/GEEE / /G M % %g . . . . / /rEcn|j|}|j|dS)z Add an xml comment to this childN)r" createCommentr@r<)r'r>comments r0 add_commentzSimpleXMLElement.add_commentos3///55 !!'*****rEcp|s|jdS|jdS)z-Return the XML representation of the documentUTF-8)encoding)r"toxml toprettyxml)r'filenameprettys r0as_xmlzSimpleXMLElement.as_xmlts: A?((11 1?...@@ @rErc4|jS))Return the XML representation of this tagr@rar's r0__repr__zSimpleXMLElement.__repr__|s=&&(( (rEc6|jdS)rgr_rhris r0rjzSimpleXMLElement.__repr__s=&&w// /rEc|jjS)z Return the tag name of this node)r@tagNameris r0get_namezSimpleXMLElement.get_names }$$rEc|jjS)z4Return the tag local name (prefix:name) of this node)r@ localNameris r0get_local_namezSimpleXMLElement.get_local_names }&&rEc|jjS)z(Return the namespace prefix of this node)r@r,ris r0 get_prefixzSimpleXMLElement.get_prefixs }##rEc|j}|?|j: |jd|zjS#t$r |j}YnwxYw| |j6dSdSdSdS)z%Return the namespace uri for a prefixNzxmlns:%s)r@ attributesvalueKeyError parentNode)r'rBrCs r0get_namespace_uriz"SimpleXMLElement.get_namespace_uris-!g&8&D -)*r/:@@ - - -!, -!g&8&D&D&D!!&D&D!!s ';;c|jjS)z(Return a dict of attributes for this tag)r@ruris r0ruzSimpleXMLElement.attributess}''rEct|tr3|j|r|jj|jSdSt|t r1t|jj|S|j |}t|g|j |j |j |j|jS)z>Return xml tag attribute value or a slice of attributes (iter)r5N)r7r8r@ hasAttributerurvslicelistitemsr&rr"rrrr)r'itemrCs r0 __getitem__zSimpleXMLElement.__getitem__s dJ ' ' }))$// <}/5;; < < e $ $  0668899$? ?od+G#!)}l#4  rEc<|j||dS)z$Set an attribute value from a stringN)r@r9)r'rArvs r0 add_attributezSimpleXMLElement.add_attributes  ""4/////rEct|tr|||dSt|tr0|D]\}}|||dSdS)zSet an attribute valueN)r7r8rr}r)r'rrvkvs r0 __setitem__zSimpleXMLElement.__setitem__s dJ ' ' )   tU + + + + + e $ $ )  ) )1""1a(((( ) ) ) )rEc:|j|dS)zRemove an attributeN)r@removeAttributer'rs r0 __delitem__zSimpleXMLElement.__delitem__s %%d+++++rEc  |r9t|jjg|j|j|j|j|jS||S|r|Sd}t|tr|j |g}|rE|sCt|ttfr|p|fD]!}|j||}|rn"|jr"|s |j|j|}|s|j|}|s|rt#ddSt||j|j|j|j|jS#t"$r}t#d|d|dd}~wwxYw)z;Search (even in child nodes) and return a child tag by namer5NzNo elements foundzTag not found: z ())rr"r%rrrr__iter__childrenr7intr&tupler~r@getElementsByTagNameNSgetElementsByTagNameAttributeError) r'rKrBrrootr$r)ns_uries r0__call__zSimpleXMLElement.__call__s/ F '"o=>!_"i=,#'#8 {}}& '}}&H#s## 2 OC01 ( (eT];;BLrfF#}CCFCPPHy P P=?? 3OO C===cBB ()<===F#!)}l#4 666 6 F F F .SSS!!!!DEE E Fs/:EEE)CE/-E F'E==Fc,||S)zShortcut for __call__)r)r'rKs r0 __getattr__zSimpleXMLElement.__getattr__s}}S!!!rEc #K |jD]3}t|g|j|j|j|j|jV4dS#xYw)z#Iterate over xml tags at this levelr5N)r&rr"rrrr)r'rTs r0rzSimpleXMLElement.__iter__sw !_ : : &'[!_"i=,#'#8 ::::::: : :  s ;AAc.d|jjDS)zList xml children tags namesc<g|]}|j|jk|jSrN)rP TEXT_NODErm)rSnodes r0rUz,SimpleXMLElement.__dir__.. s2444=DN22 222rE)r@rWris r0__dir__zSimpleXMLElement.__dir__ s(44=+444 4rEcd|jjD}|sdSt||j|j|j|j|jS)z Return xml children tags elementc2g|]}|j|jk|SrNrOrRs r0rUz-SimpleXMLElement.children..rVrENr5)r@rWrr"rrrr)r'r)s r0rzSimpleXMLElement.childrensjEEt}/GEEE 4_i=,0     rEc*t|jS)zReturn element count)lenr&ris r0__len__zSimpleXMLElement.__len__!s4?###rEc6|j|S)z4Search for a tag name in this element or child nodes)r@rrs r0 __contains__zSimpleXMLElement.__contains__%s}11$777rEc|d}|jjD],}|j|jks|j|jkr ||jz}-|S)z5Returns the unicode text nodes of the current element)r@rWrPrCDATA_SECTION_NODEr>)r'rcrs r0 __unicode__zSimpleXMLElement.__unicode__)sJ M, $ $D}..$-4CZ2Z2Z$)^ rEcP|dS)Nzutf-8)rencoderis r0__str__zSimpleXMLElement.__str__4s"##%%,,W55 5rEcDt|S)z0Returns the integer value of the current element)rrris r0__int__zSimpleXMLElement.__int__7s4<<>>"""rEc t|S#t|jxYw)z.Returns the float value of the current element)floatr IndexErrorr@raris r0 __float__zSimpleXMLElement.__float__;sB 4(( ( 4T]002233 3s #(A c|jdS)Nr)r&ris r0zSimpleXMLElement.Bs T_Q%7rEc  i}|D]}t|}d}d|vrY|ddd}|ddD]3}|d|kr%|}|dd d}n4 t |t rB||} td |ddDrt | ts| g} n|} nF#tf$r7} |d p&| | } d|vr|dd d} | d krkd |ddDd} || d d} d| vr| d| d} t| g} n t| } n5#d} Yn/xYw| dkrd} n#d|vrd} n|rtd|dt} Yd} ~ nd} ~ wwxYwt | trL||g}|p|}| rgt | dt sL|pgD]E}|| d|}||Fnt)| ddkrf|D]a}i}|pgD]1}||| d|2||bnY|pgD]1}||| d|2n!t | t.rg}i}|}t)| dkot | dt }|r |pgD]c}|r0||| d|4||| d|d|r||||vr:t||}||t/|}nt/|}nt | t r-|}|o|| |}n| |}nt1|s| tkrt1|dkrx t3j| | } | tkrt1|}n| t1|}n0#t6tf$r} t7d|d| d} ~ wwxYwd}|||<|S)z;Convert to python values the current serialized xml elementNhrefrT)rmultiRefidzxsi:typer4c g|] \}}d|v | S arrayTyperNrSrrs r0rUz/SimpleXMLElement.unmarshall.._s&EEE#!AK14D4DA4D4D4DrEr3Arrayc g|] \}}d|v | SrrNrs r0rUz/SimpleXMLElement.unmarshall..js')S)S)S!+QRBRBR!BRBRBRrEr[z http://www.w3.org/2001/XMLSchemazTag: z invalid (type not found)rz: )strrqrursplitr7dictanyr~rwryrsindexr TypeError setdefaultr unmarshallextendvaluesrupdateappendrunicoder get ValueError)r'typesstrictdrrA ref_name_typerref_nodefnrr3xsd_type array_typervrchildtmp_dictparent_das_dict_tmps r0rzSimpleXMLElement.unmarshallDsb DFFx x Dt**,,--D M**//1111F|ABB' /$ ; ;H~--'(0(<(B(B3(G(G(J . % eT**tBEEaaaEEEFF"zZ\^bOcOc" TB<   W R)?)?@Q@Q)R)R!2!2!7!7!9!999#J/55c::1=H "#w..)S)StAAAw)S)S)STU)VJ'+J'7'='=c'B'B1'EH"h+34HX^^C5H5H4H+I"28"HIH1II AV))W:WWc|j|}|rj|d} |||j|}n-#t $r t d|zYnwxYw|S)zBReplace the defined namespace alias with tohse used by the client.rzUnknown namespace alias %s)rsearchgroupsreplacerrwr#warning)r'rAprefs r0 _update_nszSimpleXMLElement._update_nss|""4((  A;;==#D A||D$*?*EFF A A A 84?@@@@@ A s!A'BBc||}t|tr|r|||p|}|D]P\}} |sd}n-t |dr|j|}nd}||| ||QdSt|trP|r|||p|}|sd}|D],\}} t|||| ||-dSt|tr|||}|sd}|r| dt|D]t\} } ||| d||t| tr@t| dkr-| t|dz kr|||}udSt|tjjjt&fr||||dS||||dS|t)jvr9|||}| t(|dSt-jt/|t0} ||| ||dS)zFAnalyze python value and add the serialized XML element using tag name)rBF namespacesN) add_commentsrBzRepetitive array of:r)rr7rrDrhasattrrrmarshallrgetattrr~r] enumeraterrrr r;r8r rr typer) r'rArvrDrrBadd_children_nsrrritrs r0rzSimpleXMLElement.marshallst$$ eT " "/ 3=$.."."="=EE G G1&BBUL11)--a00BBBq!,2FFFF G Gu % %! 3=$.."."="=EE"  U U1d##,,Q QS,TTTT U U t $ $ 3 NN4BN//E"  :!!"8999!%(( 8 81tQLRPPPa&&83q66A::!c%jj1n:L:L NN4BN77E  8 8  &&&///+++ AAAA {S ) ) ) ) 0 0 0 %%%'''$$$---((( *000))),,,@E2F2F2F2Fh"""   444    $$$888 {S 6 6 6###444x7788HCCCCJ   BG+/53535353n%%%rEr)r __future__rrrrr8rloggingrtimexml.dom.minidomrrrrrr helpersr r r r rrr getLoggerrr#rIrrNrEr0r s8(''''' ;JG AAAAAAAAAAAA==================g!!pppppvppppprE