Your IP : 172.28.240.42


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


|_c@sdZdgZddlZddlmZddlmZejdZejdZejdZ	ejdZ
ejd	Zd
ZdZ
eZdefd
YZdddYZdS(sFeedParser - An email feed parser.

The feed parser implements an interface for incrementally parsing an email
message, line by line.  This has advantages for certain applications, such as
those reading email messages off a socket.

FeedParser.feed() is the primary interface for pushing new data into the
parser.  It returns when there's nothing more it can do with the available
data.  When you have no more data to push into the parser, call .close().
This completes the parsing and returns the root message object.

The other advantage of this parser is that it will never throw a parsing
exception.  Instead, when it finds something unexpected, it adds a 'defect' to
the current message.  Defects are just instances that live on the message
object's .defects attribute.
t
FeedParseriN(terrors(tmessages
|
|
s(
|
|
)s
(
|
|
)\Zs(^(From |[\041-\071\073-\176]{1,}:|[\t ])ts
tBufferedSubFilecBsqeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
RS(skA file-ish object that can have new data loaded into it.

    You can also push and pop line-matching predicates onto a stack.  When the
    current predicate matches the current line, a false EOF response
    (i.e. empty string) is returned instead.  This lets the parser adhere to a
    simple abstraction -- it parses until EOF closes the current message.
    cCs(d|_g|_g|_t|_dS(NR(t_partialt_linest	_eofstacktFalset_closed(tself((s&/usr/lib/python2.7/email/feedparser.pyt__init__3s			cCs|jj|dS(N(Rtappend(R
tpred((s&/usr/lib/python2.7/email/feedparser.pytpush_eof_matcher=scCs
|jjS(N(Rtpop(R
((s&/usr/lib/python2.7/email/feedparser.pytpop_eof_matcher@scCs)|jj|jd|_t|_dS(NR(RRRtTrueR	(R
((s&/usr/lib/python2.7/email/feedparser.pytcloseCs	cCsn|js|jrdStS|jj}x>|jdddD]&}||r@|jj|dSq@W|S(NRi(RR	tNeedMoreDataRRR(R
tlinetateof((s&/usr/lib/python2.7/email/feedparser.pytreadlineIs		cCs&|tk	st|jj|dS(N(RtAssertionErrorRR(R
R((s&/usr/lib/python2.7/email/feedparser.pyt
unreadline[scCs|j|d}|_tj|}|j|_|jrw|rw|djdrw|jd|j|_ng}xCtt|dD]+}|j||d||ddqW|j|dS(s$Push some new data into this object.Ris
iiiN(	RtNLCRE_cracktsplitRtendswithtrangetlenRt	pushlines(R
tdatatpartstlinesti((s&/usr/lib/python2.7/email/feedparser.pytpush`s#)cCs|ddd|jd*dS(Nii(R(R
R!((s&/usr/lib/python2.7/email/feedparser.pyRwscCs|jS(N(R	(R
((s&/usr/lib/python2.7/email/feedparser.pyt	is_closed{scCs|S(N((R
((s&/usr/lib/python2.7/email/feedparser.pyt__iter__~scCs%|j}|dkr!tn|S(NR(Rt
StopIteration(R
R((s&/usr/lib/python2.7/email/feedparser.pytnexts	(t__name__t
__module__t__doc__RRRRRRR#RR$R%R'(((s&/usr/lib/python2.7/email/feedparser.pyR+s	
									cBseeZdZejdZdZdZdZdZ	dZ
dZdZd	Z
RS(
sA feed-style parser of email.cCsO||_t|_g|_|jj|_d|_d|_	t
|_dS(s@_factory is called with no arguments to create a new message objN(t_factoryRt_inputt	_msgstackt	_parsegenR't_parsetNonet_curt_lastRt_headersonly(R
R+((s&/usr/lib/python2.7/email/feedparser.pyRs				cCs
t|_dS(N(RR3(R
((s&/usr/lib/python2.7/email/feedparser.pyt_set_headersonlyscCs|jj||jdS(sPush more data into the parser.N(R,R#t_call_parse(R
R((s&/usr/lib/python2.7/email/feedparser.pytfeedscCs&y|jWntk
r!nXdS(N(R/R&(R
((s&/usr/lib/python2.7/email/feedparser.pyR5s
cCso|jj|j|j}|js3t|jdkrk|jrk|jj	t
jn|S(s<Parse all remaining data and return the root message object.t	multipart(R,RR5t_pop_messageR-Rtget_content_maintypetis_multiparttdefectsRRt!MultipartInvariantViolationDefect(R
troot((s&/usr/lib/python2.7/email/feedparser.pyRs


cCs|j}|jr:|jjdkr:|jdn|jrZ|jdj|n|jj|||_||_dS(Nsmultipart/digestsmessage/rfc822i(R+R1tget_content_typetset_default_typeR-tattachRR2(R
tmsg((s&/usr/lib/python2.7/email/feedparser.pyt_new_messages		cCs8|jj}|jr+|jd|_n	d|_|S(Ni(R-RR1R0(R
tretval((s&/usr/lib/python2.7/email/feedparser.pyR8s
		ccs|jg}xj|jD]_}|tkr7tVqntj|sltj|sh|jj|nPn|j|qW|j||j	rg}xMt
r|jj}|tkrtVqn|dkrPn|j|qW|jj
tj|dS|jjdkrxt
r
|jjtjx,|jD]}|tkratVqDnPqDW|j}|jjx1t
r|jj}|tkrtVqnPqWx1t
r|jj}|tkrtVqnPqW|dkrPn|jj|qWdS|jjdkrax,|jD]}|tkrNtVq1nPq1W|jdS|jjdkr:|jj}|dkr|jjjtjg}x5|jD]*}|tkrtVqn|j|qW|jj
tj|dSd|}tjdtj|d}t
}	g}
t}xt
r|jj}|tkrptVqDn|dkrPn|j|}|r|jdr|jd	}Pn|	r7|
r|
d
}
t j!|
}|r|
t"|jd |
d
<ntj|
|j_#nt}	|jj|qDnxYt
r|jj}|tkrftVq:n|j|}|s:|jj|Pq:q:W|jj|jx,|jD]}|tkrtVqnPqW|j$jdkra|j$j%}|dkrd|j$_%q|dk	rt j!|}|r^t"|jd}|| |j$_%q^qnc|j$j&}t'|t(rt j!|}|r|t"|jd }|j$j
|qn|jj|j|j|_$qD|	st)|
j|qDW|	r|jjjtj*|jj
tj|
g}x(|jD]}|tkrOtVqOqOqOWtj||j_%dS|rdg}ng}x5|jD]*}|tkrtVqn|j|qW|r!|d}t+j|}|r!|t"|jd|d<q!ntj||j_%dSg}x5|jD]*}|tkrgtVqJn|j|qJW|jj
tj|dS(NRsmessage/delivery-statusRR7s--s(?P<sep>s4)(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$tendtlinesepii(,RBR,RtheaderREtmatchtNLCRERRt_parse_headersR3RRR1tset_payloadtEMPTYSTRINGtjoinR>RR.R8RR9tget_boundaryR0R;RtNoBoundaryInMultipartDefecttretcompiletescapeRtgroupt	NLCRE_eoltsearchRtpreambleR2tepiloguetget_payloadt
isinstancet
basestringRtStartBoundaryNotFoundDefectt	NLCRE_bol(R
theadersRR!RCRAtboundaryt	separatort
boundaryretcapturing_preambleRUREtmotlastlineteolmoRVRDtpayloadt	firstlinetbolmo((s&/usr/lib/python2.7/email/feedparser.pyR.sL

			
		


	
!	



#c
Csd}g}xt|D]\}}|ddkrv|sctj|}|jjj|qn|j|qn|rtj|d jd}||j|<dg}}n|j	drj|dkrt
j|}|r|t|j
d }n|jj|qqj|t|dkrB|jj|dStj|}|jjj|qn|jd}	|	dkrtj|}|jjj|qn||	 }||	djg}qW|rtj|jd|j|<ndS(	NRis 	is
sFrom it:(t	enumerateRt#FirstHeaderLineIsContinuationDefectR1R;RRKRLtrstript
startswithRSRTRRRtset_unixfromR,RtMisplacedEnvelopeHeaderDefecttfindtMalformedHeaderDefecttlstrip(
R
R!t
lastheadert	lastvaluetlinenoRtdefecttlhdrRaR"((s&/usr/lib/python2.7/email/feedparser.pyRIsH


(R(R)R*RtMessageRR4R6R5RRBR8R.RI(((s&/usr/lib/python2.7/email/feedparser.pyRs					
		((R*t__all__ROtemailRRRPRHR[RSRRFRKtNLtobjectRRR(((s&/usr/lib/python2.7/email/feedparser.pyt<module>s		^