Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/test_email/__pycache__/test_message.cpython-36.opt-1.pyc

3

� fsj�@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/python36/lib64/python3.6/test/test_email/test_message.py�<lambda>
szfirst.<locals>.<lambda>)�next�filter)�iterablerrr
�first	src@s"eZdZejZdd�Zdd�ZdS)�Testc
Cs4|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_exceededcCsDttjd�tjd�}|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
src@s�eZdZejZdMffdfdNffejd�fdOffejd�fdPfdQejd�fdRfdSejd	�fdTdUdVejd
�fdWdXdYejd�fdZfd[ejd�fd\d]d^ejd
�fd_d`daejd�fdbdcddejd�fdedfdgejd�fdhdidjejd�fdkffejd�fdldmdnejd�fd�Zdd�Zdd�Z	dd�Z
Gdd �d �Zd!d"�Zd#d$�Z
d%d&�Zd'd(�Zd�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�ZGd=d>�d>�Zd?d@�ZGdAdB�dB�ZdCdD�ZdEdF�ZdGdH�ZdIdJ�ZdKdL�ZdS)��TestEmailMessageBaseNrrzV                To: foo@example.com

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

                bogus body.
                ��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>
                --===--
                a�                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>

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

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

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

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

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

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

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

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

                --===--
                z�                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.
                a�                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.

                --===--
                )Z
empty_messageZnon_mime_plainZ
mime_non_textZplain_html_alternativeZplain_html_mixedZplain_html_attachment_mixedZhtml_text_attachment_mixedZ!html_text_attachment_inline_mixed�relatedZrelated_with_startZmixed_alternative_plain_relatedZ$mixed_related_alternative_plain_htmlZ0mixed_related_alternative_plain_html_wrong_orderZmessage_rfc822Zmixed_text_message_rfc822c
s�|j|�}t|j����fdd�|D�}d}d}d}	|j|j�t|��|j|jd
d	�t|��|j|jdd	�t|||d���|j|jdd	�t||||	g��|j|jd
d	�t|||	d���|j|jdgd	�||�|j|jdgd	�||�|j|jdgd	�||	�|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>�sz<TestEmailMessageBase.message_as_get_body.<locals>.<listcomp>rr$r#r)�html�plain)Zpreferencelist)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_bodycs@|j|�}t|j����fdd�|D�}|jt|j��|�dS)Ncsg|]}�|�qSrr)r*r+)r,rr
r-�szCTestEmailMessageBase.message_as_iter_attachment.<locals>.<listcomp>)rr1r2r�iter_attachments)rr3r4r5r6rr)r,r
�message_as_iter_attachment�s
z/TestEmailMessageBase.message_as_iter_attachmentcs@|j|�}t|j����fdd�|D�}|jt|j��|�dS)Ncsg|]}�|�qSrr)r*r+)r,rr
r-�sz>TestEmailMessageBase.message_as_iter_parts.<locals>.<listcomp>)rr1r2r�
iter_parts)rr3r4r5r6rr)r,r
�message_as_iter_parts�s
z*TestEmailMessageBase.message_as_iter_partsc@seZdZdd�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�sz4TestEmailMessageBase._TestContentManager.set_contentN)rr r!r>r?rrrr
�_TestContentManager�sr@cCst|jd�}|j�}|j|j|d�|fif�|jd|ddd�\}}}|j||�|j|d�|j|tddd��dS)	Nr)�content_manager�foor$r#)rA�bar�k)rCrD)rB)rr@rr>�dict)rr�cmr6r<r=rrr
�test_get_content_with_cm�s
z-TestEmailMessageBase.test_get_content_with_cmcCs|tjj|j�d�}|jd|d�}|j|j�|fif�|jdddd�\}}}|j||�|j|d�|j|tddd��dS)	N)rAr)rrBr$r#)rCrD)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�}|j|d�|j|j|�|j|jf�|j|ji�|jd|ddd�|j|j|�|j|jd�|j|jtddd��dS)	Nr)rArBr$r#)rArCrD)rCrD)rB)rr@r?rr6r<r=rE)rrrFrrr
�test_set_content_with_cm	s
z-TestEmailMessageBase.test_set_content_with_cmcCs�|j�}tjj|d�}|jd|d�}|j�|j|j|�|j|jf�|j|j	i�|jdddd�|j|j|�|j|jd�|j|j	t
ddd��dS)	N)rAr)rrBr$r#)rCrD)rB)r@rrrHrr?rr6r<r=rE)rrFrIrrrr
�-test_set_content_default_cm_comes_from_policyszBTestEmailMessageBase.test_set_content_default_cm_comes_from_policyr)�
no_content�succeeds�noner/�alternative�raises�mixedcCs�|j�}d}ddg}|dkr d|jd�|d
krLd}|jd�|jd�n|dkrjg}|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
CsH|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}x6|D].\}}|j�jd�s
|j|||�|d7}q
W|jt|�|d�t|j��}d}x6|D].\}}|j�jd�rf|j|||�|d7}qfW|jt|�|�|j|j�|�dS)Nrzcontent-r$)�lower�
startswithr�lenrr:�get_payload)rrrerd�countrfrg�partrrr
�_check_make_multipart[sz*TestEmailMessageBase._check_make_multipartcCs�|j|�\}}}d|}|d
kr4|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�}|dkrFd||d<|jt��}t|d|��WdQRXdS|dkrXd|d<n|dkrld||d<t|d|�d	d
�|j|j��|j|j�d	�dS)NrrQz
multipart/zContent-Typervr/z
text/plainrM�abc)�boundary)rrQ)r`rrri�
assertTrueZis_multipartrZget_boundary)rrlrcr{rrFrrr
�subtype_as_make_with_boundary}s
z2TestEmailMessageBase.subtype_as_make_with_boundarycCsRxLd
D]D}|j|jjdd�d�}d|d<t||��|j|jd	�jjd�qWdS)N�make_related�make_alternative�
make_mixedrB)rA)rz
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?�sz7TestEmailMessageBase._TestSetContentManager.set_contentN)rr r!r?rrrr
�_TestSetContentManager�sr�cCsf|j|�\}}}|j�}|dkr$dnd|}|dkrH|j||||�dSt||�d|d�|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�|dk�r8|j|d
d�n*|dk�rT|j|d
d�n|j|d
�dS)NrR�add_attachmentZadd_rQ�test)rArwrMr$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._TestSetRaisingContentManagercOstd��dS)Nr�)�	Exception)rr6r�r<r=rrr
r?�sz>TestEmailMessageBase._TestSetRaisingContentManager.set_contentN)rr r!r?rrrr
�_TestSetRaisingContentManager�sr�cCsf|j�}|j|jj|d�d�}xBdD]:}|jt��}t||�d�WdQRX|jt|j	�d�q$WdS)	N)rA)r�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)NcSsg|]}|j�jd�s|�qS)zcontent-)rorp)r*�hrrr
r-�szATestEmailMessageBase.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@sNeZdZeZdd�ZGdd�d�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�ZdS)�TestEmailMessagecCs>|jd�}|j�}|jd|�|j|d�|j|dd�dS)NrzMIME-Version)rAz1.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_CMcOsd|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�sr�cCs>|jd�}|j�}|jd|�|j|d�|j|dd�dS)NrzMIME-Version)rAz1.0)rr�r�r?r)rrrFrrr
�0test_set_content_does_not_duplicate_MIME_Version�s

