AlkantarClanX12

Your IP : 18.217.224.165


Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/email/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/email/__pycache__/feedparser.cpython-35.pyc



��Yf�Y�@sdZddgZddlZddlmZddlmZddlmZddlm	Z	dd	l
mZejd
�Z
ejd�Zejd�Zejd�Zejd
�ZdZdZe�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)�message)�compat32)�deque)�StringIOz
|
|
z(
|
|
)z
(
|
|
)\Zz%^(From |[\041-\071\073-\176]*:|[\t ])��
c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�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.
    cCs4tdd�|_t�|_g|_d|_dS)N�newliner	F)r�_partialr�_lines�	_eofstack�_closed)�self�r�5/opt/alt/python35/lib64/python3.5/email/feedparser.py�__init__6s	zBufferedSubFile.__init__cCs|jj|�dS)N)r�append)rZpredrrr�push_eof_matcherAsz BufferedSubFile.push_eof_matchercCs
|jj�S)N)r�pop)rrrr�pop_eof_matcherDszBufferedSubFile.pop_eof_matchercCsP|jjd�|j|jj��|jjd�|jj�d|_dS)NrT)r
�seek�	pushlines�	readlines�truncater)rrrr�closeGs

zBufferedSubFile.closecCsg|js|jrdStS|jj�}x7t|j�D]&}||�r9|jj|�dSq9W|S)Nr	)rr�NeedMoreData�popleft�reversedr�
appendleft)r�lineZateofrrr�readlineOs		zBufferedSubFile.readlinecCs&|tk	st�|jj|�dS)N)r�AssertionErrorrr!)rr"rrr�
unreadlineaszBufferedSubFile.unreadlinecCs�|jj|�d|kr,d|kr,dS|jjd�|jj�}|jjd�|jj�|djd�s�|jj|j��|j|�dS)z$Push some new data into this object.r
�
Nr����)r
�writerrr�endswithrr)r�data�partsrrr�pushfs
zBufferedSubFile.pushcCs|jj|�dS)N)r�extend)r�linesrrrr{szBufferedSubFile.pushlinescCs|S)Nr)rrrr�__iter__~szBufferedSubFile.__iter__cCs"|j�}|dkrt�|S)Nr	)r#�
StopIteration)rr"rrr�__next__�szBufferedSubFile.__next__N)�__name__�
__module__�__qualname__�__doc__rrrrr#r%r-rr0r2rrrrr.src@s�eZdZdZddedd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)rzA feed-style parser of email.N�policycCs�||_d|_|dkrK|jtkr<tj|_q�tj|_n;||_y|d|j�Wntk
r�d|_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.

        FNr7T)r7�_old_style_factoryrrZMessage�_factoryZEmailMessage�	TypeErrorr�_input�	_msgstack�	_parsegenr2�_parse�_cur�_last�_headersonly)rr9r7rrrr�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�szFeedParser.feedcCs'y|j�Wntk
r"YnXdS)N)r>r1)rrrrrC�s
zFeedParser._call_parsecCsu|jj�|j�|j�}|js3t�|j�dkrq|j�rqtj	�}|j
j||�|S)z<Parse all remaining data and return the root message object.�	multipart)r;rrC�_pop_messager<r$�get_content_maintypeZis_multipartrZ!MultipartInvariantViolationDefectr7�
handle_defect)r�root�defectrrrr�s


zFeedParser.closecCs�|jr|j�}n|jd|j�}|jrX|jj�dkrX|jd�|jru|jdj|�|jj|�||_||_	dS)Nr7zmultipart/digestzmessage/rfc822r'r()
r8r9r7r?�get_content_typeZset_default_typer<Zattachrr@)r�msgrrr�_new_message�s	
		zFeedParser._new_messagecCs8|jj�}|jr+|jd|_n	d|_|S)Nr'r()r<rr?)r�retvalrrrrF�s
		zFeedParser._pop_messageccs�|j�g}x�|jD]x}|tkr4tVqtj|�s�tj|�s�tj�}|jj	|j
