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_defect_handling.cpython-36.pyc

3

� f�.�@s�ddlZddlZddlZddlmZddlmZddlmZGdd�d�ZGdd�dee�Z	Gd	d
�d
ee�Z
Gdd�dee�Zed
kr�ej
�dS)�N)�policy)�errors)�
TestEmailBasec@s�eZdZejZdZejdd��Zdd�Z	dd�Z
ejd�Z
d	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS) �TestDefectsBaseFccs
dVdS)N�)�self�defectrr�I/opt/alt/python36/lib64/python3.6/test/test_email/test_defect_handling.py�_raise_pointszTestDefectsBase._raise_pointcCs�tjd�}|jtj��|j|�}WdQRX|jr6dS|jd�}|jt	|d��|j
t|j|��d�|j
|j|�dtj�dS)Na_            Subject: XX
            From: xx@xx.dk
            To: XX
            Mime-version: 1.0
            Content-type: multipart/mixed;
               boundary="MS_Mac_OE_3071477847_720252_MIME_Part"

            --MS_Mac_OE_3071477847_720252_MIME_Part
            Content-type: multipart/alternative;
               boundary="MS_Mac_OE_3071477847_720252_MIME_Part"

            --MS_Mac_OE_3071477847_720252_MIME_Part
            Content-type: text/plain; charset="ISO-8859-1"
            Content-transfer-encoding: quoted-printable

            text

            --MS_Mac_OE_3071477847_720252_MIME_Part
            Content-type: text/html; charset="ISO-8859-1"
            Content-transfer-encoding: quoted-printable

            <HTML></HTML>

            --MS_Mac_OE_3071477847_720252_MIME_Part--

            --MS_Mac_OE_3071477847_720252_MIME_Part
            Content-type: image/gif; name="xx.gif";
            Content-disposition: attachment
            Content-transfer-encoding: base64

            Some removed base64 encoded chars.

            --MS_Mac_OE_3071477847_720252_MIME_Part--

            r�defects�)�textwrap�dedentr
r�StartBoundaryNotFoundDefect�_str_msg�raise_expected�get_payload�
assertTrue�hasattr�assertEqual�len�get_defects�assertIsInstance)r�source�msg�innerrrr	�test_same_boundary_inner_outers#
z.TestDefectsBase.test_same_boundary_inner_outercCs�tjd�}|jtj��|j|�}WdQRX|jr6dS|j|j�t	�|j
t|j|��d�|j|j|�dtj�|j|j|�dtj
�dS)Na�            Date: Fri, 6 Apr 2001 09:23:06 -0800 (GMT-0800)
            From: foobar
            Subject: broken mail
            MIME-Version: 1.0
            Content-Type: multipart/report; report-type=delivery-status;

            --JAB03225.986577786/zinfandel.lacita.com

            One part

            --JAB03225.986577786/zinfandel.lacita.com
            Content-Type: message/delivery-status

            Header: Another part

            --JAB03225.986577786/zinfandel.lacita.com--
            �rr)r
rr
r�NoBoundaryInMultipartDefectrrrr�strrrr�!MultipartInvariantViolationDefect)rrrrrr	�test_multipart_no_boundaryAsz*TestDefectsBase.test_multipart_no_boundarya^        Date: Wed, 14 Nov 2007 12:56:23 GMT
        From: foo@bar.invalid
        To: foo@bar.invalid
        Subject: Content-Transfer-Encoding: base64 and multipart
        MIME-Version: 1.0
        Content-Type: multipart/mixed;
            boundary="===============3344438784458119861=="{}

        --===============3344438784458119861==
        Content-Type: text/plain

        Test message

        --===============3344438784458119861==
        Content-Type: application/octet-stream
        Content-Transfer-Encoding: base64

        YWJj

        --===============3344438784458119861==--
        cCsf|jtj��|j|jjd��}WdQRX|jr4dS|jt|j	|��d�|j
|j	|�dtj�dS)Nz"
Content-Transfer-Encoding: base64rr)r
rZ-InvalidMultipartContentTransferEncodingDefectr�
multipart_msg�formatrrrrr)rrrrr	�test_multipart_invalid_cteus
z*TestDefectsBase.test_multipart_invalid_ctecCs6|jr
dS|j|jjd��}|jt|j|��d�dS)N�r)rrr"r#rrr)rrrrr	�test_multipart_no_cte_no_defect�sz/TestDefectsBase.test_multipart_no_cte_no_defectcCsN|jr
dSx>dD]6}|j|jjd|��}|jt|j|��dd|�qWdS)N�7bit�8bit�BINaryz
Content-Transfer-Encoding: rzcte=)r'r(r))rrr"r#rrr)rZcterrrr	�"test_multipart_valid_cte_no_defect�s
z2TestDefectsBase.test_multipart_valid_cte_no_defectcCs�tjd�}|jtj��|j|�}WdQRX|jr6dS|jt|d��|j	t
|j|��d�|j|j|�dtj�|j|j|�dtj
�dS)Na            From: "Allison Dunlap" <xxx@example.com>
            To: yyy@example.com
            Subject: 64423
            Date: Sun, 11 Jul 2004 16:09:27 -0300
            MIME-Version: 1.0
            Content-Type: multipart/alternative;

            Blah blah blah
            rrrr)r
