Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_email/__pycache__/test_message.cpython-35.opt-1.pyc



��Yf�f�@s�ddlZddlZddlmZmZddlmZmZddlm	Z	m
Z
dd�ZGdd�de	�Ze
Gd	d
�d
��Z
Gdd�de
e	�ZGd
d�de
e	�Zedkr�ej�dS)�N)�policy�message_from_string)�EmailMessage�MIMEPart)�
TestEmailBase�parameterizecCsttdd�|�d�S)NcSs
|dk	S)N�)�xrr�A/opt/alt/python35/lib64/python3.5/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<WdQRXdS)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�eZdZejZddZffdfdd[ffejd�fdd\ffejd�fd	d]fd^ejd�fd
d_fd`ejd�fddadbdcejd�fddddedfejd�fddgfdhejd�fddidjdkejd�fddldmdnejd�fddodpdqejd�fddrdsdtejd �fd!dudvdwejd"�fd#dxffejd$�fd%dydzd{ejd&�fiZd'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�ZdXdY�ZdS)��TestEmailMessageBaseZ
empty_messageNrrZnon_mime_plainzV                To: foo@example.com

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

                bogus body.
                Zplain_html_alternative��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_mixeda�                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_attachment_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>

                --===--
                Zhtml_text_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>

                --===--
                Z!html_text_attachment_inline_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>

                --===--
                �relateda�                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

                --===--
                Zrelated_with_starta                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>"-->

                --===--
                Zmixed_alternative_plain_related����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

                --===--
                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: 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

                --===--
                Z0mixed_related_alternative_plain_html_wrong_ordera�                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

                --===--
                Zmessage_rfc822z�                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.
                Zmixed_text_message_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.

                --===--
                c
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)r%r.r/)r%r.)r%r/)r.r/)r/r.���)r/r%)r.r%r0)r/r.r%r0)r.r/r%)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>)rr1r2r�iter_attachments)rr3r4r5r6rr)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>)rr1r2r�
iter_parts)rr3r4r5r6rr)r,r
�message_as_iter_parts�sz*TestEmailMessageBase.message_as_iter_partsc@s(eZdZdd�Zdd�ZdS)z(TestEmailMessageBase._TestContentManagercOs
|||fS)Nr)rr6�args�kwrrr
�get_content�sz4TestEmailMessageBase._TestContentManager.get_contentcOs||_||_||_dS)N)r6r<r=)rr6r<r=rrr
�set_content�s		z4TestEmailMessageBase._TestContentManager.set_contentN)rr r!r>r?rrrr
�_TestContentManager�sr@cCs�|jd�}|j�}|j|jd|�|fif�|jdd|dddd�\}}}|j||�|j|d�|j|tdddd��dS)	Nr�content_manager�foo�barr$�kr#)rB)rr@rr>�dict)rr�cmr6r<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)
NrArrrBrCr$rDr#)rB)rr�cloner@rrr>rE)r�prr6r<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)	NrrArBrCr$rDr#)rB)rr@r?rr6r<r=rE)rrrFrrr
�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)
NrArrrBrCr$rDr#)rB)r@rrrHrr?rr6r<r=rE)rrFrIrrrr
�-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}|dkr.d|jd�|d
krjd}|jd�|jd�n)|dkr�g}|jdd|f�|jd�|j|�x|D]\}}|||<q�W|||fS)Nr�foo@bar.com�From�bar@foo.comrM�content-shadow�Logrus�X-Random-Header�Corwin�textr�Content-Type�
text/plainz
multipart/�X-Trump�Random)rrS)rTrU�rVrW)r_)rXrY)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||��WdQRXt|j�}|j||�|j||�dS)N)rr�getattr�str�	exceptionZassertIn)rrZmethod_namerc�method�arZexc_textrrr
� _check_disallowed_subtype_raisesTs
z5TestEmailMessageBase._check_disallowed_subtype_raisescCs�d}xG|D]?\}}|j�jd�s
|j|||�|d7}q
W|jt|�|d�t|j��}d}xG|D]?\}}|j�jd�r�|j|||�|d7}q�W|jt|�|�|j|j�|�dS)Nrzcontent-r$)�lower�
startswithr�lenrr:�get_payload)rrrerd�countrfrg�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_rrQ�	multipartrMrzContent-Typez
multipart/r$)rrQ)
rhrnrir�get_content_maintype�get_content_subtyperqrr�itemsru)rrlrc�outcomerrerdZmake_methodrrr
�subtype_as_makeks
z$TestEmailMessageBase.subtype_as_makecCs�|j�}|dkrWd||d<|jt��}t|d|��WdQRXdS|dkrpd|d<n|dkr�d||d<t|d|�d	d
�|j|j��|j|j�d
�dS)NrrQz
multipart/zContent-Typervr/z
text/plainrM�boundary�abc)rrQ)r`rrri�
assertTrueZis_multipartrZget_boundary)rrlrcr{rrFrrr
�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_mixedrrArBz
text/plainzContent-Typer)r�r�r�)r`rrHrirrrrA)rrlrrrr
�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)rb)rr6�contentr<r=rrr
r?�s
z7TestEmailMessageBase._TestSetContentManager.set_contentN)rr r!r?rrrr
�_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)NrR�add_attachmentZadd_rQ�testrArwrMr$rr#z
text/plainzContent-Disposition�
attachmentr%�inline)rhr�rnrirrxryrqrrruZget_content_type�assertIsNone)rrlrcr{rrerdrFZ
add_methodrfrgrtrrr
�subtype_as_add�s0z#TestEmailMessageBase.subtype_as_addc@seZdZdd�ZdS)z2TestEmailMessageBase._TestSetRaisingContentManagercOstd��dS)Nr�)�	Exception)rr6r�r<r=rrr
r?�sz>TestEmailMessageBase._TestSetRaisingContentManager.set_contentN)rr r!r?rrrr
�_TestSetRaisingContentManager�sr�cCs�|j�}|jd|jjd|��}xSdD]K}|jt��}t||�d�WdQRX|jt|j	�d�q4WdS)	NrrA�add_related�add_alternativer�rr�)r�r�r�)
r�r`rrHrr�rirrjrk)rrFrrlrmrrr
�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�clearrrqr1rzr�rrr:)rr3r4r5r6rrrr
�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-)rorp)r*�hrrr
r-�s	zATestEmailMessageBase.message_as_clear_content.<locals>.<listcomp>)r�keysZ
clear_contentrr1r�rrr:)rr3r4r5r6rZexpected_headersrrr
�message_as_clear_content�s
z-TestEmailMessageBase.message_as_clear_contentcCs�|j�}|j|j��d|d<|j|j��|jdd�|j|j��|jdd�|j|j��|jddd�|j|j��dS)Nr�zContent-Dispositionr�Z
AtTachMent�filenamezabc.png)�
_make_messageZassertFalseZ
is_attachmentZreplace_headerrZ	set_param)rrrrr
�test_is_attachment�s
z'TestEmailMessageBase.test_is_attachmentcCs�|j�}|jd�|jd�|jd�|j�j�}|jtt|j���d�|j|j�|�dS)Nzarbitrary text as main partzmore text as a related partz&yet more text as a second "attachment"r#)	r�r?r�rr�copyrrqr1r8)rrZorigrrr
�test_iter_attachments_mutation�s


