ó õ^‚Rc@s]dZddlmZedddƒ[ddlZddlZddgZejd ƒZejd ƒZejd ƒZ ejd ƒZ ejd ƒZ ejdƒZ ejdƒZ ejdƒZejdƒZejdƒZejdƒZdefd„ƒYZdejfd„ƒYZdefd„ƒYZed„ZedkrYeƒndS(s;A parser for SGML, using the derived class as a static DTD.iÿÿÿÿ(twarnpy3ks1the sgmllib module has been removed in Python 3.0t stackleveliNt SGMLParsertSGMLParseErrors[&<]sN&([a-zA-Z][a-zA-Z0-9]*|#[0-9]*)?|<([a-zA-Z][^<>]*|/([a-zA-Z][^<>]*)?|![^<>]*)?s%&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]s&#([0-9]+)[^0-9]s <[>a-zA-Z]s<[a-zA-Z][-.a-zA-Z0-9]*/s"<([a-zA-Z][-.a-zA-Z0-9]*)/([^/]*)/t>s[<>]s[a-zA-Z][-_.a-zA-Z0-9]*se\s*([a-zA-Z_][-:.a-zA-Z_0-9]*)(\s*=\s*(\'[^\']*\'|"[^"]*"|[][\-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*))?cBseZdZRS(s&Exception raised for all parse errors.(t__name__t __module__t__doc__(((s/usr/lib/python2.7/sgmllib.pyR,scBsieZejdƒZdd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d Z d „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zidd6dd6dd6dd 6d!d"6Zd#„Zd$„Zd%„Zd&„Z d'„Z!d(„Z"d)„Z#d*„Z$d+„Z%d,„Z&RS(-s+&(?:([a-zA-Z][-.a-zA-Z0-9]*)|#([0-9]+))(;?)icCs||_|jƒdS(s#Initialize and reset this instance.N(tverbosetreset(tselfR((s/usr/lib/python2.7/sgmllib.pyt__init__Bs cCsJd|_d|_g|_d|_d|_d|_tjj |ƒdS(s0Reset this instance. Loses all unprocessed data.ts???iN( tNonet_SGMLParser__starttag_texttrawdatatstacktlasttagt nomoretagstliteralt markupbaset ParserBaseR (R ((s/usr/lib/python2.7/sgmllib.pyR Gs      cCsd|_|_dS(sYEnter literal mode (CDATA) till EOF. Intended for derived classes only. iN(RR(R ((s/usr/lib/python2.7/sgmllib.pyt setnomoretagsQscGs d|_dS(sPEnter literal mode (CDATA). Intended for derived classes only. iN(R(R targs((s/usr/lib/python2.7/sgmllib.pyt setliteralXscCs!|j||_|jdƒdS(sãFeed some data to the parser. Call this as often as you want, with as little or as much text as you want (may include ' '). (This just saves the text, all the processing is done by goahead().) iN(Rtgoahead(R tdata((s/usr/lib/python2.7/sgmllib.pytfeed_scCs|jdƒdS(sHandle the remaining data.iN(R(R ((s/usr/lib/python2.7/sgmllib.pytclosejscCst|ƒ‚dS(N(R(R tmessage((s/usr/lib/python2.7/sgmllib.pyterrornsc Cs@|j}d}t|ƒ}xâ||krÿ|jrQ|j|||!ƒ|}Pntj||ƒ}|rx|jƒ}n|}||kr¡|j|||!ƒn|}||kr·Pn||dkrltj||ƒr.|j r|j||ƒ|d}qn|j |ƒ}|dkr"Pn|}qn|j d|ƒrt|j |ƒ}|dkr_Pn|}d|_ qn|j r®||dkr§|jdƒ|d}qPqn|j d|ƒrë|j |ƒ}|dkrßPn|}qn|j d|ƒr,|j|ƒ}|dkrPn||}qn|j d|ƒrŠ|j|ƒ}|dkr]Pn|}qqŠn||dkr}|j r¦|j||ƒ|d}qntj||ƒ}|r|jdƒ}|j|ƒ|jdƒ}||dd kr|d}qqntj||ƒ}|rŠ|jdƒ}|j|ƒ|jdƒ}||dd kr|d}qqqŠn |jd ƒtj||ƒ}|sÃ|j||ƒ|d}qn|jdƒ}||krâPn|j|||!ƒ|}qW|r/||kr/|j|||!ƒ|}n|||_dS( Nits!unexpected call to parse_starttagit't"R(R RRt shorttagopenR(tshorttagR0tlowerR2tfinish_shorttagt endbracketR%R&RttagfindRtattrfindtentity_or_charreftsubt _convert_reftappendtfinish_starttag( R R6t start_posRR(ttagRR9R8tattrstattrnametrestt attrvalue((s/usr/lib/python2.7/sgmllib.pyR)îs^       $$  cCs†|jdƒr9|j|jdƒƒp8d|jƒdS|jdƒrq|j|jdƒƒppd|jdƒSd|jdƒSdS(Nis&#%s%siis&%s;s&%s(R0tconvert_charreftgroupstconvert_entityref(R R(((s/usr/lib/python2.7/sgmllib.pyRJ,scCsƒ|j}tj||dƒ}|s)dS|jdƒ}||d|!jƒjƒ}||dkrr|d}n|j|ƒ|S(NiiÿÿÿÿiiR(RRER%R&tstripRCt finish_endtag(R R6RR(R8RN((s/usr/lib/python2.7/sgmllib.pyR+7s   cCs.|j|gƒ|j|ƒ|j|ƒdS(N(RLR#RW(R RNR((s/usr/lib/python2.7/sgmllib.pyRDDs cCs©yt|d|ƒ}Wndtk r}yt|d|ƒ}Wn"tk rb|j||ƒdSX|j|||ƒdSn(X|jj|ƒ|j|||ƒdSdS(Ntstart_tdo_iÿÿÿÿii(tgetattrtAttributeErrortunknown_starttagthandle_starttagRRK(R RNROtmethod((s/usr/lib/python2.7/sgmllib.pyRLKs  cCsa|s9t|jƒd}|dkrÓ|j|ƒdSnš||jkr‘yt|d|ƒ}Wntk r|j|ƒnX|j|ƒdSt|jƒ}x0t|ƒD]"}|j||kr­|}q­q­Wx‡t|jƒ|kr\|jd}yt|d|ƒ}Wntk r(d}nX|rB|j||ƒn |j|ƒ|jd=qÖWdS(Niitend_iÿÿÿÿ( R"Rtunknown_endtagRZR[treport_unbalancedtrangeR t handle_endtag(R RNtfoundR^R6((s/usr/lib/python2.7/sgmllib.pyRW]s4         cCs||ƒdS(N((R RNR^RO((s/usr/lib/python2.7/sgmllib.pyR]|scCs |ƒdS(N((R RNR^((s/usr/lib/python2.7/sgmllib.pyRc€scCs)|jr%d|dGHdG|jGHndS(Ns*** Unbalanced R)RJR+RDRLRWR]RcRaRSRgR1RqRUR4R#RtRvR=R\R`RjRs(((s/usr/lib/python2.7/sgmllib.pyR<sF      g  >        )       tTestSGMLParsercBseeZdd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d „Z d „Z RS( icCsd|_tj||ƒdS(NR (ttestdataRR (R R((s/usr/lib/python2.7/sgmllib.pyR Ïs cCs<|j||_tt|jƒƒdkr8|jƒndS(NiF(R|R"treprtflush(R R((s/usr/lib/python2.7/sgmllib.pyR#ÓscCs.|j}|r*d|_dGt|ƒGHndS(NR sdata:(R|R}(R R((s/usr/lib/python2.7/sgmllib.pyR~Øs  cCsN|jƒt|ƒ}t|ƒdkrA|d d|d}ndG|GHdS(NiDi s...iàÿÿÿscomment:(R~R}R"(R Rtr((s/usr/lib/python2.7/sgmllib.pyRtÞs   cCs\|jƒ|s d|dGHn8d|Gx(|D] \}}|dd|dGq/WdGHdS(Ns start tag: s4      ÿ’7 $