rr
rrrrrrrrrrr )rrrrrr	�test_lying_multipart�s	z$TestDefectsBase.test_lying_multipartcCsxtjd�}|jtj��|j|�}WdQRX|jr6dS|jd�jd�}|jt	|j
|��d�|j|j
|�dtj�dS)Na�            Content-Type: multipart/mixed; boundary="AAA"
            From: Mail Delivery Subsystem <xxx@example.com>
            To: yyy@example.com

            --AAA

            Stuff

            --AAA
            Content-Type: message/rfc822

            From: webmaster@python.org
            To: zzz@example.com
            Content-Type: multipart/mixed; boundary="BBB"

            --BBB--

            --AAA--

            rr)r
rr
rrrrrrrrr)rrZouterZbadrrr	�test_missing_start_boundary�s	z+TestDefectsBase.test_missing_start_boundarycCs�|jtj��|jd�}WdQRX|jr,dS|j|j�dg�|j|j�d�|jt|j	|��d�|j
|j	|�tjg�|j|j	|�djd�dS)Nz Line 1
Subject: test

body�SubjectZbodyrrz Line 1
)r
rZ#FirstHeaderLineIsContinuationDefectrrr�keysrrr�assertDefectsEqual�line)rrrrr	�&test_first_line_is_continuation_header�s
z6TestDefectsBase.test_first_line_is_continuation_headerc
Csh|jtj��|jd�}WdQRX|jr,dS|j|j�dg�|j|j�d�|j|j	|�tjg�dS)Nz&Subject: test
not a header
To: abc

b
r-znot a header
To: abc

b
)
r
rZ MissingHeaderBodySeparatorDefectrrrr.rr/r)rrrrr	�"test_missing_header_body_separator�sz2TestDefectsBase.test_missing_header_body_separatorc
Cshtjd�}|j|�}|jtj��|jdd�}WdQRX|jrBdS|j|d�|j	|j
|�tjg�dS)Nz�            Subject: test
            MIME-Version: 1.0
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: base64

            dmk
            T)�decodesvi)r
rrr
rZInvalidBase64PaddingDefectrrrr/r)rrr�payloadrrr	�"test_bad_padding_in_base64_payload�s
z2TestDefectsBase.test_bad_padding_in_base64_payloadc
Cshtjd�}|j|�}|jtj��|jdd�}WdQRX|jrBdS|j|d�|j	|j
|�tjg�dS)Nz�            Subject: test
            MIME-Version: 1.0
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: base64

            dmk===
            T)r3svi)r
rrr
rZInvalidBase64CharactersDefectrrrr/r)rrrr4rrr	�$test_invalid_chars_in_base64_payload�s
z4TestDefectsBase.test_invalid_chars_in_base64_payloadc
Cshtjd�}|j|�}|jtj��|jdd�}WdQRX|jrBdS|j|d�|j	|j
|�tjg�dS)Nz�            Subject: test
            MIME-Version: 1.0
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: base64

            abcde
            T)r3sabcde)r
rrr
rZInvalidBase64LengthDefectrrrr/r)rrrr4rrr	�%test_invalid_length_of_base64_payloads
z5TestDefectsBase.test_invalid_length_of_base64_payloadc
Csztjd�}|jtj��|j|�}WdQRX|jr6dS|jt|j	��d�|j|j	d�j	�d�|j
|j|�tjg�dS)Na?            To: 1@harrydomain4.com
            Subject: Fwd: 1
            MIME-Version: 1.0
            Content-Type: multipart/alternative;
             boundary="------------000101020201080900040301"

            --------------000101020201080900040301
            Content-Type: text/plain; charset=ISO-8859-1
            Content-Transfer-Encoding: 7bit

            Alternative 1

            --------------000101020201080900040301
            Content-Type: text/html; charset=ISO-8859-1
            Content-Transfer-Encoding: 7bit

            Alternative 2

            rrzAlternative 2
)r
rr
rZCloseBoundaryNotFoundDefectrrrrrr/r)rrrrrr	�test_missing_ending_boundarysz,TestDefectsBase.test_missing_ending_boundaryN)�__name__�
__module__�__qualname__r�defaultr�
contextlib�contextmanagerr
rr!r
rr"r$r&r*r+r,r1r2r5r6r7r8rrrr	r	s$/&
rc@seZdZdd�ZdS)�TestDefectDetectioncCs|jS)N)r)r�objrrr	r2szTestDefectDetection.get_defectsN)r9r:r;rrrrr	r?0sr?c@s.eZdZGdd�dej�Zdd�Zdd�ZdS)�TestDefectCapturec@seZdZdZdd�ZdS)zTestDefectCapture.CapturePolicyNcCs|jj|�dS)N)�captured�append)rr@rrrr	�register_defect:sz/TestDefectCapture.CapturePolicy.register_defect)r9r:r;rBrDrrrr	�
CapturePolicy8srEcCs|jt�d�|_dS)N)rB)rE�listr)rrrr	�setUp=szTestDefectCapture.setUpcCs|jjS)N)rrB)rr@rrr	r@szTestDefectCapture.get_defectsN)r9r:r;rZEmailPolicyrErGrrrrr	rA6srAc@s0eZdZejZejdd�ZdZejdd��Z	dS)�TestDefectRaisingT)Zraise_on_defectc	cs |j|��dVWdQRXdS)N)ZassertRaises)rrrrr	r
JszTestDefectRaising._raise_pointN)
r9r:r;rrZclonerr=r>r
rrrr	rHDsrH�__main__)r
Zunittestr=ZemailrrZtest.test_emailrrr?rArHr9�mainrrrr	�<module>s)