f _o=@sdZddlTddlmZmZddlmZddlmZmZddlmZddlm Z m Z ddl Z e j dd d krxe d d[ zdd lmZWneye d dYn0eedse d dddlmZmZmZejZejZz ddlZWneyddZYn0ddlZejZ[[GdddZGdddejZGdddejejZ ddZ!e"dkrddl#Z$e!Z%e%&e$j'j(e%)e$j'*e%+ddS)z0.20)*)feature_validationfeature_namespaces)feature_namespace_prefixes)feature_external_gesfeature_external_pes)feature_string_interning)property_xml_stringproperty_interning_dictNjavazexpat not available in Java)expatzexpat not supported ParserCreate) xmlreadersaxutilshandlercCs|SN)orr,/usr/lib64/python3.10/xml/sax/expatreader.py_mkproxy'src@s eZdZdS) _ClosedParserN)__name__ __module__ __qualname__rrrrr.src@s4eZdZddZddZddZddZd d Zd S) ExpatLocatorcCst||_dSr)r_refselfparserrrr__init__9szExpatLocator.__init__cCs|j}|jdurdS|jjSr)r_parserErrorColumnNumberrrrrgetColumnNumber<s zExpatLocator.getColumnNumbercCs|j}|jdurdS|jjSN)rr!ErrorLineNumberrrrr getLineNumberBs zExpatLocator.getLineNumbercCs|j}|durdS|jSr)r_source getPublicIdrrrrr)HszExpatLocator.getPublicIdcCs|j}|durdS|jSr)rr( getSystemIdrrrrr*NszExpatLocator.getSystemIdN)rrrr r#r'r)r*rrrrr3s rc@seZdZdCddZddZddZd d Zd d Zd dZddZ ddZ dDddZ ddZ ddZ ddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zdd?Z d@dAZ!dBS)E ExpatParserrcCsFtj||t|_d|_||_d|_d|_g|_ d|_ d|_ dS)NFr) rIncrementalParserr Z InputSourcer(r! _namespaces_lex_handler_prop_parsing _entity_stack _external_ges _interning)rZnamespaceHandlingbufsizerrrr Zs zExpatParser.__init__cCsVt|}||_z*||jt|tj ||Wn| Yn0dSr) rprepare_input_sourcer(reset _cont_handlerZsetDocumentLocatorrrr-parse _close_sourcersourcerrrr8gs zExpatParser.parsecCs |dur|j|dSr)r*r!ZSetBaser:rrr prepareParserws zExpatParser.prepareParsercCs tj|||jr|dSr)rr-setContentHandlerr0_reset_cont_handler)rrrrrr=}szExpatParser.setContentHandlercCsP|tkr|jS|tkr |jduS|tttfvr2dS|tkr@|jSt d|dS)NrFeature '%s' not recognized) rr.rr3rrrrr2SAXNotRecognizedExceptionrnamerrr getFeatures zExpatParser.getFeaturecCs|jrtd|tkr||_n|tkr.||_nt|tkrT|rL|jdurRi|_nVd|_nN|tkrj|rtdn8|t kr|rtdn"|t kr|rtdn t d|dS)Nz!Cannot set features while parsingz!expat does not support validationz/expat does not read external parameter entitiesz(expat does not report namespace prefixesr?) r0SAXNotSupportedExceptionrr.rr2rr3rrrr@)rrBstaterrr setFeatures: zExpatParser.setFeaturecCsd|tjkr|jS|tkr|jS|tkrT|jrLt|jdrB|jSt dnt dt d|dS)NGetInputContextz=This version of expat does not support getting the XML stringz.XML string cannot be returned when not parsingProperty '%s' not recognized) rproperty_lexical_handlerr/r r3r r!hasattrrGr@rDrArrr getPropertys   zExpatParser.getPropertycCsV|tjkr ||_|jrR|n2|tkr0||_n"|tkrFtd|n t d|dS)NzProperty '%s' cannot be setrH) rrIr/r0_reset_lex_handler_propr r3r rDr@)rrBvaluerrr setPropertys  zExpatParser.setPropertyFc Cs||js|d|_|jz|j||WnFtjyv}z,tt |j ||}|j |WYd}~n d}~00dS)NT) r0r6r7Z startDocumentr!ZParser errorZSAXParseExceptionZ ErrorStringcodeZ _err_handlerZ fatalError)rdataisFinaleexcrrrfeeds zExpatParser.feedcCsZ|j}z4|}|dur |W|}|durV|n|}|durT|0dSr)r(ZgetCharacterStreamcloseZ getByteStream)rr;filerrrr9s  zExpatParser._close_sourcecCs|js|jdust|jtr dSz`|jddd|jd|_d|_Wd|_|jdurxt}|jj|_|jj |_ ||_| n:d|_|jdurt}|jj|_|jj |_ ||_| 0dS)NT)rRF) r1r! isinstancerrUr7Z endDocumentr0r"r&r9rrrrrVs.         zExpatParser.closecCs|jj|j_|jj|j_dSr)r7processingInstructionr!ZProcessingInstructionHandler charactersZCharacterDataHandlerrrrrr>szExpatParser._reset_cont_handlercCs`|j}|j}|dur4d|_d|_d|_d|_d|_n(|j|_|j|_|j |_|j |_|j |_dSr) r/r!ZCommentHandlerZStartCdataSectionHandlerZEndCdataSectionHandlerZStartDoctypeDeclHandlerZEndDoctypeDeclHandlerZcommentZ startCDATAZendCDATAstart_doctype_declZendDTD)rZlexrrrrrLsz#ExpatParser._reset_lex_handler_propcCs|jr>tj|jd|jd|_d|j_|j|j_ |j |j_ n,tj|j|jd|_|j |j_ |j |j_ ||j|j_|j|j_|j|j_|j|j_d|_|jr||j|j_z|j|j_WntyYn0|jtj d|_!g|_"dS)N )internr%F)#r.r rr(Z getEncodingr3r!Znamespace_prefixesstart_element_nsZStartElementHandlerend_element_nsZEndElementHandler start_element end_elementr>unparsed_entity_declZUnparsedEntityDeclHandler notation_declZNotationDeclHandlerstart_namespace_declZStartNamespaceDeclHandlerend_namespace_declZEndNamespaceDeclHandlerZ_decl_handler_propr/rLexternal_entity_refZExternalEntityRefHandlerskipped_entity_handlerZSkippedEntityHandlerAttributeErrorZSetParamEntityParsingZ*XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONEr0r1r\rrrr6s<           zExpatParser.resetcCs|jdurdS|jjSr)r!r"r\rrrr#;s zExpatParser.getColumnNumbercCs|jdurdS|jjSr$)r!r&r\rrrr'@s zExpatParser.getLineNumbercCs |jSr)r(r)r\rrrr)EszExpatParser.getPublicIdcCs |jSr)r(r*r\rrrr*HszExpatParser.getSystemIdcCs|j|t|dSr)r7Z startElementAttributesImpl)rrBattrsrrrrbLszExpatParser.start_elementcCs|j|dSr)r7Z endElementrArrrrcOszExpatParser.end_elementc Cs|}t|dkrd|f}n&t|dkr<|d|df}nt|}i}i}|D]|\}}|}t|} | dkr|} d|f} n>| dkrd|d|df} |d|df} n|d} t|} ||| <| || <qT|j|dt||dS)Nr%rz%s:%s)splitlentupleitemsr7ZstartElementNSAttributesNSImpl) rrBrlpairZnewattrsZqnamesZanamerMpartslengthZqnameZapairrrrr`Rs0      zExpatParser.start_element_nscCsV|}t|dkrd|f}n&t|dkr<|d|df}nt|}|j|ddS)Nr%rmr)rorprqr7Z endElementNS)rrBrtrrrrats   zExpatParser.end_element_nscCs|j||dSr)r7rZ)rtargetrQrrrprocessing_instructionsz"ExpatParser.processing_instructioncCs|j|dSr)r7r[)rrQrrrcharacter_dataszExpatParser.character_datacCs|j||dSr)r7ZstartPrefixMapping)rprefixZurirrrrfsz ExpatParser.start_namespace_declcCs|j|dSr)r7ZendPrefixMapping)rrzrrrrgszExpatParser.end_namespace_declcCs|j|||dSr)r/ZstartDTD)rrBsysidpubidZhas_internal_subsetrrrr]szExpatParser.start_doctype_declcCs|j||||dSr) _dtd_handlerZunparsedEntityDecl)rrBbaser{r|Z notation_namerrrrdsz ExpatParser.unparsed_entity_declcCs|j|||dSr)r}Z notationDecl)rrBr~r{r|rrrreszExpatParser.notation_declcCs|js dS|j||}t||jp*d}|j|j |jf|j ||_ ||_zt j ||Wn YdS|jd\|_ |_|jd=dS)Nr%r)r2Z _ent_handlerZ resolveEntityrr5r(r*r1appendr!ZExternalEntityParserCreaterr-r8)rcontextr~r{r|r;rrrrhs" zExpatParser.external_entity_refcCs|r d|}|j|dS)N%)r7Z skippedEntity)rrBZis_perrrrisz"ExpatParser.skipped_entity_handlerN)rr,)F)"rrrr r8r<r=rCrFrKrNrUr9rVr>rLr6r#r'r)r*rbrcr`rarxryrfrgr]rdrerhrirrrrr+Ws>    '" r+cOst|i|Sr)r+)argskwargsrrr create_parsersr__main__z:http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml),versionZxml.sax._exceptionsZxml.sax.handlerrrrrrrr r sysplatformZSAXReaderNotAvailableZ xml.parsersr ImportErrorrJZxml.saxrrrrkrs_weakrefrweakrefproxyrZLocatorrr-r+rrZxml.sax.saxutilsZxmlpr=ZsaxZ XMLGeneratorZsetErrorHandlerZ ErrorHandlerr8rrrrsL       $_