o
    ¯bâ  ã                   @   sN   d dl Zd dlZd dlmZmZ d dlmZ d dlm	Z	 G dd„ de	j
ƒZdS )é    N)ÚBytesIOÚStringIO)Úbounce)Úunittestc                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚBounceTestsz#
    Bounce message generation
    c                 C   s‚   t  tdƒdd¡\}}}|  |d¡ |  |d¡ tj ¡ }| t| d¡ƒ¡}|  |d d¡ |  |d d	¡ |  |d
 d¡ dS )zN
        L{twisted.mail.bounce.generateBounce} can accept L{unicode}.
        zRFrom: Moshe Zadka <moshez@example.com>
To: nonexistent@example.org
Subject: test

úmoshez@example.comúnonexistent@example.orgó    ó   moshez@example.comúutf-8ÚToÚFromúpostmaster@example.orgÚsubjectú)Returned Mail: see transcript for detailsN)	r   ÚgenerateBouncer   ÚassertEqualÚemailÚparserÚParserÚparseÚdecode©ÚselfÚfromAddressÚtoÚsÚemailParserÚmess© r   ú?/usr/lib/python3/dist-packages/twisted/mail/test/test_bounce.pyÚtest_bounceMessageUnicode   ó   ÿ
ö
z%BounceTests.test_bounceMessageUnicodec                 C   s‚   t  tdƒdd¡\}}}|  |d¡ |  |d¡ tj ¡ }| t| 	d¡ƒ¡}|  |d d¡ |  |d d	¡ |  |d
 d¡ dS )zL
        L{twisted.mail.bounce.generateBounce} can accept L{bytes}.
        óR   From: Moshe Zadka <moshez@example.com>
To: nonexistent@example.org
Subject: test

r
   ó   nonexistent@example.orgr	   r   r   r   r   r   r   r   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r    Útest_bounceMessageBytes)   r"   z#BounceTests.test_bounceMessageBytesc                 C   s®   t  tdƒddd¡\}}}|  |d¡ |  |d¡ tj ¡ }| t| 	d¡ƒ¡}|  |d d¡ |  |d	 d
¡ |  |d d¡ |  
| ¡ ¡ | ¡ }|  |d  ¡ d¡ dS )z\
        Pass a custom transcript message to L{twisted.mail.bounce.generateBounce}.
        r#   r
   r$   zCustom transcriptr	   r   r   r   r   r   r   r   r   zCustom transcript
N)r   r   r   r   r   r   r   r   r   r   Ú
assertTrueÚis_multipartÚget_payload)r   r   r   r   r   r   Úpartsr   r   r    Ú"test_bounceMessageCustomTranscriptA   s$   ÿ
õ
z.BounceTests.test_bounceMessageCustomTranscriptc                 C   s¼   t  ||| ƒdd¡\}}}tj ¡ }| t| d¡ƒ¡}|  |d d¡ |  |d d¡ |  |d d¡ |  	| 
¡ ¡ | ¡ }	|	d	  ¡ }
t|tƒrP| d¡}|  |
d
  ¡ d |¡ dS )zU
        Pass a really big message to L{twisted.mail.bounce.generateBounce}.
        r   r   r   r   r   r   r   r   é   r   Ú
N)r   r   r   r   r   r   r   r   r   r&   r'   r(   Ú
isinstanceÚbytes)r   ÚheaderÚmessageÚioTyper   r   r   r   r   r)   ÚinnerMessager   r   r    Ú_bounceBigMessage]   s   
ÿ


zBounceTests._bounceBigMessagec                 C   s2   d}|   |dd t¡ |   | d¡dd t¡ dS )zj
        L{twisted.mail.bounce.generateBounce} with big L{unicode} and
        L{bytes} messages.
        r#   s
   Test test
i'  r   z
More test
N)r3   r   r   r   )r   r/   r   r   r    Útest_bounceBigMessagep   s   z!BounceTests.test_bounceBigMessageN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r%   r*   r3   r4   r   r   r   r    r      s    r   )Úemail.messager   Úemail.parserÚior   r   Útwisted.mailr   Útwisted.trialr   ÚTestCaser   r   r   r   r    Ú<module>   s   