\STc@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z yej ej gZ Wne k rej gZ nXdZidZidZidZdejejejejfdYZd d+d YZd d,d YZd d-dYZddlmZddlZdZeedr|idZn idZdZdejfdYZ de e j!fdYZ"de fdYZ#de j$fdYZ%e%Z&dej'fdYZ(dd Z)d!d.d"YZ*d#d/d$YZ+ddl Z d%e j,fd&YZ-d'e j,fd(YZ.d)d0d*YZ/dS(1s A library of useful helper classes to the saxlib classes, for the convenience of application and driver writers. $Id: saxutils.py,v 1.35 2004/03/20 07:46:04 fdrake Exp $ iNcCs3x,|jD]\}}|j||}q W|S(s2Replace substrings of a string using a dictionary.(titemstreplace(tstdtkeytvalue((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt__dict_replacescCsR|jdd}|jdd}|jdd}|rNt||}n|S(sEscape &, <, and > in a string of data. You can escape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value. t&s&ts>(RR(tdatatentities((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytescapes cCsL|jdd}|jdd}|r<t||}n|jddS(s Unescape &, <, and > in a string of data. You can unescape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value. s<Rs>R s&R(RR(R R ((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytunescape&s cCs[t||}d|krMd|kr@d|jdd}qWd|}n d|}|S(sEscape and quote an attribute value. Escape &, <, and > in a string of data, then quote it for use as an attribute value. The " character will be escaped as well, if necessary. You can escape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value. t"t's"%s"s"s'%s'(R R(R R ((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt quoteattr4s     tDefaultHandlercBseZdZRS(sDefault base class for SAX2 event handlers. Implements empty methods for all callback methods, which can be overridden by application implementors. Replaces the deprecated SAX1 HandlerBase class.(t__name__t __module__t__doc__(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRKstLocationcBsDeZdZdZdZdZdZdZdZRS(sRepresents a location in an XML entity. Initialized by being passed a locator, from which it reads off the current location, which is then stored internally.cCs@|j|_|j|_|j|_|j|_dS(N(tgetColumnNumbert_Location__colt getLineNumbert_Location__linet getPublicIdt_Location__pubidt getSystemIdt_Location__sysid(tselftlocator((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt__init__YscCs|jS(N(R(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR_scCs|jS(N(R(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRbscCs|jS(N(R(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRescCs|jS(N(R(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRhscCse|jdkrd}n |j}|jdkr9d}n |j}d|jpZ|jpZd||fS(Nt?s%s:%s:%ss (RtNoneRRR(Rtlinetcol((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt__str__ks    ( RRRR RRRRR%(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRTs     t ErrorPrintercBsDeZdZdejdZdZdZdZdZ RS(s?A simple class that just prints error messages to standard out.icCs||_||_dS(N(t_levelt_outfile(Rtleveltoutfile((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR }s cCs?|jdkr;|jjd|j||jfndS(NisWARNING in %s: %s (R'R(twritet_ErrorPrinter__getpost getMessage(Rt exception((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytwarnings  cCs?|jdkr;|jjd|j||jfndS(NisERROR in %s: %s (R'R(R+R,R-(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyterrors  cCs?|jdkr;|jjd|j||jfndS(NisFATAL ERROR in %s: %s (R'R(R+R,R-(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt fatalErrors  cCs=t|tjr5d|j|j|jfSdSdS(Ns%s:%s:%ss (t isinstancet _exceptionstSAXParseExceptionRRR(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt__getposs   ( RRRtsyststderrR R/R0R1R,(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR&zs    t ErrorRaisercBs5eZdZddZdZdZdZRS(s<A simple class that just raises the exceptions it is passed.icCs ||_dS(N(R'(RR)((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR scCs|jdkr|ndS(Ni(R'(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR0scCs|jdkr|ndS(Ni(R'(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR1scCs|jdkr|ndS(Ni(R'(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR/s(RRRR R0R1R/(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR8s    (tAttributesImplcCstj|d}||S(Ni(tcodecstlookup(tstreamtencodingt writerclass((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt_outputwrapperstregister_errorcCs,d|_|jt||d|_dS(Ntxmlcharrefreplacetstrict(terrorsR+R (R<ttextR ((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt writetexts cCst||}y|j|Wn^tk rxN|D]B}y|j|Wq7tk rx|jdt|q7Xq7WnXdS(Nu&#%d;(R R+t UnicodeErrortord(R<RDR tc((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyREs   cCs|jd}|r\|jd}||krFidd6}d}qhidd6}d}n i}d}|j|t||||j|dS(NRRs"s'(tcountR+RE(R<RDt countdoublet countsingleR tquote((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt writeattrs      t XMLGeneratorcBsweZdZd ddZdZdZdZdZdZ dZ d Z d Z d Z d ZRS(sxml.sax.saxutils.prefix%ss iso-8859-1cCs|dkr$ddl}|j}ntjj|t|||_ig|_|jd|_ g|_ ||_ d|_ dS(Nii( R"R6tstdoutthandlertContentHandlerR R?t_outt _ns_contextst_current_contextt_undeclared_ns_mapst _encodingt_generated_prefix_ctr(RtoutR=R6((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR s       cCs|jjd|jdS(Ns$ (RRR+RV(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt startDocuments cCs@|jj|jj||j|<|jj||fdS(N(RStappendRTtcopyRU(Rtprefixturi((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytstartPrefixMappings cCs|jd|_|jd=dS(Ni(RSRT(RR\((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytendPrefixMappingscCsi|jjd|x>|jD]0\}}|jjd|t|j|q!W|jjddS(NRs %s=R (RRR+RRM(RtnametattrsR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt startElements cCs|jjd|dS(Ns(RRR+(RR`((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt endElementscCs|ddkr|d}nA|j|ddkrA|d}n|j|dd|d}|jjd|xZ|jD]O\}}|dkr|jjd|pdq||jjd||fq|Wg|_x|jD]\}}|ddkr|d}n|j|ddkr|j|j}|jd|_|d|d}|jjd|t|df||j|d(R"RTRRR+(RR`Rg((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt endElementNS(s   cCst|j|dS(N(RERR(Rtcontent((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt characters4scCs|jj|dS(N(RRR+(RRl((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytignorableWhitespace7scCs|jjd||fdS(Ns (RRR+(RttargetR ((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytprocessingInstruction:sN(RRRfR"R RYR^R_RbRcRjRkRmRnRp(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRNs      #  tLexicalXMLGeneratorcBsSeZdZd ddZdZdZdZdZdZ dZ RS( s>A XMLGenerator that also supports the LexicalHandler interfaces iso-8859-1cCs tj|||d|_dS(Ni(RNR t _in_cdata(RRXR=((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR AscCsB|jr(|jj|jddn|jjt|dS(Ns]]>s]]>]]>(RRR+(RRl((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytcommentZscCsd|_|jjddS(Nis (RrRRR+(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytendCDATAcs N( RRRR"R RmRuRvRwRxRy(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRq>s   tContentGeneratorcBseZdZRS(cCstj|||||!S(N(RNRm(Rtstrtstarttend((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRmks(RRRm(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRzist XMLFilterBasecBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZRS(sYThis class is designed to sit between an XMLReader and the client application's event handlers. By default, it does nothing but pass requests up to the reader and events on to the handlers unmodified, but subclasses can override specific methods to modify the event stream or the configuration requests as they pass through.cCs|jj|dS(N(t _err_handlerR0(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR0{scCs|jj|dS(N(RR1(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR1~scCs|jj|dS(N(RR/(RR.((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR/scCs|jj|dS(N(t _cont_handlertsetDocumentLocator(RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jjdS(N(RRY(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRYscCs|jjdS(N(Rt endDocument(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jj||dS(N(RR^(RR\R]((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR^scCs|jj|dS(N(RR_(RR\((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR_scCs|jj||dS(N(RRb(RR`Ra((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRbscCs|jj|dS(N(RRc(RR`((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRcscCs|jj|||dS(N(RRj(RR`RgRa((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRjscCs|jj||dS(N(RRk(RR`Rg((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRkscCs|jj|dS(N(RRm(RRl((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRmscCs|jj|dS(N(RRn(Rtchars((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRnscCs|jj||dS(N(RRp(RRoR ((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRpscCs|jj|dS(N(Rt skippedEntity(RR`((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jj|||dS(N(t _dtd_handlert notationDecl(RR`tpublicIdtsystemId((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jj||||dS(N(RtunparsedEntityDecl(RR`RRtndata((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jj||dS(N(t _ent_handlert resolveEntity(RRR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCsT|jj||jj||jj||jj||jj|dS(N(t_parenttsetContentHandlertsetErrorHandlertsetEntityResolvert setDTDHandlertparse(Rtsource((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRs cCs|jj|dS(N(Rt setLocale(Rtlocale((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jj|S(N(Rt getFeature(RR`((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jj||dS(N(Rt setFeature(RR`tstate((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jj|S(N(Rt getProperty(RR`((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRscCs|jj||dS(N(Rt setProperty(RR`R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRs(RRRR0R1R/RRYRR^R_RbRcRjRkRmRnRpRRRRRRRRRR(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR~qs4                        tBaseIncrementalParsercBs eZdZdZdZRS(sThis class implements the parse method of the XMLReader interface using the feed, close and reset methods of the IncrementalParser interface as a convenience to SAX 2.0 driver writers.cCst|}|j||jj|j}|jd}x,|dkro|j||jd}qDW|j|j|jj dS(Ni@Re( tprepare_input_sourcet prepareParserRRYt getByteStreamtreadtfeedtclosetresetR(RRtinftbuffer((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRs       cCstddS(stThis method is called by the parse implementation to allow the SAX 2.0 driver to prepare itself for parsing.s!prepareParser must be overridden!N(tNotImplementedError(RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRs(RRRRR(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRs RecCs;t|tkr$tj|}nSt|drw|}tj}|j|t|drw|j|jqwn|jdkr7|j }t j j t j j|}t j j||}t j j|r|j|t|d}n.|jtj||tj|j }|j|n|S(sThis function takes an InputSource and an optional base URL and returns a fully resolved InputSource object ready for reading.RR`trbN(ttypet _StringTypest xmlreadert InputSourcethasattrt setByteStreamt setSystemIdR`RR"Rtostpathtdirnametnormpathtjointisfiletopenturlparseturljointurllib2turlopen(Rtbasetftsysidtbaseheadt sysidfilename((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRs&    t AttributeMapcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z dd Zd Zd ZRS(szAn implementation of AttributeList that takes an (attr,val) hash and uses it to implement the AttributeList interface.cCs ||_dS(N(tmap(RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR scCst|jjS(N(tlenRtkeys(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt getLength!scCs0y|jj|SWntk r+}dSXdS(N(RRt IndexErrorR"(Rtite((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytgetName$scCsdS(NtCDATA((RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytgetType*scCsSy8t|tjkr,|j|j|S|j|SWntk rN}dSXdS(N(RttypestIntTypeRRtKeyErrorR"(RRR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pytgetValue-s cCs t|jS(N(RR(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt__len__6scCs5t|tjkr&|jj|S|j|SdS(N(RRRRR(RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt __getitem__9scCs |jjS(N(RR(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR?scCs |jjS(N(RR(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRBscCs|jj|S(N(Rthas_key(RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyREscCs|jj||S(N(Rtget(RRt alternative((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRHscCst|jjS(N(RRR[(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR[KscCs |jjS(N(Rtvalues(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRNsN(RRRR RRRRRRRRRR"RR[R(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRs           tEventBroadcastercBs<eZdZdddYZdZdZdZRS(sTakes a list of objects and forwards any method calls received to all objects in the list. The attribute list holds the list and can freely be modified by clients.tEventcBs eZdZdZdZRS(s,Helper objects that represent event methods.cCs||_||_dS(N(tlistR`(RRR`((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR [s cGs1x*|jD]}tt||j|q WdS(N(RtapplytgetattrR`(Rtresttobj((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt__call___s(RRRR R(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRXs cCs ||_dS(N(R(RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR cscCs|j|j|S(N(RR(RR`((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt __getattr__fscCsdt|S(Ns!(tid(R((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyt__repr__is((RRRRR RR(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRSs   tESISDocHandlercBsAeZdZejdZdZdZdZdZ RS(s7A SAX document handler that produces naive ESIS output.cCs ||_dS(N(twriter(RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR qscCs$|jjd|d|ddS(sQReceive an event signalling that a processing instruction has been found.R!t s N(RR+(RRot remainder((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRptscCsW|jjd|dx8|jD]*}|jjd|d||dq%WdS(s4Receive an event signalling the start of an element.t(s tARN(RR+R(RR`tamapta_name((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRbyscCs|jjd|ddS(s2Receive an event signalling the end of an element.t)s N(RR+(RR`((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRcscCs'|jjd||||!ddS(s?Receive an event signalling that character data has been found.t-s N(RR+(RR tstart_ixtlength((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRms( RRRR6ROR RpRbRcRm(((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRns    t CanonizercBsSeZdZejdZdZdZdZdZ dZ dZ RS(s:A SAX document handler that produces canonized XML output.cCsd|_||_dS(Ni(t elem_levelR(RR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyR s cCs3|dks/|jjd|d|dndS(Ntxmls(RR+(RRoR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRps cCs|jjd||j}|jxG|D]?}|jjd|d|j|||jjdq1W|jjd|jd|_dS(NRRs="s"R i(RR+Rtsortt write_dataR(RR`Rta_namesR((sB/opt/freeware/lib/python2.7/site-packages/_xmlplus/sax/saxutils.pyRbs   cCs,|jjd|d|jd|_dS(NssJ0  $     &#   b+b $9 0