Vco= dZdZddlTddlmZmZddlmZddlmZmZddlm Z ddlm Z m Z dd l Z e j d d d kr ed d [ dd lmZeeds edd n#e$r edd wxYwddlmZmZmZejZejZ dd lZdd lZejZ[[n#e$rdZYnwxYwGddZGddejZGddej ejZ!dZ"e#dkrdd l$Z%e"Z&e&'e%j(j)e&*e%j(+e&,dd Sd S)z] SAX driver for the pyexpat C module. This driver works with pyexpat.__version__ == '2.22'. 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)expat ParserCreatezexpat not supported) xmlreadersaxutilshandlerc|SN)os ,/usr/lib64/python3.11/xml/sax/expatreader.py_mkproxyr'sceZdZdS) _ClosedParserN)__name__ __module__ __qualname__rrrrr.sDrrc0eZdZdZdZdZdZdZdZdS) ExpatLocatorzLocator for use with the ExpatParser class. This uses a weak reference to the parser object to avoid creating a circular reference between the parser and the content handler. c.t||_dSr)r_refselfparsers r__init__zExpatLocator.__init__9sV$$ rc:|j}|jdS|jjSr)r"_parserErrorColumnNumberr#s rgetColumnNumberzExpatLocator.getColumnNumber<s# > 4~//rc:|j}|jdS|jjSN)r"r(ErrorLineNumberr#s r getLineNumberzExpatLocator.getLineNumberBs# > 1~--rcJ|j}|dS|jSr)r"_source getPublicIdr#s rr2zExpatLocator.getPublicIdH*  4~))+++rcJ|j}|dS|jSr)r"r1 getSystemIdr#s rr5zExpatLocator.getSystemIdNr3rN) rrr__doc__r&r*r/r2r5rrrr r 3si %%%000 ... ,,, ,,,,,rr ceZdZdZd%dZdZdZdZdZd Z d Z d Z d&d Z dZ dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZd Zd!Z d"Z!d#Z"d$S)' ExpatParserz$SAX driver for the pyexpat C module.rctj||tj|_d|_||_d|_d|_g|_ d|_ d|_ dS)NFr) rIncrementalParserr& InputSourcer1r( _namespaces_lex_handler_prop_parsing _entity_stack _external_ges _interning)r$namespaceHandlingbufsizes rr&zExpatParser.__init__Zsd#,,T7;;; ,..  ,!% rc(tj|}||_ ||jt |tj ||dS#| xYw)z3Parse an XML document from a URL or an InputSource.N) rprepare_input_sourcer1reset _cont_handlersetDocumentLocatorr rr;parse _close_sourcer$sources rrJzExpatParser.parsegs.v66   JJLLL   1 1,t2D2D E E E  ' - -dF ; ; ; ; ;     s AA::Bc|.|j|dSdSr)r5r(SetBaserLs r prepareParserzExpatParser.prepareParserwsH      7 L !3!3!5!5 6 6 6 6 6 7 7rctj|||jr|dSdSr)rr;setContentHandlerr?_reset_cont_handler)r$rs rrRzExpatParser.setContentHandler}sG#55dGDDD = '  $ $ & & & & & ' 'rc|tkr|jS|tkr |jduS|tt t fvrdS|tkr|jStd|z)NrFeature '%s' not recognized) rr=r rBrrrrrASAXNotRecognizedExceptionr$names r getFeaturezExpatParser.getFeatures % % &# # - - &?$. . (*>022 &1 ) ) &% %'(E(LMMMrc|jrtd|tkr ||_dS|tkr ||_dS|t kr|r|j i|_dSdSd|_dS|tkr|rtddS|tkr|rtddS|tkr|rtddStd|z)Nz!Cannot set features while parsingz!expat does not support validationz/expat does not read external parameter entitiesz(expat does not report namespace prefixesrU) r?SAXNotSupportedExceptionrr=rrAr rBrrrrV)r$rXstates r setFeaturezExpatParser.setFeaturesa = P*+NOO O % % 6$D    ) ) 6!&D    - - 6 '?)&(DOOO))#' ' ' 6 9.7999 9 9) ) 6 G.EGGG G G/ / 6 @.>@@@ @ @,-466 6rc4|tjkr|jS|tkr|jS|t krS|jr=t|jdr|jStdtdtd|z)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 rBr r(hasattrr_rVr[rWs r getPropertyzExpatParser.getPropertys 73 3 F) ) , , F? " ( ( F| F4<):;;+<779993*+++/DFFF'(F(MNNNrc|tjkr&||_|jr|dSdS|t kr ||_dS|tkrtd|ztd|z)NzProperty '%s' cannot be setr`) rrar>r?_reset_lex_handler_propr rBr r[rV)r$rXvalues r setPropertyzExpatParser.setPropertys 73 3 2%*D "} /,,..... / / , , 2#DOOO ( ( 2*+H+/,011 1,,J,0-122 2rFcr|js4|d|_|j |j||dS#t j$rM}tt j |j ||}|j |Yd}~dSd}~wwxYw)NT) r?rGrH startDocumentr(ParsererrorSAXParseException ErrorStringcode _err_handler fatalError)r$dataisFinaleexcs rfeedzExpatParser.feeds} / JJLLL DM   , , . . . . L  tW - - - - -{ . . .#E$5af$=$=q$GGC   ( ( - - - - - - - - - .sAB6)AB11B6c"|j} |}|||}||dSdS#|}||wwxYwr)r1getCharacterStreamclose getByteStream)r$rMfiles rrKzExpatParser._close_sources ,,..D  ''))D    ''))D   s *A!!-BcF|js!|jt|jtrdS |dd|jd|_d|_d|_|j7t}|jj|_|jj |_ ||_| dS#d|_|j7t}|jj|_|jj |_ ||_| wxYw)NrT)rrF) r@r( isinstancerrurH endDocumentr?r)r.rKr#s rrxzExpatParser.closes   $,  t|] 3 3  F ! IIc4I ( ( (   * * , , ,!DMDL!DM| &&+/<+I()-)E&%    "DM| &&+/<+I()-)E&%    s >CAD c^|jj|j_|jj|j_dSr)rHprocessingInstructionr(ProcessingInstructionHandler charactersCharacterDataHandlerr$s rrSzExpatParser._reset_cont_handlers+$($6$L 1,0,>,I )))rc|j}|j}|%d|_d|_d|_d|_d|_dS|j|_|j|_|j |_|j |_|j |_dSr) r>r(CommentHandlerStartCdataSectionHandlerEndCdataSectionHandlerStartDoctypeDeclHandlerEndDoctypeDeclHandlercomment startCDATAendCDATAstart_doctype_declendDTD)r$lexr%s rrez#ExpatParser._reset_lex_handler_props$  6$(F !.2F +,0F )-1F *+/F ( ( ($'KF !.1nF +,/LF )-1-DF *+.:F ( ( (rcT|jrgtj|jd|j|_d|j_|j|j_ |j |j_ nYtj|j|j|_|j |j_ |j |j_ ||j|j_|j|j_|j|j_|j|j_d|_|jr||j|j_ |j|j_n#t<$rYnwxYw|jtj d|_!g|_"dS)N )internr-F)#r=rrr1 getEncodingrBr(namespace_prefixesstart_element_nsStartElementHandlerend_element_nsEndElementHandler start_element end_elementrSunparsed_entity_declUnparsedEntityDeclHandler notation_declNotationDeclHandlerstart_namespace_declStartNamespaceDeclHandlerend_namespace_declEndNamespaceDeclHandler_decl_handler_propr>reexternal_entity_refExternalEntityRefHandlerskipped_entity_handlerSkippedEntityHandlerAttributeErrorSetParamEntityParsing*XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONEr?r@rs rrGzExpatParser.resets   > -dl.F.F.H.H#59_FFFDL./DL +/3/DDL ,-1-@DL * * -dl.F.F.H.H7;HHHDL/3/ADL ,-1-=DL *   """151J .+/+= (151J ./3/F ,"&  ! +  ( ( * * *150H - 040KDL - -    D  **  < > > > sE&& E32E3c,|jdS|jjSr)r(r)rs rr*zExpatParser.getColumnNumber;s < 4|--rc,|jdS|jjSr,)r(r.rs rr/zExpatParser.getLineNumber@s < 1|++rc4|jSr)r1r2rs rr2zExpatParser.getPublicIdE|'')))rc4|jSr)r1r5rs rr5zExpatParser.getSystemIdHrrcV|j|t|dSr)rH startElementAttributesImpl)r$rXattrss rrzExpatParser.start_elementLs) ''nU.C.CDDDDDrc:|j|dSr)rH endElementrWs rrzExpatParser.end_elementO %%d+++++rcJ|}t|dkrd|f}n3t|dkr|d|df}nt|}i}i}|D]\}}|}t|} | dkr|} d|f} nA| dkr$|dd|d} |d|df} n|d} t|} ||| <| || <|j|dt ||dS)Nr-r:)splitlentupleitemsrHstartElementNSAttributesNSImpl) r$rXrpairnewattrsqnamesanamerfpartslengthqnameapairs rrzExpatParser.start_element_nsRsUzz|| t99> $
 $
>>>>rc:|j|dSr)rHr)r$rqs rcharacter_datazExpatParser.character_datarrc<|j||dSr)rHstartPrefixMapping)r$prefixuris rrz ExpatParser.start_namespace_decls! --fc:::::rc:|j|dSr)rHendPrefixMapping)r$rs rrzExpatParser.end_namespace_decls ++F33333rc>|j|||dSr)r>startDTD)r$rXsysidpubidhas_internal_subsets rrzExpatParser.start_doctype_decls# ''eU;;;;;rc@|j||||dSr) _dtd_handlerunparsedEntityDecl)r$rXbaserr notation_names rrz ExpatParser.unparsed_entity_decls% ,,T5%OOOOOrc>|j|||dSr)r notationDecl)r$rXrrrs rrzExpatParser.notation_decls# &&tUE:::::rc|jsdS|j||}tj||jpd}|j|j |jf|j ||_ ||_ tj ||n#YdSxYw|jd\|_ |_|jd=dS)Nr-r)rA _ent_handler resolveEntityrrFr1r5r@appendr(ExternalEntityParserCreaterr;rJ)r$contextrrrrMs rrzExpatParser.external_entity_refs! 1"00>>.v/3|/G/G/I/I02/133 !!4<">???|>>wGG     ' - -dF ; ; ; ; 11'+'9"'=$t|  r "qs CCcH|rd|z}|j|dS)N%)rH skippedEntity)r$rXis_pes rrz"ExpatParser.skipped_entity_handlers0  t8D ((.....rN)rr9)F)#rrrr6r&rJrPrRrYr]rcrgrurKrxrSrerGr*r/r2r5rrrrrrrrrrrrrrrrr8r8Ws ..     777 ''' N N N666<OOO$ 2 2 2 ...."   !!!*JJJ 666 # # # N... ,,, ******EEE,,, N N ND 4 4 4???,,,;;;444<<<PPP;;;,/////rr8ct|i|Sr)r8)argskwargss r create_parserrs  ' ' ''r__main__z:http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml)-r6versionxml.sax._exceptionsxml.sax.handlerrrrrrr r r sysplatformSAXReaderNotAvailable xml.parsersrrb ImportErrorxml.saxrrrrr_weakrefweakrefproxyrrLocatorr r;r8rrxml.sax.saxutilsxmlprRsax XMLGeneratorsetErrorHandler ErrorHandlerrJrrrrs !!!!BBBBBBBB666666FFFFFFFF444444HHHHHHHH <vE   =t D DDA!!!!!! 75. ) )A##$94@@@A===   5t < <<= 1000000000)- OOO NNN}H         ,,,,,9$,,,HY/Y/Y/Y/Y/)-y/@Y/Y/Y/z (((  zJ A(5577888cg**,,---GG HIIIII JJsA11BB11B<;B<