Vcc sdZddlmZmZmZddlmZmZmZddlm Z ddl m Z m Z ddl mZejZejZejZejjZejjZejjZejjZejZejddejdd ejdd ejdd ejdd ejdd ejddejddejddd ZGddeZdZdZGddZeeefZ GddeZ!GddeZ"Gdde"Z#Gdde"Z$d Z%d!e%zZ&Gd"d#eZ'Gd$d%Z(Gd&d'e(eZ)Gd(d)e(e'Z*Gd*d+e+Z,Gd,d-eZ-d4d/Z.d4d0Z/d4d1Z0d4d2Z1d3Z2dS)5zFacility to use the Expat parser to load a minidom instance from a string or file. This avoids all the overhead of SAX and pulldom to gain performance. ) xmlbuilderminidomNode)EMPTY_NAMESPACE EMPTY_PREFIXXMLNS_NAMESPACE)expat) _append_child_set_attribute_node) NodeFilterNZcdataZ enumerationentityentitiesidZidrefZidrefsZnmtokenZnmtokens) ZCDATAENUMZENTITYZENTITIESIDZIDREFZIDREFSZNMTOKENZNMTOKENScsJeZdZdZd dZdZdZdZdZdZ d Z d Z d Z dS) ElementInfo _attr_info_modeltagNameNcs0||_g|_||_dSN)rrr)selfrmodel -/usr/lib64/python3.11/xml/dom/expatbuilder.py__init__zElementInfo.__init__?s  cs*|j|j|jfSrrr r __getstate__zElementInfo.__getstate__Ds T\99rcs0|\|_|_|_dSrr)rZstate r __setstate__zElementInfo.__setstate__Gs5:2dlllrcs|jD]F}|d|kr8|d}|ddkrtdcSt|dcSGtjS)Nrz(r)r _typeinfo_mapr_no_type)ranameinfoZt rgetAttributeTypezElementInfo.getAttributeTypeJssO 3 3DAw% 3HQ43;3(0000(b2222  3 rcstjSr)rr$)r namespaceURI localNamerrgetAttributeTypeNSzElementInfo.getAttributeTypeNSTs rcsv|jr1|jd}|tjjtjjfvSdSNrF)rrrZ XML_CTYPE_ANYZXML_CTYPE_MIXED)rtyperrisElementContentzElementInfo.isElementContentWs? ; ;q>D 9 % ; == =5rcsT|jr |jdtjjkSdSr,)rrrZXML_CTYPE_EMPTYrrrisEmptyzElementInfo.isEmpty_s' ; ;q>U[%@@ @5rcsN|jD]}|d|kr|ddkcSdS)Nr!r"rF)r)rr%r&rrisIdzElementInfo.isIdesCO ( (DAw% (Bx4'''' (urcs0|||fSr)r0)rZeuriZenameZaurir% risIdNSzElementInfo.isIdNSksyy$'''rr) __name__ __module__ __qualname__ __slots__rrr r(r+r.r/r0r2rrrr<s1I :::;;;        (((((rrcs.|||Sr)_intern_setdefault)buildersrr_internr;os  % %a + ++rcspd|vsJ|d}|j}t|dkr2|\}}}|||}|d|}|||}|||}n@t|dkr|\}}t}|||x}}nt d|z||||||fS)N iz:z4Unsupported syntax: spaces in URIs not supported: %r)Zsplitr8lenr ValueError)r9nameZpartsinternuri localnameprefixqname r_parse_ns_namerGrs $; JJsOOE  'F 5zzQ X!&Y''!6699-ue$$F9i00 UqXY"F9i888 ORVVWWW 6#s  Y 55rcseZdZdZddZdZdZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdS) ExpatBuilderzPDocument builder that uses Expat to build a ParsedXML.DOM document instance.Ncs|tj}||_|jjt |jj|_nd|_t |_d|_| dSr) rZOptions_optionsfilterFilterVisibilityController_filterr _finish_start_element_parserreset)roptionsrrrzExpatBuilder.__init__sk  + (**G =  ,5dm6JKKDLLDL*,D &  rcs(tjS)zCreate a new parser object.)r ParserCreaterrr createParserzExpatBuilder.createParsers!###rcs|jsm||_|jjj|_d|j_d|j_d|j_||j|jS)z7Return the parser object, creating a new one if needed.T) rNrRrAZ setdefaultr8Z buffer_textZordered_attributesZspecified_attributesinstallrrr getParserzExpatBuilder.getParsersi| ',,..DL&*l&9&DD #'+DL $.2DL +04DL - LL & & &|rcsttdd|_|j|_|jj|_d|_dS)z6Free all data structures used during DOM construction.NF)theDOMImplementationZcreateDocumentrdocumentcurNode _elem_info_cdatarrrrOzExpatBuilder.resets@,;; T4)) } -2 rcs|j|_|j|_|j|_|j|_|jj r |j |_ |j |_ |jjr |j|_|jjr%|j|_|j|_|j|_n |j|_|j|_|j|_|j|_|j|_ dS)z>Install the callbacks needed to build the DOM into the parser.N)!start_doctype_decl_handlerStartDoctypeDeclHandlerfirst_element_handlerStartElementHandlerend_element_handlerEndElementHandler pi_handlerProcessingInstructionHandlerrIr entity_decl_handlerEntityDeclHandlernotation_decl_handlerNotationDeclHandlercommentscomment_handlerCommentHandlerZcdata_sectionsstart_cdata_section_handlerStartCdataSectionHandlerend_cdata_section_handlerEndCdataSectionHandlercharacter_data_handler_cdataCharacterDataHandlercharacter_data_handlerexternal_entity_ref_handlerExternalEntityRefHandlerxml_decl_handlerZXmlDeclHandlerelement_decl_handlerZElementDeclHandlerattlist_decl_handlerZAttlistDeclHandlerrparserrrrSzExpatBuilder.installs*.)H&%)%?"#'#; .2o+ = ! @'+'?F $%)%?" = ! 9$($8F ! = ' F.2.NF +,0,JF )*.*KF ' '*.*EF '*.*J' $ 5$($=!$($=!!!rcsp|}d} |d}|sn<||d|r!|jjr||d}T|ddn#t $rYnwxYw|j}|d|_|S)zIParse a document from a file object, returning the document node.Tr!i@FrN) rTreadParserVdocumentElement _setup_subset ParseEscaperOrN)rfilervZ first_bufferbufferdoc r parseFilezExpatBuilder.parseFiles!!   %7++ VU+++/DM$A/&&v...$  % LLd # # # #    D m   sA+B BBcs|} ||d||n#t$rYnwxYw|j}|d|_|S)zDL '48O 1 *4< *')D $ $ $ * * * *rcs|j||}t|j||jr?|j|t kr|j|dSdSdSr)rVZcreateProcessingInstructionrrWrLrr removeChild)rZtargetdatanoder'rr`zExpatBuilder.pi_handler s}88FFdlD))) < +DL33D99]J + L $ $T * * * * * + + + +rcs|jj}|jr\|jr3|djt kr|d|dS|j|}d|_nY|r1|djtkr|d}|j |z}||_ dStj }||_ |j|_ t|j|dS)NrT)rWrrY_cdata_continuenodeTypeCDATA_SECTION_NODEZ appendDatarVZcreateCDATASection TEXT_NODErrTextrr)rrrrvaluer1rrmz)ExpatBuilder.character_data_handler_cdatas\, ; /&  n-1CC 2))$///=33D99D#'D  /JrN3y@ /b>DI$EDI F<>>DDI!%D dlD)))))rcs|jj}|r/|djtkr|d}|j|z|_dSt j}|j|z|_|j|_t|j|dSr) rWrrrrrrrVrr)rrrrr'rroz#ExpatBuilder.character_data_handler&s~\,  *R.1Y> b>D D(DI F|~~I$ !]dlD)))))rcs|rdS|jjsdS|j||||}|4|j|} |j| |jjjj||j r<|j |tkr|jjjjd=dSdSdSr) rIr rVZ_create_entityZcreateTextNoderappendrrrLrr) rZ entityNameZis_parameter_entityrbaserr notationNamerchilds rrbz ExpatBuilder.entity_decl_handler1s   F}%  F}++J,4lDD  *M0077E O " "5 ) ) ) &+224888 < 8DL33D99]J 8 %.3B777 8 8 8 8rcs|j|||}|jjjj||jr<|j|tkr|jjjjd=dSdSdSr) rVZ_create_notationrrrrrLr FILTER_ACCEPT)rrrrrrrrrdz"ExpatBuilder.notation_decl_handlerCs}--lHhOO ',33D999 < 9DL33D99]J 9 %/4R888 9 9 9 9rcs|j|}t|j||jr?|j|t kr|j|dSdSdSr)rVZ createCommentrrWrLrrr)rrrrrrgzExpatBuilder.comment_handlerIs}**400dlD))) < +DL33D99]J + L $ $T * * * * * + + + +rcs"d|_d|_dS)NTFrYrrrrriz(ExpatBuilder.start_cdata_section_handlerOs $rcs"d|_d|_dS)NFrrrrrkz&ExpatBuilder.end_cdata_section_handlerSs $rcdSNr!r7)rcontextrrrr1rrpz(ExpatBuilder.external_entity_ref_handlerWsqrcs|j|js t|_|j|_|||dSr)rLrXr rstart_element_handlerrTr])rr@ attributesrrr\z"ExpatBuilder.first_element_handlerZsN < * *')D $/3/I, ""444444rcs|j|}t|j|||_|rvt dt |dD]W}t j||tdt}||dz}||_ |j|_ t||X||jj ur||dSdS)Nrr=r!)rVZ createElementrrWranger>rAttrrrrrr ryrM)rr@rriar rrz"ExpatBuilder.start_element_handler`s}**400dlD)))  -1c*ooq11 - -LA!%|55"1Q3"&-#D!,,,, t}4 4 -  & &t , , , , , - -rcsP|jr||jjurdS|j|}|tkrt |n|t krt|ndS|j|_ |j || dSdSr) rLrVrystartContainerrRejecter FILTER_SKIPSkipper parentNoderWrunlink)rrZfiltrrrMz"ExpatBuilder._finish_start_elementqs < t}44 <..t44D}$ $  ?DL O ' ' - - - KKMMMMM#  rcsV|j}|j|_||dSr)rWrr)rr@rWrrr^z ExpatBuilder.end_element_handlers-,)    )))))rcsL|j|j}|r||||jrc||jjurdS|j|tkr2|j || dSdSdSr) rXgetr_handle_white_text_nodesrLrVryrrrWrr)rrWr&rrrz ExpatBuilder._finish_end_elements""7?33  9  ) )'4 8 8 8 < !$-77 |&&w//=@ ! ((111      ! ! ! !rcs|jjs|sdSg}|jD]@}|jt kr.|js||A|D]}| |dSr) rIZwhitespace_in_element_contentr.rrrrZstriprr)rrr&Lrr1rrz%ExpatBuilder._handle_white_text_nodess M 7 ((**  F _  E~* 5:3C3C3E3E  $ $E   U # # # # $ $rcs|j|}|t|||j|<dS|jJ||_dSr)rXrrr)rr@rr&r'rrsz!ExpatBuilder.element_decl_handlersT""4((  $/e$<$>>.,   :::OOO****+++ ***( * * *888$999 +++ %%%%%%555 ---".*** ! ! !$$$"   BBB11111rrHcsLeZdZdZdZdZdZdZej e j ej e j eje jeje jeje jeje jeje jeje jeje jeje jeje jej e j!i Z"dS)rKzoWrapper around a DOMBuilderFilter which implements the checks to make the whatToShow filter attribute work.rJcs||_dSrr)rrJrrrz#FilterVisibilityController.__init__s  rcs|j|j}|jj|zrV|j|}|t krt |tvrtdt|z|StS)Nz)startContainer() returned illegal value: ) _nodetype_maskrrJ whatToShowrFILTER_INTERRUPTr{_ALLOWED_FILTER_RETURNSr?reprr)rrmaskvalr'rrz)FilterVisibilityController.startContainers"4=1 ; !D ( !+,,T22C&& "!!11 O ADIIMOOOJ rcs~|j|j}|jj|zr|j|}|t krt |tkr5|j}|j ddD]}| |tS|tvrtdt|z|StS)Nz%acceptNode() returned illegal value: )rrrJrrrr{rrrZ appendChildrrr?rr)rrrrZparentrrrrz%FilterVisibilityController.acceptNodes"4=1 ; !D ( !+((..C&& "!!k! %!_QQQ/..E&&u----$$11 K =S IKKKJ rN)#r3r4r5rr6rrrrZ ELEMENT_NODEr Z SHOW_ELEMENTZATTRIBUTE_NODEZSHOW_ATTRIBUTErZ SHOW_TEXTrZSHOW_CDATA_SECTIONZENTITY_REFERENCE_NODEZSHOW_ENTITY_REFERENCEZ ENTITY_NODEZ SHOW_ENTITYZPROCESSING_INSTRUCTION_NODEZSHOW_PROCESSING_INSTRUCTIONZ COMMENT_NODEZ SHOW_COMMENT DOCUMENT_NODEZ SHOW_DOCUMENTZDOCUMENT_TYPE_NODEZSHOW_DOCUMENT_TYPEZDOCUMENT_FRAGMENT_NODEZSHOW_DOCUMENT_FRAGMENTZ NOTATION_NODEZ SHOW_NOTATIONrr7rrrKrKs55I ! ! !!!!* **A **C **> **G "**J **@ (**P **A **B **G #**K **B  NNNrrKceZdZdZdZdS) FilterCrutch)_builder_level _old_start_old_endcsd|_||_|j}|j|_|j|_|j|_|j|_dSr) rrrNr]rr_rrr^)rr9rvrrrzFilterCrutch.__init__sG   40 %)%?"#'#;   rN)r3r4r5r6rr7rrrrs(>I<<<< %%s ]> &fragment-builder-internal;cs>eZdZdZd dZdZdZdZdZdZ d Z dS) FragmentBuilderzBuilder which constructs document fragments given XML source text and a context node. The context node is expected to provide information about the namespace declarations which are in scope at the start of the fragment. Ncs|jtkr||_||_n|j|_||_t ||dSr)rroriginalDocumentrrrHr)rrrPrrrzFragmentBuilder.__init__[sQ  } , #$+D !"DLL$+$9D !"DLdG,,,,,rcsHt|d|_dSr)rHrOfragmentrrrrOzFragmentBuilder.resetds!4    rcsP||S)zRParse a document fragment from a file object, returning the fragment node.)rrwrr|rrrzFragmentBuilder.parseFilehs  ,,,rcs||_|}|jj}d}|rH|jp|}|jrd|jd|jd}n|jr d|jz}nd}|}t|||fz} | |dn#| xYw|j }| |S)zMParse a document fragment from a string, returning the fragment node.zPUBLIC "z" ""z SYSTEM "%s"T) _sourcerTrrr_getDeclarationsrr _getNSattrs_FRAGMENT_BUILDER_TEMPLATErxrOr) rrrvrZidentrZnsattrsrVrs rrzFragmentBuilder.parseStringms  !!'/  +Ft/D/D/F/FF 9 9#,,,g.>.>.>@! 9%(88F""$$-0HH  LL4 ( ( ( (  JJLLL = s B//Ccsb|jjj}d}|rt|jjD]Y}|j|}|r|dz}|d|j}|jr|d|jd|j d}L|d|j d}Zt|j jD]}|j |}|r|dz}|d|j}|jr|d|jd|j d }n'|j r|d|j d }n|d |j j d }|j r |d |j }|d z}|S) zRe-create the internal subset from the DocumentType node. This is only needed if we don't already have the internalSubset as a string. rz z z SYSTEM "z )rrrrrZlengthZitemnodeNamerrr Z firstChildrr)rrr:rZnotationr rrrz FragmentBuilder._getDeclarationss ,,4   7,344 C C",11!44#F A)*H,=,=>$C11h///1B1B1BDAA./QQ0A0A0ABAA7+233   )..q11#F A'(qq&//:?@11fooov@AA_@,-AAv?AA%&QQ(9(>(>(>?A&D,-AAv/B/BCAGrcr)Nrr7rrrrzFragmentBuilder._getNSattrssrrcs|tkr|j}|j}|j|}|j|_|j|_|j|_ ||j d||_||_d|_ n#||_||_d|_ wxYwdSt |||||S)NTr) $_FRAGMENT_BUILDER_INTERNAL_SYSTEM_IDrVrWrNZExternalEntityParserCreaterZcreateDocumentFragmentrrxrrHrp)rrrrrZ old_documentZ old_cur_nodervrFrrpz+FragmentBuilder.external_entity_ref_handlers ; ; 9 =Ltjd}d|_|S)z'Create a new namespace-handling parser.r<)Znamespace_separatorT)rrQZnamespace_prefixesrurrrRzNamespaces.createParsers"#<<<$(! rcspt|||jjr|j|_dSdS)z.Insert the namespace-handlers onto the parser.N)rHrSrIZnamespace_declarationsstart_namespace_decl_handlerZStartNamespaceDeclHandlerrurrrSzNamespaces.installsCT6*** = / 31  , , , 3 3rcs>|j||fdS)z/Push this namespace declaration on our storage.N)rr)rrDrBrrrz'Namespaces.start_namespace_decl_handlers# !((&#77777rcsd|vrt||\}}}}nt}|}d}t}tj||||}|j|_t|j|||_|j r|j D]y\}}|r.tj t|d|zt|d}n!tj dtdt}||_ |j|_t||z|j dd=|r||j} |j} t%dt'|dD]} || } || dz} d| vr9t|| \}}}}tj ||||}|| |<|| ||f<n2tj | t| t}|| | <|| t| f<|j|_| |_ ||_dSdS)Nr<xmlns:xmlnsrr=r!)rGrrrZElementrVrrrWrrr;rrr Z_ensure_attributes_attrs_attrsNSrr>Z ownerElement)rr@rrBrCrDrErrrrrr%rs rrz Namespaces.start_element_handlers* $; ",:4,F,F )CFEE!CEI!Fuc69==!]dlD)))  $ -#8 - - < WT8f3D%E%E%4fgGGAA Wo%,l<|j}d|vrAt||\}}}}|j|kr|j|kr |j|ks Jdn/|j|ks Jd|jt ks Jd|j|_||dS)Nr<z$element stack messed up! (namespace)z&element stack messed up - bad nodeNamez*element stack messed up - bad namespaceURI) rWrGr)r*rDrrrr)rr@rWrBrCrDrErrr^zNamespaces.end_element_handlerslGd{ D0>tT0J0J-Y,3?#-:?#Nf4??????? '4/@@?@@@+>DDCDDD"-DL  $ $W - - - - -rN) r3r4r5rrrRrSrrr^r7rrrrszAA'''  333888-&-&-&^.  . . . . .rrcr)ExpatBuilderNSz*Document builder that supports namespaces.cbt||dSr)rHrOrrrrrOzExpatBuilderNS.reset)s.4    rN)r3r4r5rrOr7rrrr&s)44rrcr)FragmentBuilderNSz*Fragment builder that supports namespaces.crr)rrOrrrrrOzFragmentBuilderNS.reset1s.d### rcsd}|j}g}|rst|drZ|jD]@\}}||vr |||rd|z}nd}|r |d|d|d}7d|d|d}A|j}|s|S) zNReturn string of namespace attributes from this element and ancestors.r_ns_prefix_urirrz z='z'r<)rZhasattrrZitemsrr)rattrsrrrDrBZdeclnamerrrzFragmentBuilderNS._getNSattrs5s,  )w 011 =#*#9#?#?#A#A = =KFC{! HHV$$$+#+f#4#*=5:UUHHHccc J=/7hh <(G )  rN)r3r4r5rrOrr7rrrr.s844rrcseZdZdZdS)r{zEException raised to short-circuit parsing in InternalSubsetExtractor.N)r3r4r5rr7rrr{r{SsOODrr{cs@eZdZdZdZdZdZdZdZdZ dZ d Z dS) rzBXML processor which can rip out the internal document type subset.Ncs|jS)z'Return the internal subset as a string.)rrrrrz!InternalSubsetExtractor.getSubset\s {rc` t||dS#t$rYdSwxYwr)rHrr{rrrrz!InternalSubsetExtractor.parseFile`sE   " "4 . . . . .    DD   --crr)rHrr{)rrrrrz#InternalSubsetExtractor.parseStringfsE   $ $T6 2 2 2 2 2    DD rcs6|j|_|j|_dSr)rZr[rr]rurrrSzInternalSubsetExtractor.installls)-)H&%)%?"""rcs|r:|}g|_|jj|_|j|_dSt r)rTrrZDefaultHandlerrrr{)rr@rrrrvrrrZz2InternalSubsetExtractor.start_doctype_decl_handlerpsH  ^^%%FDK$(K$6F !+/+HF ( ( (-- rcsd|jdddd}||_t)Nrz z z )ZjoinrZreplacer{)rr:rrrz0InternalSubsetExtractor.end_doctype_decl_handlerzsF GGDK ( ( 6 6 > >tT J J mmrcstr)r{)rr@rrrrz-InternalSubsetExtractor.start_element_handlers mmr) r3r4r5rrrrrrSrZrrr7rrrrWsLL F  @@@    rrTcs|rt}nt}t|tr>t |d5}||}dddn #1swxYwYn||}|S)z{Parse a document, returning the resulting Document node. 'file' may be either a file name or an open file object. rbN)rrH isinstancestropenr)r| namespacesr9fpresultr1rparsers ! ""..$) $   +&&r**F + + + + + + + + + + + + + + +""4(( MsA''A+.A+csj|rt}nt}||S)zOParse a document from a string, returning the resulting Document node. )rrHr)rrr9rrrrs6! ""..   v & &&rcs|rt|}nt|}t|tr>t |d5}||}dddn #1swxYwYn||}|S)zParse a fragment of a document, given the context from which it was originally extracted. context should be the parent of the node(s) which are in the fragment. 'file' may be either a file name or an open file object. rN)rrrrrr)r|rrr9rrrr parseFragmentrs+#G,,!'**$) $   +&&r**F + + + + + + + + + + + + + + +""4(( MsA))A-0A-csn|rt|}nt|}||S)zParse a fragment of a document from a string, given the context from which it was originally extracted. context should be the parent of the node(s) which are in the fragment. )rrr)rrrr9r'rparseFragmentStringrs< +#G,,!'**   v & &&rcsL|jrt|St|S)z,Create a builder based on an Options object.)rrrH)rPrr makeBuilderrs)%g&&&G$$$r)T)3rZxml.domrrrrrrZ xml.parsersrZxml.dom.minidomrr Zxml.dom.NodeFilterr rrrZDOMBuilderFilterrrrrZgetDOMImplementationrUZTypeInfor#Zobjectrr;rGrHrrKrrrrrrrrrZ Exceptionr{rrrrrrr7rrrsZ:.---------BBBBBBBBBB>>>>>>>>)))))) N ," +9 +9 )5 .?3w355! w//  }55  x00  z22  t,,  w//  x00  y11  z22   1(1(1(1(1(&1(1(1(f,,,666&|1|1|1|1|1|1|1|1B )-E7 7 7 7 7 7 7 7 t < < < < <6 < < <*****|***8!!!!!l!!!2?%*+ +r9r9r9r9r9lr9r9r9j\.\.\.\.\.\.\.\.~Z""""" O"""J     )   )))))l)))X$''''( ' ' ' '%%%%%r