U
    c6{i¾  ã                   @  sz   d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZmZ d dlmZ d dlmZ G dd	„ d	ejƒZdS )
é    )ÚannotationsN)ÚMessage)ÚBytesIOÚStringIO)ÚIOÚAnyStrÚCallable)Úbounce)Úunittestc                   @  s\   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zd
d
dddœdd„Zddœdd„ZdS )ÚBounceTestsz#
    Bounce message generation
    ÚNone)Úreturnc                 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&   úA/tmp/pip-unpacked-wheel-hfbvu0bz/twisted/mail/test/test_bounce.pyÚtest_bounceMessageUnicode   s    ÿö

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,   s    ÿö

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_bounceMessageCustomTranscriptD   s*    ÿõ


þz.BounceTests.test_bounceMessageCustomTranscriptr   zCallable[[AnyStr], IO[AnyStr]])ÚheaderÚmessageÚioTyper   c                 C  sÆ   t  ||| ƒdd¡\}}}tj ¡ }| t| d¡ƒ¡}|  |d d¡ |  |d d¡ |  |d d¡ |  	| 
¡ ¡ | ¡ }	|	d	  ¡ }
t|tƒr¢| d¡}n|}|
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    r1   r2   r3   r!   r"   r#   r$   r%   r/   ZinnerMessageZmessageTextÚplr&   r&   r'   Ú_bounceBigMessagec   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)r9   r   r   r   )r    r1   r&   r&   r'   Útest_bounceBigMessage{   s    z!BounceTests.test_bounceBigMessageN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r+   r0   r9   r:   r&   r&   r&   r'   r      s   r   )Ú
__future__r   Úemail.messager   Úemail.parserr   Úior   r   Útypingr   r   r   Ztwisted.mailr	   Ztwisted.trialr
   ZTestCaser   r&   r&   r&   r'   Ú<module>   s   