Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/test_email/__pycache__/test_generator.cpython-38.opt-1.pyc

U

i�fR7�@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 |dkr|jn|}|j||d�S)Nr)r	�msgfunc)�self�msgr	�r�C/opt/alt/python38/lib64/python3.8/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>VszTestGeneratorBase.<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	�clonerrr 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)rrr �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	�SMTPrrr �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�
)�linesepr2r4rrr�%test_flatten_linesep_overrides_policy�sz7TestGeneratorBase.test_flatten_linesep_overrides_policyc	
Cs�t�d�}dtjdftjdftjjdd�dff}|D]|\}}|rL|�dd�n|}|j||d��L|�|�	|��}|�
�}|j||d	�}|�|�|�
|��|�	|��W5QRXq4dS)
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�subTestrrrrrrr )	rr5Zvariants�pZmangler6rr"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)rrr )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)rrr �rrr6r"r#rrr�test_rfc2231_wrapping�s

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

            None
            rr&rrGrHrrr�;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&rrGrHrrr�test_keep_encoded_newlines�s

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

            None
            �r&rrGrHrrr�test_keep_long_encoded_newlines�s

z1TestGeneratorBase.test_keep_long_encoded_newlines)N)�__name__�
__module__�__qualname__r	r?rr<r=r�copyr0Z
length_paramsr$r*r,r.r1r7r:rCrDrIrJrMrOrrrrr
s4
	�*�
�
		rc@s*eZdZee�ZeZej	Z
eZdd�Z
dS)�
TestGeneratorcCsxGdd�dt�}dD]^}|j|d��Htd|jd�}|d=||�|d<|�tjj��|��W5QRXW5QRXqdS)	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)rPrQrR�namerWrrrr�
LiteralHeadersrY)zValue
Bad Injection
Z	NoNewLine)�textzHeader: Value

BodyrrUN)	�strrArr	ZassertRaises�email�errorsZHeaderWriteErrorZ	as_string)rrYrZ�messagerrr�test_verify_generated_headers
s�z+TestGenerator.test_verify_generated_headersN)rPrQrR�staticmethodrr
rr�io�StringIOrr[rr_rrrrrTs
rTc@sFeZdZee�ZeZej	Z
dd�Zdd�Zdd�Z
dd�Zd	d
�ZdS)�TestBytesGeneratorcCs
|�d�S)N�ascii)�encode)r�xrrr�<lambda>'�zTestBytesGenerator.<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?=

rd�7bit)�cte_typer)
rerra�BytesIOrr	r)rrr r4rrr�'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?
            rdrjr8)rkr9r)r<r=rerrarlrr	r)rrr )rr5rr6r"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=rer@rarlrr	ZSMTPUTF8rrr rHrrr�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=rer@rarlrr	r3rrr rHrrr�test_smtp_policyes
	�

z#TestBytesGenerator.test_smtp_policyN)rPrQrRr`rr
rrrarlrrrmrorwrxrrrrrc"src�__main__)rar<Zunittestr\rrZ
email.messagerZemail.generatorrrZemail.headerregistryrr	Zemail.errorsZtest.test_emailr
rrrTrcrP�mainrrrr�<module>s vY