3 \�X�@s�dZddgZddlZddlmZddlmZddlmZddl m Z ej d �Z ej d �Z ej d �Zej d �Zej 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�(/usr/lib64/python3.6/email/feedparser.py�__init__5s zBufferedSubFile.__init__cCs|jj|�dS)N)r�append)rZpredrrr�push_eof_matcher@sz BufferedSubFile.push_eof_matchercCs |jj�S)N)r�pop)rrrr�pop_eof_matcherCszBufferedSubFile.pop_eof_matchercCs<|jjd�|j|jj��|jjd�|jj�d|_dS)NrT)r �seek� pushlines� readlines�truncater)rrrr�closeFs    zBufferedSubFile.closecCsN|js|jrdStS|jj�}x*t|j�D]}||�r*|jj|�dSq*W|S)Nr)r r� NeedMoreData�popleft�reversedr� appendleft)r�lineZateofrrr�readlineNs  zBufferedSubFile.readlinecCs|tk s t�|jj|�dS)N)r�AssertionErrorr r )rr!rrr� unreadline`s zBufferedSubFile.unreadlinecCsx|jj|�d|kr d|kr dS|jjd�|jj�}|jjd�|jj�|djd�sj|jj|j��|j|�dS)z$Push some new data into this object.r � Nr������)r �writerrr�endswithrr)r�data�partsrrr�pushes     zBufferedSubFile.pushcCs|jj|�dS)N)r �extend)r�linesrrrrzszBufferedSubFile.pushlinescCs|S)Nr)rrrr�__iter__}szBufferedSubFile.__iter__cCs|j�}|dkrt�|S)Nr)r"� StopIteration)rr!rrr�__next__�szBufferedSubFile.__next__N)�__name__� __module__� __qualname__�__doc__rrrrr"r$r,rr/r1rrrrr -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)�policyc Cs�||_d|_|dkr<|jdkr2ddlm}||_qn|j|_n2||_y||jd�Wntk rld|_YnXt�|_g|_ |j �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)�Message)r6T)r6�_old_style_factoryZmessage_factoryZ email.messager7�_factory� TypeErrorr �_input� _msgstack� _parsegenr1�_parse�_cur�_last� _headersonly)rr9r6r7rrrr�s$     zFeedParser.__init__cCs d|_dS)NT)rA)rrrr�_set_headersonly�szFeedParser._set_headersonlycCs|jj|�|j�dS)zPush more data into the parser.N)r;r,� _call_parse)rr*rrr�feed�s zFeedParser.feedc Cs&y |j�Wntk r YnXdS)N)r>r0)rrrrrC�s zFeedParser._call_parsecCsV|jj�|j�|j�}|j s&t�|j�dkrR|j� rRtj �}|j j ||�|S)zz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$TF�end�linesepr&r)rQrPrRr'r')/rMr;r�headerRE�match�NLCRErZ MissingHeaderBodySeparatorDefectr6rHr?r$r�_parse_headersrAr"Z set_payload� EMPTYSTRING�joinrKrr=rFrrGZ get_boundaryZNoBoundaryInMultipartDefect�get�lowerZ-InvalidMultipartContentTransferEncodingDefect�re�compile�escape�group� NLCRE_eol�search�len�preambler@�epilogueZ_payload� isinstance�strr#ZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefect� NLCRE_bol)rZheadersr!rJr.rNrL�boundaryZ separatorZ boundaryreZcapturing_preamblerdrTZclose_boundary_seen�moZlastlineZeolmorerSZpayload� firstlineZbolmorrrr=�sh                                                 zFeedParser._parsegenc Cspd}g}�xFt|�D�]8\}}|ddkrV|sJtj|�}|jj|j|�q|j|�q|rx|jj|jj|��dg}}|j d��r�|dkr�t j |�}|r�|dt |j d�� �}|jj|�qn:|t |�dkr�|jj|�dStj|�}|jjj|�q|jd�}|dk�r*tjd�}|jjj|�q|dk�ss(         [