AlkantarClanX12

Your IP : 3.137.162.21


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__/message.cpython-35.opt-2.pyc



���]β�@s6dgZddlZddlZddlZddlZddlmZmZddlm	Z	ddlm
Z
ddlmZddlm
ZddlmZejZd	Zejd
�Zdd�Zdd
dd�Zdd�Zdd�ZGdd�d�ZGdd�de�ZGdd�de�ZdS)�Message�N)�BytesIO�StringIO)�utils)�errors)�compat32)�charset)�decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]cCsJt|�jd�\}}}|s4|j�dfS|j�|j�fS)N�;)�str�	partition�strip)�param�a�sep�b�r�,/opt/alt/python35/lib64/python3.5/message.py�_splitparamsrTcCs�|dk	r�t|�dkr�t|t�rf|d7}tj|d|d|d�}d||fSy|jd�Wn?tk
r�|d7}tj|dd�}d||fSYnX|s�tj|�r�d	|tj	|�fSd||fSn|SdS)
Nr�*��z%s=%s�asciizutf-8�z%s="%s")
�len�
isinstance�tuplerZencode_rfc2231�encode�UnicodeEncodeError�	tspecials�search�quote)r�valuer!rrr�_formatparam(s	
!

r#cCsIdt|�}g}x,|dd�dkrD|dd�}|jd�}xR|dkr�|jdd|�|jdd|�dr�|jd|d�}qQW|dkr�t|�}|d|�}d|kr|jd�}|d|�j�j�d||dd�j�}|j|j��||d�}qW|S)Nr
rr�"z\"r�=)r�find�countr�indexr
�lower�append)�sZplist�end�f�irrr�_parseparamJs ;8r/cCsBt|t�r1|d|dtj|d�fStj|�SdS)Nrrr)rrr�unquote)r"rrr�
_unquotevalue^s"r1c@s�eZdZedd�Zdd�Zddddd	�Zd
d�Zdddd
�Zdd�Z	dd�Z
dd�Zdd�Zdddd�Z
ddd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zdd0d1�Zd2d3�Zd4d5�Zdd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%ddHdIdJdK�Z&ddHdIdLdM�Z'dNdIddOddPdQ�Z(dHdIdRdS�Z)dNdIdTdU�Z*ddVdW�Z+ddXdY�Z,dZd[�Z-dd\d]�Z.dd^d_�Z/d`da�Z0ddbl1m2Z2dS)crcCsS||_g|_d|_d|_d|_d|_|_g|_d|_dS)Nz
text/plain)	�policy�_headers�	_unixfrom�_payload�_charsetZpreambleZepilogue�defects�
_default_type)�selfr2rrr�__init__ys						zMessage.__init__cCs
|j�S)N)�	as_string)r9rrr�__str__�szMessage.__str__FrNcCsoddlm}|dkr%|jn|}t�}||ddd|d|�}|j|d|�|j�S)Nr)�	Generator�mangle_from_F�maxheaderlenr2�unixfrom)�email.generatorr=r2r�flatten�getvalue)r9r@r?r2r=�fp�grrrr;�s			zMessage.as_stringcCs
|j�S)N)�as_bytes)r9rrr�	__bytes__�szMessage.__bytes__cCsiddlm}|dkr%|jn|}t�}||ddd|�}|j|d|�|j�S)Nr)�BytesGeneratorr>Fr2r@)rArHr2rrBrC)r9r@r2rHrDrErrrrF�s	zMessage.as_bytescCst|jt�S)N)rr5�list)r9rrr�is_multipart�szMessage.is_multipartcCs
||_dS)N)r4)r9r@rrr�set_unixfrom�szMessage.set_unixfromcCs|jS)N)r4)r9rrr�get_unixfrom�szMessage.get_unixfromcCsW|jdkr|g|_n5y|jj|�Wntk
rRtd��YnXdS)Nz=Attach is not valid on a message with a non-multipart payload)r5r*�AttributeError�	TypeError)r9�payloadrrr�attach�s
zMessage.attachcCsB|j�r4|rdS|dkr)|jS|j|S|dk	rlt|jt�rltdt|j���|j}t|jdd��j�}t|t�rRt	j
|�r|jdd�}|sRy"|j|j
dd�d�}WqRtk
r|jdd�}YqRXn=|rRy|jd�}Wn!tk
rQ|jd�}YnX|s\|S|d	krutj|�S|d
kr�tdj|j���\}}x!|D]}|jj||�q�W|S|dkr+t|�}	t�}
y$tj|	|
dd�|
j�SWntjk
r*|SYnXt|t�r>|S|S)NzExpected list, got %szcontent-transfer-encodingrr�surrogateescaper�replacezraw-unicode-escapezquoted-printable�base64��
x-uuencode�uuencode�uue�x-uue�quietT)rUrVrWrX)rJr5rrIrN�typer�getr)rZ_has_surrogatesr�decode�	get_param�LookupError�UnicodeError�quopriZdecodestringr	�join�
splitlinesr2Z
handle_defectr�uurC�Error)r9r.r\rO�cteZbpayloadr"r7ZdefectZin_fileZout_filerrr�get_payload�sV"	"


