Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/test_email/__pycache__/test_generator.cpython-39.pyc

a

XC?hR7�@s�ddlZddlZddlZddlmZmZddlmZddlm	Z	m
Z
ddlmZddlm
Z
ddlZddlmZmZeGdd	�d	��ZGd
d�dee�ZGdd
�d
ee�Zedkr�e��dS)�N)�message_from_string�message_from_bytes)�EmailMessage)�	Generator�BytesGenerator)�Address��policy)�
TestEmailBase�parameterizec@s�eZdZejZd(dd�Ze�d�e�d�e�d�d�Zeded	<e�	�Z
d
e
d<de
d	<dd
�eD�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdS))�TestGeneratorBaseNcCs |dur|jn|}|j||d�S)Nr)r	�msgfunc)�self�msgr	�r�C/opt/alt/python39/lib64/python3.9/test/test_email/test_generator.py�msgmakerszTestGeneratorBase.msgmakeraf            To: whom_it_may_concern@example.com
            From: nobody_you_want_to_know@example.com
            Subject: We the willing led by the unknowing are doing the
             impossible for the ungrateful. We have done so much for so long with so little
             we are now qualified to do anything with nothing.

            None
            a�            To: whom_it_may_concern@example.com
            From:
             nobody_you_want_to_know@example.com
            Subject: We the willing led by the
             unknowing are doing the impossible for
             the ungrateful. We have done so much
             for so long with so little we are now
             qualified to do anything with nothing.

            None
            a�            To:
             whom_it_may_concern@example.com
            From:
             nobody_you_want_to_know@example.com
            Subject: We the
             willing led by the
             unknowing are doing
             the impossible for
             the ungrateful. We
             have done so much
             for so long with so
             little we are now
             qualified to do
             anything with
             nothing.

            None
            )r�(�r�daTo: whom_it_may_concern@example.com
From: nobody_you_want_to_know@example.com
Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have done so much for so long with so little we are now qualified to do anything with nothing.

None
aTo: whom_it_may_concern@example.com
From: nobody_you_want_to_know@example.com
Subject: We the willing led by the unknowing are doing the impossible for the ungrateful. We have
 done so much for so long with so little we are now qualified to do anything with nothing.

None
cCsg|]}|�qSrr)�.0�nrrr�
<listcomp>V�zTestGeneratorBase.<listcomp>cCsZ|�|�|jd��}|��}|j|||jd�}|�|�|�|��|�|j|��dS)Nr�Zmaxheaderlenr	)	r�typ�refold_long_expected�ioclass�genclassr	�flatten�assertEqual�getvalue�rrr�s�grrr� length_as_maxheaderlen_parameterXs

z2TestGeneratorBase.length_as_maxheaderlen_parametercCs`|�|�|jd��}|��}|j||jj|d�d�}|�|�|�|�	�|�|j|��dS�Nr��max_line_lengthr�
rrrrrr	�clonerr r!r"rrr� length_as_max_line_length_policy_s

z2TestGeneratorBase.length_as_max_line_length_policycCsb|�|�|jd��}|��}|j|||jjdd�d�}|�|�|�|�	�|�|j|��dS)Nr�
r'rr)r"rrr�,length_as_maxheaderlen_parm_overrides_policyfs�
z>TestGeneratorBase.length_as_maxheaderlen_parm_overrides_policycCsb|�|�|jd��}|��}|j||jjd|d�d�}|�|�|�|�	�|�|jd��dS)NrZnone�Z
refold_sourcer(rr)r"rrr�8length_as_max_line_length_with_refold_none_does_not_foldns�

zJTestGeneratorBase.length_as_max_line_length_with_refold_none_does_not_foldcCsb|�|�|jd��}|��}|j||jjd|d�d�}|�|�|�|�	�|�|j
|��dS)Nr�allr.r)rrrrrr	r*rr r!�refold_all_expectedr"rrr�/length_as_max_line_length_with_refold_all_foldsvs�

zATestGeneratorBase.length_as_max_line_length_with_refold_all_foldscCsTd}|}|�|�|��}|��}|j|tjd�}|�|�|�|��|�|��dS)NzSubject: test

test body
r�	rrrrr	�SMTPrr r!�r�source�expectedrr#r$rrr�test_crlf_control_via_policy~s
z.TestGeneratorBase.test_crlf_control_via_policycCsXd}|}|�|�|��}|��}|j|tjd�}|j|dd�|�|��|�|��dS)NzSubject: test

test body
r�
)�linesepr3r5rrr�%test_flatten_linesep_overrides_policy�sz7TestGeneratorBase.test_flatten_linesep_overrides_policyc		Cs�t�d�}dtjdftjdftjjdd�dff}|D]�\}}|rL|�dd�n|}|j||d��V|�|�	|��}|�
�}|j||d	�}|�|�|�
|��|�	|��Wd�q41s�0Yq4dS)
Nz�            Subject: test that
             from is mangled in the body!

            From time to time I write a rhyme.
            )NTTF)�mangle_from_zFrom z>From )r	r<r)�textwrap�dedentr	�compat32�defaultr*�replace�subTestrrrrrr r!)	rr6Zvariants�pZmangler7rr#r$rrr�test_set_mangle_from_via_policy�s
�
z1TestGeneratorBase.test_set_mangle_from_via_policycCs`|�|�|jd��}|��}|j|tjjdd�d�}|�|�|�	|�
�|�|jd��dSr&)rrrrrr	r?r*rr r!)rrr#r$rrr�5test_compat32_max_line_length_does_not_fold_when_none�s

