�`^c@s dZdZddlTddlmZmZddlmZddlmZmZddlm Z ddlm
Z
mZdd lZej
d
dkr�ede��n[ydd
lmZWn ek
r�ede��n#Xeed�rede��nddlmZmZmZejZejZydd lZWnek
r_d�ZnXdd lZejZ[[dejfd��YZdej ejfd��YZ!d�Z"e#dkrdd l$Z%e"�Z&e&j'e%j(jj)��e&j*e%j(j+��e&j,d�nd 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 supportedtParserCreate(t xmlreadertsaxutilsthandlercCs|S(N((to((s)/sys/lib/python2.7/xml/sax/expatreader.pyt_mkproxy'stExpatLocatorcBs;eZdZd�Zd�Zd�Zd�Zd�ZRS(s�Locator 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)/sys/lib/python2.7/xml/sax/expatreader.pyt__init__6scCs&|j}|jdkrdS|jjS(N(Rt_parsertNonetErrorColumnNumber(RR((s)/sys/lib/python2.7/xml/sax/expatreader.pytgetColumnNumber9s cCs&|j}|jdkrdS|jjS(Ni(RRRtErrorLineNumber(RR((s)/sys/lib/python2.7/xml/sax/expatreader.pyt
getLineNumber?s cCs&|j}|dkrdS|jj�S(N(RRt_sourcetgetPublicId(RR((s)/sys/lib/python2.7/xml/sax/expatreader.pyREs cCs&|j}|dkrdS|jj�S(N(RRRtgetSystemId(RR((s)/sys/lib/python2.7/xml/sax/expatreader.pyRKs (t__name__t
__module__t__doc__RRRRR(((s)/sys/lib/python2.7/xml/sax/expatreader.pyR0s tExpatParsercBs%eZdZdd$d�Zd�Zd�Zd�Zd �Zd
�Zd�Z d�Z
dd
�Zd�Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Zd!�Zd"�Z RS(%s$SAX driver for the pyexpat C module.iiiicCsetjj||�tj�|_d|_||_d|_d|_ g|_
d|_d|_dS(Nii(
RtIncrementalParserRtInputSourceRRRt_namespacest_lex_handler_propt_parsingt
_entity_stackt
_external_gest
_interning(RtnamespaceHandlingtbufsize((s)/sys/lib/python2.7/xml/sax/expatreader.pyRWs cCsOtj|�}||_|j�|jjt|��tjj ||�dS(s3Parse an XML document from a URL or an InputSource.N(
R
tprepare_input_sourceRtresett
_cont_handlertsetDocumentLocatorRRR#tparse(Rtsource((s)/sys/lib/python2.7/xml/sax/expatreader.pyR1ds
cCsV|j�dk rR|j�}t|t�r?|jd�}n|jj|�ndS(Nsutf-8(RRt
isinstancetunicodetencodeRtSetBase(RR2tbase((s)/sys/lib/python2.7/xml/sax/expatreader.pyt
prepareParserms
cCs-tjj||�|jr)|j�ndS(N(RR#tsetContentHandlerR't_reset_cont_handler(RR((s)/sys/lib/python2.7/xml/sax/expatreader.pyR9vs cCsl|tkr|jS|tkr,|jdk S|tttfkrEdS|tkrX|j St
d|��dS(NisFeature '%s' not recognized(RR%RR*RRRRRR)tSAXNotRecognizedException(Rtname((s)/sys/lib/python2.7/xml/sax/expatreader.pyt
getFeature{s
cCs|jrtd��n|tkr0||_n�|tkrH||_n�|tkr�|rx|jdkr�i|_q�qd|_n||t kr�|rtd��qnX|t
kr�|rtd��qn4|tkr�rtd��qntd|��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)/sys/lib/python2.7/xml/sax/expatreader.pyt
setFeature�s2 cCs�|tjkr|jS|tkr)|jS|tkr{|jrlt|jd�r]|jj�St d��q{t
d��nt 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*RRthasattrRAR;R>(RR<((s)/sys/lib/python2.7/xml/sax/expatreader.pytgetProperty�s
cCs||tjkr1||_|jrx|j�qxnG|tkrI||_n/|tkrhtd|��nt d|��dS(NsProperty '%s' cannot be setsProperty '%s' not recognized(
RRBR&R't_reset_lex_handler_propRR*RR>R;(RR<tvalue((s)/sys/lib/python2.7/xml/sax/expatreader.pytsetProperty�s
cCs�|js,|j�d|_|jj�ny|jj||�WnDtjk
r�}ttj |j
�||�}|jj|�nXdS(Ni(
R'R.R/t
startDocumentRtParseR
terrortSAXParseExceptiontErrorStringtcodet_err_handlert
fatalError(RtdatatisFinaltetexc((s)/sys/lib/python2.7/xml/sax/expatreader.pytfeed�s
cCsC|jr
dS|jddd�|jj�d|_d|_dS(NtRQii(R(RTR/tendDocumentR'RR(R((s)/sys/lib/python2.7/xml/sax/expatreader.pytclose�s
cCs(|jj|j_|jj|j_dS(N(R/tprocessingInstructionRtProcessingInstructionHandlert
characterstCharacterDataHandler(R((s)/sys/lib/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)/sys/lib/python2.7/xml/sax/expatreader.pyRE�s cCsc|jr]tj|jj�dd|j�|_d|j_|j|j_ |j
|j_nBtj|jj�d|j�|_|j|j_ |j
|j_|j�|j|j_|j|j_|j|j_|j|j_d|_|jr|j�n|j|j_y|j|j_Wntk
r9nX|jj tj!�d|_"g|_#dS(Nt tinternii($R%R
RRtgetEncodingR*Rtnamespace_prefixeststart_element_nstStartElementHandlertend_element_nstEndElementHandlert
start_elementtend_elementR:tunparsed_entity_decltUnparsedEntityDeclHandlert
notation_decltNotationDeclHandlertstart_namespace_decltStartNamespaceDeclHandlertend_namespace_decltEndNamespaceDeclHandlerRt_decl_handler_propR&REtexternal_entity_reftExternalEntityRefHandlertskipped_entity_handlertSkippedEntityHandlertAttributeErrortSetParamEntityParsingt*XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONER'R((R((s)/sys/lib/python2.7/xml/sax/expatreader.pyR.�s6
cCs|jdkrdS|jjS(N(RRR(R((s)/sys/lib/python2.7/xml/sax/expatreader.pyRscCs|jdkrdS|jjS(Ni(RRR(R((s)/sys/lib/python2.7/xml/sax/expatreader.pyR#scCs
|jj�S(N(RR(R((s)/sys/lib/python2.7/xml/sax/expatreader.pyR(scCs
|jj�S(N(RR(R((s)/sys/lib/python2.7/xml/sax/expatreader.pyR+scCs|jj|t|��dS(N(R/tstartElementtAttributesImpl(RR<tattrs((s)/sys/lib/python2.7/xml/sax/expatreader.pyRo/scCs|jj|�dS(N(R/t
endElement(RR<((s)/sys/lib/python2.7/xml/sax/expatreader.pyRp2scCsL|j�}t|�dkr-d|f}n5t|�dkrV|d|df}nt|�}i}i}x�|j�D]�\}}|j�}t|�} | dkr�|}
d|f}nQ| dkr�|d|df}
|d|df}n|d}
t|�}|||<|
||<q{W|jj|dt||��dS(Niiis%s:%si(tsplittlenRttupletitemsR/tstartElementNStAttributesNSImpl(RR<R�tpairtnewattrstqnamestanameRFtpartstlengthtqnametapair((s)/sys/lib/python2.7/xml/sax/expatreader.pyRk5s.
cCsy|j�}t|�dkr-d|f}n5t|�dkrV|d|df}nt|�}|jj|d�dS(Niii(R�R�RR�R/tendElementNS(RR<R�((s)/sys/lib/python2.7/xml/sax/expatreader.pyRmWscCs|jj||�dS(N(R/RX(RttargetRP((s)/sys/lib/python2.7/xml/sax/expatreader.pytprocessing_instructioncscCs|jj|�dS(N(R/RZ(RRP((s)/sys/lib/python2.7/xml/sax/expatreader.pytcharacter_datagscCs|jj||�dS(N(R/tstartPrefixMapping(Rtprefixturi((s)/sys/lib/python2.7/xml/sax/expatreader.pyRujscCs|jj|�dS(N(R/tendPrefixMapping(RR�((s)/sys/lib/python2.7/xml/sax/expatreader.pyRwmscCs|jj|||�dS(N(R&tstartDTD(RR<tsysidtpubidthas_internal_subset((s)/sys/lib/python2.7/xml/sax/expatreader.pyRdpscCs|jj||||�dS(N(t_dtd_handlertunparsedEntityDecl(RR<R7R�R�t
notation_name((s)/sys/lib/python2.7/xml/sax/expatreader.pyRqsscCs|jj|||�dS(N(R�tnotationDecl(RR<R7R�R�((s)/sys/lib/python2.7/xml/sax/expatreader.pyRsvscCs�|js
dS|jj||�}tj||jj�p=d�}|jj|j |jf�|j j
|�|_ ||_ytjj
||�WndSX|jd\|_ |_|jd=dS(NiRUii�(R)t_ent_handlert
resolveEntityR
R-RRR(tappendRtExternalEntityParserCreateRR#R1(RtcontextR7R�R�R2((s)/sys/lib/python2.7/xml/sax/expatreader.pyRzys
cCs'|rd|}n|jj|�dS(Nt%(R/t
skippedEntity(RR<tis_pe((s)/sys/lib/python2.7/xml/sax/expatreader.pyR|�s
ii�(!RR R!RR1R8R9R=R@RDRGRTRWR:RER.RRRRRoRpRkRmR�R�RuRwRdRqRsRzR|(((s)/sys/lib/python2.7/xml/sax/expatreader.pyR"Ts>
' " cOs
t||�S(N(R"(targstkwargs((s)/sys/lib/python2.7/xml/sax/expatreader.pyt
create_parser�st__main__s:http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml(-R!tversiontxml.sax._exceptionstxml.sax.handlerRRRRRRRRtsystplatformtSAXReaderNotAvailableRtxml.parsersR
tImportErrorRCtxml.saxRR
RR�R�t_weakrefRtweakreftproxytLocatorRR#R"R�Rtxml.sax.saxutilstxmltpR9tsaxtXMLGeneratortsetErrorHandlertErrorHandlerR1(((s)/sys/lib/python2.7/xml/sax/expatreader.pyt<module>sJ
$�
|