Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_email/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_email/__pycache__/test_defect_handling.cpython-35.pyc



��Yf=,�@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�ZdS)�TestDefectsBaseFccs	dVdS)N�)�self�defectrr�I/opt/alt/python35/lib64/python3.5/test/test_email/test_defect_handling.py�_raise_pointszTestDefectsBase._raise_pointcCs�tjd�}|jtj��|j|�}WdQRX|jrEdS|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|jrEdS|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_boundaryAs		
z*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==--
        cCs�|jtj�� |j|jjd��}WdQRX|jrBdS|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_ctecCsK|jr
dS|j|jjd��}|jt|j|��d�dS)N�r)rrr"r#rrr)rrrrr	�test_multipart_no_cte_no_defect�s	z/TestDefectsBase.test_multipart_no_cte_no_defectcCsg|jr
dSxSdD]K}|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|jrEdS|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_multipartcCs�tjd�}|jtj��|j|�}WdQRX|jrEdS|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|jr6dS|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
Cs�|jtj��|jd�}WdQRX|jr6dS|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
Cs�tjd�}|j|�}|jtj��|jdd�}WdQRX|jrWdS|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
            �decodeTsvi)r
rrr
rZInvalidBase64PaddingDefectrrrr/r)rrr�payloadrrr	�"test_bad_padding_in_base64_payload�s		z2TestDefectsBase.test_bad_padding_in_base64_payloadc
Cs�tjd�}|j|�}|jtj��|jdd�}WdQRX|jrWdS|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===
            r3Tsvi)r
rrr
rZInvalidBase64CharactersDefectrrrr/r)rrrr4rrr	�$test_invalid_chars_in_base64_payload�s		z4TestDefectsBase.test_invalid_chars_in_base64_payloadc
Cs�tjd�}|jtj��|j|�}WdQRX|jrEdS|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,r1r2r5r6r7rrrr	r	s"	/	&
rc@seZdZdd�ZdS)�TestDefectDetectioncCs|jS)N)r)r�objrrr	r!szTestDefectDetection.get_defectsN)r8r9r:rrrrr	r>sr>c@sAeZdZGdd�dej�Zdd�Zdd�ZdS)�TestDefectCapturec@s"eZdZdZdd�ZdS)zTestDefectCapture.CapturePolicyNcCs|jj|�dS)N)�captured�append)rr?rrrr	�register_defect)sz/TestDefectCapture.CapturePolicy.register_defect)r8r9r:rArCrrrr	�
CapturePolicy'srDcCs|jdt��|_dS)NrA)rD�listr)rrrr	�setUp,szTestDefectCapture.setUpcCs
|jjS)N)rrA)rr?rrr	r/szTestDefectCapture.get_defectsN)r8r9r:rZEmailPolicyrDrFrrrrr	r@%sr@c@sFeZdZejZejdd�ZdZejdd��Z	dS)�TestDefectRaisingZraise_on_defectTc	cs |j|��
dVWdQRXdS)N)ZassertRaises)rrrrr	r
9szTestDefectRaising._raise_pointN)
r8r9r:rrZclonerr<r=r
rrrr	rG3s	rG�__main__)r
Zunittestr<ZemailrrZtest.test_emailrrr>r@rGr8�mainrrrr	�<module>s