zGTestGeneratorBase.test_compat32_max_line_length_does_not_fold_when_nonecCsd|�|�t�d���}t�d�}|��}|j||jjdd�d�}|�|�|�	|�
�|�|��dS)N��            To: nobody
            Content-Disposition: attachment;
             filename="afilenamelongenoghtowraphere"

            None
            z�            To: nobody
            Content-Disposition: attachment;
             filename*0*=us-ascii''afilename;
             filename*1*=longenoghtowraphere

            None
            �!r'r�rrr=r>rrr	r*rr r!�rrr7r#r$rrr�test_rfc2231_wrapping�s

z'TestGeneratorBase.test_rfc2231_wrappingcCsd|�|�t�d���}t�d�}|��}|j||jjdd�d�}|�|�|�	|�
�|�|��dS)NrFz�            To: nobody
            Content-Disposition:
             attachment;
             filename*0*=us-ascii''afilenamelongenoghtowraphere

            None
            rr'rrHrIrrr�;test_rfc2231_wrapping_switches_to_default_len_if_too_narrow�s

zMTestGeneratorBase.test_rfc2231_wrapping_switches_to_default_len_if_too_narrowcCsd|�|�t�d���}t�d�}|��}|j||jjdd�d�}|�|�|�	|�
�|�|��dS)N�            To: nobody
            Subject: Bad subject=?UTF-8?Q?=0A?=Bcc: injection@example.com

            None
            �Pr'rrHrIrrr�test_keep_encoded_newlines�s

z,TestGeneratorBase.test_keep_encoded_newlinescCsd|�|�t�d���}t�d�}|��}|j||jjdd�d�}|�|�|�	|�
�|�|��dS)NrLz�            To: nobody
            Subject: Bad subject
             =?utf-8?q?=0A?=Bcc:
             injection@example.com

            None
            �r'rrHrIrrr�test_keep_long_encoded_newlines�s

z1TestGeneratorBase.test_keep_long_encoded_newlines)N)�__name__�
__module__�__qualname__r	r@rr=r>r�copyr1Z
length_paramsr%r+r-r/r2r8r;rDrErJrKrNrPrrrrr
s4
	�*�
�
		rc@s*eZdZee�ZeZej	Z
eZdd�Z
dS)�
TestGeneratorc
Cs�Gdd�dt�}dD]�}|j|d��ftd|jd�}|d=||�|d<|�tjj��|��Wd�n1sr0YWd�q1s�0YqdS)	z=gh-121650: by default the generator prevents header injectionc@seZdZdZdd�ZdS)zBTestGenerator.test_verify_generated_headers.<locals>.LiteralHeader�Headerc[s|S)Nr)r�kwargsrrr�foldszGTestGenerator.test_verify_generated_headers.<locals>.LiteralHeader.foldN)rQrRrS�namerXrrrr�
LiteralHeadersrZ)zValue
Bad Injection
Z	NoNewLine)�textzHeader: Value

