o ?OgüXã@s¶dZddgZddlZddlmZddlmZddlmZddl m Z e  d ¡Z e  d ¡Z e  d ¡Ze  d ¡Ze  d ¡Zd ZdZeƒZGdd„deƒZGdd„dƒZGdd„deƒZdS)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. Ú 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`eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z 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$tdd|_tƒ|_g|_d|_dS)Nr)ÚnewlineF)rÚ_partialrÚ_linesÚ _eofstackÚ_closed©Úself©rú7/opt/alt/python310/lib64/python3.10/email/feedparser.pyÚ__init__5s  zBufferedSubFile.__init__cCó|j |¡dS©N)rÚappend)rZpredrrrÚpush_eof_matcher@óz BufferedSubFile.push_eof_matchercCs |j ¡Sr)rÚpoprrrrÚpop_eof_matcherCó zBufferedSubFile.pop_eof_matchercCs<|j d¡| |j ¡¡|j d¡|j ¡d|_dS)NrT)r ÚseekÚ pushlinesÚ readlinesÚtruncaterrrrrÚcloseFs    zBufferedSubFile.closecCsL|js |jrdStS|j ¡}t|jƒD]}||ƒr#|j |¡dSq|S©Nr)r rÚ NeedMoreDataÚpopleftÚreversedrÚ appendleft)rÚlineZateofrrrÚreadlineNs  ýzBufferedSubFile.readlinecCs|tusJ‚|j |¡dSr)r#r r&©rr'rrrÚ unreadline`s zBufferedSubFile.unreadlinecCsx|j |¡d|vrd|vrdS|j d¡|j ¡}|j d¡|j ¡|d d¡s5|j | ¡¡| |¡dS)z$Push some new data into this object.r ú Nréÿÿÿÿ)r Úwriterrr Úendswithrr)rÚdataÚpartsrrrÚpushes     zBufferedSubFile.pushcCrr)r Úextend)rÚlinesrrrrzrzBufferedSubFile.pushlinescCs|SrrrrrrÚ__iter__}szBufferedSubFile.__iter__cCs| ¡}|dkr t‚|Sr")r(Ú StopIterationr)rrrÚ__next__€szBufferedSubFile.__next__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr!r(r*r1rr4r6rrrrr -s  r c@s`eZdZdZdedœdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dS)rzA feed-style parser of email.N©ÚpolicycCsœ||_d|_|dur|jdurddlm}||_n|j|_n||_z||jdWn ty5d|_Ynwtƒ|_g|_ |  ¡j |_ d|_ d|_d|_dS)a_factory is called with no arguments to create a new message obj The policy keyword specifies a policy object that controls a number of aspects of the parser's operation. The default policy maintains backward compatibility. FNr)ÚMessager;T)r<Ú_old_style_factoryZmessage_factoryZ email.messager=Ú_factoryÚ TypeErrorr Ú_inputÚ _msgstackÚ _parsegenr6Ú_parseÚ_curÚ_lastÚ _headersonly)rr?r<r=rrrr‹s&     þ  zFeedParser.__init__cCs d|_dS)NT)rGrrrrÚ_set_headersonlyªrzFeedParser._set_headersonlycCs|j |¡| ¡dS)zPush more data into the parser.N)rAr1Ú _call_parse©rr/rrrÚfeed­s  zFeedParser.feedcCs$z| ¡WdStyYdSwr)rDr5rrrrrI²s  ÿzFeedParser._call_parsecCsR|j ¡| ¡| ¡}|jrJ‚| ¡dkr'| ¡s't ¡}|j   ||¡|S)zr?r<rEÚget_content_typeZset_default_typerBZattachrrF)rÚmsgrrrÚ _new_messageÅs    zFeedParser._new_messagecCs*|j ¡}|jr|jd|_|Sd|_|S)Nr,)rBrrE)rÚretvalrrrrMÒs  ÿzFeedParser._pop_messageccsð| ¡g}|jD]-}|turtVq t |¡s2t |¡s0t ¡}|j  |j |¡|j  |¡n|  |¡q |  |¡|jrfg} |j ¡}|turPtVqB|dkrUn|  |¡qC|j  t |¡¡dS|j  ¡dkr¹ |j tj¡| ¡D] }|turƒtVqy| ¡}|j ¡ |j ¡}|tur›tVq |j ¡}|turªtVqœ |dkr² dS|j  |¡qn|j  ¡dkrÕ| ¡D] }|turÎtVqÄ| ¡dS|j  ¡dkrÕ|j  ¡}|durt ¡}|j  |j |¡g}|jD]}|turtVqø|  |¡qø|j  t |¡¡dSt|j  dd¡ƒ ¡dvr.t ¡}|j  |j |¡d |}t  d t !|¡d ¡} d} g} d } d } |j ¡}|turVtVqF|dkr\nð|  |¡}|r@| "d ¡rrd} | "d¡} nÚ| r£| r™| d}t# $|¡}|r’|dt%| "d¡ƒ …| d<t | ¡|j _&d } |j  |¡qF |j ¡}|tur³tVq£|  |¡}|sÂ|j  |¡nq¤|j | j¡| ¡D] }|turÛtVqÏ|j' ¡dkr|j'j(}|dkròd|j'_(n@|durt# $|¡}|rt%| "d¡ƒ}|d| …|j'_(n"|j'j)}t*|tƒr2t# $|¡}|r2|dt%| "d¡ƒ …}||j'_)|j ¡| ¡|j |_'n | sEJ‚|   |¡qG| r€t +¡}|j  |j |¡|j  t | ¡¡g}|jD] }|turutVqiqit |¡|j _(dS| s‘t ,¡}|j  |j |¡dS| r˜dg}ng}|jD]}|tur©tVq|  |¡q|rÌ|d}t- |¡}|rÌ|t%| "d¡ƒd…|d<t |¡|j _(dSg}|jD]}|turætVqÚ|  |¡qÚ|j  t |¡¡dS)NTrzmessage/delivery-statusÚmessagerLzcontent-transfer-encodingÚ8bit)Z7bitrWZbinaryz--z(?Pz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$FÚendÚlinesepr,r).rTrAr#ÚheaderREÚmatchÚNLCRErZ MissingHeaderBodySeparatorDefectr<rOrEr*rÚ_parse_headersrGr(Z set_payloadÚ EMPTYSTRINGÚjoinrRrrCrMrrNZ get_boundaryZNoBoundaryInMultipartDefectÚstrÚgetÚlowerZ-InvalidMultipartContentTransferEncodingDefectÚreÚcompileÚescapeÚgroupÚ NLCRE_eolÚsearchÚlenÚpreamblerFÚepilogueZ_payloadÚ isinstanceZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefectÚ NLCRE_bol)rZheadersr'rQr3rUrSÚboundaryZ separatorZ boundaryreZcapturing_preamblerjrYZclose_boundary_seenÚmoZlastlineZeolmorkrXZpayloadÚ firstlineZbolmorrrrCÚs|€        ù     ÿá!      ÿ ÿÿ            ø      €      ±S  þ     zFeedParser._parsegenc Csdd}g}t|ƒD]™\}}|ddvr(|s"t |¡}|j |j|¡q| |¡q|r9|jj|j |¡Ždg}}|  d¡rz|dkr\t   |¡}|rU|dt |  d¡ƒ …}|j |¡q|t |ƒdkrm|j |¡dSt |¡}|jj |¡q| d¡}|dkrt d¡}|jj |¡q|dks˜Jdƒ‚|d|…}|g}q|r°|jj|j |¡ŽdSdS) Nrrz zFrom éú:zMissing header name.z3_parse_headers fed line with no : and no leading WS)Ú enumeraterZ#FirstHeaderLineIsContinuationDefectr<rOrErZset_rawZheader_source_parseÚ startswithrgrhrirfZ set_unixfromrAr*ZMisplacedEnvelopeHeaderDefectZdefectsÚfindZInvalidHeaderDefect) rr3Z lastheaderZ lastvalueÚlinenor'rQroÚirrrr]×sJ            ÿzFeedParser._parse_headersr)r7r8r9r:rrrHrKrIr!rTrMrCr]rrrrrˆs   ~cs eZdZdZ‡fdd„Z‡ZS)rz(Like FeedParser, but feed accepts bytes.cstƒ | dd¡¡dS)NÚasciiÚsurrogateescape)ÚsuperrKÚdecoderJ©Ú __class__rrrKszBytesFeedParser.feed)r7r8r9r:rKÚ __classcell__rrr|rrs)r:Ú__all__rcZemailrZemail._policybaserÚ collectionsrÚiorrdr\rmrgZ NLCRE_crackrZr^ÚNLÚobjectr#r rrrrrrÚs*         [