U e5d @sddlmZmZmZddlmZmZmZddlmZddl m Z m Z ddl m Z ejZejZejZejjZejjZejjZejjZeZeddeddedd edd edd edd edd eddeddd ZGdddeZddZddZGdddZeeefZGdddeZ GdddeZ!Gddde!Z"Gdd d e!Z#d!Z$d"e$Z%Gd#d$d$eZ&Gd%d&d&Z'Gd'd(d(e'eZ(Gd)d*d*e'e&Z)Gd+d,d,e*Z+Gd-d.d.eZ,d:d0d1Z-d;d2d3Z.d) xmlbuilderminidomNode)EMPTY_NAMESPACE EMPTY_PREFIXXMLNS_NAMESPACE)expat) _append_child_set_attribute_node) NodeFilterNZcdata enumerationentityentitiesidZidrefZidrefsZnmtokenZnmtokens) ZCDATAENUMZENTITYZENTITIESIDZIDREFZIDREFSZNMTOKENZNMTOKENSc@sZeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS) ElementInfo _attr_info_modeltagNameNcCs||_g|_||_dSN)rrr)selfrmodelr,/usr/lib64/python3.8/xml/dom/expatbuilder.py__init__?szElementInfo.__init__cCs|j|j|jfSrrrrrr __getstate__DszElementInfo.__getstate__cCs|\|_|_|_dSrr)rstaterrr __setstate__GszElementInfo.__setstate__cCsN|jD]@}|d|kr|d}|ddkr6tdSt|dSqtjS)Nr(r)r _typeinfo_mapr_no_type)ranameinfotrrrgetAttributeTypeJs    zElementInfo.getAttributeTypecCstjSr)rr%)rZ namespaceURIZ localNamerrrgetAttributeTypeNSTszElementInfo.getAttributeTypeNScCs,|jr$|jd}|tjjtjjfkSdSdSNrF)rrrZ XML_CTYPE_ANYZXML_CTYPE_MIXED)rtyperrrisElementContentWs  zElementInfo.isElementContentcCs |jr|jdtjjkSdSdSr+)rrrZXML_CTYPE_EMPTYrrrrisEmpty_szElementInfo.isEmptycCs,|jD] }|d|kr|ddkSqdS)Nr!r"rF)r)rr&r'rrrisIdes  zElementInfo.isIdcCs|||fSr)r/)rZeuriZenameZaurir&rrrisIdNSkszElementInfo.isIdNS)N) __name__ __module__ __qualname__ __slots__rrr r)r*r-r.r/r0rrrrr<s  rcCs |||Sr)_intern_setdefault)buildersrrr_internosr8cCs|d}|j}t|dkrR|\}}}|||}d||f}|||}|||}n4t|dkrz|\}}t}|||}}n td|||||||fS)N z%s:%sz4Unsupported syntax: spaces in URIs not supported: %r)splitr5lenr ValueError)r6namepartsinternuri localnameprefixqnamerrr_parse_ns_namers         rFc@seZdZd:ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9ZdS); ExpatBuilderNcCsP|dkrt}||_|jjdk r2t|jj|_n d|_t|_d|_| dSr) rZOptions_optionsfilterFilterVisibilityController_filterr_finish_start_element_parserreset)roptionsrrrrs zExpatBuilder.__init__cCstSr)r ParserCreaterrrr createParserszExpatBuilder.createParsercCsF|js@||_|jjj|_d|j_d|j_d|j_||j|jSNT) rMrQrA setdefaultr5Z buffer_textZordered_attributesZspecified_attributesinstallrrrr getParsers   zExpatBuilder.getParsercCs,ttdd|_|j|_|jj|_d|_dSNF)theDOMImplementationZcreateDocumentrdocumentcurNode _elem_info_cdatarrrrrNs zExpatBuilder.resetcCs|j|_|j|_|j|_|j|_|jj r0|j |_ |j |_ |jjrH|j|_|jjrj|j|_|j|_|j|_n|j|_|j|_|j|_|j|_|j|_ dSr)!start_doctype_decl_handlerStartDoctypeDeclHandlerfirst_element_handlerStartElementHandlerend_element_handlerEndElementHandler pi_handlerProcessingInstructionHandlerrHrentity_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_handlerZAttlistDeclHandlerrparserrrrrTs$ zExpatBuilder.installcCs|}d}zH|d}|sqF||d|r@|jjr@||d}q|ddWntk rhYnX|j}|d|_|S)NTi@rF) rUreadParserXdocumentElement _setup_subset ParseEscaperNrM)rfilerxZ first_bufferbufferdocrrr parseFiles"    zExpatBuilder.parseFilecCsP|}z||d||Wntk r6YnX|j}|d|_|SrR)rUr{r}r~rXrNrM)rstringrxrrrr parseStrings zExpatBuilder.parseStringcCs.|jjr*t}|||}||jj_dSr)rXdoctypeInternalSubsetExtractorr getSubsetinternalSubset)rrZ extractorsubsetrrrr}s  zExpatBuilder._setup_subsetcCs|jj|||}|j|_t|j|||j_|jrj|j|tkrjd|j_|jj d=d}d|j _ d|j _ |r|dk rg|j _g|j_d|j _d|j _|j|j _dSN)rXimplementationZcreateDocumentType ownerDocumentr rrK acceptNode FILTER_REJECT childNodesrMrergr_seq notationsrjrcend_doctype_decl_handlerEndDoctypeDeclHandler)rZ doctypeNamesystemIdpublicIdhas_internal_subsetrrrrr\s*  z'ExpatBuilder.start_doctype_decl_handlercCs2|jjr|j|j_|j|j_|js.|js.t |_ dSr) rHrhrirMrjrbrcrZrKr_finish_end_elementrrrrrs    z%ExpatBuilder.end_doctype_decl_handlercCs@|j||}t|j||jr<|j|tkr<|j|dSr)rXZcreateProcessingInstructionr rYrKrr removeChild)rtargetdatanoderrrrb s zExpatBuilder.pi_handlercCs|jj}|jrH|jr4|djtkr4|d|dS|j|}d|_nD|rv|djt krv|d}|j |}||_ dSt }||_ |j|_ t|j|dS)NrT)rYrr[_cdata_continuenodeTypeCDATA_SECTION_NODEZ appendDatarXZcreateCDATASection TEXT_NODErrTextrr )rrrrvaluerrrros$   z)ExpatBuilder.character_data_handler_cdatacCs^|jj}|r2|djtkr2|d}|j||_dSt}|j||_|j|_t |j|dSr) rYrrrrrrrXrr )rrrrrrrrq&s  z#ExpatBuilder.character_data_handlerc Cs|rdS|jjsdS|j||||}|dk rF|j|} |j| |jjjj||j r||j |t kr||jjjjd=dSr) rHrrXZ_create_entityZcreateTextNoderappendrrrKrr) rZ entityNameZis_parameter_entityrbaserr notationNamerchildrrrrd1s   z ExpatBuilder.entity_decl_handlercCsJ|j|||}|jjjj||jrF|j|tkrF|jjjjd=dSr) rXZ_create_notationrrrrrKr FILTER_ACCEPT)rrrrrrrrrrfCsz"ExpatBuilder.notation_decl_handlercCs>|j|}t|j||jr:|j|tkr:|j|dSr)rXZ createCommentr rYrKrrr)rrrrrrriIs  zExpatBuilder.comment_handlercCsd|_d|_dS)NTFr[rrrrrrkOsz(ExpatBuilder.start_cdata_section_handlercCsd|_d|_dSrVrrrrrrmSsz&ExpatBuilder.end_cdata_section_handlercCsdSNr!r)rcontextrrrrrrrrWsz(ExpatBuilder.external_entity_ref_handlercCs2|jdkr|jst|_|j|_|||dSr)rKrZrrstart_element_handlerrUr_)rr? attributesrrrr^Zs z"ExpatBuilder.first_element_handlercCs|j|}t|j|||_|rptdt|dD]<}t||tdt }||d}||_ |j|_ t ||q2||jj k r||dS)Nrr;r!)rXZ createElementr rYranger=rAttrrrrrr r|rL)rr?rriarrrrr`s      z"ExpatBuilder.start_element_handlercCsj|jrf||jjkrdS|j|}|tkr4t|n|tkrFt|ndS|j|_ |j || dSr) rKrXr|startContainerrRejecter FILTER_SKIPSkipper parentNoderYrunlink)rrZfiltrrrrLqs     z"ExpatBuilder._finish_start_elementcCs|j}|j|_||dSr)rYrr)rr?rYrrrr`sz ExpatBuilder.end_element_handlercCs\|j|j}|r||||jrX||jjkr4dS|j|tkrX|j || dSr) rZgetr_handle_white_text_nodesrKrXr|rrrYrr)rrYr'rrrrs   z ExpatBuilder._finish_end_elementcCsZ|jjs|sdSg}|jD]"}|jtkr|js||q|D]}| |qFdSr) rHZwhitespace_in_element_contentr-rrrrstriprr)rrr'Lrrrrrs  z%ExpatBuilder._handle_white_text_nodescCs0|j|}|dkr&t|||j|<n||_dSr)rZrrr)rr?rr'rrrrus z!ExpatBuilder.element_decl_handlerc CsF|j|}|dkr&t|}||j|<|jd|dd|d||gdSNr)rZrrrr)relemr?r,defaultZrequiredr'rrrrvs  z!ExpatBuilder.attlist_decl_handlercCs2||j_||j_|dkr.|r&d|j_nd|j_dS)NrTF)rXversionencoding standalone)rrrrrrrrts  zExpatBuilder.xml_decl_handler)N)r1r2r3rrQrUrNrTrrr}r\rrbrorqrdrfrirkrmrrr^rrLr`rrrurvrtrrrrrGs8     rGc@seZdZdZddZddZddZeje j ej e j ej e jeje jeje jeje jeje jeje jeje jeje jeje jeje j i Z!dS) rJrIcCs ||_dSrr)rrIrrrrsz#FilterVisibilityController.__init__cCsT|j|j}|jj|@rL|j|}|tkr0t|tkrHtdt ||St SdS)Nz)startContainer() returned illegal value: ) _nodetype_maskrrI whatToShowrFILTER_INTERRUPTr~_ALLOWED_FILTER_RETURNSr>reprr)rrmaskvalrrrrs    z)FilterVisibilityController.startContainercCs|j|j}|jj|@r||j|}|tkr0t|tkr`|j}|j ddD]}| |qLt S|t krxt dt||StSdS)Nz%acceptNode() returned illegal value: )rrrIrrrr~rrrZ appendChildrrr>rr)rrrrparentrrrrrs      z%FilterVisibilityController.acceptNodeN)"r1r2r3r4rrrrZ 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_NOTATIONrrrrrrJs: rJc@seZdZdZddZdS) FilterCrutch)_builder_level _old_start_old_endcCs6d|_||_|j}|j|_|j|_|j|_|j|_dSr) rrrMr_rrarrr`)rr6rxrrrrszFilterCrutch.__init__N)r1r2r3r4rrrrrrsrc@s(eZdZdZddZddZddZdS) rrcCs,t|||j}dD]}t||dqdS)N)rcrjrprlrnrs)rrrMsetattr)rr6rxr?rrrrs zRejecter.__init__cGs|jd|_dSr)rrargsrrrrszRejecter.start_element_handlercGs@|jdkr0|jj}|j||j|_|j|_n |jd|_dSNrr!)rrrMrTrr_rra)rrrxrrrr` s    zRejecter.end_element_handlerN)r1r2r3r4rrr`rrrrrs rc@s eZdZdZddZddZdS)rrcGs.|jj}|j||jj|k r*|jd|_dSr)rrYrr)rrrrrrr-s  zSkipper.start_element_handlercGsD|jdkr*|j|jj_|j|jj_d|_n|jd|_|j|dSr)rrrrMr_rrarrrrr`3s     zSkipper.end_element_handlerN)r1r2r3r4rr`rrrrr*srz8http://xml.python.org/entities/fragment-builder/internalz %%s ]> &fragment-builder-internal;c@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS)FragmentBuilderNcCs6|jtkr||_||_n|j|_||_t||dSr)rroriginalDocumentrrrGr)rrrOrrrr[s  zFragmentBuilder.__init__cCst|d|_dSr)rGrNfragmentrrrrrNds zFragmentBuilder.resetcCs||Sr)rrzrrrrrrhszFragmentBuilder.parseFilec Cs||_|}|jj}d}|rV|jp*|}|jrDd|j|jf}qZ|jrZd|j}nd}|}t |||f}z| |dWn| YnX|j }| |S)NryzPUBLIC "%s" "%s"z SYSTEM "%s"r!) _sourcerUrrr_getDeclarationsrr _getNSattrs_FRAGMENT_BUILDER_TEMPLATEr{rNr) rrrxrZidentrZnsattrsrXrrrrrms.  zFragmentBuilder.parseStringcCs |jjj}d}|rt|jjD]R}|j|}|r<|d}d||jf}|jrdd||j|j f}q d||j f}q t|j jD]}|j |}|r|d}d||jf}|jrd||j|j f}n&|j rd||j f}nd ||j j f}|j rd ||j f}|d }q|S) Nryz z%sz%s SYSTEM "%s">z %s)rrrrrZlengthitemZnodeNamerrrZ firstChildrr)rrr7rZnotationr rrrrs:      z FragmentBuilder._getDeclarationscCsdS)NryrrrrrrszFragmentBuilder._getNSattrscCs~|tkrh|j}|j}|j|}|j|_|j|_|j|_z| |jdW5||_||_d|_XdSt |||||SdS)Nr!r) $_FRAGMENT_BUILDER_INTERNAL_SYSTEM_IDrXrYrMZExternalEntityParserCreaterZcreateDocumentFragmentrrr{rGrr)rrrrrZ old_documentZ old_cur_noderxrrrrrs(  z+FragmentBuilder.external_entity_ref_handler)N) r1r2r3rrNrrrrrrrrrrrRs $rc@s4eZdZddZddZddZddZd d Zd S) NamespacescCs g|_dSr)_ns_ordered_prefixesrrrr_initNamespacesszNamespaces._initNamespacescCstjdd}d|_|S)Nr9)Znamespace_separatorT)rrPZnamespace_prefixesrwrrrrQs zNamespaces.createParsercCs t|||jjr|j|_dSr)rGrTrHZnamespace_declarationsstart_namespace_decl_handlerZStartNamespaceDeclHandlerrwrrrrTs zNamespaces.installcCs|j||fdSr)rr)rrDrBrrrrsz'Namespaces.start_namespace_decl_handlercCsd|krt||\}}}}nt}|}d}t}t||||}|j|_t|j|||_|j r|j D]P\}}|rt t |d|t |d}nt dt dt}||_ |j|_t||qb|j dd=|r~||j} |j} tdt|dD]} || } || d} d| krDt|| \}}}}t ||||}|| |<|| ||f<n$t | t| t}|| | <|| t| f<|j|_| |_ ||_qdS)Nr9xmlns:xmlnsrr;r!)rFrrrZElementrXrr rYrrr8rrr Z_ensure_attributes_attrs_attrsNSrr=Z ownerElement)rr?rrBrCrDrErrrrrr&rrrrrs^      z Namespaces.start_element_handlerN) r1r2r3rrQrTrrr`rrrrrs 5rc@seZdZddZdS)ExpatBuilderNScCst||dSr)rGrNrrrrrrN)s zExpatBuilderNS.resetN)r1r2r3rNrrrrr&src@seZdZddZddZdS)FragmentBuilderNScCst||dSr)rrNrrrrrrN1s zFragmentBuilderNS.resetcCsd}|j}g}|r~t|drv|jD]N\}}||kr8q&|||rPd|}nd}|rhd|||f}q&d||f}q&|j}q|S)Nry_ns_prefix_urirrz%s %s='%s'z %s='%s')rhasattrritemsrr)rattrsrrrDrBZdeclnamerrrr5s"   zFragmentBuilderNS._getNSattrsN)r1r2r3rNrrrrrr.src@s eZdZdS)r~N)r1r2r3rrrrr~Ssr~c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)rNcCs|jSr)rrrrrr\sz!InternalSubsetExtractor.getSubsetcCs*zt||Wntk r$YnXdSr)rGrr~rrrrr`sz!InternalSubsetExtractor.parseFilecCs*zt||Wntk r$YnXdSr)rGrr~)rrrrrrfsz#InternalSubsetExtractor.parseStringcCs|j|_|j|_dSr)r\r]rr_rwrrrrTlszInternalSubsetExtractor.installcCs0|r&|}g|_|jj|_|j|_ntdSr)rUrrZDefaultHandlerrrr~)rr?rrrrxrrrr\ps   z2InternalSubsetExtractor.start_doctype_decl_handlercCs,d|jdddd}||_tdS)Nryz   )joinrreplacer~)rr7rrrrzsz0InternalSubsetExtractor.end_doctype_decl_handlercCs tdSr)r~)rr?rrrrrsz-InternalSubsetExtractor.start_element_handler) r1r2r3rrrrrTr\rrrrrrrWs rTc CsL|r t}nt}t|tr>t|d}||}W5QRXn ||}|SNrb)rrG isinstancestropenr)r namespacesr6fpresultrrrparses   rcCs|r t}nt}||Sr)rrGr)rrr6rrrrsrc CsP|rt|}nt|}t|trBt|d}||}W5QRXn ||}|Sr)rrrrrr)rrrr6rrrrr parseFragments    rcCs |rt|}nt|}||Sr)rrr)rrrr6rrrparseFragmentStrings rcCs|jrt|St|SdSr)rrrG)rOrrr makeBuildersr)T)T)T)T)2Zxml.domrrrrrrZ xml.parsersrZxml.dom.minidomr r Zxml.dom.NodeFilterr rrrZDOMBuilderFilterrrrrZgetDOMImplementationrWZTypeInfor$objectrr8rFrGrrJrrrrrrrrr Exceptionr~rrrrrrrrrrsd            3C :   u_%,