Your IP : 216.73.216.52


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



��Yf8�@s�dZddlZddlZddlZddddddd	gZd
ddd
dddgZeeddgZGdd�dej�ZGdd�de�Z	Gdd�de�Z
Gdd�de�Zedkr�ej
�dS)zTest the binascii C module.�N�
b2a_base64�b2a_hex�b2a_hqx�b2a_qp�b2a_uu�hexlify�rlecode_hqx�
a2b_base64�a2b_hex�a2b_hqx�a2b_qp�a2b_uu�	unhexlify�
rledecode_hqx�crc32�crc_hqxc@s�eZdZeZdZeeed��7Zed7Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�BinASCIITests.The quick brown fox jumps over the lazy dog.
�s
Hello world.
cCs|j|j�|_dS)N)�	type2test�rawdata�data)�self�r�7/opt/alt/python35/lib64/python3.5/test/test_binascii.py�setUpszBinASCIITest.setUpcCs6|jttjt��|jttjt��dS)N)�
assertTrue�
issubclass�binascii�Error�	ExceptionZ
Incomplete)rrrr�test_exceptionsszBinASCIITest.test_exceptionscCsMxFtD]>}|jttt|�d��|jttt|��qWdS)N�__call__)�
all_functionsr�hasattr�getattrr�assertRaises�	TypeError)r�namerrr�test_functions s
zBinASCIITest.test_functionscCsud}|jd|�}x ttt�D]\}}tt|�}tt|�}y.||j|��}||j|��}WnAtk
r�}	z!|jdj	|||	��WYdd}	~	XnX|dkr�|\}}
|j
||dj	||||��|j|t�|j|t�|j
t|�d�q)W|jtj|d�t�|jtj|�t�dS)N�-z{}/{} conversion raises {!r}rz{}/{} conversion: {!r} != {!r}�r)r�zip�
a2b_functions�
b2a_functionsr$rrr�fail�format�assertEqual�assertIsInstance�bytesZ
assertLess�maxr�intr)r�MAX_ALL�raw�fa�fb�a2b�b2a�a�res�err�_rrr�test_returned_value&s&/z BinASCIITest.test_returned_valuecCs�d}g}x_tdt|j�|�D]B}|j|j|||��}tj|�}|j|�q(Wt�}x6|D].}|j|�}tj|�}||7}q~W|j	||j�dS)N�9r)
�range�lenrrrr�appendr2r	r0)r�
MAX_BASE64�lines�i�br;r<�linerrr�test_base64valid=s" 	
zBinASCIITest.test_base64validc
sCd}g}x_tdt|j�|�D]B}|j|j|||��}tj|�}|j|�q(Wt��d}x-td�D]}||kr��j|�q�W�fdd�}t�}x?t	||�D].}	|j|	�}tj
|�}||7}q�W|j||j�|jtj
|j���d�dS)Nr@rs@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/rcs��}t|�t|�}t�}xr|r�|r�t|�t|�|krn|d|dd�}}n|d|dd�}}|j|�q(W|||S)Nr�)rB�	bytearrayrC)rHZnoiseZratior<�c)�fillersrr�addnoise[s	z1BinASCIITest.test_base64invalid.<locals>.addnoise�)rArBrrrrrrCrK�mapr	r0)
rrDrErFrGr;ZvalidrNr<rHr)rMr�test_base64invalidLs&" 		zBinASCIITest.test_base64invalidcCs�d}g}x_tdt|j�|�D]B}|j|j|||��}tj|�}|j|�q(Wt�}x6|D].}|j|�}tj	|�}||7}q~W|j
||j�|j
tj	d�dd�|j
tj	d�dd�|j
tj	d�dd�|jtjtj	d	�|jtjtj	d
�|jtjtjdd�|j
tjd
�d�dS)Nr)rss�s�� s�s�s!!!!�.�!�xs!>   
)
rArBrrrrrrCr2r
r0r%r)rZMAX_UUrErFrGr;r<rHrrr�test_uuqs&" 	
zBinASCIITest.test_uucCs�tj|jd�d�}tj|jd�|�}|j|d�|jttj�|jttj|jd��x7dD]/}|jtj|jd�|�|d
@�qWdS)
NsTest the CRC-32 ofrs
 this string.i�7rOrJ�4�E#�xV4i�����)rrJrXrYrZr[)rrrr0r%r&)r�crcrrr�test_crc_hqx�s
zBinASCIITest.test_crc_hqxcCsZtj|jd��}tj|jd�|�}|j|d�|jttj�dS)NsTest the CRC-32 ofs
 this string.ij�])rrrr0r%r&)rr\rrr�
test_crc32�szBinASCIITest.test_crc32cCsntj|j�}tj|j|��}tj|j|��\}}tj|�}|j||j�dS)N)	rrrrrrrr0r)rZrler;rGr>r<rrr�test_hqx�s
zBinASCIITest.test_hqxcCs�d}tj|j|��}tj|j|��}|j||�|jtjtj|dd��|jtjtj|dd�d�|jtj|j|��|�|jtj|j|��|�dS)Ns {sworldishelloi0rJ�qr[r[)	rrrr
r0r%rrr)r�s�t�urrr�test_hex�s#'"zBinASCIITest.test_hexcCs�|j}tj}tj}|dddd�y|dddi�Wntk
rYYnX|jd�|j||d��d�|j||d��d�|j||d	��d�|j||d
��d�|j||d��d�|j||d
��d�|j||d��d�|j||d��d�|j||d��d�|j||d��d�|j||d��d�|j||d�ddU��d�|j||d��d�|j||d�dd�d�|jt|dd�|j||d��d�|j||d��d�|j||dd d!��dd d"�|j||d#��d$�|j||d��d%�|j||d��d�|j||d�dd�d&�|j||d'�dd�d(�|j||d)�dd�d*�|j||d'�ddd+d�d,�|j||d-�dd�d-�|j||d��d.�|j||d/��d0�|j||d1��d1�|j||d2��d2�|j||d1�ddV��d.�|j||d2�ddW��d0�|j||d3��d4�|j||d5��d6�|j||d5�d+d�d6�|j||d7��d7�|j||d7�d+d�d8�|j||d7�d9d�d7�|j||d:��d;�|j||d:�d+d�d;�|j||d:�d9d�d<�|j||d=��d=�|j||d=�d+d�d>�|j||d=�d9d�d?�|j||d@��dA�|j||d@�d+d�dA�|j||d@�d9d�dB�|j||dC�ddX��dD�|j||dE�ddY��dF�|j||dC�ddZ�d+d�dG�|j||dE�dd[�d+d�dH�|j||dC�dd\�d9d�dI�|j||dE�dd]�d9d�dJ�|j||dK��dL�|j||dM��dN�|j||dO��dP�|j||dQ��dR�|j||dS��dS�|j||dT�dd^��dL�dS)_NrrO�headerFrJz/binascii.a2b_qp(**{1:1}) didn't raise TypeError�=s= s==s=
ABsABs=
ABs=
ABs=
AB
CDsCDs=ABs�s=abs=AXs=XAs=A�_T� ZfooZbars=00
=00s
s�
�
�s
=FF
=FF
=FF�0�Ks�
�
�s=
=FF
=FF
=FFss=7Fs=3Ds=5Fsx ysx_ysx sx=20Z	quotetabssx=20ysx	ys=20s	s=09s xs	xss=00s
s=00
sx y	zs	x=20y=09z�istextsx 
y	
s
x=20
y=09
s
x =0Ay	=0Asx 
y	
s
x=20
y=09
s
x =0Dy	=0Dsx 
y	
sx=20
y=09
sx =0D=0Ay	=0D=0Asx 
sx 
sx	
sx	
sx=20
sx=09
sx =0Dsx	=0D�.s=2Es.
s=2E
s.
s=2E
s.s=2E=00sa.
s.ar[r[r[r[r[r[r[r[r[r[)rrrrr&r.r0r%)rrrrrrr�test_qp�s�			

&""""!"&&"&&%%%%zBinASCIITest.test_qpcCs�|jd�}x�tD]�}|dkr;tj|d�qtt|�}y||�Wqtk
r�}z!|jdj|||��WYdd}~XqXqWdS)NrOrrz{}({!r}) raises {!r})rr"rrr$rr.r/)r�empty�func�fr=rrr�test_empty_strings
zBinASCIITest.test_empty_stringcCs�x�tt�tt�dhBD]g}y |jttt|�d�Wqtk
r�}z|jdj	||��WYdd}~XqXqW|jttj
dd�dS)NrZtestz{}("test") raises {!r}r)�setr"r,r%r&r$rrr.r/r)rror=rrr�test_unicode_b2a(s$ 0zBinASCIITest.test_unicode_b2acCsjd}|jd|�}xJttt�D]9\}}|dkrDq)tt|�}tt|�}y@||j|��}||�}|jd�}||�}	WnAtk
r�}
z!|j	dj
|||
��WYdd}
~
XnX|dkr
|	\}	}|\}}|j|	|dj
|||	|��|j|	|�|j|	t
�|jt|d�q)WdS)Nr)r�asciiz{}/{} conversion raises {!r}rz{}/{} conversion: {!r} != {!r}�€)rr+r,r-r$rr�decoderr.r/r0r1r2r%�
ValueError)rr5r6r7r8r9r:r;Z
binary_resr<r=r>rrr�test_unicode_a2b2s,/zBinASCIITest.test_unicode_a2bN)�__name__�
__module__�__qualname__r2rrrArr r(r?rIrQrWr]r^r_rdrmrqrsrxrrrrrs&
%

f
rc@seZdZdd�ZdS)�ArrayBinASCIITestcCstjdt|��S)N�B)�array�list)rrarrrrPszArrayBinASCIITest.type2testN)ryrzr{rrrrrr|Osr|c@seZdZeZdS)�BytearrayBinASCIITestN)ryrzr{rKrrrrrr�Tsr�c@seZdZeZdS)�MemoryviewBinASCIITestN)ryrzr{�
memoryviewrrrrrr�Xsr��__main__)�__doc__Zunittestrr~r-r,r"ZTestCaserr|r�r�ry�mainrrrr�<module>s�A