!
		zMessage.get_payloadcCs�t|d�rU|dkr(||_dSt|t�sCt|�}|j|j�}t|d�r||jdd�|_n	||_|dk	r�|j|�dS)Nrr\rrQ)�hasattrr5r�Charsetr�output_charsetr\�set_charset)r9rOrrrr�set_payload0s		zMessage.set_payloadcCs{|dkr&|jd�d|_dSt|t�sAt|�}||_d|krf|jdd�d|kr�|jddd|j��n|jd|j��||j�kr�|j|j�|_d|krw|j	�}y||�Wn�t
k
rv|j}|rPy|jdd�}Wn$tk
rO|j|j
�}YnX|j|�|_|jd|�YnXdS)	NrzMIME-Versionz1.0zContent-Typez
text/plainzContent-Transfer-EncodingrrQ)�	del_paramr6rrh�
add_headerZget_output_charset�	set_paramZbody_encoder5Zget_body_encodingrNrr_ri)r9rrerOrrrrjDs8
		
	
zMessage.set_charsetcCs|jS)N)r6)r9rrr�get_charsetsszMessage.get_charsetcCs
t|j�S)N)rr3)r9rrr�__len__{szMessage.__len__cCs
|j|�S)N)r[)r9�namerrr�__getitem__s	zMessage.__getitem__cCs�|jj|�}|r�|j�}d}xW|jD]L\}}|j�|kr4|d7}||kr4tdj||���q4W|jj|jj||��dS)Nrrz/There may be at most {} {} headers in a message)r2Zheader_max_countr)r3�
ValueError�formatr*�header_store_parse)r9rq�valZ	max_countZlname�found�k�vrrr�__setitem__�s
	zMessage.__setitem__cCs^|j�}g}x<|jD]1\}}|j�|kr|j||f�qW||_dS)N)r)r3r*)r9rq�
