m TEc@sdZdklZlZdklZdZdZdZdZ e dZ dZ d Z d Z d Zd Zd efdYZdefdYZedjoIdklZdZeZeieedZeiendS(s *S*mall, *U*ncomplicated *X*ML. This is a very simple implementation of XML/HTML as a network protocol. It is not at all clever. Its main features are that it does not: - support namespaces - mung mnemonic entity references - validate - perform *any* external actions (such as fetching URLs or writing files) under *any* circumstances - has lots and lots of horrible hacks for supporting broken HTML (as an option, they're not on by default). (sProtocols FileWrapper(sprefixedMethodNamesiiis.-_:s;+#/%~cOsdS(s Do nothing.N((targstkw((tg/home/radix/Projects/Twisted/branches/releases/twisted-core-2.5.x-2329-2/Twisted.exp/twisted/web/sux.pytnop$scGs[g}x|D]}|i|q Wtg}|D]}||dfq2~}|iS(Ni(tlRtxtextendtdictt_[1]tdtkeys(RR RRR((Rt unionlist(s -cOs|idt}h}xltg}|D]}||i q)~D]=}t g}|D]}||i||qZ~||d6Z?d7Z@d8ZAd9ZBd:ZCRS(;NsicCsd|_d|_g|_dS(Nii(Rtlinenotcolnot encodings(R((RtconnectionMadeYs  cCs|i|ifS(s;Get the line number and column of the last character parsedN(RR&R'(R((RtsaveMark^scCs't|if|i|fdS(N(RRRR*R (RR ((Rt _parseErrorcscCsdt|idd}|djo>tg}dD]}|t||q0~}|i_ n|S(s;Return a dictionary of begin, do, end state function tuplest __stateTabletbegin_tdo_tend_N(R-R.R/( RRRtNonet stateTableRRRRt_XMLParser__stateTable(RRRR1((Rt_buildStateTablefs  >cCsd|ijpd|ijo t|d@ p tdn|io|i|}nx |iD]}t||}qeW|S(NsUTF-16sUCS-2is!UTF-16 must come in pairs for now(RR(tlentdatatAssertionErrort_prependtencodingtunicode(RR5R8((Rt_decoders    cCsO|iodSn|idjo)|iid o|iddSndS(Ntbodydatatscripttsrctwaitforendscript(RtendtagttagNamet tagAttributesthas_keytbegin_bodydataR0(R((Rt maybeBodyData{s   $ c s|i} |ip{|ido'd|_|iid|d}n8|ido'd|_|iid|d}nd|_n|io|i |}n|i |i |i}|i }d}||_ | |\}}}zx|D]} | djod7d n d7|| }|dj o;||jo.||}| |\}}}|| qqWWd||_ |_ |_ X||_dS( NssUTF-16istbegincs fS(N(R&R'((R&R'(RR*ss ii(RR3R1tstateR5t startswithR7R(tappendR:R&R'tcurStateR*t _saveMarktbeginFntdoFntendFntbytetnewStateR0( RR5R*RJRIRLRORKRMR&R'RNR1((R&R'Rt dataReceivedsH               cCs"|i}||itdS(s0 End the last state we were in. N(RR3R1RFt END_HANDLER(RtreasonR1((RtconnectionLosts cCsY|iodSn|djo3|io||_dSn|id|fndS(NtiR;(RR[RNtendswitht gotComment(RRN((Rt do_commentscCs(d|_h|_d|_d|_dS(NRZi(RR@RAttermtagR?(RRN((Rtbegin_tagstarts   cCs|ip |tjo+|i|7_|idjodSqn|io5|io|iodSndSq|idnC|djoU|io|i|idSq|i |ih|i odp |i Sn|djo|iod Sqd |_n|d joE|io|i p|id qcq|i|7_d |_ nc|d jo)|idjodSq|idn-|i od|_ dSn|id|dS(Ns!--tcommentt waitforgttattrssWhitespace before tag-namet>R;t/t afterslashis!?sInvalid character in tag-namet[t!t expectcdatasInvalid '[' in tag-nameRTtunentitysInvalid tag character: %r(RNtisalnumt identCharsRR@RVR?R+t gotTagEndt gotTagStartRWRDR`R;(RRN((Rt do_tagstartsD                 cCs|i|7_dS(N(RR;RN(RRN((Rtbegin_unentityscCs|i|7_dS(NR;(RR;RN(RRN((Rt do_unentityscCs|i|idS(N(RtgotTextR;(R((Rt end_unentityscCs ||_dS(N(RNRtcdatabuf(RRN((Rtbegin_expectcdatascCs|i|7_|i}d}t|t|jo;|i|odSqr|iodSqr|idn||jod|_dSn|iddS(Ns[CDATA[RcsMal-formed CDATA headerRZtcdata( RRuRNtcdbtcdR4RGRWR+(RRNRxRy((Rtdo_expectcdatas    cCs>|i|7_|iido|id |_dSndS(Ns]]>iR;(RRuRNR](RRN((Rtdo_cdata1scCs|i|id|_dS(NRZ(RtgotCDataRu(R((Rt end_cdata7scCs|ip |tjo<|idjodSn|iddjodSndSn|iodSnk|djo6|i|i|i|i odp |i Sn(|d jod Sn|iodSn|i d |dS( Ns!DOCTYPEtdoctypeis!?RctattrnameReR;RfRgsUnexpected character: %r( RNRlRmRR@RVRoRARWRDR+(RRN((Rtdo_attrs;s      cCs ||_dS(N(RNRR~(RRN((Rt begin_doctypePscCs(|djodSn|i|7_dS(NReR;(RNRR~(RRN((Rt do_doctypeSs cCs|i|id|_dS(N(Rt gotDoctypeR~R0(R((Rt end_doctypeXscCs<|djo+|ip |i odSn|iSndS(NReR;(RNRR?RWRD(RRN((Rt do_waitforgt\s cCs||_d|_dS(Ni(RNRRt_attrname_termtag(RRN((Rtbegin_attrnamebs cCs^|ip |tjo|i|7_dSn|djodSn|iodSn|io|djodSn|tjp |io|i|7_dSn|djod|_dSn|djobd |_ |i |i |i<|i |i |i |io|i |i d Sn|iSndSn|id |i|fdS( Nt=t beforeattrvaltbeforeeqs"'tattrvalRfiRetTrueR;sInvalid attribute name: %r %r(RNRlRmRRRVRWtlenientIdentCharsRRRARoR@RnRDR+(RRN((Rt do_attrnamefs4         cCs|djodSn|iodSn|io|tjp |iodSn|djo@d|_|i|i|i<|i |i |i|i Sn|djodSqn|i d|dS(Ns"'Rt messyattrReRs\sEInvalid initial attribute value: %r; Attribute values must be quoted.( RNRVRRWRRlRRARRoR@RDR+(RRN((Rtdo_beforeattrvals       RZcCs d|_dS(Ni(Rt_beforeeq_termtag(RRN((Rtbegin_beforeeqscCs|djodSn|iodSn|io|ip |tjo$d|_|i|i|iR<RcR( RRRNRR?R;RlRmR@RGRsRnRV(RRN((Rtdo_waitscriptendtags&      cCsd|_d|_dS(NRZ(Rterefbuft erefextra(RRN((Rtbegin_entityref0s cCs|ip |djoz|io_|io |idjo|i|_nd|_|djodSq|i|7_dSn|idn%|djo|i|7_ndSdS(NRTtampRUt spacebodydatasBad entity referencet;R;(RNRVRRWRRR+(RRN((Rt do_entityref4s    cCs|i|idS(N(RtgotEntityReferenceR(R((Rt end_entityrefFscCs|i|_d|_dS(N(RRR;R0(RRN((Rtbegin_spacebodydataKs cCsdG|G|GHdS(sCEncountered an opening tag. Default behaviour is to print.REN(Rt attributes(RRR((RRoSscCsdGt|GHdS(s8Encountered text Default behaviour is to print.stext:N(treprR5(RR5((RRsYscCs d|GHdS(sMEncountered mnemonic entity reference Default behaviour is to print.sentityRef: &%s;N(t entityRef(RR((RR_scCsdS(s=Encountered comment. Default behaviour is to ignore.N((RRb((RR^escCs|i|dS(sJEncountered CDATA Default behaviour is to call the gotText methodN(RRsRw(RRw((RR|kscCsdGt|GHdS(sEncountered DOCTYPE This is really grotty: it basically just gives you everything between '' as an argument. s!DOCTYPEN(RR~(RR~((RRqscCs dG|GHdS(s?Encountered closing tag Default behaviour is to print.tendN(R(RR((RRnys(DR#R$R0RFR(RRWR7RXR)R*R+R3R:RDRPRSRYR\R_RaRpRqRrRtRvRzR{R}RRRRRRRRRRRRRRRRRRRRRCRRRRRRRRRtdo_spacebodydatatend_spacebodydataRoRsRR^R|RRn(((RR%Ls     /    ,                               (          t__main__(sStringIOs A boz &zop; s/home/glyph/gruesome.xmlN(t__doc__ttwisted.internet.protocoltProtocolt FileWrapperttwisted.python.reflectRt BEGIN_HANDLERt DO_HANDLERRQRmRRR RRRt ExceptionRR%R#t cStringIOtStringIOt testDocumentRtmakeConnectiontfnRP(RR%RRRR RRRRRRQRRRRRRRm((Rt?s.        5