ó ›çXjc@sdZddlZddlZejdƒZejdƒZejdƒZejdƒZejdƒZejdƒZ ejd ƒZ ejd ƒZ ejd ƒZ ejd ƒZ ejd ejƒZejdƒZejdƒZdefd„ƒYZdejfd„ƒYZdS(sA parser for HTML and XHTML.iÿÿÿÿNs[&<]s &[a-zA-Z#]s%&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]s)&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]s <[a-zA-Z]t>s--\s*>s(([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*s[a-zA-Z][^ />]*s]((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*s <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name (?:[\s/]* # optional whitespace before attribute name (?:(?<=['"\s/])[^\s/>][^\s/=>]* # attribute name (?:\s*=+\s* # value indicator (?:'[^']*' # LITA-enclosed value |"[^"]*" # LIT-enclosed value |(?!['"])[^>\s]* # bare value ) )?(?:\s|/(?!>))* )* )? \s* # trailing whitespace s#tHTMLParseErrorcBs#eZdZdd„Zd„ZRS(s&Exception raised for all parse errors.cCs3|s t‚||_|d|_|d|_dS(Nii(tAssertionErrortmsgtlinenotoffset(tselfRtposition((s"/usr/lib64/python2.7/HTMLParser.pyt__init__9s   cCsW|j}|jdk r,|d|j}n|jdk rS|d|jd}n|S(Ns , at line %ds , column %di(RRtNoneR(Rtresult((s"/usr/lib64/python2.7/HTMLParser.pyt__str__?s  N(NN(t__name__t __module__t__doc__R RR (((s"/usr/lib64/python2.7/HTMLParser.pyR6s t HTMLParsercBs eZdZdZd„Zd„Zd„Zd„Zd„ZdZ d„Z d „Z d „Z d „Zd „Zd d„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZdZd„Z RS( sÇFind tags and other markup and call handler functions. Usage: p = HTMLParser() p.feed(data) ... p.close() Start tags are handled by calling self.handle_starttag() or self.handle_startendtag(); end tags by self.handle_endtag(). The data between tags is passed from the parser to the derived class by calling self.handle_data() with the data as argument (the data may be split up in arbitrary chunks). Entity references are passed by calling self.handle_entityref() with the entity reference as the argument. Numeric character references are passed to self.handle_charref() with the string containing the reference as the argument. tscripttstylecCs|jƒdS(s#Initialize and reset this instance.N(treset(R((s"/usr/lib64/python2.7/HTMLParser.pyR_scCsSd|_d|_t|_d|_g|_d|_d|_t j j |ƒdS(s1Reset this instance. Loses all unprocessed data.ts???iiN( trawdatatlasttagtinteresting_normalt interestingR t cdata_elemt_pendingt _pending_lent_parse_thresholdt markupbaset ParserBaseR(R((s"/usr/lib64/python2.7/HTMLParser.pyRcs       cCsã|jt|ƒ7_|j|jkr:|jj|ƒn¥|jsU|j|7_n2|jj|ƒ|jdj|jƒ7_|j2d|_t|jƒ}|jdƒt|jƒ|krÍd|_nt|jƒ|_dS(s‘Feed data to the parser. Call this as often as you want, with as little or as much text as you want (may include '\n'). RiiN(RtlenRRtappendRtjointgoahead(Rtdatatn((s"/usr/lib64/python2.7/HTMLParser.pytfeedns     cCsH|jr7|jdj|jƒ7_|j2d|_n|jdƒdS(sHandle any buffered data.RiiN(RRR RR!(R((s"/usr/lib64/python2.7/HTMLParser.pytcloseŒs   cCst||jƒƒ‚dS(N(Rtgetpos(Rtmessage((s"/usr/lib64/python2.7/HTMLParser.pyterror”scCs|jS(s)Return full source of start tag: '<...>'.(t_HTMLParser__starttag_text(R((s"/usr/lib64/python2.7/HTMLParser.pytget_starttag_text™scCs2|jƒ|_tjd|jtjƒ|_dS(Ns (tlowerRtretcompiletIR(Rtelem((s"/usr/lib64/python2.7/HTMLParser.pytset_cdata_modescCst|_d|_dS(N(RRR R(R((s"/usr/lib64/python2.7/HTMLParser.pytclear_cdata_mode¡s c Cst|j}d}t|ƒ}x||kr|jj||ƒ}|rT|jƒ}n|jraPn|}||krŠ|j|||!ƒn|j||ƒ}||kr¬Pn|j}|d|ƒr7t j ||ƒrè|j |ƒ}n¯|d|ƒr |j |ƒ}nŽ|d|ƒr*|j |ƒ}nm|d|ƒrK|j|ƒ}nL|d|ƒrl|j|ƒ}n+|d|kr–|jdƒ|d}nP|dkr"|s­Pn|jd|dƒ}|dkr|jd|dƒ}|dkr |d}q n |d7}|j|||!ƒn|j||ƒ}q|d |ƒrÿtj ||ƒ}|rÂ|jƒd d !} |j| ƒ|jƒ}|d |dƒsª|d}n|j||ƒ}qqd ||krû|j|dd !ƒ|j|d ƒ}nPq|d |ƒrtj ||ƒ}|r†|jdƒ} |j| ƒ|jƒ}|d |dƒsn|d}n|j||ƒ}qntj ||ƒ}|rÎ|rÊ|jƒ||krÊ|jdƒnPq|d|kr|jd ƒ|j||dƒ}qPqdstdƒ‚qW|rc||krc|j rc|j|||!ƒ|j||ƒ}n|||_dS(Nittparse_marked_sectionR+RAt handle_decltparse_bogus_comment(RRIRtgtpos((s"/usr/lib64/python2.7/HTMLParser.pyR@s    icCs|j}|||d!dkr0|jdƒn|jd|dƒ}|dkrVdS|rw|j||d|!ƒn|dS( Niss (Rs/>(R R)tcheck_for_whole_start_tagRttagfindR;RRERCR+RtattrfindtunescapeRtstripR&tcountRtrfindR7tendswiththandle_startendtagthandle_starttagtCDATA_CONTENT_ELEMENTSR0(RRItendposRtattrsR;RKttagtmtattrnametrestt attrvalueRERR((s"/usr/lib64/python2.7/HTMLParser.pyR<3sR     $$  cCsý|j}tj||ƒ}|rí|jƒ}|||d!}|dkrR|dS|dkr²|jd|ƒrx|dS|jd|ƒrŽdS|j||dƒ|jdƒn|dkrÂdS|d krÒdS||krâ|S|dSntd ƒ‚dS( NiRt/s/>iiÿÿÿÿsmalformed empty start tagRs6abcdefghijklmnopqrstuvwxyz=/ABCDEFGHIJKLMNOPQRSTUVWXYZswe should not get here!(RtlocatestarttagendR;RER9R8R(R(RRIRReRJtnext((s"/usr/lib64/python2.7/HTMLParser.pyRWgs,        cCsŠ|j}|||d!dks,tdƒ‚tj||dƒ}|sLdS|jƒ}tj||ƒ}|s!|jdk r—|j |||!ƒ|St j||dƒ}|sâ|||d!dkrÒ|dS|j |ƒSn|j ƒj ƒ}|jd|jƒƒ}|j|ƒ|dS|j dƒj ƒ}|jdk ro||jkro|j |||!ƒ|Sn|j|ƒ|jƒ|S( NisR(RRt endendtagR5REt endtagfindR;RR R7ttagfind_tolerantRORCR+RAt handle_endtagR1(RRIRR;RPt namematchttagnameR/((s"/usr/lib64/python2.7/HTMLParser.pyR=‡s8 #    cCs!|j||ƒ|j|ƒdS(N(R`Ro(RRdRc((s"/usr/lib64/python2.7/HTMLParser.pyR_¯scCsdS(N((RRdRc((s"/usr/lib64/python2.7/HTMLParser.pyR`´scCsdS(N((RRd((s"/usr/lib64/python2.7/HTMLParser.pyRo¸scCsdS(N((RRL((s"/usr/lib64/python2.7/HTMLParser.pyRD¼scCsdS(N((RRL((s"/usr/lib64/python2.7/HTMLParser.pyRGÀscCsdS(N((RR"((s"/usr/lib64/python2.7/HTMLParser.pyR7ÄscCsdS(N((RR"((s"/usr/lib64/python2.7/HTMLParser.pyRQÈscCsdS(N((Rtdecl((s"/usr/lib64/python2.7/HTMLParser.pyRNÌscCsdS(N((RR"((s"/usr/lib64/python2.7/HTMLParser.pyRUÐscCsdS(N((RR"((s"/usr/lib64/python2.7/HTMLParser.pyt unknown_declÓscs2d|kr|S‡fd†}tjd||ƒS(NR4cs|jƒd}yZ|ddkri|d}|dd krSt|ddƒ}n t|ƒ}t|ƒSWntk r†d|dSXd dl}tjdkréid d 6}t_x0|jj ƒD]\}}t|ƒ||s&