newheadersrxryrrr�__delitem__�szMessage.__delitem__cCs |j�dd�|jD�kS)NcSs"g|]\}}|j��qSr)r))�.0rxryrrr�
<listcomp>�s	z(Message.__contains__.<locals>.<listcomp>)r)r3)r9rqrrr�__contains__�szMessage.__contains__ccs#x|jD]\}}|Vq
WdS)N)r3)r9Zfieldr"rrr�__iter__�szMessage.__iter__cCsdd�|jD�S)NcSsg|]\}}|�qSrr)r}rxryrrrr~�s	z Message.keys.<locals>.<listcomp>)r3)r9rrr�keys�szMessage.keyscs�fdd��jD�S)Ncs+g|]!\}}�jj||��qSr)r2�header_fetch_parse)r}rxry)r9rrr~�s	z"Message.values.<locals>.<listcomp>)r3)r9r)r9r�values�szMessage.valuescs�fdd��jD�S)Ncs1g|]'\}}|�jj||�f�qSr)r2r�)r}rxry)r9rrr~�s	z!Message.items.<locals>.<listcomp>)r3)r9r)r9r�items�sz
Message.itemscCsO|j�}x<|jD]1\}}|j�|kr|jj||�SqW|S)N)r)r3r2r�)r9rq�failobjrxryrrrr[�s
zMessage.getcCs|jj||f�dS)N)r3r*)r9rqr"rrr�set_raw�szMessage.set_rawcCst|jj��S)N)�iterr3�copy)r9rrr�	raw_items�szMessage.raw_itemscCshg}|j�}xE|jD]:\}}|j�|kr|j|jj||��qW|sd|S|S)N)r)r3r*r2r�)r9rqr�r�rxryrrr�get_all�s	 zMessage.get_allcKs�g}xd|j�D]V\}}|dkrG|j|jdd��q|jt|jdd�|��qW|dk	r�|jd|�tj|�||<dS)N�_�-r)r�r*rRr#�insert�	SEMISPACEra)r9�_name�_valueZ_params�partsrxryrrrrms&zMessage.add_headercCs�|j�}xpttt|j��|j�D]A\}\}}|j�|kr.|jj||�|j|<Pq.Wt|��dS)N)r)�zip�rangerr3r2ru�KeyError)r9r�r�r.rxryrrr�replace_header"s4zMessage.replace_headercCsdt�}|jd|�}||kr1|j�St|�dj�}|jd�dkr`dS|S)Nzcontent-typer�/rz
text/plain)�objectr[�get_default_typerr)r')r9�missingr"�ctyperrr�get_content_type5s
	
zMessage.get_content_typecCs|j�}|jd�dS)Nr�r)r��split)r9r�rrr�get_content_maintypeMszMessage.get_content_maintypecCs|j�}|jd�dS)Nr�r)r�r�)r9r�rrr�get_content_subtypeVszMessage.get_content_subtypecCs|jS)N)r8)r9rrrr�_szMessage.get_default_typecCs
||_dS)N)r8)r9r�rrr�set_default_typehszMessage.set_default_typec	Cs�t�}|j||�}||kr+|Sg}x�t|�D]t}y4|jdd�\}}|j�}|j�}Wn$tk
r�|j�}d}YnX|j||f�q>Wtj|�}|S)Nr%rr)	r�r[r/r�r
rsr*rZ
decode_params)	r9r��headerr�r"�params�prqrvrrr�_get_params_preserveqs 	
zMessage._get_params_preservezcontent-typeTcCsJt�}|j||�}||kr+|S|rBdd�|D�S|SdS)NcSs(g|]\}}|t|�f�qSr)r1)r}rxryrrrr~�s	z&Message.get_params.<locals>.<listcomp>)r�r�)r9r�r�r0r�r�rrr�
get_params�s
	zMessage.get_paramscCsc||kr|SxL|j||�D]8\}}|j�|j�kr#|rWt|�S|Sq#W|S)N)r�r)r1)r9rr�r�r0rxryrrrr]�s
zMessage.get_paramzContent-TypercCs�t|t�r%|r%|||f}||krL|j�dkrLd}n|j|�}|j|d|�s�|s�t|||�}qGtj|t|||�g�}n�d}x�|jd|d|�D]u\}	}
d}|	j�|j�kr
t|||�}nt|	|
|�}|s.|}q�tj||g�}q�W||j|�kr�|ru|j	||�n||=|||<dS)Nzcontent-typez
text/plainr�rr0)
rrr)r[r]r#r�rar�r�)r9rr"r��requoter�languagerRr�Z	old_paramZ	old_valueZappend_paramrrrrn�s2		zMessage.set_paramcCs�||krdSd}xz|jd|d|�D]`\}}|j�|j�kr/|snt|||�}q/tj|t|||�g�}q/W||j|�kr�||=|||<dS)Nrr�r0)r�r)r#r�rar[)r9rr�r�Z	new_ctyper�ryrrrrl�s%	zMessage.del_paramcCs�|jd�dkst�|j�dkr>|d=d|d<||krX|||<dS|jd|d|�}||=|||<x4|dd�D]"\}}|j||||�q�WdS)	Nr�rzcontent-typezmime-versionz1.0zMIME-Versionr�r0)r'rsr)r�rn)r9rZr�r�r�r�ryrrr�set_types


