ó £Jýfc@smdZdZdZddlZddlZejddkr{ejeƒdZeefZ ej dƒdZ d „Z neZ d „Z dd l Tdd lmZmZdd lmZmZmZmZmZmZmZmZmZmZyddlZWn+ek r-edejƒdƒ‚nXdej fd„ƒYZ dej!fd„ƒYZ"d„Z#dS(sí A SAX2 driver for libxml2, on top of it's XmlReader API USAGE # put this file (drv_libxml2.py) in PYTHONPATH import xml.sax reader = xml.sax.make_parser(["drv_libxml2"]) # ...and the rest is standard python sax. CAVEATS - Lexical handlers are supported, except for start/endEntity (waiting for XmlReader.ResolveEntity) and start/endDTD - Error callbacks are not exactly synchronous, they tend to be invoked before the corresponding content callback, because the underlying reader interface parses data by chunks of 512 bytes TODO - search for TODO - some ErrorHandler events (warning) - some ContentHandler events (setDocumentLocator, skippedEntity) - EntityResolver (using libxml2.?) - DTDHandler (if/when libxml2 exposes such node types) - DeclHandler (if/when libxml2 exposes such node types) - property_xml_string? - feature_string_interning? - Incremental parser - additional performance tuning: - one might cache callbacks to avoid some name lookups - one might implement a smarter way to pass attributes to startElement (some kind of lazy evaluation?) - there might be room for improvement in start/endPrefixMapping - other? sStéphane Bidoul s0.3iÿÿÿÿNiitutf8icCs"|dkr|St|ƒdSdS(Ni(tNonet_decoder(ts((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt_d1s cCs|S(N((R((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyR9s(t*(t xmlreadertsaxutils( tfeature_namespacestfeature_namespace_prefixestfeature_string_interningtfeature_validationtfeature_external_gestfeature_external_pestproperty_lexical_handlertproperty_declaration_handlertproperty_dom_nodetproperty_xml_strings+libxml2 not available: import error was: %stLocatorcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s4SAX Locator adapter for libxml2.xmlTextReaderLocatorcCs ||_dS(N(t_Locator__locator(tselftlocator((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt__init__SscCsdS(s6Return the column number where the current event ends.iÿÿÿÿ((R((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pytgetColumnNumberVscCs |jjƒS(s4Return the line number where the current event ends.(Rt LineNumber(R((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt getLineNumberZscCsdS(s3Return the public identifier for the current event.N(R(R((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt getPublicId^scCs |jjƒS(s3Return the system identifier for the current event.(RtBaseURI(R((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt getSystemIdbs(t__name__t __module__t__doc__RRRRR(((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyRPs     t LibXml2ReadercBsbeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z RS( cCs\tjj|ƒd|_d|_d|_d|_d|_d|_ d|_ d|_ dS(Nii( Rt XMLReaderRt_LibXml2Reader__nst_LibXml2Reader__nspfxt_LibXml2Reader__validatet_LibXml2Reader__extparamst_LibXml2Reader__parsingRt_LibXml2Reader__lex_handlert_LibXml2Reader__decl_handlert_LibXml2Reader__errors(R((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyRhs       cCsG|jdkrg|_n|jj|t|dt|ƒƒfƒdS(N(R)RtappendtSAXParseExceptionR(RtargtmsgtseverityR((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt _errorHandlerws    cCs’x‚|jD]w\}}|tjtjfkrA|jj|ƒq |rq||jddkrq|jj|ƒq |jj|ƒq Wd|_dS(Niÿÿÿÿi( R)tlibxml2t PARSER_SEVERITY_VALIDITY_WARNINGtPARSER_SEVERITY_WARNINGt _err_handlertwarningt fatalErrorterrorR(RtfatalR.t exception((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt _reportErrors~s cCsCd|_z)t|tƒr-tj|ƒ}nZtj|ƒ}|jƒ}|dkrc|j ƒ}ntj |ƒ}|j |j ƒƒ}|j |jdƒ|jrõ|jtjdƒ|jtjdƒ|jtjdƒ|jtj|jƒn|jtjdƒ|jr&tjiiƒ}ntjiƒ}g}|jjƒxÀ|jƒ}|dkr…|jdk rê|jdƒqêne|dkr´|jdk r°|jdƒnPn6|jdk rÓ|jdƒn|jj t!dƒƒP|j"ƒ} | dkrB|jr©t#|j$ƒƒt#|j%ƒƒf} t#|j&ƒƒ} i|_'} i|_(} g}xÒ|j)ƒr5t#|j&ƒƒ}t#|j*ƒƒ}|j+dƒrút,|ƒdkrÂ|d}nd}|j-|ƒ|jj.||ƒ|j/súqdqúnt#|j$ƒƒt#|j%ƒƒf}|| |<|| |ƒqK| d krE|j:dk r|j?t#|j&ƒƒƒqqK| d kr|jj@t#|j&ƒƒt#|j*ƒƒƒqK| dkr¼|j:dk r|j:jAt#|j*ƒƒƒqqK| dkrËqK| dkrÚqK| dkréqK| dkrøqKt!d| ƒ‚qK|dkr'|jjBƒn|jCƒWdd|_XdS(Niis"Read failed (no details available)txmlnsiiiii iiiiii ii sUnexpected node type %d(DR&t isinstancet StringTypesR0tnewTextReaderFilenameRtprepare_input_sourcetgetCharacterStreamRt getByteStreamt inputBuffert newTextReaderRtSetErrorHandlerR/R%t SetParserProptPARSER_LOADDTDtPARSER_DEFAULTATTRStPARSER_SUBST_ENTITIEStPARSER_VALIDATER$R"RtAttributesNSImpltAttributesImplt _cont_handlert startDocumenttReadR)R9R3R5t SAXExceptiontNodeTypeRt NamespaceUrit LocalNametNamet_attrst_qnamestMoveToNextAttributetValuet startswithtlenR*tstartPrefixMappingR#t MoveToElementtstartElementNStIsEmptyElementt endElementNStendPrefixMappingt startElementt endElementtpopt characterstignorableWhitespaceR't startCDATAtendCDATAt startEntityt ResolveEntityt endEntitytprocessingInstructiontcommentt endDocumenttClose(RtsourcetreadertstreamtinputtattributesNSImpltattributesImpltprefixestrtnodeTypeteltNameteltQNametattrstqnamest newPrefixestqnametvaluet newPrefixtattNametprefix((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pytparsesú                                    !         % "     cCstdƒ‚dS(NsDTDHandler not supported(tSAXNotSupportedException(Rthandler((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt setDTDHandler;scCstdƒ‚dS(NsEntityResolver not supported(R(Rtresolver((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pytsetEntityResolver?scCsp|tkr|jS|tkr&|jS|tkr9|jS|tkrIdS|tkr\|jSt d|ƒ‚dS(NisFeature '%s' not recognized( RR"R R#R R$R R R%tSAXNotRecognizedException(Rtname((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt getFeatureCs     cCs¾|jrtd|ƒ‚n|tkr4||_n†|tkrL||_nn|tkrd||_nV|tkr’|dkrºtd|ƒ‚qºn(|t krª||_ nt d|ƒ‚dS(Ns#Cannot set feature %s while parsingisFeature '%s' not supportedsFeature '%s' not recognized( R&RRR"R R#R R$R R R%R†(RR‡tstate((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt setFeatureRs"            cCs:|tkr|jS|tkr&|jStd|ƒ‚dS(NsProperty '%s' not recognized(RR'RR(R†(RR‡((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt getPropertygs   cCsT|tkr||_n8|tkr@td|ƒ‚||_ntd|ƒ‚dS(NsProperty '%s' not supportedsProperty '%s' not recognized(RR'RRR(R†(RR‡R|((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt setPropertyps     ( RRRR/R9R€RƒR…RˆRŠR‹RŒ(((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyR fs    ®     cCstƒS(N(R (((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt create_parser|s($Rt __author__t __version__tsystcodecst version_infotunicode_escape_decodetstrtunicodeR<tlookupRRtxml.sax._exceptionstxml.saxRRtxml.sax.handlerRR R R R R RRRRR0t ImportErrortSAXReaderNotAvailabletexc_infoRR!R R(((sA/opt/cpanel/ea-libxml2/lib/python2.7/site-packages/drv_libxml2.pyt#s.      F  ÿ