ó ’,bc@sČdZdgZddlZddlmZddlmZejdƒZejdƒZejdƒZ ejdƒZ ejd ƒZ d Z d Z eƒZd efd „ƒYZddd„ƒYZdS(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 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. t FeedParseri˙˙˙˙N(terrors(tmessages | | s( | | )s ( | | )\Zs(^(From |[\041-\071\073-\176]{1,}:|[\t ])ts tBufferedSubFilecBszeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Z 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(g|_g|_g|_t|_dS(N(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 |jjƒS(N(Rtpop(R ((s&/usr/lib/python2.7/email/feedparser.pytpop_eof_matcher@scCs8|jdj|jƒjtƒƒg|_t|_dS(NR(t pushlinestjoinRt splitlinestTrueR (R ((s&/usr/lib/python2.7/email/feedparser.pytcloseCs" cCsn|js|jrdStS|jjƒ}x>|jddd…D]&}||ƒ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ż|jtƒ}| s*|djdƒ r=|j|7_dS|jr†|jj|dƒdj|jƒjtƒ|dd+|j2n|djdƒsŽ|jƒg|_n|j|ƒdS( s$Push some new data into this object.is s NRii˙˙˙˙(s s (RRtendswithRR RRR(R tdatatparts((s&/usr/lib/python2.7/email/feedparser.pytpush`s " cCs˝tjtƒ}|jƒ|_|j r`|r`|djdƒr`|jdƒ|jƒ|_ng}xCtt|ƒdƒD]+}|j||d||ddƒq}W|j |ƒdS(Ni˙˙˙˙s iţ˙˙˙ii( t NLCRE_cracktsplitRRRRtrangetlenR R(R tlinesRti((s&/usr/lib/python2.7/email/feedparser.pyRxs#)cCs|ddd…|jd*dS(Ni˙˙˙˙i(R(R R$((s&/usr/lib/python2.7/email/feedparser.pyRŒscCs|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!t‚n|S(NR(Rt StopIteration(R R((s&/usr/lib/python2.7/email/feedparser.pytnext–s   (t__name__t __module__t__doc__R RRRRRRRR&R'R)(((s&/usr/lib/python2.7/email/feedparser.pyR+s          cBseeZdZejd„Zd„Zd„Zd„Zd„Z d„Z d„Z d„Z d „Z RS( sA feed-style parser of email.cCsO||_tƒ|_g|_|jƒj|_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.pyR Ąs     cCs t|_dS(N(RR5(R ((s&/usr/lib/python2.7/email/feedparser.pyt_set_headersonlyŹscCs|jj|ƒ|jƒdS(sPush more data into the parser.N(R.Rt _call_parse(R R((s&/usr/lib/python2.7/email/feedparser.pytfeedŻscCs&y|jƒWntk r!nXdS(N(R1R((R ((s&/usr/lib/python2.7/email/feedparser.pyR7´s cCso|jjƒ|jƒ|jƒ}|j s3t‚|jƒdkrk|jƒ rk|jj t j ƒƒn|S(s<Parse all remaining data and return the root message object.t multipart( R.RR7t _pop_messageR/Rtget_content_maintypet is_multiparttdefectsR Rt!MultipartInvariantViolationDefect(R troot((s&/usr/lib/python2.7/email/feedparser.pyRşs    cCs€|jƒ}|jr:|jjƒdkr:|jdƒn|jrZ|jdj|ƒn|jj|ƒ||_||_dS(Nsmultipart/digestsmessage/rfc822i˙˙˙˙(R-R3tget_content_typetset_default_typeR/tattachR R4(R tmsg((s&/usr/lib/python2.7/email/feedparser.pyt _new_messageĆs   cCs8|jjƒ}|jr+|jd|_n d|_|S(Ni˙˙˙˙(R/RR3R2(R tretval((s&/usr/lib/python2.7/email/feedparser.pyR:Đs   ccs•|jƒg}xj|jD]_}|tkr7tVqntj|ƒsltj|ƒsh|jj|ƒnPn|j|ƒqW|j|ƒ|j rg}xMt rč|jj ƒ}|tkrČtVqœn|dkrŘPn|j|ƒqœW|j j tj|ƒƒdS|j jƒdkrxít r |jjtjƒx,|jƒD]}|tkratVqDnPqDW|jƒ}|jjƒx1t r˛|jj ƒ}|tkrŽtVq‚nPq‚Wx1t rć|jj ƒ}|tkrâtVqśnPqśW|dkr÷Pn|jj|ƒqWdS|j jƒdkrax,|jƒD]}|tkrNtVq1nPq1W|jƒdS|j jƒdkr:|j jƒ}|dkr|j jjtjƒƒg}x5|jD]*}|tkr×tVqşn|j|ƒqşW|j j tj|ƒƒdSd|}tjdtj|ƒdƒ}t } g} t} xĂt r|jj ƒ}|tkrptVqDn|dkr€Pn|j|ƒ} | rę| jdƒrˇ| jd ƒ} Pn| r7| r| d } t j!| ƒ}|r| t"|jd ƒƒ | d s4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$tendtlinesepi˙˙˙˙i(,RDR.RtheaderREtmatchtNLCRERR t_parse_headersR5RRR3t set_payloadt EMPTYSTRINGRR@RR0R:RR;t get_boundaryR2R=RtNoBoundaryInMultipartDefecttretcompiletescapeRtgroupt NLCRE_eoltsearchR#tpreambleR4tepiloguet get_payloadt isinstancet basestringRtStartBoundaryNotFoundDefectt NLCRE_bol(R theadersRR$RERCtboundaryt separatort boundaryretcapturing_preambleRVRGtmotlastlineteolmoRWRFtpayloadt firstlinetbolmo((s&/usr/lib/python2.7/email/feedparser.pyR0ŘsL                          !              # c Csţd}g}xĂt|ƒD]ľ\}}|ddkrv|sctj|ƒ}|jjj|ƒqn|j|ƒqn|rľtj|ƒd jdƒ}||j|s   s