zMessage.set_typecCsbt�}|jd|d�}||kr?|jd|d�}||krO|Stj|�j�S)N�filenamezcontent-dispositionrqzcontent-type)r�r]r�collapse_rfc2231_valuer
)r9r�r�r�rrr�get_filename's	zMessage.get_filenamecCs>t�}|jd|�}||kr+|Stj|�j�S)N�boundary)r�r]rr��rstrip)r9r�r�r�rrr�get_boundary7s
	zMessage.get_boundarycCs�t�}|j|d�}||kr6tjd��g}d}xY|D]Q\}}|j�dkr�|jdd|f�d}qI|j||f�qIW|s�|jdd|f�g}x�|jD]�\}	}
|	j�dkrgg}xG|D]?\}}
|
dkr|j|�q�|jd||
f�q�Wtj|�}
|j|j	j
|	|
��q�|j|	|
f�q�W||_dS)	Nzcontent-typezNo Content-Type header foundFr�z"%s"Trz%s=%s)r�r�rZHeaderParseErrorr)r*r3r�rar2ru)r9r�r�r�Z	newparamsZfoundpZpkZpvr{�hryr�rxrvrrr�set_boundaryDs2
		zMessage.set_boundarycCs�t�}|jd|�}||kr+|St|t�r�|dpGd}y&|djd�}t||�}Wn"ttfk
r�|d}YnXy|jd�Wntk
r�|SYnX|j�S)Nrrzus-asciirzraw-unicode-escape)	r�r]rrrrr^r_r))r9r�r�rZpcharsetrFrrr�get_content_charsetrs 	
	zMessage.get_content_charsetcs�fdd�|j�D�S)Ncsg|]}|j���qSr)r�)r}�part)r�rrr~�s	z(Message.get_charsets.<locals>.<listcomp>)�walk)r9r�r)r�r�get_charsets�szMessage.get_charsetscCs9|jd�}|dkrdSt|�dj�}|S)Nzcontent-dispositionr)r[rr))r9r"�c_drrr�get_content_disposition�s
