Ñò Š™Vc @shdZdZdZddkZddkZeiddjo#eieƒdZeefZ neZ ddk Tddk l Z l Z dd klZlZlZlZlZlZlZlZlZlZeid ƒd Zd „ZyddkZWn-ej o!ed eiƒd ƒ‚nXde i fd„ƒYZ de i!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ÿÿÿÿNii(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((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt_dBs 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((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt__init__QscCsdS(s6Return the column number where the current event ends.iÿÿÿÿ((R((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pytgetColumnNumberTscCs |iiƒS(s4Return the line number where the current event ends.(Rt LineNumber(R((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt getLineNumberXscCsdS(s3Return the public identifier for the current event.N(R(R((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt getPublicId\scCs |iiƒS(s3Return the system identifier for the current event.(RtBaseURI(R((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt getSystemId`s(t__name__t __module__t__doc__RRRRR(((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyRNs     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((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyRfs       cCsI|idjo g|_n|ii|t|dt|ƒƒfƒdS(N(R)RtappendtSAXParseExceptionR(RtargtmsgtseverityR((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt _errorHandlerus    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(RtfatalR.t exception((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt _reportErrors|s  cCsld|_zRt|tƒoti|ƒ}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.pqUqònt"|i#ƒƒt"|i$ƒƒf}|| |<|| |t"|i%ƒƒƒq/q0|d jo/|ii?t"|i%ƒƒt"|i)ƒƒƒq0|djo4|i9dj o |i9i@t"|i)ƒƒƒq/q0|djoq0|djoq0|djoq0|djoq0t d|ƒ‚q0|djo|iiAƒn|iBƒWdd|_XdS(Niis"Read failed (no details available)txmlnsiiiii iiiiii ii sUnexpected node type %d(CR&t isinstancet StringTypesR0tnewTextReaderFilenameRtprepare_input_sourcet inputBuffert getByteStreamt newTextReaderRtSetErrorHandlerR/RR%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(RtsourcetreadertinputtattributesNSImpltattributesImpltprefixestrtnodeTypeteltNameteltQNametattrstqnamest newPrefixestqnametvaluet newPrefixtattNametprefix((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pytparse‹sü                                  !           !  & $     cCstdƒ‚dS(NsDTDHandler not supported(tSAXNotSupportedException(Rthandler((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt setDTDHandler6scCstdƒ‚dS(NsEntityResolver not supported(R(Rtresolver((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pytsetEntityResolver:scCsz|tjo|iS|tjo|iS|tjo|iS|tjodS|tjo|iSt d|ƒ‚dS(NisFeature '%s' not recognized( RR"RR#RR$RRR%tSAXNotRecognizedException(Rtname((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt getFeature>s     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$RRR%R„(RR…tstate((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt setFeatureMs"           cCs>|tjo|iS|tjo|iStd|ƒ‚dS(NsProperty '%s' not recognized(R R'R R(R„(RR…((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt getPropertybs   cCsX|tjo ||_n;|tjotd|ƒ‚||_ntd|ƒ‚dS(NsProperty '%s' not supportedsProperty '%s' not recognized(R R'R RR(R„(RR…Rz((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt setPropertyks     ( RRRR/R9R~RRƒR†RˆR‰RŠ(((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyR ds    «     cCstƒS(N(R (((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt create_parserws($Rt __author__t __version__tsystcodecst version_infotunicode_escape_decodetstrtunicodeR<txml.sax._exceptionstxml.saxRRtxml.sax.handlerRRRRRRR R R R tlookupRRR0t ImportErrortSAXReaderNotAvailabletexc_infoRR!R R‹(((so/builds/ul11u3sru-gate/components/libxml2/build/prototype/i386/usr/lib/python2.6/vendor-packages/drv_libxml2.pyt#s,   F  ÿ