Ñò ‚£kWc @s9dZdZdZddkZddklZlZeefZddkTddk l Z l Z ddk l Z lZlZlZlZlZlZlZlZlZeid ƒd Zd „ZyddkZWn%ej oZed eƒ‚nXd e ifd„ƒYZde ifd„ƒ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? u Stéphane Bidoul s0.3iÿÿÿÿN(t StringTypet UnicodeType(t*(t xmlreadertsaxutils( tfeature_namespacestfeature_namespace_prefixestfeature_string_interningtfeature_validationtfeature_external_gestfeature_external_pestproperty_lexical_handlertproperty_declaration_handlertproperty_dom_nodetproperty_xml_stringtutf8icCs$|djo|St|ƒdSdS(Ni(tNonet_decoder(ts((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt_d<s s+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((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt__init__KscCsdS(s6Return the column number where the current event ends.iÿÿÿÿ((R((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pytgetColumnNumberNscCs |iiƒS(s4Return the line number where the current event ends.(Rt LineNumber(R((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt getLineNumberRscCsdS(s3Return the public identifier for the current event.N(R(R((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt getPublicIdVscCs |iiƒS(s3Return the system identifier for the current event.(RtBaseURI(R((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt getSystemIdZs(t__name__t __module__t__doc__RRRRR(((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyRHs     t LibXml2ReadercBsbeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z RS( cCs\tii|ƒ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((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyR`s       cCsI|idjo g|_n|ii|t|dt|ƒƒfƒdS(N(R+RtappendtSAXParseExceptionR(RtargtmsgtseverityR((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt _errorHandleros    cCs—x‡|iD]|\}}|titifjo|ii|ƒq |o,||iddjo|ii|ƒq |ii|ƒq Wd|_dS(Niÿÿÿÿi( R+tlibxml2t PARSER_SEVERITY_VALIDITY_WARNINGtPARSER_SEVERITY_WARNINGt _err_handlertwarningt fatalErrorterrorR(RtfatalR0t exception((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt _reportErrorsvs  cCsod|_zUt|ƒtjoti|ƒ}n:ti|ƒ}ti|iƒƒ}|i |i ƒƒ}|i |i dƒ|ioS|itidƒ|itidƒ|itidƒ|iti|iƒn|itidƒ|iotihhƒ}ntihƒ}g}|iiƒx|iƒ}|djo%|idj o|idƒqÜnl|djo&|idj o|idƒnPn9|idj o|idƒn|iit dƒƒP|i!ƒ}|djoQ|io©t"|i#ƒƒt"|i$ƒƒf} t"|i%ƒƒ} h|_&} h|_'} g} xÚ|i(ƒoÌt"|i%ƒƒ}t"|i)ƒƒ}|i*dƒo\t+|ƒdjo|d}nd}| i,|ƒ|ii-||ƒ|i.pqXqõnt"|i#ƒƒt"|i$ƒƒf}|| |<|| |t"|i%ƒƒƒq2q3|d jo/|ii?t"|i%ƒƒt"|i)ƒƒƒq3|djo4|i9dj o |i9i@t"|i)ƒƒƒq2q3|djoq3|djoq3|djoq3|djoq3t d|ƒ‚q3|djo|iiAƒn|iBƒWdd|_XdS(Niis"Read failed (no details available)txmlnsiiiii iiiiii ii sUnexpected node type %d(CR(ttypet StringTypesR2tnewTextReaderFilenameRtprepare_input_sourcet inputBuffert getByteStreamt newTextReaderRtSetErrorHandlerR1RR't SetParserProptPARSER_LOADDTDtPARSER_DEFAULTATTRStPARSER_SUBST_ENTITIEStPARSER_VALIDATER&R$RtAttributesNSImpltAttributesImplt _cont_handlert startDocumenttReadR+R;R5R7t SAXExceptiontNodeTypeRt NamespaceUrit LocalNametNamet_attrst_qnamestMoveToNextAttributetValuet startswithtlenR,tstartPrefixMappingR%t MoveToElementtstartElementNStIsEmptyElementt endElementNStendPrefixMappingt startElementt endElementtpopt characterstignorableWhitespaceR)t startCDATAtendCDATAt startEntityt ResolveEntityt endEntitytprocessingInstructiontcommentt endDocumenttClose(RtsourcetreadertinputtattributesNSImpltattributesImpltprefixestrtnodeTypeteltNameteltQNametattrstqnamest newPrefixestqnametvaluet newPrefixtattNametprefix((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pytparse…sü                                  !           !  & $     cCstdƒ‚dS(NsDTDHandler not supported(tSAXNotSupportedException(Rthandler((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt setDTDHandler0scCstdƒ‚dS(NsEntityResolver not supported(R(Rtresolver((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pytsetEntityResolver4scCsz|tjo|iS|tjo|iS|tjo|iS|tjodS|tjo|iSt d|ƒ‚dS(NisFeature '%s' not recognized( RR$RR%RR&R R R'tSAXNotRecognizedException(Rtname((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt getFeature8s     cCsÌ|iotd|ƒ‚n|tjo ||_n‘|tjo ||_nw|tjo ||_n]|tjo%|djotd|ƒ‚qÈn+|t jo ||_ nt d|ƒ‚dS(Ns#Cannot set feature %s while parsingisFeature '%s' not supportedsFeature '%s' not recognized( R(RRR$RR%RR&R R R'R†(RR‡tstate((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt setFeatureGs"           cCs>|tjo|iS|tjo|iStd|ƒ‚dS(NsProperty '%s' not recognized(R R)R R*R†(RR‡((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt getProperty\s   cCsX|tjo ||_n;|tjotd|ƒ‚||_ntd|ƒ‚dS(NsProperty '%s' not supportedsProperty '%s' not recognized(R R)R RR*R†(RR‡R|((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt setPropertyes     ( RR RR1R;R€RƒR…RˆRŠR‹RŒ(((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyR"^s    «     cCstƒS(N(R"(((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt create_parserqs("R!t __author__t __version__tcodecsttypesRRR>txml.sax._exceptionstxml.saxRRtxml.sax.handlerRRRRR R R R R RtlookupRRR2t ImportErrortetSAXReaderNotAvailableRR#R"R(((s1/usr/lib64/python2.6/site-packages/drv_libxml2.pyt#s&   F  ÿ