a
    	3jN                     @   s   d dl Z d dlmZ d dlmZ d dlmZ G dd deZG dd deZG d	d
 d
eZ	G dd deZ
G dd deZG dd deZedkre   dS )    N)_encoded_words)errors)TestEmailBasec                   @   s0   e Zd Zg fddZdd Zdd Zdd Zd	S )
TestDecodeQc                 C   s*   t |\}}| || | || d S N)_ewZdecode_qassertEqualassertDefectsEqualselfsourceZ	ex_resultZ
ex_defectsresultdefects r   _/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_email/test__encoded_words.py_test	   s    zTestDecodeQ._testc                 C   s   |  dd d S )N   foobarr   r   r   r   r   test_no_encoded   s    zTestDecodeQ.test_no_encodedc                 C   s   |  dd |  dd d S )Ns   foo=20bar=20   foo bar s   foo_bar_r   r   r   r   r   test_spaces   s    zTestDecodeQ.test_spacesc                 C   s   |  dd d S )Ns   foo=20=20=21=2Cbars
   foo  !,barr   r   r   r   r   test_run_of_encoded   s    zTestDecodeQ.test_run_of_encodedN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r      s   r   c                   @   s@   e Zd Zg fddZdd Zdd Zdd Zd	d
 Zdd ZdS )TestDecodeBc                 C   s*   t |\}}| || | || d S r   )r   Zdecode_br   r	   r
   r   r   r   r      s    zTestDecodeB._testc                 C   s   |  dd d S )Ns   Zm9v   foor   r   r   r   r   test_simple    s    zTestDecodeB.test_simplec                 C   s(   |  ddtjg |  ddtjg d S )Ns   dmk   vis   dg   vr   r   InvalidBase64PaddingDefectr   r   r   r   test_missing_padding#   s    z TestDecodeB.test_missing_paddingc                 C   s   |  ddtjg d S )Ns   dmk===r   r   r   InvalidBase64CharactersDefectr   r   r   r   test_invalid_character)   s    z"TestDecodeB.test_invalid_characterc                 C   s   |  ddtjtjg d S )Ns   dmkr   r   r   r%   r"   r   r   r   r   &test_invalid_character_and_bad_padding,   s    z2TestDecodeB.test_invalid_character_and_bad_paddingc                 C   s   |  ddtjg d S )Ns   abcde)r   r   ZInvalidBase64LengthDefectr   r   r   r   test_invalid_length0   s    zTestDecodeB.test_invalid_lengthN)	r   r   r   r   r   r#   r&   r(   r)   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd Zddg fddZdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#S )$
TestDecodec                 C   s   |  t td W d    n1 s*0    Y  |  t td W d    n1 s^0    Y  |  t td W d    n1 s0    Y  |  t td W d    n1 s0    Y  d S )Nz
=?badone?=z=? z=?utf-8?X?somevalue?=)ZassertRaises
ValueErrorr   decodeKeyErrorr   r   r   r   test_wrong_format_input_raises6   s    (((z)TestDecode.test_wrong_format_input_raisesus-asciir+   c           
      C   sF   t |\}}}}	| || | || | || | |	| d S r   )r   r-   r   r	   )
r   r   r   charsetlangr   rescharldr   r   r   r   @   s
    zTestDecode._testc                 C   s   |  dd d S )Nz=?us-ascii?q?foo?=foor   r   r   r   r   test_simple_qG   s    zTestDecode.test_simple_qc                 C   s   |  dd d S )Nz=?us-ascii?b?dmk=?=vir   r   r   r   r   test_simple_bJ   s    zTestDecode.test_simple_bc                 C   s   |  dd d S )Nz=?us-ascii?Q?foo?=r7   r   r   r   r   r   test_q_case_ignoredM   s    zTestDecode.test_q_case_ignoredc                 C   s   |  dd d S )Nz=?us-ascii?B?dmk=?=r9   r   r   r   r   r   test_b_case_ignoredP   s    zTestDecode.test_b_case_ignoredc                 C   s   |  ddd d S )Nz!=?latin-1?q?=20F=fcr=20Elise=20?=u    Für Elise zlatin-1r   r   r   r   r   test_non_trivial_qS   s    zTestDecode.test_non_trivial_qc                 C   s    | j ddddtjgd d S )Ns   =?us-ascii?q?=20foo?=r0   surrogateescapeu    foor   )r   r-   r   ZUndecodableBytesDefectr   r   r   r   test_q_escaped_bytes_preservedV   s    
