mò &U²Ic@s¶dZdkZdklZdklZeidƒZeidƒZeidƒZeidƒZ eidƒZ dZ d Z e ƒZd e fd „ƒYZd fd „ƒ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 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. N(sErrors(sMessages | | s( | | )s ( | | )$s(^(From |[\041-\071\073-\176]{1,}:|[\t ])ts tBufferedSubFilecBsqtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„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(d|_g|_g|_t|_dS(NR(tselft_partialt_linest _eofstacktFalset_closed(R((t-/data/zmath/lib/python2.4/email/FeedParser.pyt__init__0s   cCs|ii|ƒdS(N(RRtappendtpred(RR ((Rtpush_eof_matcher:scCs |iiƒS(N(RRtpop(R((Rtpop_eof_matcher=scCs)|ii|iƒd|_t|_dS(NR(RRR RtTrueR(R((Rtclose@s cCs}|ip|iodSntSn|iiƒ}xC|iddd…D]+}||ƒo|ii|ƒdSqJqJW|S(NRiÿÿÿÿ( RRRt NeedMoreDataR tlineRtateofR (RRR((RtreadlineFs    cCs|ii|ƒdS(N(RRR R(RR((Rt unreadlineXscCs’|i|d}|_ti|ƒ}|iƒ|_g}xCtt |ƒdƒD]+}|i ||d||ddƒqRW|i |ƒdS(s$Push some new data into this object.RiiN( RRtdatat NLCRE_cracktsplittpartsR tlinestrangetlentiR t pushlines(RRRRR((Rtpush]s)cCs|ddd…|id*dS(Niÿÿÿÿi(RRR(RR((RRpscCs|iS(N(RR(R((Rt is_closedtscCs|S(N(R(R((Rt__iter__wscCs'|iƒ}|djo t‚n|S(NR(RRRt StopIteration(RR((Rtnextzs   (t__name__t __module__t__doc__R R RRRRRRR R!R#(((RR(s          t FeedParsercBsetZdZeid„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z RS( sA feed-style parser of email.cCsO||_tƒ|_g|_|iƒi|_d|_ d|_ t |_ dS(s@_factory is called with no arguments to create a new message objN( t_factoryRRt_inputt _msgstackt _parsegenR#t_parsetNonet_curt_lastRt _headersonly(RR(((RR …s     cCs t|_dS(N(RRR0(R((Rt_set_headersonlyscCs|ii|ƒ|iƒdS(sPush more data into the parser.N(RR)RRt _call_parse(RR((Rtfeed“scCs(y|iƒWntj onXdS(N(RR,R"(R((RR2˜scCsb|iiƒ|iƒ|iƒ}|iƒdjo(|iƒ o|ii t i ƒƒn|S(s<Parse all remaining data and return the root message object.t multipartN( RR)RR2t _pop_messagetroottget_content_maintypet is_multiparttdefectsR tErrorst!MultipartInvariantViolationDefect(RR6((RRžs   !cCs…|iƒ}|io'|iiƒdjo|idƒn|io|idi|ƒn|ii|ƒ||_||_ dS(Nsmultipart/digestsmessage/rfc822iÿÿÿÿ( RR(tmsgR.tget_content_typetset_default_typeR*tattachR R/(RR<((Rt _new_messageªs    cCs:|iiƒ}|io|id|_n d|_|S(Niÿÿÿÿ(RR*R tretvalR.R-(RRA((RR5´s   ccsè|iƒg}xo|iD]d} | tjo tVqnti| ƒp)ti| ƒp|ii | ƒnPn|i | ƒqW|i |ƒ|i o|g}xRtoJ|iiƒ} | tjo tVq¢n| djoPn|i | ƒq¢W|iiti|ƒƒdSn|iiƒdjoxøtoð|iitiƒx-|iƒD]}|tjo tVqUnPqUW|iƒ}|iiƒx4to,|iiƒ} | tjo tVq”nPq”Wx4to,|iiƒ} | tjo tVqËnPqËW| djoPn|ii | ƒq.WdSn|iiƒdjoBx-|iƒD]}|tjo tVqQnPqQW|iƒdSn|iiƒdjoð|iiƒ} | djoy|iii t i!ƒƒg}x6|iD]+} | tjo tVqán|i | ƒqáW|iiti|ƒƒdSnd| }t#i$dt#i%|ƒdƒ} t} g}t)}xØtoÐ|iiƒ} | tjo tVqpn| djoPn| i| ƒ}|op|i,dƒo|i,d ƒ}Pn| o|o[|d }t.i/|ƒ} | o"|t1| i,d ƒƒ |d s4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$tendtlinesepiÿÿÿÿi(=RR@theadersR)RRtheaderREtmatchtNLCRERR t_parse_headersR0RRRR.t set_payloadt EMPTYSTRINGtjoinR=R R+RAR5R<RR7t get_boundarytboundaryR-R9R:tNoBoundaryInMultipartDefectt separatortretcompiletescapet boundaryretcapturing_preambletpreambleRRDtmotgrouptlastlinet NLCRE_eoltsearchteolmoRR/tepilogueRCt get_payloadtpayloadt isinstancet basestringtStartBoundaryNotFoundDefectt firstlinet NLCRE_boltbolmo(RRcR_RCR]RDReRYR<RNRTR\RURRVRWRRERPRA((RR+¼sd                         "                %  c Csd} g}xÖt|ƒD]È\}}|ddjoD| p)ti|ƒ}|i i i |ƒqn|i |ƒqn| o:t i|ƒd idƒ}||i |