ž ¦ÿfåVc@sñdZddgZddlZddlmZddlmZddlmZejdƒZ ejd ƒZ ejd ƒZ ejd ƒZ ejd ƒZ d Zd ZeƒZGdd„deƒZGdd„dƒZGdd„deƒZdS(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. u FeedParseruBytesFeedParseriN(uerrors(umessage(ucompat32u | | u( | | )u ( | | )\Zu(^(From |[\041-\071\073-\176]{1,}:|[\t ])uu cBs’|EeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dS(uBufferedSubFileukA 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|_d|_dS(NuF(u_partialu_linesu _eofstackuFalseu_closed(uself((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu__init__4s   uBufferedSubFile.__init__cCs|jj|ƒdS(N(u _eofstackuappend(uselfupred((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyupush_eof_matcher>su BufferedSubFile.push_eof_matchercCs |jjƒS(N(u _eofstackupop(uself((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyupop_eof_matcherAsuBufferedSubFile.pop_eof_matchercCs)|jj|jƒd|_d|_dS(NuT(u_linesuappendu_partialuTrueu_closed(uself((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyucloseDs uBufferedSubFile.closecCsn|js|jrdStS|jjƒ}x>|jddd…D]&}||ƒr@|jj|ƒdSq@W|S(Nuiiÿÿÿÿ(u_linesu_closedu NeedMoreDataupopu _eofstackuappend(uselfulineuateof((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyureadlineJs   uBufferedSubFile.readlinecCs&|tk st‚|jj|ƒdS(N(u NeedMoreDatauAssertionErroru_linesuappend(uselfuline((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu unreadline\suBufferedSubFile.unreadlinecCsÔ|j|d}|_tj|ƒ}|jƒ|_|j rw|rw|djdƒrw|jdƒ|jƒ|_ng}xCtt|ƒdƒD]+}|j||d||ddƒq”W|j|ƒdS(u$Push some new data into this object.uiu iNiÿÿÿÿiþÿÿÿ( u_partialu NLCRE_crackusplitupopuendswithurangeulenuappendu pushlines(uselfudataupartsulinesui((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyupushas#)uBufferedSubFile.pushcCs$|ddd…|jdd…–su%FeedParser.__init__..cSsiS(N((((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu™sNF(u_factoryupolicyu _factory_kwdsu TypeErroruBufferedSubFileu_inputu _msgstacku _parsegenu__next__u_parseuNoneu_curu_lastuFalseu _headersonly(uselfu_factoryupolicy((uselfu5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu__init__Šs       uFeedParser.__init__cCs d|_dS(NT(uTrueu _headersonly(uself((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu_set_headersonly¢suFeedParser._set_headersonlycCs|jj|ƒ|jƒdS(uPush more data into the parser.N(u_inputupushu _call_parse(uselfudata((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyufeed¥suFeedParser.feedc Cs'y|jƒWntk r"YnXdS(N(u_parseu StopIteration(uself((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu _call_parseªs uFeedParser._call_parsecCsx|jjƒ|jƒ|jƒ}|j s3t‚|jƒdkrt|jƒ rttj ƒ}|j j ||ƒn|S(u<Parse all remaining data and return the root message object.u multipart( u_inputucloseu _call_parseu _pop_messageu _msgstackuAssertionErroruget_content_maintypeu is_multipartuerrorsu!MultipartInvariantViolationDefectupolicyu handle_defect(uselfurootudefect((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyuclose°s     uFeedParser.closecCs‰|j|jƒ}|jrC|jjƒdkrC|jdƒn|jrc|jdj|ƒn|jj|ƒ||_||_dS(Numultipart/digestumessage/rfc822iiÿÿÿÿ( u_factoryu _factory_kwdsu_curuget_content_typeuset_default_typeu _msgstackuattachuappendu_last(uselfumsg((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu _new_message½s  uFeedParser._new_messagecCs8|jjƒ}|jr+|jd|_n d|_|S(Niiÿÿÿÿ(u _msgstackupopu_curuNone(uselfuretval((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu _pop_messageÇs   uFeedParser._pop_messageccs.|jƒg}xŒ|jD]}|tkr7tVqntj|ƒsŽtj|ƒsŠtjƒ}|jj |j |ƒ|jj |ƒnPn|j |ƒqW|j |ƒ|jr!g}xF|jjƒ}|tkrätVq¾n|dkrôPn|j |ƒq¾|j jtj|ƒƒdS|j jƒdkrxØ|jjtjƒx,|jƒD]}|tkrvtVqYnPqYW|jƒ}|jjƒx*|jjƒ}|tkr½tVq—nPq—x*|jjƒ}|tkrêtVqÄnPqÄ|dkrþPn|jj |ƒq9dS|j jƒdkrgx,|jƒD]}|tkrTtVq7nPq7W|jƒdS|j jƒdkrÓ|j jƒ}|dkrtjƒ}|jj |j |ƒg}x5|jD]*}|tkrætVqÉn|j |ƒqÉW|j jtj|ƒƒdS|j jddƒjƒdkrZtjƒ}|jj |j |ƒnd |}tj d tj!|ƒd ƒ} d} g} d} d} xÆ|jjƒ}|tkrÅtVqŸn|dkrÕPn| j|ƒ}|rI|j$d ƒrd} |j$d ƒ} Pn| r˜| r|| d}t%j&|ƒ}|rd|dt'|j$dƒƒ …| dn|j |ƒq>W|rº|d}t1j|ƒ}|rº|t'|j$dƒƒd…|du4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$uendulinesepii(u7bitu8bitubinaryTFiÿÿÿÿiÿÿÿÿ(2u _new_messageu_inputu NeedMoreDatauheaderREumatchuNLCREuerrorsu MissingHeaderBodySeparatorDefectupolicyu handle_defectu_curu unreadlineuappendu_parse_headersu _headersonlyureadlineu set_payloadu EMPTYSTRINGujoinuget_content_typeupush_eof_matcheru _parsegenu _pop_messageupop_eof_matcheruget_content_maintypeu get_boundaryuNoneuNoBoundaryInMultipartDefectugetuloweru-InvalidMultipartContentTransferEncodingDefectureucompileuescapeuTrueuFalseugroupu NLCRE_eolusearchulenupreambleu_lastuepilogueu_payloadu isinstanceustruAssertionErroruStartBoundaryNotFoundDefectuCloseBoundaryNotFoundDefectu NLCRE_bol(uselfuheadersulineudefectulinesuretvalumsguboundaryu separatoru boundaryreucapturing_preambleupreambleulinesepuclose_boundary_seenumoulastlineueolmouepilogueuendupayloadu firstlineubolmo((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu _parsegenÏsh                         '                  ) uFeedParser._parsegenc CsÓd}g}x›t|ƒD]\}}|ddkry|sftj|ƒ}|jj|j|ƒqn|j|ƒqn|r«|jj|jj|ƒŒdg}}n|j dƒrf|dkrt j |ƒ}|rþ|dt |j dƒƒ …}n|jj|ƒqqf|t |ƒdkr>|jj|ƒdStj|ƒ}|jjj|ƒqn|jdƒ}|dkstdƒ‚|d|…}|g}qW|rÏ|jj|jj|ƒŒndS(Nuiu uFrom iu:u3_parse_headers fed line with no : and no leading WS(u enumerateuerrorsu#FirstHeaderLineIsContinuationDefectupolicyu handle_defectu_curuappenduset_rawuheader_source_parseu startswithu NLCRE_eolusearchulenugroupu set_unixfromu_inputu unreadlineuMisplacedEnvelopeHeaderDefectudefectsufinduAssertionError( uselfulinesu lastheaderu lastvalueulinenoulineudefectumoui((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu_parse_headersÌs@  # uFeedParser._parse_headersN(u__name__u __module__u __qualname__u__doc__ucompat32umessageuMessageu__init__u_set_headersonlyufeedu _call_parseucloseu _new_messageu _pop_messageu _parsegenu_parse_headers(u __locals__((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyu FeedParser‡s     ýcs,|EeZdZdZ‡fdd†Z‡S(uBytesFeedParseru(Like FeedParser, but feed accepts bytes.cs tƒj|jddƒƒdS(Nuasciiusurrogateescape(usuperufeedudecode(uselfudata(u __class__(u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyufeedsuBytesFeedParser.feed(u__name__u __module__u __qualname__u__doc__ufeed(u __locals__((u __class__u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyuBytesFeedParsers(u__doc__u__all__ureuemailuerrorsumessageuemail._policybaseucompat32ucompileuNLCREu NLCRE_bolu NLCRE_eolu NLCRE_crackuheaderREu EMPTYSTRINGuNLuobjectu NeedMoreDatauBufferedSubFileu FeedParseruBytesFeedParser(((u5/opt/alt/python33/lib64/python3.3/email/feedparser.pyus"   [ÿz