U e5dX=@sdZddlTddlmZmZddlmZddlmZmZddlmZddlm Z m Z ddl Z e j dd d krxe d d[ zdd lmZWnek re d dYnXeedse d dddlmZmZmZejZejZz ddlZWnek rddZYnXddlZejZ[[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.8/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}|jdkrdS|jjSr)r_parserErrorColumnNumberrrrrgetColumnNumber<s zExpatLocator.getColumnNumbercCs|j}|jdkrdS|jjSN)rr!ErrorLineNumberrrrr getLineNumberBs zExpatLocator.getLineNumbercCs|j}|dkrdS|jSr)r_source getPublicIdrrrrr)HszExpatLocator.getPublicIdcCs|j}|dkrdS|jSr)rr( getSystemIdrrrrr*NszExpatLocator.getSystemIdN)rrrr r#r'r)r*rrrrr3s rc@seZdZdBddZddZddZd d Zd d Zd dZddZ ddZ dCddZ ddZ ddZ ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Z d?d@Z!dAS)D ExpatParserrcCsFtj||t|_d|_||_d|_d|_g|_ d|_ d|_ dS)Nr) rIncrementalParserr Z InputSourcer(r! _namespaces_lex_handler_prop_parsing _entity_stack _external_ges _interning)rZnamespaceHandlingbufsizerrrr Zs zExpatParser.__init__cCsVt|}||_z*||jt|tj ||Wn| YnXdSr) rprepare_input_sourcer(reset _cont_handlerZsetDocumentLocatorrrr-parse _close_sourcersourcerrrr8gs zExpatParser.parsecCs |dk r|j|dSr)r*r!ZSetBaser:rrr prepareParserws zExpatParser.prepareParsercCs tj|||jr|dSr)rr-setContentHandlerr0_reset_cont_handler)rrrrrr=}szExpatParser.setContentHandlercCsP|tkr|jS|tkr |jdk S|tttfkr2dS|tkr@|jSt d|dS)NrFeature '%s' not recognized) rr.rr3rrrrr2SAXNotRecognizedExceptionrnamerrr getFeatures zExpatParser.getFeaturecCs|jrtd|tkr||_n|tkr.||_nt|tkrT|rL|jdkrRi|_qd|_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.setPropertyc Csz|js|d|_|jz|j||WnDtjk rt}z$tt |j ||}|j |W5d}~XYnXdSr$) r0r6r7Z startDocumentr!ZParser errorZSAXParseExceptionZ ErrorStringcodeZ _err_handlerZ fatalError)rdataisFinaleexcrrrfeeds zExpatParser.feedcCsB|j}z|}|dk r |W5|}|dk r<|XdSr)r(Z getByteStreamcloseZgetCharacterStream)rr;filerrrr9s zExpatParser._close_sourcecCs|js|jdkst|jtr dSz(|jddd|j d|_d|_W5d|_|jdk rzt}|jj|_|jj|_||_|XdS)Nrr%)rR) r1r! isinstancerr0r"r&r9rUr7Z endDocumentrrrrrVs       zExpatParser.closecCs|jj|j_|jj|j_dSr)r7processingInstructionr!ZProcessingInstructionHandler charactersZCharacterDataHandlerrrrrr>szExpatParser._reset_cont_handlercCs`|j}|j}|dkr4d|_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_Wntk rYnX|jtj d|_!g|_"dS)N )internr%r)#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|jdkrdS|jjSr)r!r"r\rrrr#;s zExpatParser.getColumnNumbercCs|jdkrdS|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) rrBrlpairZnewattrsZqnamesZanamerMpartsZlengthZqnameZapairrrrr`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)rryrrrrgszExpatParser.end_namespace_declcCs|j|||dSr)r/ZstartDTD)rrBsysidpubidZhas_internal_subsetrrrr]szExpatParser.start_doctype_declcCs|j||||dSr) _dtd_handlerZunparsedEntityDecl)rrBbaserzr{Z notation_namerrrrdsz ExpatParser.unparsed_entity_declcCs|j|||dSr)r|Z notationDecl)rrBr}rzr{rrrreszExpatParser.notation_declcCs|js dS|j||}t||jp*d}|j|j |jf|j ||_ ||_zt j ||WnYdSX|jd\|_ |_|jd=dS)Nr%rXr)r2Z _ent_handlerZ resolveEntityrr5r(r*r1appendr!ZExternalEntityParserCreaterr-r8)rcontextr}rzr{r;rrrrhs" zExpatParser.external_entity_refcCs|r d|}|j|dS)N%)r7Z skippedEntity)rrBZis_perrrrisz"ExpatParser.skipped_entity_handlerN)rr,)r)"rrrr r8r<r=rCrFrKrNrUr9rVr>rLr6r#r'r)r*rbrcr`rarwrxrfrgr]rdrerhrirrrrr+Ws>    '" r+cOs t||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      $_