Edit File: feedparser.cpython-36.pyc
3 � \�X������������������@���s����d�Z�ddgZddlZddlmZ�ddlmZ�ddlmZ�ddl m Z �ejd �Zejd �Z ejd�Zejd �Zejd�Zd ZdZe��ZG�dd��de�ZG�dd��d�ZG�dd��de�ZdS�)a��FeedParser - 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`���e�Zd�ZdZdd��Zdd��Zdd��Zdd ��Zd d��Zdd ��Z dd��Z dd��Zdd��Zdd��Z dS�)�BufferedSubFileak��A 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. c�������������C���s$���t�dd�|�_t��|�_g�|�_d|�_d�S�)Nr���)�newlineF)r����_partialr����_lines� _eofstack�_closed)�self��r����(/usr/lib64/python3.6/email/feedparser.py�__init__5���s����zBufferedSubFile.__init__c�������������C���s���|�j�j|��d�S�)N)r����append)r���Zpredr���r���r����push_eof_matcher@���s����z BufferedSubFile.push_eof_matcherc�������������C���s ���|�j�j��S�)N)r����pop)r���r���r���r����pop_eof_matcherC���s����zBufferedSubFile.pop_eof_matcherc�������������C���s<���|�j�jd��|�j|�j�j����|�j�jd��|�j�j���d|�_d�S�)Nr���T)r����seek� pushlines� readlines�truncater���)r���r���r���r����closeF���s ���� zBufferedSubFile.closec�������������C���sN���|�j�s|�jrdS�tS�|�j�j��}x*t|�j�D�]}||�r*|�j�j|��dS�q*W�|S�)Nr���)r ���r����NeedMoreData�popleft�reversedr���� appendleft)r����lineZateofr���r���r����readlineN���s���� zBufferedSubFile.readlinec�������������C���s���|t�k st�|�jj|��d�S�)N)r����AssertionErrorr ���r ���)r���r!���r���r���r���� unreadline`���s����zBufferedSubFile.unreadlinec�������������C���sx���|�j�j|��d|kr d|kr dS�|�j�jd��|�j�j��}|�j�jd��|�j�j���|d�jd�sj|�j�j|j����|�j|��dS�)z$Push some new data into this object.r ���� Nr����������)r����writer���r���r����endswithr���r���)r����data�partsr���r���r����pushe���s���� zBufferedSubFile.pushc�������������C���s���|�j�j|��d�S�)N)r ����extend)r����linesr���r���r���r���z���s����zBufferedSubFile.pushlinesc�������������C���s���|�S�)Nr���)r���r���r���r����__iter__}���s����zBufferedSubFile.__iter__c�������������C���s���|�j���}|dkrt�|S�)Nr���)r"���� StopIteration)r���r!���r���r���r����__next__����s����zBufferedSubFile.__next__N)�__name__� __module__�__qualname__�__doc__r���r���r���r���r"���r$���r,���r���r/���r1���r���r���r���r���r ���-���s���r ���c���������������@���s`���e�Zd�ZdZded�dd�Zdd��Zdd ��Zd d��Zdd ��Z dd��Z dd��Zdd��Zdd��Z dS�)r���zA feed-style parser of email.N)�policyc������������C���s����||�_�d|�_|dkr<|jdkr2ddlm}�||�_qn|j|�_n2||�_y||�j�d��W�n�tk rl���d|�_Y�nX�t��|�_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)r6���T)r6����_old_style_factoryZmessage_factoryZ email.messager7����_factory� TypeErrorr ����_input� _msgstack� _parsegenr1����_parse�_cur�_last�_headersonly)r���r9���r6���r7���r���r���r���r�������s$���� zFeedParser.__init__c�������������C���s ���d|�_�d�S�)NT)rA���)r���r���r���r����_set_headersonly����s����zFeedParser._set_headersonlyc�������������C���s���|�j�j|��|�j���dS�)zPush more data into the parser.N)r;���r,����_call_parse)r���r*���r���r���r����feed����s����zFeedParser.feedc�������������C���s&���y|�j����W�n�tk r ���Y�nX�d�S�)N)r>���r0���)r���r���r���r���rC�������s����zFeedParser._call_parsec�������������C���sV���|�j�j���|�j���|�j��}|�j�s&t�|j��dkrR|j���rRtj ��}|�j j||��|S�)z<Parse all remaining data and return the root message object.� multipart)r;���r���rC����_pop_messager<���r#����get_content_maintypeZis_multipartr���Z!MultipartInvariantViolationDefectr6���� handle_defect)r����root�defectr���r���r���r�������s���� zFeedParser.closec�������������C���sn���|�j�r|�j��}n|�j|�jd�}|�jr<|�jj��dkr<|jd��|�jrR|�jd�j|��|�jj|��||�_||�_ d�S�)N)r6���zmultipart/digestzmessage/rfc822r&���r'���) r8���r9���r6���r?����get_content_typeZset_default_typer<���Zattachr���r@���)r����msgr���r���r����_new_message����s���� zFeedParser._new_messagec�������������C���s(���|�j�j��}|�j�r|�j�d�|�_nd�|�_|S�)Nr&���r'���)r<���r���r?���)r����retvalr���r���r���rF�������s ���� zFeedParser._pop_messagec�������������c���s@��|�j����g�}xb|�jD�]X}|tkr(tV��qtj|�sbtj|�s`tj��}|�jj |�j |��|�jj|��P�|j|��qW�|�j |��|�jr�g�}x2|�jj��}|tkr�tV��q�|dkr�P�|j|��q�W�|�j jtj|���d�S�|�j j��dk�r�x�|�jjtj��x$|�j��D�]}|tk�rtV��q�P�q�W�|�j��}|�jj���x&|�jj��}|tk�rFtV���q(P��q(W�x&|�jj��}|tk�rntV���qPP��qPW�|dk�r�P�|�jj|��q�W�d�S�|�j j��dk�r�x(|�j��D�]}|tk�r�tV���q�P��q�W�|�j���d�S�|�j j��dk�r�|�j j��}|d�k�rbtj��}|�jj |�j |��g�}x.|�jD�]$}|tk�r<tV���q$|j|���q$W�|�j jtj|���d�S�|�j jdd�j��dk�r�tj��}|�jj |�j |��d |�}tjd tj |��d��} d} g�}d }d } �x|�jj��}|tk�r�tV���q�|dk�r�P�| j|�}|�r�|j!d��rd} |j!d�}P�| �r~|�rj|d�}t"j#|�}|�r\|d�t$|j!d�����|d<�tj|�|�j _%d } |�jj|���q�xB|�jj��}|tk�r�tV���q�| j|�}|�s�|�jj|��P��q�W�|�jj| j��x(|�j��D�]}|tk�r�tV���q�P��q�W�|�j&j��dk�rb|�j&j'}|dk�r&d�|�j&_'n:|d�k �r�t"j#|�}|�r�t$|j!d��}|d�|���|�j&_'nD|�j&j(}t)|t*��r�t"j#|�}|�r�|d�t$|j!d�����}||�j&_(|�jj���|�j���|�j |�_&n| �s�t+�|j|���q�W�| �rHtj,��}|�jj |�j |��|�j jtj|���g�}x$|�jD�]}|tk�rtV���q�qW�tj|�|�j _'d�S�| �sjtj-��}|�jj |�j |��d�S�|�rxdg}ng�}x.|�jD�]$}|tk�r�tV���q�|j|���q�W�|�r�|d�}t.j|�}|�r�|t$|j!d��d���|d<�tj|�|�j _'d�S�g�}x.|�jD�]$}|tk�rtV���q|j|���qW�|�j jtj|���d�S�)Nr���zmessage/delivery-status�messagerE���zcontent-transfer-encoding�8bit�7bit�binaryz--z(?P<sep>z4)(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$TF�end�linesepr&���r���)rQ���rP���rR���r'���r'���)/rM���r;���r����headerRE�match�NLCREr���Z MissingHeaderBodySeparatorDefectr6���rH���r?���r$���r����_parse_headersrA���r"���Zset_payload�EMPTYSTRING�joinrK���r���r=���rF���r���rG���Zget_boundaryZNoBoundaryInMultipartDefect�get�lowerZ-InvalidMultipartContentTransferEncodingDefect�re�compile�escape�group� NLCRE_eol�search�len�preambler@����epilogueZ_payload� isinstance�strr#���ZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefect� NLCRE_bol)r���Zheadersr!���rJ���r.���rN���rL����boundaryZ separatorZ boundaryreZcapturing_preamblerd���rT���Zclose_boundary_seen�moZlastlineZeolmore���rS���Zpayload� firstlineZbolmor���r���r���r=�������sh��� zFeedParser._parsegenc������� ������C���sp��d}g�}�xFt�|�D��]8\}}|d�dkrV|sJtj|�}|�jj|�j|��q|j|��q|rx|�jj|�jj|����dg��}}|j d���r�|dkr�t j|�}|r�|d�t|j d�����}|�jj|��qn:|t|�d�kr�|�jj|��d�S�tj|�}|�jjj|��q|jd�}|dk�r*tjd�}|�jjj|��q|dk�s<td��|d�|��}|g}qW�|�rl|�jj|�jj|����d�S�) Nr���r���z zFrom r&����:zMissing header name.z3_parse_headers fed line with no : and no leading WS)� enumerater���Z#FirstHeaderLineIsContinuationDefectr6���rH���r?���r���Zset_rawZheader_source_parse� startswithra���rb���rc���r`���Zset_unixfromr;���r$���ZMisplacedEnvelopeHeaderDefectZdefects�findZInvalidHeaderDefectr#���) r���r.���Z lastheaderZ lastvalue�linenor!���rJ���rj����ir���r���r���rX������sH���� zFeedParser._parse_headers)N)r2���r3���r4���r5���r���r���rB���rD���rC���r���rM���rF���r=���rX���r���r���r���r���r�������s��� �~c�������������������s ���e�Zd�ZdZ��fdd�Z���ZS�)r���z(Like FeedParser, but feed accepts bytes.c����������������s���t���j|jdd���d�S�)N�ascii�surrogateescape)�superrD����decode)r���r*���)� __class__r���r���rD�����s����zBytesFeedParser.feed)r2���r3���r4���r5���rD���� __classcell__r���r���)rv���r���r�����s���)r5����__all__r]���Zemailr���Zemail._policybaser����collectionsr����ior���r^���rW���rh���ra���ZNLCRE_crackrU���rY����NL�objectr���r ���r���r���r���r���r���r����<module>���s(��� [���