zMessage.get_content_disposition)r�)3�__name__�
__module__�__qualname__rr:r<r;rGrFrJrKrLrPrfrkrjrorprrrzr|rr�r�r�r�r[r�r�r�rmr�r�r�r�r�r�r�r�r]rnrlr�r�r�r�r�r�r�Zemail.iteratorsr�rrrrrjs`Z/
				!2 
.
c@seZdZddd�Zdd�Zdd�Zd.dd�Zd/d0d1d2hZdd�Zdd�Z	dddd�Z
dddd�Zdd�Zddd�Z
ddd�Zddd �Zd!dd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdS)3�MIMEPartNcCs6|dkr"ddlm}|}tj||�dS)Nr)�default)Zemail.policyr�rr:)r9r2r�rrrr:�szMIMEPart.__init__cCs,|jd�}|dkrdS|jdkS)Nzcontent-dispositionF�
attachment)r[Zcontent_disposition)r9r�rrr�
is_attachment�szMIMEPart.is_attachmentc	csc|j�rdS|j�jd�\}}|dkr[||krW|j|�|fVdS|dkrkdS|dkr�x)|j�D]}|j||�EdHq�WdSd|kr�|jd�|fVd}|jd�}|rx+|j�D]}|d|kr�|}Pq�W|dkr>|j�}|r8|dnd}|dk	r_|j||�EdHdS)Nr��text�	multipart�related�startz
content-idr)r�r�r�r(�
iter_parts�
_find_bodyr]rf)	r9r��preferencelist�maintype�subtypeZsubpart�	candidater�Zsubpartsrrrr��s6zMIMEPart._find_bodyr��html�plaincCs^t|�}d}xE|j||�D]1\}}||kr%|}|}|dkr%Pq%W|S)Nr)rr�)r9r�Z	best_prioZbodyZprior�rrr�get_body�s
zMIMEPart.get_bodyr�r��alternativec	csd|j�jd�\}}|dks3|dkr7dS|j�j�}|dkr�|dkr�|jd�}|r�d}g}x9|D]1}|jd�|kr�d}q�|j|�q�W|r�|EdHdS|jd	�|EdHdSg}xl|D]d}|j�jd�\}}||f|jkrW|j	�rW||krW|j|�q�|Vq�WdS)
Nr�r�r�r�r�Fz
content-idTr)
r�r�rfr�r]r[r*�pop�_body_typesr�)	r9r�r�r�r�rwZattachmentsr��seenrrr�iter_attachments�s6
		
	

zMIMEPart.iter_attachmentsccs%|j�dkr!|j�EdHdS)Nr�)r�rf)r9rrrr�!szMIMEPart.iter_parts�content_managercOs+|dkr|jj}|j|||�S)N)r2r��get_content)r9r��args�kwrrrr�)szMIMEPart.get_contentcOs/|dkr|jj}|j|||�dS)N)r2r��set_content)r9r�r�r�rrrr�.szMIMEPart.set_contentc
Cs5|j�dkrO|j�}||f}||krOtdj||���g}g}xU|jD]J\}}|j�jd�r�|j||f�qe|j||f�qeW|r�t|�d|j	�}	||	_|j
|	_
|	g|_
n	g|_
||_d||d<|dk	r1|jd|�dS)Nr�zCannot convert {} to {}zcontent-r2z
multipart/zContent-Typer�)r�r�rsrtr3r)�
startswithr*rZr2r5rn)
r9r�Zdisallowed_subtypesr�Zexisting_subtypeZkeep_headersZpart_headersrqr"r�rrr�_make_multipart3s,
				zMIMEPart._make_multipartcCs|jdd|�dS)Nr�r��mixed)r�r�)r�)r9r�rrr�make_relatedNszMIMEPart.make_relatedcCs|jdd|�dS)Nr�r�)r�)r�)r9r�rrr�make_alternativeQszMIMEPart.make_alternativecCs|jdf|�dS)Nr�)r�)r9r�rrr�
make_mixedTszMIMEPart.make_mixed�_dispcOs�|j�dks$|j�|kr8t|d|��t|�d|j�}|j||�|r|d|kr|||d<|j|�dS)Nr�Zmake_r2zcontent-dispositionzContent-Disposition)r�r��getattrrZr2r�rP)r9Z_subtyper�r�r�r�rrr�_add_multipartWs
zMIMEPart._add_multipartcOs|jd|dd|�dS)Nr�r�Zinline)r�)r9r�r�rrr�add_relatedaszMIMEPart.add_relatedcOs|jd||�dS)Nr�)r�)r9r�r�rrr�add_alternativedszMIMEPart.add_alternativecOs|jd|dd|�dS)Nr�r�r�)r�)r9r�r�rrr�add_attachmentgszMIMEPart.add_attachmentcCsg|_d|_dS)N)r3r5)r9rrr�clearjs	zMIMEPart.clearcCs&dd�|jD�|_d|_dS)NcSs7g|]-\}}|j�jd�s||f�qS)zcontent-)r)r�)r}�nryrrrr~os		z*MIMEPart.clear_content.<locals>.<listcomp>)r3r5)r9rrr�
clear_contentnszMIMEPart.clear_content)r�r�r�)r�r�)r�r�)r�r�)r�r�)r�r�r�r:r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s,	.
r�cs"eZdZ�fdd�Z�S)�EmailMessagecs-t�j||�d|kr)d|d<dS)NzMIME-Versionz1.0)�superr�)r9r�r�)�	__class__rrr�vszEmailMessage.set_content)r�r�r�r�rr)r�rr�tsr�)�__all__�rercr`�warnings�iorrZemailrrZemail._policybaserrr6Zemail._encoded_wordsr	rhr��compilerrr#r/r1rr�r�rrrr�<module>s.		
"���K