Spade
Mini Shell
| Directory:~$ /lib/python2.7/site-packages/future/backports/email/ |
| [Home] [System Details] [Kill Me] |
�
,�]c@`sVdZddlmZddlmZddlmZddlmZmZmZddl m
Z
mZddgZdd l
Z
dd
lmZddlmZddlmZe
jd
�Ze
jd�Ze
jd�Ze
jd�Ze
jd�ZdZdZe�Zdefd��YZdefd��YZdefd��YZd S(uFeedParser
- 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 raise 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.
i(tunicode_literals(tdivision(tabsolute_import(tobjecttrangetsuper(timplements_iteratortPY3u
FeedParseruBytesFeedParserN(terrors(tmessage(tcompat32u
|
|
u(
|
|
)u
(
|
|
)\Zu(^(From |[\041-\071\073-\176]{1,}:|[\t ])uu
tBufferedSubFilecB`sheZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Zd
�ZRS(ukA 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.
cC`s(d|_g|_g|_t|_dS(Nu(t_partialt_linest _eofstacktFalset_closed(tself((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyt__init__9s cC`s|jj|�dS(N(Rtappend(Rtpred((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pytpush_eof_matcherCscC`s
|jj�S(N(Rtpop(R((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pytpop_eof_matcherFscC`s)|jj|j�d|_t|_dS(Nu(R
RRtTrueR(R((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pytcloseIs cC`sn|js|jrdStS|jj�}x>|jddd�D]&}||�r@|jj|�dSq@W|S(Nui����(R
RtNeedMoreDataRRR(Rtlinetateof((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pytreadlineOs cC`s&|tk st�|jj|�dS(N(RtAssertionErrorR
R(RR((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyt
unreadlineascC`s�|j|d}|_tj|�}|j�|_|jrw|rw|djd�rw|jd�|j�|_ng}xCtt|�d�D]+}|j||d||dd�q�W|j|�dS(u$Push
some new data into this
object.ui����u
i����iiN( RtNLCRE_cracktsplitRtendswithRtlenRt pushlines(Rtdatatpartstlinesti((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pytpushfs#)cC`s|ddd�|jd*dS(Ni����i(R
(RR'((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyR$}scC`s|S(N((R((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyt__iter__�scC`s%|j�}|dkr!t�n|S(Nu(Rt
StopIteration(RR((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyt__next__�s (
t__name__t
__module__t__doc__RRRRRRR)R$R*R,(((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyR1s
t
FeedParsercB`seeZdZejd�Zd�Zd�Zd�Zd�Z d�Z
d�Zd�Zd �Z
RS(
uA feed-style parser of email.c`s�d|kr
|d}|d=nt}|�_|�_y&|d�j��fd��_Wntk
r}d��_nXt��_g�_tr��j �j
�_n�j �j�_d�_d�_t�_dS(Nupolicytpolicyc`si�jd6S(Nupolicy(R1((R(sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyt<lambda>�scS`siS(N((((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyR2�s(R
t_factoryR1t
_factory_kwdst TypeErrorRt_inputt _msgstackRt _parsegenR,t_parsetnexttNonet_curt_lastRt_headersonly(RR3t_3to2kwargsR1((RsE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyR�s&
cC`s
t|_dS(N(RR>(R((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyt_set_headersonly�scC`s|jj|�|j�dS(uPush
more data into the
parser.N(R6R)t_call_parse(RR%((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pytfeed�scC`s&y|j�Wntk
r!nXdS(N(R9R+(R((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyRA�s
cC`sx|jj�|j�|j�}|js3t�|j�dkrt|j�rttj �}|j
j||�n|S(u<Parse all remaining data and return the root message
object.u multipart(R6RRAt_pop_messageR7Rtget_content_maintypetis_multipartRt!MultipartInvariantViolationDefectR1t
handle_defect(Rtroottdefect((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyR�s
cC`s�|j|j��}|jrC|jj�dkrC|jd�n|jrc|jdj|�n|jj|�||_||_dS(Numultipart/digestumessage/rfc822i����( R3R4R<tget_content_typetset_default_typeR7tattachRR=(Rtmsg((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyt_new_message�s cC`s8|jj�}|jr+|jd|_n d|_|S(Ni����(R7RR<R;(Rtretval((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyRC�s
cc`s@|j�g}x�|jD]�}|tkr7tVqntj|�s�tj|�s�tj�}|jj |j
|�|jj|�nPn|j|�qW|j
|�|jr(g}xMtr
|jj�}|tkr�tVq�n|dkr�Pn|j|�q�W|j
jtj|��dS|j
j�dkr1x�tr,|jjtj�x,|j�D]}|tkr�tVqfnPqfW|j�}|jj�x1tr�|jj�}|tkr�tVq�nPq�Wx1tr|jj�}|tkrtVq�nPq�W|dkrPn|jj|�q@WdS|j
j�dkr�x,|j�D]}|tkrptVqSnPqSW|j�dS|j
j�dkr�|j
j�}|dkr0tj�}|jj |j
|�g}x5|jD]*}|tkrtVq�n|j|�q�W|j
jtj|��dS|j
jdd�j�dkrvtj�}|jj |j
|�nd |}t j!d
t j"|�d�} t}
g}t#}t#}
x�tr||jj�}|tkr�tVq�n|dkr�Pn| j|�}|r`|j$d�r4t}
|j$d
�}Pn|
r�|r�|d}t%j&|�}|r�|t'|j$d��
|d<ntj|�|j
_(nt#}
|jj|�q�nxYtr|jj�}|tkr�tVq�n| j|�}|s�|jj|�Pq�q�W|jj| j�x,|j�D]}|tkrMtVq0nPq0W|j)j�dkr�|j)j*}|dkr�d|j)_*q:|dk r:t%j&|�}|r�t'|j$d��}||
|j)_*q�q:n\|j)j+}t,|t-�r:t%j&|�}|r:|t'|j$d��
}||j)_+q:n|jj�|j�|j
|_)q�|
slt.�|j|�q�W|
rtj/�}|jj |j
|�|j
jtj|��g}x(|jD]}|tkr�tVq�q�q�Wtj|�|j
_*dS|
s4tj0�}|jj |j
|�dS|rFdg}ng}x5|jD]*}|tkrstVqVn|j|�qVW|r�|d}t1j|�}|r�|t'|j$d��|d<q�ntj|�|j
_*dSg}x5|jD]*}|tkrtVq�n|j|�q�W|j
jtj|��dS(Nuumessage/delivery-statusumessageu multipartucontent-transfer-encodingu8bitu7bitubinaryu--u(?P<sep>u4)(?P<end>--)?(?P<ws>[
\t]*)(?P<linesep>\r\n|\r|\n)?$uendulinesepi����i(u7bitu8bitubinary(2RNR6RtheaderREtmatchtNLCRERt
MissingHeaderBodySeparatorDefectR1RGR<RRt_parse_headersR>RRtset_payloadtEMPTYSTRINGtjoinRJRR8RCRRDtget_boundaryR;tNoBoundaryInMultipartDefecttgettlowert-InvalidMultipartContentTransferEncodingDefecttretcompiletescapeRtgroupt NLCRE_eoltsearchR#tpreambleR=tepiloguet_payloadt
isinstancetstrRtStartBoundaryNotFoundDefecttCloseBoundaryNotFoundDefectt NLCRE_bol(RtheadersRRIR'RORMtboundaryt separatort
boundaryretcapturing_preambleRctlineseptclose_boundary_seentmotlastlineteolmoRdtendtpayloadt firstlinetbolmo((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyR8�sh
!
#c C`s�d}g}x�t|�D]�\}}|ddkry|sftj|�}|jj|j|�qn|j|�qn|r�|jj|jj|��dg}}n|j d�r`|dkrt
j|�}|r�|t|j
d��
}n|jj|�qq`|t|�dkr8|jj|�dStj|�}|jjj|�qn|jd�}|dks�td��||
}|g}qW|r�|jj|jj|��ndS(Nuiu uFrom
iu:u3_parse_headers fed line with no : and no leading
WS(t enumerateRt#FirstHeaderLineIsContinuationDefectR1RGR<Rtset_rawtheader_source_parset
startswithRaRbR#R`tset_unixfromR6RtMisplacedEnvelopeHeaderDefecttdefectstfindR( RR't
lastheadert lastvaluetlinenoRRIRrR(((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyRT�s@
(R-R.R/R tMessageRR@RBRARRNRCR8RT(((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyR0�s
�tBytesFeedParsercB`seZdZd�ZRS(u(Like FeedParser, but feed
accepts bytes.cC`s
t�j|jdd��dS(Nuasciiusurrogateescape(RRBtdecode(RR%((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyRBs(R-R.R/RB(((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyR� s(R/t
__future__RRRtfuture.builtinsRRRtfuture.utilsRRt__all__R]tfuture.backports.emailRR t"future.backports.email._policybaseR
R^RRRjRaR
RPRVtNLRRR0R�(((sE/usr/lib/python2.7/site-packages/future/backports/email/feedparser.pyt<module>s, Z