3 \X=@sdZddlTddlmZmZddlmZddlmZmZddlmZddlm Z m Z ddl Z e j dd d krxe d d[ ydd lmZWnek re d dYnXeedse d dddlmZmZmZejZejZy ddlZWnek rddZYnXddlZejZ[[GdddZGdddejZGdddejejZ ddZ!e"dkrddl#Z$e!Z%e%j&e$j'jj(e%j)e$j'j*e%j+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|S)N)orr+/usr/lib64/python3.6/xml/sax/expatreader.py_mkproxy'src@s eZdZdS) _ClosedParserN)__name__ __module__ __qualname__rrrrr.src@s4eZdZddZddZddZddZd d Zd S) ExpatLocatorcCst||_dS)N)r_ref)selfparserrrr__init__9szExpatLocator.__init__cCs|j}|jdkrdS|jjS)N)r_parserErrorColumnNumber)rrrrrgetColumnNumber<s zExpatLocator.getColumnNumbercCs|j}|jdkrdS|jjS)N)rrErrorLineNumber)rrrrr getLineNumberBs zExpatLocator.getLineNumbercCs|j}|dkrdS|jjS)N)r_source getPublicId)rrrrrr&HszExpatLocator.getPublicIdcCs|j}|dkrdS|jjS)N)rr% getSystemId)rrrrrr'NszExpatLocator.getSystemIdN)rrrrr!r$r&r'rrrrr3s rc@seZdZdFddZddZd d Zd d Zd dZddZddZ ddZ dGddZ ddZ ddZ ddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Zd?d@Z dAdBZ!dCS)H ExpatParserrcCsFtjj||tj|_d|_||_d|_d|_g|_ d|_ d|_ dS)Nr) rIncrementalParserrZ InputSourcer%r _namespaces_lex_handler_prop_parsing _entity_stack _external_ges _interning)rZnamespaceHandlingbufsizerrrrZs zExpatParser.__init__c CsVtj|}||_y*|j|jjt|tjj ||Wn|j YnXdS)N) rprepare_input_sourcer%reset _cont_handlerZsetDocumentLocatorrrr,parse _close_source)rsourcerrrr7gs zExpatParser.parsecCs |jdk r|jj|jdS)N)r'rZSetBase)rr9rrr prepareParserws zExpatParser.prepareParsercCs tjj|||jr|jdS)N)rr,setContentHandlerr/_reset_cont_handler)rrrrrr;}szExpatParser.setContentHandlercCsP|tkr|jS|tkr |jdk S|tttfkr2dS|tkr@|jSt d|dS)NrzFeature '%s' not recognized) rr-rr2rrrrr1SAXNotRecognizedException)rnamerrr 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 prefixeszFeature '%s' not recognized) r/SAXNotSupportedExceptionrr-rr1rr2rrrr=)rr>staterrr setFeatures2 zExpatParser.setFeaturecCsd|tjkr|jS|tkr|jS|tkrT|jrLt|jdrB|jjSt dnt dt d|dS)NGetInputContextz=This version of expat does not support getting the XML stringz.XML string cannot be returned when not parsingzProperty '%s' not recognized) rproperty_lexical_handlerr.r r2r rhasattrrCr=r@)rr>rrr getPropertys   zExpatParser.getPropertycCsV|tjkr ||_|jrR|jn2|tkr0||_n"|tkrFtd|n t d|dS)NzProperty '%s' cannot be setzProperty '%s' not recognized) rrDr.r/_reset_lex_handler_propr r2r r@r=)rr>valuerrr setPropertys   zExpatParser.setPropertycCsz|js|jd|_|jjy|jj||WnDtjk rt}z&ttj |j ||}|j j |WYdd}~XnXdS)Nr") r/r5r6Z startDocumentrZParser errorZSAXParseExceptionZ ErrorStringcodeZ _err_handlerZ fatalError)rdataisFinaleexcrrrfeeds zExpatParser.feedc CsB|j}z|j}|dk r |jWd|j}|dk r<|jXdS)N)r%ZgetCharacterStreamcloseZ getByteStream)rr9filerrrr8s zExpatParser._close_sourcec Cs|js|jdkst|jtr dSz(|jddd|jjd|_d|_Wdd|_|jdk rzt}|jj|_|jj |_ ||_|j XdS)Nr")rMr) r0r isinstancerrPr6Z endDocumentr/r r#r8)rrrrrrQs      zExpatParser.closecCs|jj|j_|jj|j_dS)N)r6processingInstructionrZProcessingInstructionHandler charactersZCharacterDataHandler)rrrrr<s zExpatParser._reset_cont_handlercCs`|j}|j}|dkr4d|_d|_d|_d|_d|_n(|j|_|j|_|j |_|j |_|j |_dS)N) r.rZCommentHandlerZStartCdataSectionHandlerZEndCdataSectionHandlerZStartDoctypeDeclHandlerZEndDoctypeDeclHandlerZcommentZ startCDATAZendCDATAstart_doctype_declZendDTD)rZlexrrrrrGsz#ExpatParser._reset_lex_handler_propc Cs|jr>tj|jjd|jd|_d|j_|j|j_ |j |j_ n,tj|jj|jd|_|j |j_ |j |j_ |j|j|j_|j|j_|j|j_|j|j_d|_|jr|j|j|j_y|j|j_Wntk rYnX|jjtj d|_!g|_"dS)N )internr"r)#r-r rr%Z getEncodingr2rZnamespace_prefixesstart_element_nsZStartElementHandlerend_element_nsZEndElementHandler start_element end_elementr<unparsed_entity_declZUnparsedEntityDeclHandler notation_declZNotationDeclHandlerstart_namespace_declZStartNamespaceDeclHandlerend_namespace_declZEndNamespaceDeclHandlerZ_decl_handler_propr.rGexternal_entity_refZExternalEntityRefHandlerskipped_entity_handlerZSkippedEntityHandlerAttributeErrorZSetParamEntityParsingZ*XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONEr/r0)rrrrr5s6            zExpatParser.resetcCs|jdkrdS|jjS)N)rr )rrrrr!;s zExpatParser.getColumnNumbercCs|jdkrdS|jjS)Nr")rr#)rrrrr$@s zExpatParser.getLineNumbercCs |jjS)N)r%r&)rrrrr&EszExpatParser.getPublicIdcCs |jjS)N)r%r')rrrrr'HszExpatParser.getSystemIdcCs|jj|t|dS)N)r6Z startElementAttributesImpl)rr>attrsrrrr\LszExpatParser.start_elementcCs|jj|dS)N)r6Z endElement)rr>rrrr]OszExpatParser.end_elementc Cs|j}t|dkrd|f}n&t|dkr<|d|df}nt|}i}i}x|jD]|\}}|j}t|} | dkr|} d|f} n>| dkrd|d|df} |d|df} n|d} t|} ||| <| || <qVW|jj|dt||dS)Nr"rz%s:%sr))splitlentupleitemsr6ZstartElementNSAttributesNSImpl) rr>rfpairZnewattrsZqnamesZanamerHpartsZlengthZqnameZapairrrrrZRs.      zExpatParser.start_element_nscCsV|j}t|dkrd|f}n&t|dkr<|d|df}nt|}|jj|ddS)Nr"rgr)rhrirjr6Z endElementNS)rr>rmrrrr[ts   zExpatParser.end_element_nscCs|jj||dS)N)r6rU)rtargetrLrrrprocessing_instructionsz"ExpatParser.processing_instructioncCs|jj|dS)N)r6rV)rrLrrrcharacter_dataszExpatParser.character_datacCs|jj||dS)N)r6ZstartPrefixMapping)rprefixZurirrrr`sz ExpatParser.start_namespace_declcCs|jj|dS)N)r6ZendPrefixMapping)rrrrrrraszExpatParser.end_namespace_declcCs|jj|||dS)N)r.ZstartDTD)rr>sysidpubidZhas_internal_subsetrrrrWszExpatParser.start_doctype_declcCs|jj||||dS)N) _dtd_handlerZunparsedEntityDecl)rr>basersrtZ notation_namerrrr^sz ExpatParser.unparsed_entity_declcCs|jj|||dS)N)ruZ notationDecl)rr>rvrsrtrrrr_szExpatParser.notation_declc Cs|js dS|jj||}tj||jjp*d}|jj|j |jf|j j ||_ ||_yt j j ||Wn dS|jd\|_ |_|jd=dS)Nr"rSrrw)r1Z _ent_handlerZ resolveEntityrr4r%r'r0appendrZExternalEntityParserCreaterr,r7)rcontextrvrsrtr9rrrrbs  zExpatParser.external_entity_refcCs|r d|}|jj|dS)N%)r6Z skippedEntity)rr>Zis_perrrrcsz"ExpatParser.skipped_entity_handlerNi)rr{)r)"rrrrr7r:r;r?rBrFrIrPr8rQr<rGr5r!r$r&r'r\r]rZr[rprqr`rarWr^r_rbrcrrrrr(Ws>    '" r(cOs t||S)N)r()argskwargsrrr create_parsersr~__main__z:http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml),versionZxml.sax._exceptionsZxml.sax.handlerrrrrrrr r sysplatformZSAXReaderNotAvailableZ xml.parsersr ImportErrorrEZxml.saxrrrrerl_weakrefrweakrefproxyrZLocatorrr,r(r~rZxml.sax.saxutilsZxmlpr;ZsaxZ XMLGeneratorZsetErrorHandlerZ ErrorHandlerr7rrrrsL      $_