e fmY@sdZddgZddlZddlmZddlmZddlmZejdZ ejd Z ejd Z ejd Z ejd Z d Zd ZeZGdddeZGdddZGdddeZdS)aFeedParser - 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. FeedParserBytesFeedParserN)errors)message)compat32z | | z( | | )z ( | | )\Zz%^(From |[\041-\071\073-\176]*:|[\t ]) c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS)BufferedSubFileakA 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|_d|_dS)NF)_partial_lines _eofstack_closed)selfr5/opt/alt/python34/lib64/python3.4/email/feedparser.py__init__4s   zBufferedSubFile.__init__cCs|jj|dS)N)r append)rZpredrrrpush_eof_matcher>sz BufferedSubFile.push_eof_matchercCs |jjS)N)r pop)rrrrpop_eof_matcherAszBufferedSubFile.pop_eof_matchercCs8|jdj|jjdg|_d|_dS)NrT) pushlinesjoinr splitlinesr )rrrrcloseDs" zBufferedSubFile.closecCsn|js|jrdStS|jj}x>|jdddD]&}||r@|jj|dSq@W|S)Nr)r r NeedMoreDatarr r)rlineZateofrrrreadlineJs   zBufferedSubFile.readlinecCs|jj|dS)N)r r)rrrrr unreadline\szBufferedSubFile.unreadlinecCs|jd}| s*|djd r=|j|7_dS|jr|jj|ddj|jjd|dd<|jdd=n|d jds|jg|_n|j|dS) z$Push some new data into this object.Trr Nrr)rr r)rendswithr rrrr)rdatapartsrrrpushas %zBufferedSubFile.pushcCs$|ddd|jddsz%FeedParser.__init__..Nr-cSsiS)Nrrrrrr.sF)r- _factory_kwdsrrZMessage_factoryZ EmailMessage TypeErrorr _input _msgstack _parsegenr(_parse_cur_last _headersonly)rr0r-r)rrrs"        zFeedParser.__init__cCs d|_dS)NT)r8)rrrr_set_headersonlyszFeedParser._set_headersonlycCs|jj||jdS)zPush more data into the parser.N)r2r$ _call_parse)rr"rrrfeedszFeedParser.feedc Cs'y|jWntk r"YnXdS)N)r5r')rrrrr:s zFeedParser._call_parsecCsh|jj|j|j}|jdkrd|j rdtj}|jj ||n|S)zz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$TFendlineseprr)rGrFrHrr).rDr2rheaderREmatchNLCRErZ MissingHeaderBodySeparatorDefectr-r?r6rr_parse_headersr8rZ set_payload EMPTYSTRINGrrBrr4r=rr>Z get_boundaryZNoBoundaryInMultipartDefectgetlowerZ-InvalidMultipartContentTransferEncodingDefectrecompileescapegroup NLCRE_eolsearchlenpreambler7epilogueZ_payload isinstancestrZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefect NLCRE_bol)rZheadersrrAr%rErCboundaryZ separatorZ boundaryreZcapturing_preamblerYrJZclose_boundary_seenmoZlastlineZeolmorZrIZpayload firstlineZbolmorrrr4sf                         '                 ) zFeedParser._parsegenc Csd}g}xt|D]\}}|ddkry|sftj|}|jj|j|qn|j|qn|r|jj|jj|dg}}n|j drf|dkrt j |}|r|dt |j d }n|jj|qqf|t |dkr>|jj|dStj|}|jjj|qn|jd}|dkrtjd}|jjj|qn|d|}|g}qW|r|jj|jj|ndS)Nrrz zFrom r:zMissing header name.) enumeraterZ#FirstHeaderLineIsContinuationDefectr-r?r6rZset_rawZheader_source_parse startswithrVrWrXrUZ set_unixfromr2rZMisplacedEnvelopeHeaderDefectZdefectsfindZInvalidHeaderDefect) rr%Z lastheaderZ lastvaluelinenorrAr_irrrrNsF  #  zFeedParser._parse_headers)r)r*r+r,rrr9r;r:rrDr=r4rNrrrrrs !     cs(eZdZdZfddZS)rz(Like FeedParser, but feed accepts bytes.cs tj|jdddS)Nasciisurrogateescape)superr;decode)rr") __class__rrr;szBytesFeedParser.feed)r)r*r+r,r;rr)rkrrs )r,__all__rRZemailrrZemail._policybaserrSrMr]rVZ NLCRE_crackrKrONLobjectrr rrrrrrs"   \