z)TestDecode.test_q_escaped_bytes_preservedc                 C   s$   | j ddddtjtjgd d S )Ns   =?us-ascii?b?dmk?=r0   r>   r9   r?   )r   r-   r   r%   r"   r   r   r   r   ,test_b_undecodable_bytes_ignored_with_defect\   s    
z7TestDecode.test_b_undecodable_bytes_ignored_with_defectc                 C   s   | j ddtjgd d S )Nz=?us-ascii?b?dmk===?=r9   r?   r$   r   r   r   r   (test_b_invalid_bytes_ignored_with_defectd   s    z3TestDecode.test_b_invalid_bytes_ignored_with_defectc                 C   s   | j ddtjtjgd d S )Nz=?us-ascii?b?dmk?=r9   r?   r'   r   r   r   r   &test_b_invalid_bytes_incorrect_paddingi   s    z1TestDecode.test_b_invalid_bytes_incorrect_paddingc                 C   s   | j ddtjgd d S )Nz=?us-ascii?b?dmk?=r9   r?   r!   r   r   r   r   test_b_padding_defectp   s    z TestDecode.test_b_padding_defectc                 C   s   | j dddd d S )Nz=?us-ascii*jive?q?test?=testjiver2   r   r   r   r   r   test_nonnull_langu   s    zTestDecode.test_nonnull_langc                 C   s   | j dddddg d d S )N=?unknown-8bit?q?foo=ACbar?=   foobarasciir>   unknown-8bitr1   r   )r   r-   r   r   r   r   test_unknown_8bit_charsetx   s
    
z$TestDecode.test_unknown_8bit_charsetc                 C   s"   | j dddddtjgd d S )Nz=?foobar?q?foo=ACbar?=rJ   rK   r>   foobarrM   )r   r-   r   ZCharsetErrorr   r   r   r   test_unknown_charset~   s
    
zTestDecode.test_unknown_charsetc                 C   s   | j dddd d S )Nz=?utf-8?q?=C3=89ric?=u   Éricutf-8r1   r   r   r   r   r   test_q_nonascii   s    zTestDecode.test_q_nonasciiN)r   r   r   r/   r   r8   r:   r;   r<   r=   r@   rA   rB   rC   rD   rH   rN   rP   rS   r   r   r   r   r*   4   s    
r*   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestEncodeQc                 C   s   |  t|| d S r   )r   r   Zencode_q)r   srcZexpectedr   r   r   r      s    zTestEncodeQ._testc                 C   s   |  dd d S )Nr   rO   r   r   r   r   r   test_all_safe   s    zTestEncodeQ.test_all_safec                 C   s   |  dd d S )Nr   Zfoo_bar_r   r   r   r   r   r      s    zTestEncodeQ.test_spacesc                 C   s   |  dd d S )Ns
   foo  ,,barzfoo__=2C=2Cbarr   r   r   r   r   test_run_of_encodables   s    z"TestEncodeQ.test_run_of_encodablesN)r   r   r   r   rV   r   rW   r   r   r   r   rT      s   rT   c                   @   s   e Zd Zdd Zdd ZdS )TestEncodeBc                 C   s   |  tdd d S )Nr   ZZm9vr   r   Zencode_br   r   r   r   r      s    zTestEncodeB.test_simplec                 C   s   |  tdd d S )Nr   zdmk=rY   r   r   r   r   test_padding   s    zTestEncodeB.test_paddingN)r   r   r   r   rZ   r   r   r   r   rX      s   rX   c                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )
TestEncodec                 C   s   |  tdddd d S )Nr7   rQ   q=?utf-8?q?foo?=r   r   encoder   r   r   r   test_q   s    zTestEncode.test_qc                 C   s   |  tdddd d S )Nr7   rQ   bz=?utf-8?b?Zm9v?=r^   r   r   r   r   test_b   s    zTestEncode.test_bc                 C   s   |  tddd d S )Nr7   rQ   r]   r^   r   r   r   r   test_auto_q   s    zTestEncode.test_auto_qc                 C   s   |  tddd d S )Nzvi.rQ   z=?utf-8?q?vi=2E?=r^   r   r   r   r    test_auto_q_if_short_mostly_safe   s    z+TestEncode.test_auto_q_if_short_mostly_safec                 C   s   |  tddd d S )Nz.....rQ   z=?utf-8?b?Li4uLi4=?=r^   r   r   r   r   test_auto_b_if_enough_unsafe   s    z'TestEncode.test_auto_b_if_enough_unsafec                 C   s   |  tddd d S )Nzvi.vi.vi.vi.vi.rQ   z =?utf-8?b?dmkudmkudmkudmkudmku?=r^   r   r   r   r   test_auto_b_if_long_unsafe   s    z%TestEncode.test_auto_b_if_long_unsafec                 C   s   |  tddd d S )Nzvi vi vi.vi rQ   z=?utf-8?q?vi_vi_vi=2Evi_?=r^   r   r   r   r   test_auto_q_if_long_mostly_safe   s    z*TestEncode.test_auto_q_if_long_mostly_safec                 C   s   |  tdd d S )Nr7   r]   r^   r   r   r   r   test_utf8_default   s    zTestEncode.test_utf8_defaultc                 C   s   |  tjdddd d S )Nr7   rF   rG   z=?utf-8*jive?q?foo?=r^   r   r   r   r   	test_lang   s    zTestEncode.test_langc                 C   s   |  tjdddd d S )Nu	   foobarrL   rR   rI   r^   r   r   r   r   test_unknown_8bit   s    zTestEncode.test_unknown_8bitN)r   r   r   r`   rb   rc   rd   re   rf   rg   rh   ri   rj   r   r   r   r   r[      s   r[   __main__)ZunittestZemailr   r   r   Ztest.test_emailr   r   r   r*   rT   rX   r[   r   mainr   r   r   r   <module>   s   W	$