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&|tk st|jj|dS)N)rAssertionErrorr 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)rr1r.r)rrrs"        zFeedParser.__init__cCs d|_dS)NT)r9)rrrr_set_headersonlyszFeedParser._set_headersonlycCs|jj||jdS)zPush more data into the parser.N)r3r% _call_parse)rr#rrrfeedszFeedParser.feedc Cs'y|jWntk r"YnXdS)N)r6r()rrrrr;s zFeedParser._call_parsecCsx|jj|j|j}|j s3t|jdkrt|j rttj }|j j ||n|S)zs   zFeedParser._pop_messageccs4|jg}x|jD]}|tkr7tVqntj|stj|stj}|jj |j ||jj |nPn|j |qW|j ||jr"g}xG|jj}|tkrtVqn|dkrPn|j |qW|j jtj|dS|j jdkrx|jjtjx,|jD]}|tkrwtVqZnPqZW|j}|jjx+|jj}|tkrtVqnPqWx+|jj}|tkrtVqnPqW|dkrPn|jj |q:WdS|j jdkrkx,|jD]}|tkrXtVq;nPq;W|jdS|j jdkr|j j}|dkrtj}|jj |j |g}x5|jD]*}|tkrtVqn|j |qW|j jtj|dS|j jddjdkr^tj}|jj |j |nd |}tjd tj |d } d } g} d } d } x|jj}|tkrtVqn|dkrPn| j|}|rN|j!drd } |j!d} Pn| r| r| d}t"j#|}|rh|dt$|j!d | dz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$TFendlineseprr)rHrGrIrr)/rEr3rheaderREmatchNLCRErZ MissingHeaderBodySeparatorDefectr.r@r7r r_parse_headersr9rZ set_payload EMPTYSTRINGrrCrr5r>rr?Z get_boundaryZNoBoundaryInMultipartDefectgetlowerZ-InvalidMultipartContentTransferEncodingDefectrecompileescapegroup NLCRE_eolsearchlenpreambler8epilogueZ_payload isinstancestrrZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefect NLCRE_bol)rZheadersrrBr&rFrDboundaryZ separatorZ boundaryreZcapturing_preamblerZrKZclose_boundary_seenmoZlastlineZeolmor[rJZpayload firstlineZbolmorrrr5sh                         '                  ) 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|dkstd|d|}|g}qW|r|jj|jj|ndS) Nrrz zFrom r:zMissing header name.z3_parse_headers fed line with no : and no leading WS) enumeraterZ#FirstHeaderLineIsContinuationDefectr.r@r7rZset_rawZheader_source_parse startswithrWrXrYrVZ set_unixfromr3r ZMisplacedEnvelopeHeaderDefectZdefectsfindZInvalidHeaderDefectr) rr&Z lastheaderZ lastvaluelinenorrBr`irrrrOsH  #  zFeedParser._parse_headers)r*r+r,r-rrr:r<r;rrEr>r5rOrrrrrs !     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)rlrrs )r-__all__rSZemailrrZemail._policybaserrTrNr^rWZ NLCRE_crackrLrPNLobjectrr rrrrrrs"   \