7ec@s3dZdZddlTddlmZmZddlmZddlmZmZddlm Z ddlm Z m Z dd l Z e j d d kred en[ ydd lmZWn ek reden#Xeed redenddlmZmZmZejZejZydd lZWnek r_dZnXdd lZejZ[[dfdYZdejfdYZ dej!ejfdYZ"dZ#e$dkr/dd l%Z&e#Z'e'j(e&j)jj*e'j+e&j)j,e'j-dnd S(s] SAX driver for the pyexpat C module. This driver works with pyexpat.__version__ == '2.22'. s0.20i(t*(tfeature_validationtfeature_namespaces(tfeature_namespace_prefixes(tfeature_external_gestfeature_external_pes(tfeature_string_interning(tproperty_xml_stringtproperty_interning_dictNitjavasexpat not available in Java(texpatsexpat not supportedt ParserCreate(t xmlreadertsaxutilsthandlercCs|S(N((to((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt_mkproxy'st _ClosedParsercBseZRS((t__name__t __module__(((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR.st ExpatLocatorcBs;eZdZdZdZdZdZdZRS(sLocator 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. cCst||_dS(N(Rt_ref(tselftparser((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt__init__9scCs&|j}|jdkrdS|jjS(N(Rt_parsertNonetErrorColumnNumber(RR((s+/usr/lib64/python2.7/xml/sax/expatreader.pytgetColumnNumber<s cCs&|j}|jdkrdS|jjS(Ni(RRRtErrorLineNumber(RR((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt getLineNumberBs cCs&|j}|dkrdS|jjS(N(RRt_sourcet getPublicId(RR((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR Hs  cCs&|j}|dkrdS|jjS(N(RRRt getSystemId(RR((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR!Ns  (RRt__doc__RRRR R!(((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR3s     t ExpatParsercBs.eZdZdd%dZdZdZdZd Zd Zd Z d Z dd Z dZ dZ dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZd Zd!Zd"Z d#Z!RS(&s$SAX driver for the pyexpat C module.iiiicCsetjj||tj|_d|_||_d|_d|_ g|_ d|_ d|_ dS(Nii( R tIncrementalParserRt InputSourceRRRt _namespacest_lex_handler_propt_parsingt _entity_stackt _external_gest _interning(RtnamespaceHandlingtbufsize((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRZs      cCsjtj|}||_y7|j|jjt|tjj ||Wn|j nXdS(s3Parse an XML document from a URL or an InputSource.N( R tprepare_input_sourceRtresett _cont_handlertsetDocumentLocatorRR R$tparset _close_source(Rtsource((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR2gs   cCsV|jdk rR|j}t|tr?|jd}n|jj|ndS(Nsutf-8(R!Rt isinstancetunicodetencodeRtSetBase(RR4tbase((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt prepareParserws  cCs-tjj|||jr)|jndS(N(R R$tsetContentHandlerR(t_reset_cont_handler(RR((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR;s cCsl|tkr|jS|tkr,|jdk S|tttfkrEdS|tkrX|j St d|dS(NisFeature '%s' not recognized( RR&RR+RRRRRR*tSAXNotRecognizedException(Rtname((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt getFeatures      cCs|jrtdn|tkr0||_n|tkrH||_n|tkr|rx|jdkri|_qqd|_n||t kr|rtdqnX|t kr|rtdqn4|t kr|rtdqnt d|dS(Ns!Cannot set features while parsings!expat does not support validations/expat does not read external parameter entitiess(expat does not report namespace prefixessFeature '%s' not recognized( R(tSAXNotSupportedExceptionRR&RR*RR+RRRRR=(RR>tstate((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt setFeatures2          cCs|tjkr|jS|tkr)|jS|tkr{|jrlt|jdr]|jjSt dq{t dnt d|dS(NtGetInputContexts=This version of expat does not support getting the XML strings.XML string cannot be returned when not parsingsProperty '%s' not recognized( Rtproperty_lexical_handlerR'RR+RRthasattrRCR=R@(RR>((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt getPropertys      cCs||tjkr1||_|jrx|jqxnG|tkrI||_n/|tkrhtd|nt d|dS(NsProperty '%s' cannot be setsProperty '%s' not recognized( RRDR'R(t_reset_lex_handler_propRR+RR@R=(RR>tvalue((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt setPropertys      cCs|js,|jd|_|jjny|jj||WnDtjk r}ttj |j ||}|j j |nXdS(Ni( R(R/R0t startDocumentRtParseR terrortSAXParseExceptiont ErrorStringtcodet _err_handlert fatalError(RtdatatisFinaltetexc((s+/usr/lib64/python2.7/xml/sax/expatreader.pytfeeds   cCs_|j}z)|j}|dk r1|jnWd|j}|dk rZ|jnXdS(N(RtgetCharacterStreamRtcloset getByteStream(RR4tfile((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR3s     cCs|js*|jdks*t|jtr.dSz6|jddd|jjd|_d|_Wdd|_|jdk rt}|jj |_ |jj |_ ||_n|j XdS(NtRSii( R)RRR5RRVR0t endDocumentR(RRR3(RR((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRXs      cCs(|jj|j_|jj|j_dS(N(R0tprocessingInstructionRtProcessingInstructionHandlert characterstCharacterDataHandler(R((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR<scCs|j}|j}|dkrNd|_d|_d|_d|_d|_n<|j|_|j |_|j |_|j |_|j |_dS(N( R'RRtCommentHandlertStartCdataSectionHandlertEndCdataSectionHandlertStartDoctypeDeclHandlertEndDoctypeDeclHandlertcommentt startCDATAtendCDATAtstart_doctype_decltendDTD(RtlexR((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRGs            cCsc|jr]tj|jjdd|j|_d|j_|j|j_ |j |j_ nBtj|jjd|j|_|j |j_ |j |j_ |j|j|j_|j|j_|j|j_|j|j_d|_|jr|jn|j|j_y|j|j_Wntk r9nX|jj tj!d|_"g|_#dS(Nt tinternii($R&R R Rt getEncodingR+Rtnamespace_prefixeststart_element_nstStartElementHandlertend_element_nstEndElementHandlert start_elementt end_elementR<tunparsed_entity_decltUnparsedEntityDeclHandlert notation_decltNotationDeclHandlertstart_namespace_decltStartNamespaceDeclHandlertend_namespace_decltEndNamespaceDeclHandlerRt_decl_handler_propR'RGtexternal_entity_reftExternalEntityRefHandlertskipped_entity_handlertSkippedEntityHandlertAttributeErrortSetParamEntityParsingt*XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONER(R)(R((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR/s6          cCs|jdkrdS|jjS(N(RRR(R((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR>scCs|jdkrdS|jjS(Ni(RRR(R((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRCscCs |jjS(N(RR (R((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR HscCs |jjS(N(RR!(R((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR!KscCs|jj|t|dS(N(R0t startElementtAttributesImpl(RR>tattrs((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRtOscCs|jj|dS(N(R0t endElement(RR>((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRuRsc CsL|j}t|dkr-d|f}n5t|dkrV|d|df}n t|}i}i}x|jD]\}}|j}t|} | dkr|} d|f} nQ| dkrd|d|df} |d|df} n|d} t|} ||| <| || RtpairtnewattrstqnamestanameRHtpartstlengthtqnametapair((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRpUs.         cCsy|j}t|dkr-d|f}n5t|dkrV|d|df}n t|}|jj|ddS(Niii(RRRRR0t endElementNS(RR>R((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRrws  cCs|jj||dS(N(R0R](RttargetRR((s+/usr/lib64/python2.7/xml/sax/expatreader.pytprocessing_instructionscCs|jj|dS(N(R0R_(RRR((s+/usr/lib64/python2.7/xml/sax/expatreader.pytcharacter_datascCs|jj||dS(N(R0tstartPrefixMapping(Rtprefixturi((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRzscCs|jj|dS(N(R0tendPrefixMapping(RR((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR|scCs|jj|||dS(N(R'tstartDTD(RR>tsysidtpubidthas_internal_subset((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRiscCs|jj||||dS(N(t _dtd_handlertunparsedEntityDecl(RR>R9RRt notation_name((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRvscCs|jj|||dS(N(Rt notationDecl(RR>R9RR((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRxscCs|js dS|jj||}tj||jjp=d}|jj|j |jf|j j ||_ ||_yt j j ||WndSX|jd\|_ |_|jd=dS(NiR[ii(R*t _ent_handlert resolveEntityR R.RR!R)tappendRtExternalEntityParserCreateR R$R2(RtcontextR9RRR4((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRs      cCs'|rd|}n|jj|dS(Nt%(R0t skippedEntity(RR>tis_pe((s+/usr/lib64/python2.7/xml/sax/expatreader.pyRs ii("RRR"RR2R:R;R?RBRFRIRVR3RXR<RGR/RRR R!RtRuRpRrRRRzR|RiRvRxRR(((s+/usr/lib64/python2.7/xml/sax/expatreader.pyR#Ws@          '       "        cOs t||S(N(R#(targstkwargs((s+/usr/lib64/python2.7/xml/sax/expatreader.pyt create_parserst__main__s:http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml(.R"tversiontxml.sax._exceptionstxml.sax.handlerRRRRRRRRtsystplatformtSAXReaderNotAvailableRt xml.parsersR t ImportErrorREtxml.saxR R RRRt_weakrefRtweakreftproxyRtLocatorRR$R#RRtxml.sax.saxutilstxmltpR;tsaxt XMLGeneratortsetErrorHandlert ErrorHandlerR2(((s+/usr/lib64/python2.7/xml/sax/expatreader.pytsL         $a