Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/
Upload File :
Current File : //usr/lib/python2.7/HTMLParser.pyc


|_c@sdZddlZddlZejdZejdZejdZejdZejdZejdZ	ejd	Z
ejd
ZejdZejdZ
ejd
ejZejdZejdZdefdYZdejfdYZdS(sA parser for HTML and XHTML.iNs[&<]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[a-zA-Z][^	

 />]*sc[\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#</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>tHTMLParseErrorcBs#eZdZddZdZRS(s&Exception raised for all parse errors.cCs3|st||_|d|_|d|_dS(Nii(tAssertionErrortmsgtlinenotoffset(tselfRtposition((s /usr/lib/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/lib/python2.7/HTMLParser.pyt__str__?s	N(NN(t__name__t
__module__t__doc__R	RR(((s /usr/lib/python2.7/HTMLParser.pyR6st
HTMLParsercBs
eZdZdZdZdZdZdZdZdZ
dZd	Zd
Z
dZdZd
dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ RS( sFind 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|jdS(s#Initialize and reset this instance.N(treset(R((s /usr/lib/python2.7/HTMLParser.pyR_scCs8d|_d|_t|_d|_tjj|dS(s1Reset this instance.  Loses all unprocessed data.ts???N(	trawdatatlasttagtinteresting_normaltinterestingR	t
cdata_elemt
markupbaset
ParserBaseR(R((s /usr/lib/python2.7/HTMLParser.pyRcs
				cCs!|j||_|jddS(sFeed data to the parser.

        Call this as often as you want, with as little or as much text
        as you want (may include '\n').
        iN(Rtgoahead(Rtdata((s /usr/lib/python2.7/HTMLParser.pytfeedkscCs|jddS(sHandle any buffered data.iN(R(R((s /usr/lib/python2.7/HTMLParser.pytclosetscCst||jdS(N(Rtgetpos(Rtmessage((s /usr/lib/python2.7/HTMLParser.pyterrorxscCs|jS(s)Return full source of start tag: '<...>'.(t_HTMLParser__starttag_text(R((s /usr/lib/python2.7/HTMLParser.pytget_starttag_text}scCs2|j|_tjd|jtj|_dS(Ns</\s*%s\s*>(tlowerRtretcompiletIR(Rtelem((s /usr/lib/python2.7/HTMLParser.pytset_cdata_modescCst|_d|_dS(N(RRR	R(R((s /usr/lib/python2.7/HTMLParser.pytclear_cdata_modes	c
Cst|j}d}t|}x||kr|jj||}|rT|j}n|jraPn|}||kr|j|||!n|j||}||krPn|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"|sPn|jd|d}|dkr|jd|d}|dkr|d}qn
|d7}|j|||!n|j||}q|d	|rtj
||}|r|jd
d!}	|j|	|j}|d|ds|d}n|j||}qqd||kr|j|dd
!|j|d
}nPq|d
|rtj
||}|r|jd}	|j|	|j}|d|dsn|d}n|j||}qntj
||}|r|r|j||kr|jdnPq|d|kr|jd
|j||d}qPqdstdqW|rc||krc|jrc|j|||!|j||}n|||_dS(Nit<s</s<!--s<?s<!iRs&#iit;t&s#EOF in middle of entity or char refsinteresting.search() lied(RtlenRtsearchtstartRthandle_datat	updatepost
startswithtstarttagopentmatchtparse_starttagtparse_endtagt
parse_commenttparse_pitparse_html_declarationtfindtcharreftgroupthandle_charreftendt	entityrefthandle_entityreft
incompleteR!R(
RR?RtitnR5tjR3tktname((s /usr/lib/python2.7/HTMLParser.pyRs			







cCs|j}|||d!dkr0|jdn|||d!dkrT|j|S|||d!dkrx|j|S|||d!jd	kr|jd
|d}|dkrdS|j||d|!|dS|j|SdS(
Nis<!s+unexpected call to parse_html_declaration()is<!--is<![i	s	<!doctypeRii(RR!R8tparse_marked_sectionR$R;thandle_decltparse_bogus_comment(RRCRtgtpos((s /usr/lib/python2.7/HTMLParser.pyR:s	

icCs|j}|||d!dkr0|jdn|jd|d}|dkrVdS|rw|j||d|!n|dS(	Nis<!s</s"unexpected call to parse_comment()Rii(s<!s</(RR!R;thandle_comment(RRCtreportRtpos((s /usr/lib/python2.7/HTMLParser.pyRJs	cCs|j}|||d!dks,tdtj||d}|sLdS|j}|j||d|!|j}|S(Nis<?sunexpected call to parse_pi()i(RRtpicloseR/R0t	handle_piR?(RRCRR5RE((s /usr/lib/python2.7/HTMLParser.pyR9s	#cCsd|_|j|}|dkr(|S|j}|||!|_g}tj||d}|sotd|j}||d|!j|_	}x||krt
j||}|sPn|jddd\}	}
}|
sd}nX|d dko|dkns9|d dko4|dknrI|dd!}n|ra|j|}n|j
|	j|f|j}qW|||!j}|dkr-|j\}
}d|jkr|
|jjd}
t|j|jjd}n|t|j}|j|||!|S|jd
rO|j||n/|j||||jkr~|j|n|S(
Niis#unexpected call to parse_starttag()iis'it"Rs/>s
(Rs/>(R	R"tcheck_for_whole_start_tagRttagfindR5RR?R$RtattrfindR=tunescapetappendtstripRtcountR.trfindR1tendswiththandle_startendtagthandle_starttagtCDATA_CONTENT_ELEMENTSR)(RRCtendposRtattrsR5RFttagtmtattrnametrestt	attrvalueR?RR((s /usr/lib/python2.7/HTMLParser.pyR6sR			$$cCs|j}tj||}|r|j}|||d!}|dkrR|dS|dkr|jd|rx|dS|jd|rdS|j||d|jdn|dkrdS|d	krdS||kr|S|dSntd
dS(NiRt/s/>iismalformed empty start tagRs6abcdefghijklmnopqrstuvwxyz=/ABCDEFGHIJKLMNOPQRSTUVWXYZswe should not get here!(RtlocatestarttagendR5R?R3R2R!R(RRCRRaREtnext((s /usr/lib/python2.7/HTMLParser.pyRRKs,	cCs|j}|||d!dks,tdtj||d}|sLdS|j}tj||}|s!|jdk	r|j	|||!|St
j||d}|s|||d!dkr|dS|j|Sn|jj
}|jd|j}|j||dS|jdj
}|jdk	ro||jkro|j	|||!|Sn|j||j|S(	Nis</sunexpected call to parse_endtagiiis</>R(RRt	endendtagR/R?t
endtagfindR5RR	R1ttagfind_tolerantRJR=R$R;t
handle_endtagR*(RRCRR5RKt	namematchttagnameR(((s /usr/lib/python2.7/HTMLParser.pyR7ks8	#


cCs!|j|||j|dS(N(R\Rk(RR`R_((s /usr/lib/python2.7/HTMLParser.pyR[scCsdS(N((RR`R_((s /usr/lib/python2.7/HTMLParser.pyR\scCsdS(N((RR`((s /usr/lib/python2.7/HTMLParser.pyRkscCsdS(N((RRG((s /usr/lib/python2.7/HTMLParser.pyR>scCsdS(N((RRG((s /usr/lib/python2.7/HTMLParser.pyRAscCsdS(N((RR((s /usr/lib/python2.7/HTMLParser.pyR1scCsdS(N((RR((s /usr/lib/python2.7/HTMLParser.pyRLscCsdS(N((Rtdecl((s /usr/lib/python2.7/HTMLParser.pyRIscCsdS(N((RR((s /usr/lib/python2.7/HTMLParser.pyRPscCsdS(N((RR((s /usr/lib/python2.7/HTMLParser.pytunknown_declscs2d|kr|Sfd}tjd||S(NR-cs|jd}yZ|ddkri|d}|dd
krSt|dd}nt|}t|SWntk
rd|dSXd	dl}tjdkrid
d6}t_x0|jj	D]\}}t|||<qWnyj|SWnt
k
rd|dSXdS(Nit#itxtXis&#R,iu'taposR-(RqRr(tgroupstinttunichrt
ValueErrorthtmlentitydefsRt
entitydefsR	tname2codepointt	iteritemstKeyError(tstcRxRyRFtv(R(s /usr/lib/python2.7/HTMLParser.pytreplaceEntitiess&



s#&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));(R%tsub(RR}R((Rs /usr/lib/python2.7/HTMLParser.pyRUs(RRN(!RR
RR]RRRRR!R	R"R#R)R*RR:RJR9R6RRR7R[R\RkR>RAR1RLRIRPRoRyRU(((s /usr/lib/python2.7/HTMLParser.pyRHs<										^			4	 	(										(RRR%R&RRBR@R<R4ROtcommentcloseRSRjRTtVERBOSERfRhRit	ExceptionRRR(((s /usr/lib/python2.7/HTMLParser.pyt<module>s&