Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/test_email/__pycache__/test_message.cpython-34.pyc

�
f f
g�@s�ddlZddlZddlmZmZddlmZmZddlm	Z	m
Z
dd�ZGdd�de	�Ze
Gd	d
�d
��Z
Gdd�de
e	�ZGd
d�de
e	�Zedkr�ej�ndS)�N)�policy�message_from_string)�EmailMessage�MIMEPart)�
TestEmailBase�parameterizecCsttdd�|�d�S)NcSs
|dk	S)N�)�xrr�A/opt/alt/python34/lib64/python3.4/test/test_email/test_message.py�<lambda>
szfirst.<locals>.<lambda>)�next�filter)�iterablerrr
�first	src@s1eZdZejZdd�Zdd�ZdS)�Testc
Cs=|jd�}d|d<|jt��d|d<WdQXdS)N�zabc@xyz�Tozxyz@abc)�_str_msg�assertRaises�
ValueError)�self�mrrr
�+test_error_on_setitem_if_max_count_exceededs
z0Test.test_error_on_setitem_if_max_count_exceededcCsZttjd�dtj�}|j|dd�|j|dd�|j|t�dS)Na>            Subject: Ayons asperges pour le =?utf-8?q?d=C3=A9jeuner?=
            From: =?utf-8?q?Pep=C3=A9?= Le Pew <pepe@example.com>
            To: "Penelope Pussycat" <"penelope@example.com">
            MIME-Version: 1.0
            Content-Type: text/plain; charset="utf-8"

            sample text
            rZsubjectu Ayons asperges pour le déjeuner�fromuPepé Le Pew <pepe@example.com>)r�textwrap�dedentr�default�assertEqualZassertIsInstancer)rrrrr
�/test_rfc2043_auto_decoded_and_emailmessage_useds
	z4Test.test_rfc2043_auto_decoded_and_emailmessage_usedN)�__name__�
__module__�__qualname__rrrrrrrr
r
s	rc@s�eZdZejZidXffdfd6dYffejd�fd6dZffejd�fd6d[fd\ejd�fd6d]fd^ejd
�fd6d_d`daejd�fd6dbdcddejd�fd6defdfejd�fd6dgdhdiejd�fd6djdkdlejd�fd6dmdndoejd�fd6dpdqdrejd�fd 6dsdtduejd!�fd"6dvffejd#�fd$6dwdxdyejd%�fd&6Zd'd(�Zd)d*�Z	d+d,�Z
Gd-d.�d.�Zd/d0�Zd1d2�Z
d3d4�Zd5d6�Zd�Zd>d?�Zd@dA�ZdBdC�ZdDdE�ZdFdG�ZdHdI�ZGdJdK�dK�ZdLdM�ZGdNdO�dO�ZdPdQ�ZdRdS�ZdTdU�ZdVdW�ZdS)��TestEmailMessageBaseNrrZ
empty_messagezV                To: foo@example.com

                simple text body
                Znon_mime_plainz�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: image/jpg

                bogus body.
                Z
mime_non_text��a�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/alternative; boundary="==="

                preamble

                --===
                Content-Type: text/plain

                simple body

                --===
                Content-Type: text/html

                <p>simple body</p>
                --===--
                Zplain_html_alternativea�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/mixed; boundary="==="

                preamble

                --===
                Content-Type: text/plain

                simple body

                --===
                Content-Type: text/html

                <p>simple body</p>

                --===--
                Zplain_html_mixeda�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/mixed; boundary="==="

                --===
                Content-Type: text/plain

                simple body

                --===
                Content-Type: text/html
                Content-Disposition: attachment

                <p>simple body</p>

                --===--
                Zplain_html_attachment_mixeda�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/mixed; boundary="==="

                --===
                Content-Type: text/plain
                Content-Disposition: AtTaChment

                simple body

                --===
                Content-Type: text/html

                <p>simple body</p>

                --===--
                Zhtml_text_attachment_mixeda�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/mixed; boundary="==="

                --===
                Content-Type: text/plain
                Content-Disposition: InLine

                simple body

                --===
                Content-Type: text/html
                Content-Disposition: inline

                <p>simple body</p>

                --===--
                Z!html_text_attachment_inline_mixeda�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/related; boundary="==="; type=text/html

                --===
                Content-Type: text/html

                <p>simple body</p>

                --===
                Content-Type: image/jpg
                Content-ID: <image1>

                bogus data

                --===--
                �relateda                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/related; boundary="==="; type=text/html;
                 start="<body>"

                --===
                Content-Type: text/html
                Content-ID: <include>

                useless text

                --===
                Content-Type: text/html
                Content-ID: <body>

                <p>simple body</p>
                <!--#include file="<include>"-->

                --===--
                Zrelated_with_start����a�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/mixed; boundary="==="

                --===
                Content-Type: multipart/alternative; boundary="+++"

                --+++
                Content-Type: text/plain

                simple body

                --+++
                Content-Type: multipart/related; boundary="___"

                --___
                Content-Type: text/html

                <p>simple body</p>

                --___
                Content-Type: image/jpg
                Content-ID: <image1@cid>

                bogus jpg body

                --___--

                --+++--

                --===
                Content-Type: image/jpg
                Content-Disposition: attachment

                bogus jpg body

                --===
                Content-Type: image/jpg
                Content-Disposition: AttacHmenT

                another bogus jpg body

                --===--
                Zmixed_alternative_plain_relateda�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/mixed; boundary="==="

                --===
                Content-Type: multipart/related; boundary="+++"

                --+++
                Content-Type: multipart/alternative; boundary="___"

                --___
                Content-Type: text/plain

                simple body

                --___
                Content-Type: text/html

                <p>simple body</p>

                --___--

                --+++
                Content-Type: image/jpg
                Content-ID: <image1@cid>

                bogus jpg body

                --+++--

                --===
                Content-Type: image/jpg
                Content-Disposition: attachment

                bogus jpg body

                --===
                Content-Type: image/jpg
                Content-Disposition: attachment

                another bogus jpg body

                --===--
                Z$mixed_related_alternative_plain_htmla�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/mixed; boundary="==="

                --===
                Content-Type: multipart/related; boundary="+++"

                --+++
                Content-Type: image/jpg
                Content-ID: <image1@cid>

                bogus jpg body

                --+++
                Content-Type: multipart/alternative; boundary="___"

                --___
                Content-Type: text/plain

                simple body

                --___
                Content-Type: text/html

                <p>simple body</p>

                --___--

                --+++--

                --===
                Content-Type: image/jpg
                Content-Disposition: attachment

                bogus jpg body

                --===
                Content-Type: image/jpg
                Content-Disposition: attachment

                another bogus jpg body

                --===--
                Z0mixed_related_alternative_plain_html_wrong_orderz�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: message/rfc822

                To: bar@example.com
                From: robot@examp.com

                this is a message body.
                Zmessage_rfc822a�                To: foo@example.com
                MIME-Version: 1.0
                Content-Type: multipart/mixed; boundary="==="

                --===
                Content-Type: text/plain

                Your message has bounced, ser.

                --===
                Content-Type: message/rfc822

                To: bar@example.com
                From: robot@examp.com

                this is a message body.

                --===--
                Zmixed_text_message_rfc822c
s|j|�}t|j����fdd�|D�}d}d}d}	|j|j�t|��|j|jdd
�t|��|j|jdd�t|||d���|j|jdd�t||||	g��|j|jdd
�t|||	d���|j|jddg�||�|j|jddg�||�|j|jdd	g�||	�|j|jdd�t||	|dd���|j|jdd�t||	||g��|j|jdd�t||dd���|j|jdd�t|ddd���|j|jdd�t||||	||g��dS)Ncs,g|]"}|dkrdn�|�qS)Nr)�.0�n)�allpartsrr
�
<listcomp>�s	z<TestEmailMessageBase.message_as_get_body.<locals>.<listcomp>rr$r#Zpreferencelistr%�html�plain)�related�html�plain)r0r1)r0r2)r1r2)r2r1���)r2r0)r1r0r3)r2r1r0r3)r1r2r0)r�list�walkrZget_bodyr)
r�
body_parts�attachments�parts�msgrZexpectedr%r.r/r)r,r
�message_as_get_body�s@
##
z(TestEmailMessageBase.message_as_get_bodycsZ|j|�}t|j����fdd�|D�}|jt|j��|�dS)Ncsg|]}�|�qSrr)r*r+)r,rr
r-�s	zCTestEmailMessageBase.message_as_iter_attachment.<locals>.<listcomp>)rr4r5rZiter_attachments)rr6r7r8r9rr)r,r
�message_as_iter_attachment�sz/TestEmailMessageBase.message_as_iter_attachmentcsZ|j|�}t|j����fdd�|D�}|jt|j��|�dS)Ncsg|]}�|�qSrr)r*r+)r,rr
r-�s	z>TestEmailMessageBase.message_as_iter_parts.<locals>.<listcomp>)rr4r5r�
iter_parts)rr6r7r8r9rr)r,r
�message_as_iter_parts�sz*TestEmailMessageBase.message_as_iter_partsc@s(eZdZdd�Zdd�ZdS)z(TestEmailMessageBase._TestContentManagercOs
|||fS)Nr)rr9�args�kwrrr
�get_content�sz4TestEmailMessageBase._TestContentManager.get_contentcOs||_||_||_dS)N)r9r>r?)rr9r>r?rrr
�set_content�s		z4TestEmailMessageBase._TestContentManager.set_contentN)rr r!r@rArrrr
�_TestContentManager�srBcCs�|jd�}|j�}|j|jd|�|fif�|jdd|dddd�\}}}|j||�|j|d�|j|tdddd��dS)	Nr�content_manager�foo�barr$�kr#)rD)rrBrr@�dict)rr�cmr9r>r?rrr
�test_get_content_with_cm�s%*z-TestEmailMessageBase.test_get_content_with_cmcCs�tjjd|j��}|jdd|�}|j|j�|fif�|jddddd�\}}}|j||�|j|d	�|j|tdddd��dS)
NrCrrrDrEr$rFr#)zfoo)rr�clonerBrrr@rG)r�prr9r>r?rrr
�-test_get_content_default_cm_comes_from_policys$zBTestEmailMessageBase.test_get_content_default_cm_comes_from_policycCs�|jd�}|j�}|jd|�|j|j|�|j|jf�|j|ji�|jdd|dddd�|j|j|�|j|jd�|j|jtdddd��dS)	NrrCrDrEr$rFr#)zfoo)rrBrArr9r>r?rG)rrrHrrr
�test_set_content_with_cm	sz-TestEmailMessageBase.test_set_content_with_cmcCs�|j�}tjjd|�}|jdd|�}|j�|j|j|�|j|jf�|j|j	i�|jddddd�|j|j|�|j|jd	�|j|j	t
dddd��dS)
NrCrrrDrEr$rFr#)zfoo)rBrrrJrrArr9r>r?rG)rrHrKrrrr
�-test_set_content_default_cm_comes_from_policys
zBTestEmailMessageBase.test_set_content_default_cm_comes_from_policy�
no_content�succeeds�noner/�alternative�raises�mixedcCs�|j�}d}ddg}|dkr1dn|jd�|d
krmd}|jd�|jd�n,|dkr�g}|jdd|f�n|jd�|j|�x|D]\}}|||<q�W|||fS)Nr�foo@bar.com�From�bar@foo.comrO�content-shadow�Logrus�X-Random-Header�Corwin�textr�Content-Type�
text/plainz
multipart/�X-Trump�Random)zTorU)rVrW�rXrY)ra)rZr[)r]r^)r_r`)�message�append�set_payload)r�subtyper�payload�msg_headers�name�valuerrr
�_make_subtype_test_message=s&	