zATestEmailMessage.test_set_content_does_not_duplicate_MIME_VersioncCs6|jdddd�}|jt|j�j�j��d�dS)NzSubject: long linez ab�2z

r%)rrrq�	as_string�strip�
splitlines)rrrrr
�0test_as_string_uses_max_header_length_by_default�szATestEmailMessage.test_as_string_uses_max_header_length_by_defaultcCsZ|jdddd�}|jt|jdd�j�j��d�|jt|jdd�j�j��d	�dS)
NzSubject: long linez abr�z

r)Zmaxheaderlenr$�"r')rrrqr�r�r�)rrrrr
�"test_as_string_allows_maxheaderlens
z3TestEmailMessage.test_as_string_allows_maxheaderlencCs6|jdddd�}|jtt|�j�j��d�dS)NzSubject: long linez abr�z

r%)rrrqrjr�r�)rrrrr
�+test_str_defaults_to_policy_max_line_length
sz<TestEmailMessage.test_str_defaults_to_policy_max_line_lengthcCs"t�}d|d<|jt|�d�dS)NuunicödeZSubjectuSubject: unicöde

)rrrj)rrrrr
�test_str_defaults_to_utf8sz*TestEmailMessage.test_str_defaults_to_utf8N)rr r!rr`r�r�r�r�r�r�r�rrrr
r��sr�c@seZdZeZdd�ZdS)�TestMIMEPartcCs:|jd�}|j�}|jd|�|j|d�|jd|�dS)NrzMIME-Version)rA)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�sr��__main__)ZunittestrZemailrrZ
email.messagerrZtest.test_emailrrrrr"r�r�r�mainrrrr
�<module>s I*