B Rßvj/mã@s²ddgZddlZddlmZddlmZddlmZddlm Z e  d¡Z e  d ¡Z e  d ¡Z e  d ¡Ze  d ¡Zd Zd ZeƒZGdd„deƒZGdd„dƒZGdd„deƒZdS)Ú FeedParserÚBytesFeedParseréN)Úerrors)Úcompat32)Údeque)ÚStringIOz \r\n|\r|\nz (\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ])ÚÚ c@s\eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dS)ÚBufferedSubFilecCs$tdd|_tƒ|_g|_d|_dS)Nr)ÚnewlineF)rÚ_partialrÚ_linesÚ _eofstackÚ_closed)Úself©rú3/opt/alt/python37/lib/python3.7/email/feedparser.pyÚ__init__5s zBufferedSubFile.__init__cCs|j |¡dS)N)rÚappend)rZpredrrrÚpush_eof_matcher@sz BufferedSubFile.push_eof_matchercCs |j ¡S)N)rÚpop)rrrrÚpop_eof_matcherCszBufferedSubFile.pop_eof_matchercCs<|j d¡| |j ¡¡|j d¡|j ¡d|_dS)NrT)r ÚseekÚ pushlinesÚ readlinesÚtruncater)rrrrÚcloseFs    zBufferedSubFile.closecCsN|js|jrdStS|j ¡}x*t|jƒD]}||ƒr*|j |¡dSq*W|S)Nr)r rÚ NeedMoreDataÚpopleftÚreversedrÚ appendleft)rÚlineZateofrrrÚreadlineNs  zBufferedSubFile.readlinecCs|j |¡dS)N)r r )rr!rrrÚ unreadline`szBufferedSubFile.unreadlinecCsx|j |¡d|kr d|kr dS|j d¡|j ¡}|j d¡|j ¡|d d¡sj|j | ¡¡| |¡dS)Nr ú réÿÿÿÿ)r ÚwriterrrÚendswithrr)rÚdataÚpartsrrrÚpushes     zBufferedSubFile.pushcCs|j |¡dS)N)r Úextend)rÚlinesrrrrzszBufferedSubFile.pushlinescCs|S)Nr)rrrrÚ__iter__}szBufferedSubFile.__iter__cCs| ¡}|dkrt‚|S)Nr)r"Ú StopIteration)rr!rrrÚ__next__€szBufferedSubFile.__next__N) Ú__name__Ú __module__Ú __qualname__rrrrr"r#r*rr-r/rrrrr -s r c@s\eZdZdedœdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dS)rN)ÚpolicycCsž||_d|_|dkr<|jdkr2ddlm}||_qn|j|_n2||_y||jdWntk rld|_YnXtƒ|_g|_ |  ¡j |_ d|_ d|_d|_dS)NFr)ÚMessage)r3T)r3Ú_old_style_factoryZmessage_factoryZ email.messager4Ú_factoryÚ TypeErrorr Ú_inputÚ _msgstackÚ _parsegenr/Ú_parseÚ_curÚ_lastÚ _headersonly)rr6r3r4rrrr‹s$     zFeedParser.__init__cCs d|_dS)NT)r>)rrrrÚ_set_headersonlyªszFeedParser._set_headersonlycCs|j |¡| ¡dS)N)r8r*Ú _call_parse)rr(rrrÚfeed­s zFeedParser.feedcCs&y | ¡Wntk r YnXdS)N)r;r.)rrrrr@²s zFeedParser._call_parsecCsH|j ¡| ¡| ¡}| ¡dkrD| ¡sDt ¡}|j  ||¡|S)NÚ multipart) r8rr@Ú _pop_messageÚget_content_maintypeZ is_multipartrZ!MultipartInvariantViolationDefectr3Ú handle_defect)rÚrootÚdefectrrrr¸s  zFeedParser.closecCsn|jr| ¡}n|j|jd}|jr<|j ¡dkr<| d¡|jrR|jd |¡|j |¡||_||_ dS)N)r3zmultipart/digestzmessage/rfc822r%) r5r6r3r<Úget_content_typeZset_default_typer9Zattachrr=)rÚmsgrrrÚ _new_messageÅs   zFeedParser._new_messagecCs(|j ¡}|jr|jd|_nd|_|S)Nr%)r9rr<)rÚretvalrrrrCÒs  zFeedParser._pop_messageccs:| ¡g}xb|jD]X}|tkr(tVqt |¡sbt |¡s`t ¡}|j  |j |¡|j  |¡P|  |¡qW|  |¡|jrÎg}x2|j ¡}|tkr tVq†|dkrªP|  |¡q†W|j  t |¡¡dS|j  ¡dkr–x²|j tj¡x$| ¡D]}|tkrtVqøPqøW| ¡}|j ¡x&|j ¡}|tkrFtVq(Pq(Wx&|j ¡}|tkrntVqPPqPW|dkr‚P|j  |¡qàWdS|j  ¡dkrÜx(| ¡D]}|tkrÈtVq°Pq°W| ¡dS|j  ¡dkrð|j  ¡}|dkrbt ¡}|j  |j |¡g}x.|jD]$}|tkrz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$TFÚendÚlinesepr%r).rJr8rÚheaderREÚmatchÚNLCRErZ MissingHeaderBodySeparatorDefectr3rEr<r#rÚ_parse_headersr>r"Z set_payloadÚ EMPTYSTRINGÚjoinrHrr:rCrrDZ get_boundaryZNoBoundaryInMultipartDefectÚstrÚgetÚlowerZ-InvalidMultipartContentTransferEncodingDefectÚreÚcompileÚescapeÚgroupÚ NLCRE_eolÚsearchÚlenÚpreambler=ÚepilogueZ_payloadÚ isinstanceZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefectÚ NLCRE_bol)rZheadersr!rGr,rKrIÚboundaryZ separatorZ boundaryreZcapturing_preambler`rOZclose_boundary_seenÚmoZlastlineZeolmorarNZpayloadÚ firstlineZbolmorrrr:Úsf                                                zFeedParser._parsegenc Cs\d}g}x2t|ƒD]$\}}|ddkrV|sJt |¡}|j |j|¡q| |¡q|rx|jj|j |¡Ždg}}|  d¡rú|dkrÀt   |¡}|r°|dt |  d¡ƒ …}|j |¡qn:|t |ƒdkrà|j |¡dSt |¡}|jj |¡q| d¡}|dkr(t d¡}|jj |¡q|d|…}|g}qW|rX|jj|j |¡ŽdS)Nrrz zFrom éú:zMissing header name.)Ú enumeraterZ#FirstHeaderLineIsContinuationDefectr3rEr<rZset_rawZheader_source_parseÚ startswithr]r^r_r\Z set_unixfromr8r#ZMisplacedEnvelopeHeaderDefectZdefectsÚfindZInvalidHeaderDefect) rr,Z lastheaderZ lastvalueÚlinenor!rGreÚirrrrS×sF              zFeedParser._parse_headers)N) r0r1r2rrr?rAr@rrJrCr:rSrrrrrˆs  ~cseZdZ‡fdd„Z‡ZS)rcstƒ | dd¡¡dS)NÚasciiÚsurrogateescape)ÚsuperrAÚdecode)rr()Ú __class__rrrAszBytesFeedParser.feed)r0r1r2rAÚ __classcell__rr)rrrrs)Ú__all__rYZemailrZemail._policybaserÚ collectionsrÚiorrZrRrcr]Z NLCRE_crackrPrTÚNLÚobjectrr rrrrrrÚs&         [