"z3TestEmailMessageBase.test_iter_attachments_mutation)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#�r%rMrN�r%rOrN�r%r/rN�r%r%r�r%rPrQ�r%rRrQ�rPrMrN�rPrOrN�rPr/rN�rPr%rN�rPrPr�rPrRrQ�rRrMrN�rRrOrN�rRr/rN�rRr%rN�rRrPrN�rRrRr)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�)rr r!rrrrZmessage_paramsr7r9r;r@rGrJrKrLZsubtype_paramsrhrnrur|r�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-VersionrAz1.0)rr@�assertNotInr?r)rrrFrrr
�"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)rr6r<r=rrr
r?�sz4TestEmailMessage._MIME_Version_adding_CM.set_contentN)rr r!r?rrrr
�_MIME_Version_adding_CM�sr�cCsS|jd�}|j�}|jd|�|jd|�|j|dd�dS)NrzMIME-VersionrAz1.0)rr�r�r?r)rrrFrrr
�0test_set_content_does_not_duplicate_MIME_Version�s
zATestEmailMessage.test_set_content_does_not_duplicate_MIME_VersionN)rr r!rr`r�r�r�rrrr
r��sr�c@s"eZdZeZdd�ZdS)�TestMIMEPartcCsO|jd�}|j�}|jd|�|jd|�|jd|�dS)NrzMIME-VersionrA)rr@r�r?)rrrFrrr
�*test_set_content_does_not_add_MIME_Versions
z7TestMIMEPart.test_set_content_does_not_add_MIME_VersionN)rr r!rr`r�rrrr
r�sr��__main__)ZunittestrZemailrrZ
email.messagerrZtest.test_emailrrrrr"r�r�r�mainrrrr
�<module>s���