!Vfi &ddlZddlZddlmcmZdZGddejZ ddZ ddZ ddZ d Z dd Z dd Z d Z dd Z dddddddeddZ dddddddeddZ dddddddeddZejdZdS)NcRdtjDS)Nci|]\}}|| Sr.0uriprefixs Jc:\PYTHON\DbComparer\venv\Lib\site-packages\et_xmlfile/incremental_tree.py z(current_global_nsmap..0s+   #V   )ET_namespace_mapitemsrr r current_global_nsmapr/s2  ')'8'>'>'@'@   r c*eZdZ dddddddZdS)IncrementalTreeNTF)short_empty_elementsnsmap root_ns_onlyminimal_ns_onlyc |sd}n|dvrtd|z|sd}t||5\} } |dkrA|s0|=|dkr%| dvr| d| d |d krtj| |jn|dkrd } nd } |r(d|vrtd |} ni} |r|| d<|s| r6t|j|| } | s|r| ||r|| d<dtj D}d|vrtdi}t| |j||| d || ddddS#1swxYwYdS)a- Write element tree to a file as XML. Arguments: *file_or_filename* -- file name or a file object opened for writing *encoding* -- the output encoding (default: US-ASCII) *xml_declaration* -- bool indicating if an XML declaration should be added to the output. If None, an XML declaration is added if encoding IS NOT either of: US-ASCII, UTF-8, or Unicode *default_namespace* -- sets the default XML namespace (for "xmlns"). Takes precedence over any default namespace provided in nsmap or xml.etree.ElementTree.register_namespace(). *method* -- either "xml" (default), "html, "text", or "c14n" *short_empty_elements* -- controls the formatting of elements that contain no content. If True (default) they are emitted as a single self-closed tag, otherwise they are emitted as a pair of start/end tags *nsmap* -- a mapping of namespace prefixes to URIs. These take precedence over any mappings registered using xml.etree.ElementTree.register_namespace(). The default_namespace argument, if supplied, takes precedence over any default namespace supplied in nsmap. All supplied namespaces will be declared on the root element, even if unused in the document. *root_ns_only* -- bool indicating namespace declrations should only be written on the root element. This requires two passes of the xml tree adding additional time to the writing process. This is primarily meant to mimic xml.etree.ElementTree's behaviour. *minimal_ns_only* -- bool indicating only namespaces that were used to qualify elements or attributes should be declared. All namespace declarations will be written on the root element regardless of the value of the root_ns_only arg. Requires two passes of the xml tree adding additional time to the writing process. xml)textrhtmlzunknown method %rus-asciiNunicode)utf-8rz rFTzTFound None as default nsmap prefix in nsmap. Use "" as the default namespace prefix.ci|]\}}|| Srrrs r r z)IncrementalTree.write..s+   $/CFC   r zxFound None as default nsmap prefix in nsmap registered with register_namespace. Use "" for the default namespace prefix.)is_htmlis_rootr new_nsmap) ValueError _get_writerlowerr _serialize_text_rootcopy _namespacesupdaterr_serialize_ns_xml)selffile_or_filenameencodingxml_declarationdefault_namespacemethodrrrrwritedeclared_encodingr r" global_nsmap nsmap_scopes r r2zIncrementalTree.write7sz ;FF 2 2 2069:: : "!H )8 4 4> 8R@Q$+ ((I55)//119NNNARARARTUUU"5$*5555U??#GG"G#u}}(F!& II "I$6$5IbM>?>!, )!!!I +> 4&,,U333,>,=IbM  353D3J3J3L3L    <''$W! !J # )='    k> > > > > > > > > > > > > > > > > > sD=E::E>E>)NNNN)__name__ __module__ __qualname__r2rr r rr5sV  B"BBBBBBBr rcnt|}| d|vr|dz } d|}||vr ||vr|r||vr|S|dz })NrTns)len)r5global_prefixes local_nsmapr0ir s r _make_new_ns_prefixr@sz KA$;)>)> Q a + % %o--.#)#<#<M Q r Fc|D]\}}||kr||vr|}nt||}|||<|||<|s|||<|dkr|||S)aAFind a prefix that doesn't conflict with the ns scope or create a new prefix This function mutates nsmap_scope, global_nsmap, new_namespace_prefixes and uri_to_prefix. It is intended to keep state in _serialize_ns_xml consistent while deduplicating the house keeping code or updating these dictionaries. )r=r)rr@add) rr5r4new_namespace_prefixes uri_to_prefix!for_default_namespace_attr_prefix global_prefix global_urir s r _get_or_create_prefixrHs$&2%7%7%9%9##! z *  k!A!A"F E%[,OOO" VK ,$# c ""6*** Mr c|D]\}}||kr |dkr|cS|D]\}}||kr |dkr|cStj|}|r||vr|St ||||S)Nr)rr rgetr@)r0rr>r=provided_default_namespacer rs r #_find_default_namespace_attr_prefixrLs{{}}  # # #" MMM"((**  # # #" MMM  " "#4 5 5F &%%  "   r c g}|D]M\}} t|tjr|j} |dddkr|dddd} || d} nU#t $rH|s*|}|}d}t| d||||} YnwxYw| s~|r|} ny|D]\} } | | dkr | dkr| }nJ|s*|}|}d}t| d||||d} | }| d| d}n$#t$rtj |YnwxYwt| tjr| jdddkr| j} n| jdddd} || d} nU#t $rH|s*|}|}d}t| d||||} YnwxYw| d| d} | || fO|||fS) Nr:{}rTr)rE:) r isinstancer QNamerrsplitKeyErrorr(rH TypeError_raise_serialization_errorappend) elemis_nsmap_scope_changeddefault_ns_attr_prefixr5r4rCrD item_partskv uri_and_namer known_uris r process_attribsr`s!J O"O"1 a " " A2 -!u|| u||C33 *<?;FF16 '2&6&6&8&8 (5(:(:(<(< 15.2$Q#$.% FFF"<- /:.>.>.@.@ 0=0B0B0D0D 9= 6%: ,Q + , 6 -BF &&&F6<211 Q11 - - -  )! , , , , , - a " " 2vbqbzS  F vabbz00a88 *<?;FF16 '2&6&6&8&8 (5(:(:(<(< 15.2$Q#$.% FFF 11 Q111a&!!!! -{ ::sJ-E-A<;E (returns tag = 'foo') - text (returns tag = 'foo') - (returns tag = None) Returns: tag: The tag name to be closed or None if no closing required. nsmap_scope: The current nsmap after any prefix to uri additions from this element. This is the input dict if unmodified or an updated copy. default_ns_attr_prefix: The prefix for the default namespace to use with attrs. uri_to_prefix: The current uri to prefix map after any uri to prefix additions from this element. This is the input dict if unmodified or an updated copy. next_remains_root: A bool indicating if the child element(s) should be treated as their own roots. z NFzTrzIFound None as a namespace prefix. Use "" as the default namespace prefix.ci|]\}}|| Srrrr rs r r z$write_elem_start..sPPP[VSS&PPPr rr:rNrOrrPz$write_elem_start..s<"^"^"^TQPQ#Hq#H#HB,B1,E,E#H#H#H"^"^"^r cJg|] \}}d|dtj|d!Srhr _escape_attribrms r rnz$write_elem_start..s;"Y"Y"Y1#Cq#C#CB,=a,@,@#C#C#C"Y"Y"Yr cJg|] \}}d|dtj|d!Srhrkrms r rnz$write_elem_start..s<"`"`"`TQPQ#Hq#H#HB,B1,E,E#H#H#H"`"`"`r cJg|] \}}d|dtj|d!Srhrprms r rnz$write_elem_start..s;"["["[1#Cq#C#CB,=a,@,@#C#C#C"["["[r >scriptstylez />)tagrr CommentProcessingInstructionr(r*setkeysdiscardr#r _escape_cdatarQrRrSrTrHrUrVattribr`sortedrWjoinr% HTML_EMPTYr<)r2rXr5r4rr r!rDrZr"kwargsrwrnext_remains_rootrYrCr^r r[ns_attrsr\r]ltags r write_elem_startrts^R (C 9D bj kD !!!! ( ( ( ho!  +%) "%**,,K   y ) ) )%()9)9%:%: " " * *5 1 1 1 M%) " "%* "%(UU "  {"" _QPK>#&qrr7>>#q#9#9L!.|A!?#5: +6*:*:*<*,>,@,@M592!6(O'(2) "" .!';;,q/;;*1o;&&$V 3 3 3-c22222 3 E#)   { BQ** *!CC? 2KK % \ 677,,A#AA$$qL#OOQF++++\E"''"^"^U]"^"^"^__````E"''"Y"YPX"Y"Y"YZZ[[[ ^^E"''"`"`U_"`"`"`aabbbbE"''"["[PZ"["["[\\]]] c yy{{6x''47??d b.t445552=((C T *> c 2E"*400111e    s7,HFHAG$!H#G$$/HH54H5c t||||||||||  \} }}}} |D]} t|| ||||| ||d | r|d| d|jr$|tj|jdSdS)aSerialize an element or tree using 'write' for output. Args: write: A function to write the xml to its destination. elem: The element to serialize. nsmap_scope: The current prefix to uri mapping for this element. This should be an empty dictionary for the root element. Additional namespaces are progressively added using the new_nsmap arg. global_nsmap: A dict copy of the globally registered _namespace_map in uri to prefix form short_empty_elements: Controls the formatting of elements that contain no content. If True (default) they are emitted as a single self-closed tag, otherwise they are emitted as a pair of start/end tags. is_html: Set to True to serialize as HTML otherwise XML. is_root: Boolean indicating if this is a root element. uri_to_prefix: Current state of the mapping of uri to prefix. default_ns_attr_prefix: new_nsmap: New prefix -> uri mapping to be applied to this element. )r"Nz.sEEE VEEEr rFr:rNrOrTrdr)rrzr rvaluesrrSrJr@rLrUrVr#pop) rXr0r out_nsmapseen_uri_to_prefixlocal_prefix_mapr= has_unqual_eldefault_namespace_attr_prefixqnameis_elr^r s r r)r)sh  }IFEu{{}}EEE$.0*++ u&(r#"+224455OM$(!$T**(1(1 u' 1RaRyC$QRRy//Q77 +// Q@@>-11,q/BBF~9)<)Vy-@-@%8 ) / % 1 &&F EE,8O &)>D*<?; OV O4Q O5X$Q!') 551@LAI;< )$(M 1 1 1  )% 0 0 0 0 0 1 Y= J   MM% sC0E44FFT)r/r0rrrrtree_clsc |dkrtjntj} | || |||||||| | S)a Generate string representation of XML element. All subelements are included. If encoding is "unicode", a string is returned. Otherwise a bytestring is returned. *element* is an Element instance, *encoding* is an optional output encoding defaulting to US-ASCII, *method* is an optional output which can be one of "xml" (default), "html", "text" or "c14n", *default_namespace* sets the default XML namespace (for "xmlns"). Returns an (optionally) encoded string containing the XML data. rr/r0r1rrrr)ioStringIOBytesIOr2getvalue) elementr.r1r/r0rrrrrstreams r tostringrsw4')33R[]]]F HW'+1!'    ??  r c g} tj| } | || |||||||| | S)Nr)r _ListDataStreamr2) rr.r1r/r0rrrrrlstrs r tostringlistr$sb C   $ $F HW'+1!'    Jr c 4t||||||||||  S)ztostring with options that produce the same results as xml.etree.ElementTree.tostring root_ns_only=True is a bit slower than False as it needs to traverse the tree one more time to collect all the namespaces. ) r.r1r/r0rrrrr)r) rr.r1r/r0rrrrrs r compat_tostringrAs9$ '+1!'    r c#xK |j}|dkr|t|ddpdfVdStj5}t |t jr|}nt |t jr/t j |}| |j nLt j}d|_ ||_ |j |_ |j|_n#t$rYnwxYwt j||dd}| |j |j|fVddddS#1swxYwYdS#t$rV|dkrd}t#|d|d 5}|j|fVdddYdS#1swxYwYYdSwxYw) Nrr.rcdS)NTrrr r z_get_writer..sDr xmlcharrefreplace )r.errorsnewlinew)r.r)r2r%getattr contextlib ExitStackrQrBufferedIOBase RawIOBaseBufferedWritercallbackdetachwritableseekabletellAttributeError TextIOWrapperopen)r-r.r2stackfiles r r$r$ds-+ & >>  y ( (!1:tDDOO O O O O O%'' +5.0ABB+DD 0",??,-=>>DNN4;////,..D$0LDM!&DJ)9(A $4$9 )'19/B04666 t{+++j(****9 + + + + + + + + + + + + + + + + + + ''' >>  y ( (H "C(,... '15*h& & & & ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'smEB E C21E 2 C?<E >C??AE  EE7F9 F* F9*F. .F91F. 2F98F9)NN)F)N)FNNN)rrxml.etree.ElementTreeetree ElementTreer rrr@rHrLr`rr+rr)rrrcontextmanagerr$rr r rs?R """"""""" DDDDDbnDDDT >', !!!!R $     F 0+0+0+0+0+r