BodyrrVN)	�strrBrr	ZassertRaises�email�errorsZHeaderWriteErrorZ	as_string)rrZr[�messagerrr�test_verify_generated_headers
s�z+TestGenerator.test_verify_generated_headersN)rQrRrS�staticmethodrr
rr�io�StringIOrr\rr`rrrrrUs
rUc@sFeZdZee�ZeZej	Z
dd�Zdd�Zdd�Z
dd�Zd	d
�ZdS)�TestBytesGeneratorcCs
|�d�S)N�ascii)�encode)r�xrrr�<lambda>'rzTestBytesGenerator.<lambda>cCsXd�d�}d�d�}t|�}t��}t||jjdd�d�}|�|�|�|�	�|�dS)Nu5Subject: Maintenant je vous présente mon collègue

�utf-8zPSubject: Maintenant je vous =?unknown-8bit?q?pr=C3=A9sente_mon_coll=C3=A8gue?=

re�7bit)�cte_typer)
rfrrb�BytesIOrr	r*rr r!r5rrr�'test_cte_type_7bit_handles_unknown_8bit)s��
z:TestBytesGenerator.test_cte_type_7bit_handles_unknown_8bitcCsft�d��d�}t|�}t�d��d�}t��}t||jjddd�d�}|�	|�|�
|��|�dS)	Nu/            From: foo@bar.com
            To: Dinsdale
            Subject: Nudge nudge, wink, wink
            Mime-Version: 1.0
            Content-Type: text/plain; charset="latin-1"
            Content-Transfer-Encoding: 8bit

            oh là là, know what I mean, know what I mean?
            �latin1a@            From: foo@bar.com
            To: Dinsdale
            Subject: Nudge nudge, wink, wink
            Mime-Version: 1.0
            Content-Type: text/plain; charset="iso-8859-1"
            Content-Transfer-Encoding: quoted-printable

            oh l=E0 l=E0, know what I mean, know what I mean?
            rerjr9)rkr:r)r=r>rfrrbrlrr	r*rr r!)rr6rr7r#r$rrr�&test_cte_type_7bit_transforms_8bit_cte4s
	�

	�
�

z9TestBytesGenerator.test_cte_type_7bit_transforms_8bit_ctecCstt�}d|d<d|d<d|d<|�d�t�d��d	��d
d�}t��}t|t	j
d�}|�|�|�|�
�|�dS)
NuPáolo <főo@bar.com>�From�Dinsdale�TouNudge nudge, wink, wink ὠ9�Subjectu/oh là là, know what I mean, know what I mean?u<            From: Páolo <főo@bar.com>
            To: Dinsdale
            Subject: Nudge nudge, wink, wink ὠ9
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 8bit
            MIME-Version: 1.0

            oh là là, know what I mean, know what I mean?
            ri�
�
r)r�set_contentr=r>rfrArbrlrr	ZSMTPUTF8rr r!rIrrr�test_smtputf8_policyPs

	�	�

z'TestBytesGenerator.test_smtputf8_policycCs�t�}tddd�|d<tddd�|d<d|d	<|�d
�t�d����dd
�}t��}t	|t
jd�}|�|�|�
|��|�dS)Nzfoo@bar.comuPáolo)Z	addr_specZdisplay_namerpzbar@foo.comrqrrzNudge nudge, wink, winkrsz+oh boy, know what I mean, know what I mean?aP            From: =?utf-8?q?P=C3=A1olo?= <foo@bar.com>
            To: Dinsdale <bar@foo.com>
            Subject: Nudge nudge, wink, wink
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: 7bit
            MIME-Version: 1.0

            oh boy, know what I mean, know what I mean?
            rtrur)rrrvr=r>rfrArbrlrr	r4rr r!rIrrr�test_smtp_policyes
	�

z#TestBytesGenerator.test_smtp_policyN)rQrRrSrarr
rrrbrlrrrmrorwrxrrrrrd"srd�__main__)rbr=Zunittestr]rrZ
email.messagerZemail.generatorrrZemail.headerregistryrr	Zemail.errorsZtest.test_emailr
rrrUrdrQ�mainrrrr�<module>s vY