|�|jj|�P|j|�qW|j
|�|jrg}xA|jj�}|tkr�tVq�|dkr�P|j|�q�W|j
jtj|��dS|j
j�dkr�x�|jjtj�x)|j�D]}|tkretVqKPqKW|j�}|jj�x(|jj�}|tkr�tVq�Pq�Wx(|jj�}|tkr�tVq�Pq�W|dkr�P|jj|�q+WdS|j
j�dkrMx)|j�D]}|tkr:tVq Pq W|j�dS|j
j�dkr�|j
j�}|dkr�tj�}|jj	|j
|�g}x2|jD]'}|tkr�tVq�|j|�q�W|j
jtj|��dS|j
jdd�j�dkr:tj�}|jj	|j
|�d	|}tjd
tj |�d�}	d}
g}d
}d
}
x�|jj�}|tkr�tVq|dkr�P|	j|�}|r|j!d�r�d}
|j!d�}P|
rf|rM|d}t"j#|�}|r8|dt$|j!d���|d<tj|�|j
_%d
}
|jj|�qxM|jj�}|tkr�tVqi|	j|�}|si|jj|�PqiW|jj|	j�x)|j�D]}|tkr�tVq�Pq�W|j&j�dkr�|j&j'}|dkr1d|j&_'q�|dk	r�t"j#|�}|r�t$|j!d��}|d|�|j&_'n\|j&j(}t)|t*�r�t"j#|�}|r�|dt$|j!d���}||j&_(|jj�|j�|j
|_&q|
st+�|j|�qW|
r�tj,�}|jj	|j
|�|j
jtj|��g}x%|jD]}|tkrqtVqqqqWtj|�|j
_'dS|
s�tj-�}|jj	|j
|�dS|r�dg}ng}x2|jD]'}|tkrtVq�|j|�q�W|ri|d}t.j|�}|ri|t$|j!d��d�|d<tj|�|j
_'dSg}x2|jD]'}|tkr�tVq�|j|�q�W|j
jtj|��dS)Nr	zmessage/delivery-statusrrEzcontent-transfer-encoding�8bit�7bit�binaryz--z(?P<sep>z4)(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$TF�end�linesepr'r)rPrOrQr(r()/rMr;r�headerRE�match�NLCRErZ MissingHeaderBodySeparatorDefectr7rHr?r%r�_parse_headersrAr#Zset_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_preamblercrSZclose_boundary_seen�moZlastlineZeolmordrRZpayload�	firstlineZbolmorrrr=�sh

	

	


$ 


#zFeedParser._parsegenc	Cs�d}g}x�t|�D]�\}}|ddkrs|sctj|�}|jj|j|�q|j|�q|r�|jj|jj|��dg}}|j	d�rW|dkrt
j|�}|r�|dt|j
d���}|jj|�qnO|t|�dkr2|jj|�dStj|�}|jjj|�q|jd�}|dkr�tjd�}|jjj|�q|dks�td��|d|�}|g}qW|r�|jj|jj|��dS)	Nr	rz 	zFrom r'�:zMissing header name.z3_parse_headers fed line with no : and no leading WS)�	enumeraterZ#FirstHeaderLineIsContinuationDefectr7rHr?rZset_rawZheader_source_parse�
startswithr`rarbr_Zset_unixfromr;r%ZMisplacedEnvelopeHeaderDefectZdefects�findZInvalidHeaderDefectr$)	rr/Z
lastheaderZ	lastvalue�linenor"rJri�irrrrW�sH

 
zFeedParser._parse_headers)r3r4r5r6rrrBrDrCrrMrFr=rWrrrrr�s!

�cs(eZdZdZ�fdd�Z�S)rz(Like FeedParser, but feed accepts bytes.cs t�j|jdd��dS)N�ascii�surrogateescape)�superrD�decode)rr+)�	__class__rrrDszBytesFeedParser.feed)r3r4r5r6rDrr)rurrs)r6�__all__r\ZemailrrZemail._policybaser�collectionsr�iorr]rVrgr`ZNLCRE_crackrTrX�NL�objectrrrrrrrr�<module>s&	[��