z/TestEmailMessageBase._make_subtype_test_messagec
Cs[|jt��}t||��WdQXt|j�}|j||�|j||�dS)N)rr�getattr�str�	exceptionZassertIn)rrZmethod_namere�method�arZexc_textrrr
� _check_disallowed_subtype_raisesTs
z5TestEmailMessageBase._check_disallowed_subtype_raisescCsd}xJ|D]B\}}|j�jd�s
|j|||�|d7}q
q
W|jt|�|d�t|j��}d}xJ|D]B\}}|j�jd�r�|j|||�|d7}q�q�W|jt|�|�|j|j�|�dS)Nrzcontent-r$)�lower�
startswithr�lenrr<�get_payload)rrrgrf�countrhri�partrrr
�_check_make_multipart[sz*TestEmailMessageBase._check_make_multipartcCs	|j|�\}}}d|}|d
krH|j||||�dSt||��|j|j�d�|j|j�|�|dkr�|jt|j��d�|j|j�|dd|fg�n/|jt|j��d	�|j	|||�dS)N�make_rrS�	multipartrOrzContent-Typez
multipart/r$)rrS)
rjrprkr�get_content_maintype�get_content_subtypersrt�itemsrw)rrnre�outcomerrgrfZmake_methodrrr
�subtype_as_makeks
z$TestEmailMessageBase.subtype_as_makecCs�|j�}|dkrVd||d<|jt��}t|d|��WdQXdS|dkrod|d<n|dkr�d||d<nt|d|�d	d
�|j|j��|j|j�d
�dS)NrrSz
multipart/zContent-Typerxr/z
text/plainrO�boundary�abc)rzraises)rbrrrk�
assertTrueZis_multipartrZget_boundary)rrnrer}rrHrrr
�subtype_as_make_with_boundary}s
z2TestEmailMessageBase.subtype_as_make_with_boundarycCsoxhd
D]`}|jd|jjdd��}d|d<t||��|j|jd	�jjd�qWdS)N�make_related�make_alternative�
make_mixedrrCrDz
text/plainzContent-Typer)r�r�r�)rbrrJrkrrtrC)rrnrrrr
�3test_policy_on_part_made_by_make_comes_from_message�s

!
zHTestEmailMessageBase.test_policy_on_part_made_by_make_comes_from_messagec@seZdZdd�ZdS)z+TestEmailMessageBase._TestSetContentManagercOsd|d<|j|�dS)Nz
text/plainzContent-Type)rd)rr9�contentr>r?rrr
rA�s
z7TestEmailMessageBase._TestSetContentManager.set_contentN)rr r!rArrrr
�_TestSetContentManager�sr�cCs�|j|�\}}}|j�}|dkr6dnd|}|dkrf|j||||�dSt||�dd|�|j|j�d�|j|j�|�||ks�|dkr|jt|j��d	�x(|D] \}	}
|j||	|
�q�W|j�d
}n?|jt|j��d�|j	|||�|j�d	}|j|j
�d�|j|j�d�|dkr�|j|d
d�n4|dkr�|j|d
d�n|j|d
�dS)NrT�add_attachmentZadd_rS�testrCryrOr$rr#z
text/plainzContent-Disposition�
attachmentr%�inline)rjr�rprkrrzr{rsrtrwZget_content_type�assertIsNone)rrnrer}rrgrfrHZ
add_methodrhrirvrrr
�subtype_as_add�s0z#TestEmailMessageBase.subtype_as_addc@seZdZdd�ZdS)z2TestEmailMessageBase._TestSetRaisingContentManagercOstd��dS)Nr�)�	Exception)rr9r�r>r?rrr
rA�sz>TestEmailMessageBase._TestSetRaisingContentManager.set_contentN)rr r!rArrrr
�_TestSetRaisingContentManager�sr�cCs�|j�}|jd|jjd|��}xRdD]J}|jt��}t||�d�WdQX|jt|j	�d�q4WdS)	NrrC�add_related�add_alternativer�rr�)r�r�zadd_attachment)
r�rbrrJrr�rkrrlrm)rrHrrnrorrr
�6test_default_content_manager_for_add_comes_from_policy�s!
zKTestEmailMessageBase.test_default_content_manager_for_add_comes_from_policycCs~|j|�}|j�|jt|�d�|jt|j��g�|j|j��|jt|j��g�dS)Nr)	r�clearrrsr4r|r�rtr<)rr6r7r8r9rrrr
�message_as_clear�s
z%TestEmailMessageBase.message_as_clearcCs�|j|�}dd�|j�D�}|j�|jt|j��|�|j|j��|jt|j��g�dS)NcSs+g|]!}|j�jd�s|�qS)zcontent-)rqrr)r*�hrrr
r-�s	zATestEmailMessageBase.message_as_clear_content.<locals>.<listcomp>)r�keysZ
clear_contentrr4r�rtr<)rr6r7r8r9rZexpected_headersrrr
�message_as_clear_content�s
z-TestEmailMessageBase.message_as_clear_contentc!Csj|j�}|j|j��|jt��|j|j�WdQXd|d<|j|j��|jt��|j|j�WdQX|jdd�|j|j��|jt��|j|j�WdQX|jdd�|j|j��|jt��|j|j�WdQX|jddd�|j|j��|jt��|j|j�WdQXdS)Nr�zContent-Dispositionr�Z
AtTachMent�filenamezabc.png)Z
_make_messageZassertFalseZ
is_attachmentZassertWarns�DeprecationWarningZreplace_headerr�Z	set_param)rrrrr
�test_is_attachment�s(
z'TestEmailMessageBase.test_is_attachment)NNr)NNr)NNN)Nr#r$)r$r#)Nr#r$)r$r#)NNr$)r#)r$r#)Nr#N)r$)r$r#)Nr#r$)r$r#)rr$N)r#)r$r#)rr#N)r$)r$r#)r&r'r#)r(r))r$r(r))r$r'r&)r(r))r$r(r))r$NN)r(r))r$r(r))NNN)NNr$)r#)r$r#��related�
no_contentrP�r�rQrP�r��plainrP�r�r�r�r�rR�raises�r��mixedr��rRr�rP�rRrQrP�rRr�rP�rRr�rP�rRrRr�rRr�r��r�r�rP�r�rQrP�r�r�rP�r�r�rP�r�rRrP�r�r�r)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�)rr r!rrrrZmessage_paramsr:r;r=rBrIrLrMrNZsubtype_paramsrjrprwr~r�r�r�r�r�r�r�r�r�rrrr
r"&s�	









,
,
,
	
 			r"c@sAeZdZeZdd�ZGdd�d�Zdd�ZdS)�TestEmailMessagecCsS|jd�}|j�}|jd|�|jd|�|j|dd�dS)NrzMIME-VersionrCz1.0)rrB�assertNotInrAr)rrrHrrr
�"test_set_content_adds_MIME_Version�s
z3TestEmailMessage.test_set_content_adds_MIME_Versionc@seZdZdd�ZdS)z(TestEmailMessage._MIME_Version_adding_CMcOsd|d<dS)Nz1.0zMIME-Versionr)rr9r>r?rrr
rA�sz4TestEmailMessage._MIME_Version_adding_CM.set_contentN)rr r!rArrrr
�_MIME_Version_adding_CM�sr�cCsS|jd�}|j�}|jd|�|jd|�|j|dd�dS)NrzMIME-VersionrCz1.0)rr�r�rAr)rrrHrrr
�0test_set_content_does_not_duplicate_MIME_Version�s
zATestEmailMessage.test_set_content_does_not_duplicate_MIME_VersionN)rr r!rrbr�r�r�rrrr
r��sr�c@s"eZdZeZdd�ZdS)�TestMIMEPartcCsO|jd�}|j�}|jd|�|jd|�|jd|�dS)NrzMIME-VersionrC)rrBr�rA)rrrHrrr
�*test_set_content_does_not_add_MIME_Versions
z7TestMIMEPart.test_set_content_does_not_add_MIME_VersionN)rr r!rrbr�rrrr
r�sr��__main__)ZunittestrZemailrrZ
email.messagerrZtest.test_emailrrrrr"r�r�r�mainrrrr
�<module>s���