%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµù Õ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream

nadelinn - rinduu

Command :

ikan Uploader :
Directory :  /vddos/python/lib/python3.9/test/__pycache__/
Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 
Current File : //vddos/python/lib/python3.9/test/__pycache__/test_zipfile.cpython-39.pyc
a

�_g���@sPddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlZddlmZddlmZmZmZddlmZddlmZmZmZmZmZmZmZmZm Z m!Z!edZ"edZ#dZ$d	Z%gd
�Z&dd�Z'Gd
d�d�Z(Gdd�de(e
j)�Z*e�Gdd�de(e
j)��Z+e�Gdd�de(e
j)��Z,e �Gdd�de(e
j)��Z-Gdd�d�Z.Gdd�de.e
j)�Z/e�Gdd�de.e
j)��Z0e�Gdd�de.e
j)��Z1e �Gdd �d e.e
j)��Z2Gd!d"�d"�Z3Gd#d$�d$e3e
j)�Z4e�Gd%d&�d&e3e
j)��Z5e�Gd'd(�d(e3e
j)��Z6e �Gd)d*�d*e3e
j)��Z7Gd+d,�d,e
j)�Z8Gd-d.�d.e
j)�Z9Gd/d0�d0e
j)�Z:Gd1d2�d2�Z;Gd3d4�d4e;e
j)�Z<e�Gd5d6�d6e;e
j)��Z=e�Gd7d8�d8e;e
j)��Z>e �Gd9d:�d:e;e
j)��Z?Gd;d<�d<e
j)�Z@Gd=d>�d>�ZAGd?d@�d@eAe
j)�ZBe�GdAdB�dBeAe
j)��ZCe�GdCdD�dDeAe
j)��ZDe �GdEdF�dFeAe
j)��ZEGdGdH�dH�ZFGdIdJ�dJ�ZGGdKdL�dLe
j)�ZHe�GdMdN�dNe
j)��ZIGdOdP�dPe
j)�ZJGdQdR�dRe
j)�ZKGdSdT�dTe
j)�ZLGdUdV�dVe
j)�ZMeNZOGdWdX�dX�ZPdYdZ�ZQd[d\�ZRGd]d^�d^e
j)�ZSeTd_k�rLe
�U�dS)`�N)�
TemporaryFile)�randint�random�	randbytes)�
script_helper)
�TESTFN�findfile�unlink�rmtree�temp_dir�temp_cwd�
requires_zlib�requires_bz2�
requires_lzma�captured_stdout�2�d��Zzipfile_datafiles))Z	_ziptest1Z
1q2w3e4r5t)zziptest2dir/_ziptest2Z
qawsedrftg)z!ziptest2dir/ziptest3dir/_ziptest3Z
azsxdcfvgb)z-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3Z
6y7u8i9o0pccs|tVt��"}|V|�|j�Wd�n1s40Yt���"}|V|�|j�Wd�n1sn0YdS�N)�TESTFN2r�assertFalse�closed�io�BytesIO)�test�f�r�0/vddos/python/lib/python3.9/test/test_zipfile.py�	get_files$s*
rc@seZdZedd��Zdd�ZdBdd�ZdCdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dS)D�AbstractTestsWithSourceFilecCs&dd�tt�D�|_d�|j�|_dS)NcSs g|]}td|t�fd��qS)z'Zipfile test line %d. random float: %f
�ascii)�bytesr��.0�irrr�
<listcomp>0s���z:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>�)�range�FIXEDTEST_SIZE�line_gen�join�data��clsrrr�
setUpClass.s�z&AbstractTestsWithSourceFile.setUpClasscCs:ttd��}|�|j�Wd�n1s,0YdS�N�wb��openr�writer+��self�fprrr�setUp5sz!AbstractTestsWithSourceFile.setUpNc	Cs�||d�}tj|dfi|���z}|�td�|�tt�|�d|j�|jddd��&}|jD]}|�|�q\Wd�n1s�0YWd�n1s�0YdS)N)�compression�
compresslevel�w�another.name�strfile�written-open-w��mode)�zipfile�ZipFiler3r�writestrr+r2r))r5rr8r9�kwargs�zipfp�linerrr�make_test_archive:s

z-AbstractTestsWithSourceFile.make_test_archivecCsD|�|||�t�|d|���}|�|�t�|j�|�|�d�|j�|�|�d�|j�t��}|j	|d�|�
�}|��}|�t|�d�|�
d|d�|�
d|d�|�
d	|d�|d
��\}}	}
}|�|d�|�t�|	d��|�t�|
d��|�|tt|j���|��}|�t|�d
�|�
t|�|�
d|�|�
d|�|�
d|�|��}
dd�|
D�}|�t|�d
�|�
t|�|�
d|�|�
d|�|�
d|�|
D]}|�|jt|j���q�tdddfD]2}|�|�}|�|j|�|�|jt|j���q�|��Wd�n1�s60YdS)N�rr;r<)�file��	File Namer�Modified�Size��%Y-%m-%d�%H:%M:%S�r=cSsg|]
}|j�qSr��filenamer"rrrr%ir&z8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>)rFr@rA�assertEqual�readrr+r�StringIO�printdir�getvalue�
splitlines�len�assertIn�split�
assertTrue�time�strptime�str�namelist�infolist�	file_size�getinforR�testzip)r5rr8r9rDr6�	directory�lines�fn�date�time_�size�names�infosr$�nm�inforrr�zip_testEsL
z$AbstractTestsWithSourceFile.zip_testcCs t|�D]}|�||j�qdSr�rror8�r5rrrr�
test_basic{sz&AbstractTestsWithSourceFile.test_basicc		Cs�|�||�t�|d|���}g}|�t��,}|�d�}|s<qH|�|�q,Wd�n1s\0Yg}|�d��,}|�d�}|s�q�|�|�qvWd�n1s�0Y|�d�|�|j	�|�d�|�|j	�Wd�n1s�0YdS�NrG�r;r&)
rFr@rAr2rrT�appendrSr*r+)	r5rr8rD�zipdata1�zipopen1�	read_data�zipdata2�zipopen2rrr�
zip_open_tests 
*
*z)AbstractTestsWithSourceFile.zip_open_testcCs t|�D]}|�||j�qdSr�rr{r8rqrrr�	test_open�sz%AbstractTestsWithSourceFile.test_opencCsZt�t�}|�||j�t�|d|j��}|�|jt	�Wd�n1sL0YdS�NrG)
�pathlib�Pathrr{r8r@rA�assertIsInstancerRr_)r5�pathrDrrr�test_open_with_pathlike�s
z3AbstractTestsWithSourceFile.test_open_with_pathlikec	Cs�|�||�t�|d|��t}g}|�t��2}|�tdd��}|sBqN|�|�q,Wd�n1sb0Y|�d�	|�|j
�Wd�n1s�0YdS�NrGrM�r&)rFr@rAr2rrTrrurSr*r+)r5rr8rDrvrwrxrrr�zip_random_open_test�s*z0AbstractTestsWithSourceFile.zip_random_open_testcCs t|�D]}|�||j�qdSr�rr�r8rqrrr�test_random_open�sz,AbstractTestsWithSourceFile.test_random_openc	Cs�|�||�t�|d��Z}|�t��0}g}|�d�}|s:qF|�|�q*Wd�n1sZ0YWd�n1sx0Y|�d�|�|j	�dS)NrG���r&)
rFr@rAr2r�read1rurSr*r+�r5rr8rD�zipopen�zipdatarxrrr�zip_read1_test�s�
Hz*AbstractTestsWithSourceFile.zip_read1_testcCs t|�D]}|�||j�qdSr)rr�r8rqrrr�
test_read1�sz&AbstractTestsWithSourceFile.test_read1c	Cs�|�||�t�|d��j}|�t��@}g}|�d�}|�t|�d�|sJqV|�|�q*Wd�n1sj0YWd�n1s�0Y|�	d�
|�|j�dS)NrG�
r&)rFr@rAr2rr�ZassertLessEqualrYrurSr*r+r�rrr�zip_read1_10_test�s�
Hz-AbstractTestsWithSourceFile.zip_read1_10_testcCs t|�D]}|�||j�qdSr)rr�r8rqrrr�
test_read1_10�sz)AbstractTestsWithSourceFile.test_read1_10c	Cs�|�||�t�|d��n}|�t��D}d}|��}|s8qZ||7}|�d�}|sPqZ||7}q*Wd�n1sn0YWd�n1s�0Y|�||j�dS)NrGr&�d)	rFr@rAr2r�readlinerTrSr+)r5rr8rDr�r+rTrrr�zip_readline_read_test�s�
Fz2AbstractTestsWithSourceFile.zip_readline_read_testcCs t|�D]}|�||j�qdSr)rr�r8rqrrr�test_readline_read�sz.AbstractTestsWithSourceFile.test_readline_readc	Cs�|�||�t�|d��Z}|�t��0}|jD]}|��}|�||�q,Wd�n1sZ0YWd�n1sx0YdSr~)rFr@rAr2rr)r�rS)r5rr8rDr�rEZlinedatarrr�zip_readline_test�s
z-AbstractTestsWithSourceFile.zip_readline_testcCs t|�D]}|�||j�qdSr)rr�r8rqrrr�
test_readline�sz)AbstractTestsWithSourceFile.test_readlinec	Cs�|�||�t�|d��d}|�t��}|��}Wd�n1sB0Yt|j|�D]\}}|�||�qXWd�n1s�0YdSr~)	rFr@rAr2r�	readlines�zipr)rS)r5rr8rDr�ZziplinesrE�ziplinerrr�zip_readlines_tests&z.AbstractTestsWithSourceFile.zip_readlines_testcCs t|�D]}|�||j�qdSr)rr�r8rqrrr�test_readlinessz*AbstractTestsWithSourceFile.test_readlinesc	Cs�|�||�t�|d��\}|�t��2}t|j|�D]\}}|�||�q2Wd�n1s\0YWd�n1sz0YdSr~)rFr@rAr2rr�r)rS)r5rr8rDr�rEr�rrr�zip_iterlines_tests
z.AbstractTestsWithSourceFile.zip_iterlines_testcCs t|�D]}|�||j�qdSr)rr�r8rqrrr�test_iterlinessz*AbstractTestsWithSourceFile.test_iterlinesc	Cs�t�td|j��}|�dd�Wd�n1s20Yt�td|j��^}|�d��4}|�|�d�d�|�|�d�d�Wd�n1s�0YWd�n1s�0YdS)	z>Check for cases where compressed data is larger than original.r:r<Z12NrGrM�1�2)r@rArr8rBr2rSrT)r5rDZopenobjrrr�test_low_compressions*z0AbstractTestsWithSourceFile.test_low_compressioncCs<t�td�}|jdd|jd�|�d�}|�|j|j�dS)Nr:�b.txt�hello world��
compress_type)r@rArrBr8rcrSr�)r5rDrnrrr�test_writestr_compression)s
z5AbstractTestsWithSourceFile.test_writestr_compressioncCs�tjtddd�}|jdd|jd�|jdd|jdd	�|�d�}|�|j|j�|�|jd�|�d�}|�|j|j�|�|jd�dS)
Nr:rM�r9�a.txtr�r�r��)r�r9)	r@rArrBr8rcrSr��_compresslevel)r5rDZa_infoZb_inforrr�test_writestr_compresslevel/s�

z7AbstractTestsWithSourceFile.test_writestr_compresslevelc
Cs�dD]�}|d}t|�}t�t��d|j��b}|�d|�|�dd��*}|�|�}|�	t
|�|�Wd�n1sv0YWd�q1s�0YqdS)N)rMi�iii@rMr:�foorG)rr@rArrr8rBr2rTrSrY)r5Z	test_sizerbZjunk�zipfr6�bufrrr�test_read_return_size?s
z1AbstractTestsWithSourceFile.test_read_return_sizec
CsTt��}tj|dd��,}|jd|j|jd�|��}Wd�n1sH0Y|��}t�|�}t�|��z}|�	d��P}|�
|d�|�t��|�
�Wd�n1s�0YWd�n1s�0YWd�n1s�0Yt�|�}t�|���}|�	d��Z}|�
|d�|�t�� |�
d��rD�q4Wd�n1�sZ0YWd�n1�sz0YWd�n1�s�0Yt�|�}t�|���}|�	d��Z}|�
|d�|�t�� |�d��r�q�Wd�n1�s0YWd�n1�s&0YWd�n1�sF0YdS)Nr:r>r<r��r�)rrr@rArBr+r8�tellrWr2�truncate�assertRaises�EOFErrorrTr�)r5r6r�Z
end_offset�zipfiledatar�rrr�test_truncated_zipfileKs2&
b
d
z2AbstractTestsWithSourceFile.test_truncated_zipfilec
Cs�d}t|�D�]�}t�|d|j��0}|�t|�t|�}|�d|�Wd�n1sX0Yt�|d���&}t|�}t|t	�r�|�d||�n|�d||�|�d|�t|�
|��}|�d||�|�d|�|�d	|�|jtjk�r|�d
|�|�d|�|�|��N}t|�}|�d||�|�d|�|jtjk�rX|�d
|�Wd�n1�sn0Y|�d
t|��Wd�n1�s�0Y|�d
t|��qdS)Nz	file.namer:zmode='w'rGzfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])
rr@rAr8r3r�reprrZ�
isinstancer_rc�
ZIP_STOREDr2)r5�fnamerrDrGr�rrr�	test_repris6*
,0z%AbstractTestsWithSourceFile.test_reprcCs$t|�D]}|j||jdd�qdS)N�	r�rprqrrr�test_compresslevel_basic�sz4AbstractTestsWithSourceFile.test_compresslevel_basiccCs�tjtddd��\}|�td�|jtddd�|�d�}|�d�}|�|jd�|�|jd�Wd�n1sr0YdS)zTCheck that files within a Zip archive can have different
        compression levels.r:rMr�Z
compress_1Z
compress_9r�N)r@rArr3rrcrSr�)r5rDZone_infoZ	nine_inforrr�test_per_file_compresslevel�s

z7AbstractTestsWithSourceFile.test_per_file_compresslevelc	s�G��fdd�dtj�}d�|�}d�t�|d|j���}|�dd��}|�d�Wd�n1sd0Yd�ztz:|�dd��}|�d�Wd�n1s�0YWnty��d	7�Yn0Wd�Wd��qjWd�nd�0Wd�n1�s0Yt�t�|�����4}|�	|�
�dg�|�	|�d�d�Wd�q1�s^0Yqt�t�|�����H}|�	|�
�ddg�|�	|�d�d�|�	|�d�d�Wd�n1�s�0YdS)
Ncs eZdZ���fdd�Z�ZS)zCAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFilecs,�dur��krt��d7�t��|�dS�NrM)�OSError�superr3�r5r+)�	__class__�count�stoprrr3�s
zIAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFile.write)�__name__�
__module__�__qualname__r3�
__classcell__r�r�r�)r�r�
BrokenFile�sr�rr:Zfile1sdata1Zfile2sdata2rM)rrr@rAr8r2r3r�rWrSr`rT)r5r�ZtestfilerDrrr�r�test_writing_errors�s0	(,�,4z/AbstractTestsWithSourceFile.test_writing_errorscCstt�tt�dSr�r	rr�r5rrr�tearDown�sz$AbstractTestsWithSourceFile.tearDown)N)N)$r�r�r��classmethodr.r7rFrorrr{r}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr-sB


6

	%rc@s�eZdZejZdZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�StoredTestsWithSourceFileNcCsl|�||�t�|d��@}|�d�}|�|jd�|�d�}|�|jd�Wd�n1s^0YdS)NrGr<��r=)rFr@rArcrS�
external_attr)r5rr8rD�zinfoZzinfo2rrr�zip_test_writestr_permissions�s

z7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs t|�D]}|�|tj�qdSr)rr�r@r�rqrrr�test_writestr_permissions�sz3StoredTestsWithSourceFile.test_writestr_permissionscCs�t�tdtj��}|�td�Wd�n1s20Yt�tdtj��"}|�|��dg�Wd�n1st0YdS)Nr:�	/absoluterG�absolute�r@rArr�r3rrSr`�r5rDrrr�test_absolute_arcnames�s*z0StoredTestsWithSourceFile.test_absolute_arcnamescCs�t�tdtj��}|�tt�Wd�n1s20Yt�tdtj��2}|�d|j�|�|�	�tdg�Wd�n1s�0YdS)z&Test appending to an existing zipfile.r:N�ar<)
r@rArr�r3rrBr+rSr`r�rrr�test_append_to_zip_file�s
*z1StoredTestsWithSourceFile.test_append_to_zip_filec	Cs�d}ttd��}|�|�Wd�n1s.0Yt�tdtj��}|�tt�Wd�n1sj0Yttd��p}|�t|��t�|d��6}|�	|�
�tg�|�	|�t�|j�Wd�n1s�0YWd�n1s�0Yttd��.}|�	|�t|��|�|��}Wd�n1�s>0Yt
�|��b}t�|��6}|�	|�
�tg�|�	|�t�|j�Wd�n1�s�0YWd�n1�s�0YdS)z9Test appending to an existing file that is not a zipfile.�I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!r0Nr��rbrG)r2rr3r@rAr�r�seekrYrSr`rTr+rr)r5r+rrDr��biorrr�test_append_to_non_zip_file�s (*P(z5StoredTestsWithSourceFile.test_append_to_non_zip_filec	Cst���T}t�|dtj��}|�tt�Wd�n1s<0Y|��}Wd�n1sb0Yd}tt	d��$}|�|�|�|�Wd�n1s�0Yt�t	��6}|�
|��tg�|�
|�t�|j
�Wd�n1s�0YdS)Nr:r�r0)rrr@rAr�r3rrWr2rrSr`rTr+�r5r�rDr�r+rrrr�test_read_concatenated_zip_file�s
*&
(z9StoredTestsWithSourceFile.test_read_concatenated_zip_filec	Cs�t���T}t�|dtj��}|�tt�Wd�n1s<0Y|��}Wd�n1sb0Ydd}tt	d��$}|�|�|�|�Wd�n1s�0Yt�t	d��0}|�
|��tg�|�d|j
�Wd�n1s�0Ytt	d��.}|�
|�t|��|�|��}Wd�n1�s>0Yt�|��x}t�|��L}|�
|��tdg�|�
|�t�|j
�|�
|�d�|j
�Wd�n1�s�0YWd�n1�s�0YdS)Nr:sI am not a ZipFile!i@Br0r�r<r�)rrr@rAr�r3rrWr2rrSr`rBr+rTrYr�rrr�$test_append_to_concatenated_zip_files$
*&
(,(z>StoredTestsWithSourceFile.test_append_to_concatenated_zip_filecCs�t�tdtj��}|�tt�Wd�n1s20Yttd��}|�d�Wd�n1sf0Yt�td��}|�|tj�Wd�n1s�0YdS)Nr:r�z
rG)r@rArr�r3rr2r��r5rDrrrr�test_ignores_newline_at_end"s*(z5StoredTestsWithSourceFile.test_ignores_newline_at_endcCs�t�tdtj��"}d|_|�tt�Wd�n1s80Yttd��}|�d�Wd�n1sl0Yt�td��,}|�|tj�|�	|jd�Wd�n1s�0YdS)Nr:�this is a commentr�zabcdef
rG)
r@rArr��commentr3rr2r�rSr�rrr�)test_ignores_stuff_appended_past_comments*s*(zCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentsc	Cszt�td��Z}|�t�ttd��&}|�|�t�|���Wd�n1sN0YWd�n1sl0YdS)z`Check that calling ZipFile.write without arcname specified
        produces the expected result.r:r�N)r@rArr3rr2rSrTr�rrr�test_write_default_name4s
z1StoredTestsWithSourceFile.test_write_default_namec	Cs�d}tjtdd��}|�|d�Wd�n1s40Ytjtdd���}|�|��`}|��|�t|j�|�t|j	d�|�t|j
�|�t|j�|�t|j�Wd�n1s�0YWd�n1s�0YdS)N�somefile.txtr:r>�bogusrGr)
r@rArrBr2�closer��
ValueErrorrTr�r��readable�seekable)r5r�rDZfidrrr�test_io_on_closed_zipextfile<s*z6StoredTestsWithSourceFile.test_io_on_closed_zipextfilec	Cs�tjtdd��}|�dd�Wd�n1s00Ytjtdd�� }|�t|jt�Wd�n1sn0Ytjtdd��H}|�t��|jtdd�Wd�n1s�0YWd�n1s�0YdS)z[Check that trying to call write() on a readonly ZipFile object
        raises a ValueError.r:r>r�r�NrG)	r@rArrBr�r�r3rr2r�rrr�test_write_to_readonlyJs*.z0StoredTestsWithSourceFile.test_write_to_readonlycCs�t�td�t�td�� }|�t|jt�Wd�n1s>0Ytjtddd��2}|�t�|�	t�}|�
|jd�Wd�n1s�0YdS)N)rrr:F�Zstrict_timestamps�i�rMrMrrr)�os�utimerr@rArr�r�r3rcrS�	date_time)r5rDr�rrr�test_add_file_before_1980Ws.

z3StoredTestsWithSourceFile.test_add_file_before_1980cCs$d}zt�|�Wn$ty6|�d|�d��Yn0zt�t||f�Wntyh|�d�Yn0t�t�j}|dkr�|�d|���t	�
td��"}|�t
j|jt�Wd�n1s�0Yt	j
tddd	��2}|�t�|�t�}|�|jd
�Wd�n1�s0YdS)Nl�&�
ztime.localtime(z) raises OverflowErrorz/Host fs cannot set timestamp to required value.l�b� �fz,Linux VFS/XFS kernel bug detected: mtime_ns=r:Fr�)i;����;r�)r]�	localtime�
OverflowError�skipTestr�r�r�stat�st_mtime_nsr@rArr��struct�errorr3rcrSr�)r5�tsZmtime_nsrDr�rrr�test_add_file_after_2107bs$	0

z2StoredTestsWithSourceFile.test_add_file_after_2107)r�r�r�r@r�r8r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr��s 
	

r�c@seZdZejZdd�ZdS)�DeflateTestsWithSourceFilecCs�t�td��d}|�tdtj�|�tdtj�|�d�}|�d�}|�|j	tj�|�|j	tj�Wd�n1sv0YdS)zUCheck that files within a Zip archive can have different
        compression options.r:ZstoremeZ	deflatemeN)
r@rArr3rr��ZIP_DEFLATEDrcrSr�)r5rD�sinfoZdinforrr�test_per_file_compression�s

z4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�r@r	r8rrrrrr�src@seZdZejZdS)�Bzip2TestsWithSourceFileN�r�r�r�r@�	ZIP_BZIP2r8rrrrr�src@seZdZejZdS)�LzmaTestsWithSourceFileN�r�r�r�r@�ZIP_LZMAr8rrrrr�src@sHeZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�AbstractTestZip64InSmallFilescCs$dd�tdt�D�}d�|�|_dS)Ncss|]}td|d�VqdS)zTest of zipfile line %d.r N)r!r"rrr�	<genexpr>�s�z;AbstractTestZip64InSmallFiles.setUpClass.<locals>.<genexpr>r�
)r'r(r*r+)r-r)rrrr.�s�z(AbstractTestZip64InSmallFiles.setUpClasscCsVtj|_tj|_dt_dt_ttd��}|�|j�Wd�n1sH0YdS)Nrr�r0)	r@�ZIP64_LIMIT�_limit�ZIP_FILECOUNT_LIMIT�_filecount_limitr2rr3r+r4rrrr7�sz#AbstractTestZip64InSmallFiles.setUpcCsrtj|d|dd��6}|�td�|�tt�|�d|j�Wd�n1sN0Yt�|d|����}|�|�t�|j�|�|�d�|j�|�|�d�|j�t�	�}|�
|�|��}|��}|�t
|�d�|�d|d	�|�d
|d	�|�d|d	�|d��\}}}	}
|�|d�|�t�|d
��|�t�|	d��|�|
tt
|j���|��}|�t
|�d�|�t|�|�d|�|�d|�|��}dd�|D�}|�t
|�d�|�t|�|�d|�|�d|�|D]}
|�|
jt
|j���q�tddfD]2}|�|�}|�|j|�|�|jt
|j���q|��Wd�n1�sd0YdS)Nr:T�Z
allowZip64r;r<rGrPrJrrKrLrMrNrO�cSsg|]
}|j�qSrrQr"rrrr%�r&z:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>)r@rAr3rrBr+rSrTrrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrRrd)r5rr8rDr6rerfrgrhrirjrkrlr$rmrnrrrro�sN,

z&AbstractTestZip64InSmallFiles.zip_testcCs t|�D]}|�||j�qdSrrprqrrrrr�sz(AbstractTestZip64InSmallFiles.test_basiccCs�tjtd|jdd�}d|_d}t|�D] }|�d|d|dd	�q&|�t|�	��|�|�
�t�td
|j�}|�t|�	��|�t|�D]0}|�d|��d�}|�|d|dd	�q�|�
�dS)Nr:Trr���foo%08d�%dr�9rGr )
r@rArr8�debugr'rBrSrYr`r�rT�decode)r5r��numfilesr$�zipf2�contentrrr�test_too_many_files�s�z1AbstractTestZip64InSmallFiles.test_too_many_filescCs$tjtd|jdd�}d|_d}t|�D] }|�d|d|dd	�q&|�t|�	��|�|�
tj�� |�d|d
�Wd�n1s�0Y|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�|�
tj�� |�d|d
�Wd�n1�s0Y|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�d
}t||�D]"}|�d|d|dd	��qx|�t|�	��|�|��t�td|j�}|�t|�	��|�t|�D]2}|�
d|��d�}|�|d|dd	��q�|��dS)Nr:Frr�r�rrrrr&r�TrrGr )r@rArr8rr'rBrSrYr`r��LargeZipFiler�rTr )r5r�r!r$Z	numfiles2r"r#rrr�test_too_many_files_appendsJ�.�0� z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs$|jt_|jt_tt�tt�dSr)rr@rrrr	rrr�rrrr�)sz&AbstractTestZip64InSmallFiles.tearDownN)r�r�r�r�r.r7rorrr$r&r�rrrrr�s

9'rc@sTeZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
ddd
�Zdd�Zdd�Z
dS)�StoredTestZip64InSmallFilescCsJtj|d|dd��$}|�tj|jtd�Wd�n1s<0YdS�Nr:Frr;)r@rAr�r%r3r�r5rr8rDrrr�large_file_exception_test4s�z5StoredTestZip64InSmallFiles.large_file_exception_testcCsLtj|d|dd��&}|�tj|jd|j�Wd�n1s>0YdSr()r@rAr�r%rBr+r)rrr�large_file_exception_test29s
�z6StoredTestZip64InSmallFiles.large_file_exception_test2cCs.t|�D] }|�|tj�|�|tj�qdSr)rr*r@r�r+rqrrr�test_large_file_exception>sz5StoredTestZip64InSmallFiles.test_large_file_exceptioncCs�tjtdtjdd��}|�td�Wd�n1s60Yt�tdtj��"}|�|��dg�Wd�n1sx0YdS)Nr:Trr�rGr�r�r�rrrr�Cs�*z2StoredTestZip64InSmallFiles.test_absolute_arcnamescCstjtddd��}|�d|j�Wd�n1s40Ytjtddd�� }|�d�}|j}Wd�n1st0Ytjtddd��}|�d|j�Wd�n1s�0Ytjtddd��(}|�d�}|�|j|�Wd�n1s�0YdS)Nr:Trr<rGr�Zstrfile2)r@rArrBr+rc�extrarS)r5rDr�r-rrr�test_appendKs,
$,
z'StoredTestZip64InSmallFiles.test_appendFcCs�d}d}g}	g}
|}|r4d}|r4|	�|�|
�|�t�d|�}|}|rdd}|rd|	�|�|
�|�t�d|�}|}
|r�d}
|r�|
�|�t�d|
�}
tjddt|	�ddt|	�g|	�R�}tjddt|
�ddt|
�g|
�R�}t�dd	dt|
��}t�dd
dt|	��}t�dddt|	��}t�dddt|
��}d
}d}t�dt|��}d|||||||d||||d|
||ddd||dddd}|S)z�Generate bytes sequence for a zip with (incomplete) zip64 data.

        The actual values (not the zip 64 0xffffffff values) stored in the file
        are:
        file_size: 8
        compress_size: 8
        header_offset: 0
        �rl��z<Lz<HH�QrMz<Q�:�2z<HrPstest.txt�test1234sPK!�%��sPK--!�%��s
�sPK,--ss
sPKlssPK:2s)rur�packrY)r5�file_size_64_set�file_size_extra�compress_size_64_set�compress_size_extra�header_offset_64_set�header_offset_extraZactual_sizeZactual_header_offsetZlocal_zip64_fieldsZcentral_zip64_fieldsrb�
compress_size�
header_offsetZlocal_extraZ
central_extraZcentral_dir_sizeZoffset_to_central_dirZlocal_extra_lengthZcentral_extra_lengthrRr#Zfilename_lengthZzip64_contentsrrr�make_zip64_fileYs�






��
���������	�
���
���������������!z+StoredTestZip64InSmallFiles.make_zip64_filecCs�|jdd�}|�tj�� }t�t�|��Wd�n1s>0Y|�dt|j	��
��|jdddd�}|�tj�� }t�t�|��Wd�n1s�0Y|�dt|j	��
��|jdd�}|�tj�� }t�t�|��Wd�n1s�0Y|�dt|j	��
��|jdddddd�}|�tj�� }t�t�|��Wd�n1�sf0Y|�d	t|j	��
��|jd
dddd�}|�tj�� }t�t�|��Wd�n1�s�0Y|�d	t|j	��
��|jddd
dd�}|�tj�� }t�t�|��Wd�n1�s20Y|�d	t|j	��
��|jd
d
dd
�}|�tj�� }t�t�|��Wd�n1�s�0Y|�d	t|j	��
��dS)a
Missing zip64 extra records raises an exception.

        There are 4 fields that the zip64 format handles (the disk number is
        not used in this module and so is ignored here). According to the zip
        spec:
              The order of the fields in the zip64 extended
              information record is fixed, but the fields MUST
              only appear if the corresponding Local or Central
              directory record field is set to 0xFFFF or 0xFFFFFFFF.

        If the zip64 extra content doesn't contain enough entries for the
        number of fields marked with 0xFFFF or 0xFFFFFFFF, we raise an error.
        This test mismatches the length of the zip64 extra field and the number
        of fields set to indicate the presence of zip64 data.
        T)r5Nz	file size)r5r6r7z
compress size)r7)r5r6r7r8r9z
header offsetF)r5r7r8r9)r5r6r7r9)r5r7r9)r=r�r@�
BadZipFilerArrrZr_�	exception�lower)r5Zmissing_file_size_extra�eZmissing_compress_size_extraZmissing_header_offset_extrarrr�test_bad_zip64_extra�sp�.�.�.�0�0�0�0z0StoredTestZip64InSmallFiles.test_bad_zip64_extrac
Cs�d}d}d}d}ddd�ddd�ddd�f}tdt|�d�D]�}t�||�D]�}i}|D]}	|�|	�qZt�t�|j	fi|�����X}
|
�
�d}|�|j|�|�|j
|�|�|j|�|�|
�|�|�Wd�qN1s�0YqNq>dS)	Nr/rr3T)r5r6)r7r8)r9r:rM)r'rY�	itertools�combinations�updater@rArrr=rarSrbr;r<rT)r5Zexpected_file_sizeZexpected_compress_sizeZexpected_header_offsetZexpected_content�paramsrGZcomborC�c�zfr�rrr� test_generated_valid_zip64_extras&�z<StoredTestZip64InSmallFiles.test_generated_valid_zip64_extraN)FFFFFF)r�r�r�r@r�r8r*r+r,r�r.r=rBrIrrrrr'0s�
c^r'c@seZdZejZdS)�DeflateTestZip64InSmallFilesN�r�r�r�r@r	r8rrrrrJ6srJc@seZdZejZdS)�Bzip2TestZip64InSmallFilesNr
rrrrrL;srLc@seZdZejZdS)�LzmaTestZip64InSmallFilesNrrrrrrM@srMc@s$eZdZdd�Zdd�Zdd�ZdS)�AbstractWriterTestscCstt�dSr�r	rr�rrrr�HszAbstractWriterTests.tearDowncCs�d}t�td|j��`}|�dd�}|�|�|��|�|j�|��|�|j�|�	|�
d�|�Wd�n1sz0YdS)N�contentr:r)r@rArr8r2r3r�r\rrSrT�r5r+r�r:rrr�test_close_after_closeKs
z*AbstractWriterTests.test_close_after_closecCs�d}t�td|j��\}|�dd�}|�|�|��|�|j�|�	t
|jd�|�|�d�|�Wd�n1sv0YdS)NrPr:rr&)
r@rArr8r2r3r�r\rr�r�rSrTrQrrr�test_write_after_closeVs
z*AbstractWriterTests.test_write_after_closeN)r�r�r�r�rRrSrrrrrNFsrNc@seZdZejZdS)�StoredWriterTestsN�r�r�r�r@r�r8rrrrrT`srTc@seZdZejZdS)�DeflateWriterTestsNrKrrrrrVcsrVc@seZdZejZdS)�Bzip2WriterTestsNr
rrrrrWgsrWc@seZdZejZdS)�LzmaWriterTestsNrrrrrrXksrXc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�PyZipFileTestscCs |d|vr|�|d|�dS)N�orG)rZ)r5�namer`rrr�assertCompiledInqszPyZipFileTests.assertCompiledIncCs~tj|tjtjtjvd�s$|�d�tj�|d�}z"t�|tjtj	B�}t�
|�Wntyp|�d�Yn0t|�dS)N)Z
effective_idsz/requires write access to the installed locationztest_zipfile.try)
r��access�W_OK�supports_effective_idsrr�r*r2�O_WRONLY�O_CREATr��	Exceptionr	)r5r�rR�fdrrr�requiresWriteAccessus

�
z"PyZipFileTests.requiresWriteAccessc	Cs�|�tj�t��t���}t�|d���}t}|�d�r�|�	tj
�}tjdur^|�|�	tj��d|vrtt
j�|�}n|dd�}|�|�tj�|�}|�||���|�||���Wd�n1s�0YWd�n1s�0Yt���}t�|d��l}t}|�d��r$|dd�}|�|d�ddtj�|�f}|�||���|�||���Wd�n1�sz0YWd�n1�s�0YdS)Nr:�.pyc�__pycache__r�Ztestpackagez%s/%s)rdr�r��dirname�__file__rr@�	PyZipFile�endswithr[�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInr`r\)r5�trDrgZ
path_splitZbnrrr�test_write_pyfile�s,


Lz PyZipFileTests.test_write_pyfilec	Cs�ddl}tj�|j�}|�|�t��f}t�|d��:}|�	|�|�
�}|�d|�|�d|�Wd�n1st0YWd�n1s�0YdS)Nrr:zemail/__init__.pyzemail/mime/text.py)�emailr�r�rgrhrdrr@rirqr`r\)r5rv�
packagedirrtrDrkrrr�test_write_python_package�s

z(PyZipFileTests.test_write_python_packagecCs�ddl}tj�|j�}|�|�t���b}t�|d���2}t	��}|�
|�Wd�n1s`0Y|��}|�d|v�t	��"}|j
|dd�d�Wd�n1s�0Y|��}|�d|v�dd�}t	��J}|�
t��|j
||d�Wd�n1�s0YWd�n1�s.0Y|��}|�rNt|�|�d|v�Wd�n1�sr0YWd�n1�s�0YdS)	Nrr:�SyntaxErrorcSsdS)NFr)Zwhateverrrr�<lambda>�r&zCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>�Z
filterfunccSstj�|��d�S)NZbad)r�r�rr�
startswith)r�rrr�filter�szAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)rr�r�rgrhrdrr@rirrqrWr\�assertWarns�UserWarning�print)r5rrwrtrDZ	reportSIOZ	reportStrr}rrr�"test_write_filtered_python_package�s&
(0Nz1PyZipFileTests.test_write_filtered_python_packagec	Cs�ddl}tj�|j�}|�|�dnd}d}t��r}tj|d|d��B}|�	|�|�
�}|�d||�|�d||�Wd�n1s�0YWd�n1s�0YdS)	NrTrMrer:)�optimizezemail/__init__zemail/mime/text)rvr�r�rgrhrdrr@rirqr`rZ)r5rvrwZoptlevel�extrtrDrkrrr�test_write_with_optimization�s
�
z+PyZipFileTests.test_write_with_optimizationc	Csnt�t��zRttj�td�d��}|�d�Wd�n1sB0Yttj�td�d��}|�d�Wd�n1s�0Yttj�td�d��}|�d�Wd�n1s�0Yt��t}t�	|d��F}|�
t�|��}|�d|�|�d|�|�
d|�Wd�n1�s*0YWd�n1�sJ0YWtt�n
tt�0dS)N�mod1.pyr:�
print(42)
�mod2.py�print(42 * 42)
zmod2.txtzbla bla bla
�r��mkdirrr2r�r*r3rr@rirqr`r\rsr
�r5r6rtrDrkrrr�test_write_python_directory�s
(((
Nz*PyZipFileTests.test_write_python_directoryc	Cs*t�t��zttj�td�d��}|�d�Wd�n1sB0Yttj�td�d��}|�d�Wd�n1s�0Yt��n}t�	|d��B}|j
tdd�d�|��}|�d|�|�
d|�Wd�n1s�0YWd�n1�s0YWtt�n
tt�0dS)	Nr�r:r�r�r�cSs|�d�S)Nr�)rj)rgrrrrz�szEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>r{r�r�rrr�$test_write_python_directory_filtered�s
((Lz3PyZipFileTests.test_write_python_directory_filteredc
Cs�t���}t�|d��\}ttd��}|�d�Wd�n1s@0Y|�t|jt�t	t�Wd�n1sv0YWd�n1s�0YdS)Nr:z!most definitely not a python file)
rr@rir2rr3r��RuntimeErrorrqr	)r5rtrDrrrr�test_write_non_pyfiles
(z$PyZipFileTests.test_write_non_pyfilec
Cs"t�t��zttj�td�d��}|�d�Wd�n1sB0Yt���}t�	|d��z}t
��$}|�tj�td��Wd�n1s�0Y|�d|�
��|��}|�d|�|�d|�Wd�n1s�0YWd�n1s�0YWtt�n
tt�0dS)Nr�r:zBad syntax in python file
ryzmod1.pyc)r�r�rr2r�r*r3rr@rirrqrZrWr`rsr
)r5r6rtrD�srkrrr�test_write_pyfile_bad_syntax
s
(2Jz+PyZipFileTests.test_write_pyfile_bad_syntaxc	Cs�t�t�z�ttj�td�d��}|�d�Wd�n1s@0Yt��d}t�	|d��8}|�
t�t�d�|�
�}|�d|�Wd�n1s�0YWd�n1s�0YWtt�n
tt�0dS)Nr�r:r�)r�r�rr2r�r*r3rr@rirqrr�r`r\r
r�rrr�test_write_pathlike#s
(Jz"PyZipFileTests.test_write_pathlikeN)r�r�r�r\rdrurxr�r�r�r�r�r�r�rrrrrYps
rYc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Ze�ejjdkd�dd��Ze�ejjdkd�dd ��Zd!d"�Zd#S)$�ExtractTestscCsNt�tdtj��*}tD]\}}|�||�qWd�n1s@0YdS)Nr:)r@rArr��SMALL_TEST_DATArB�r5rD�fpath�fdatarrr�make_test_file3szExtractTests.make_test_filecCs�t���|��t�td���}tD]�\}}|�|�}tj�	t�
�|�}tj�|�}|�||�t
|d��$}|�|��|���Wd�n1s�0Yt|�q"Wd�n1s�0YWd�n1s�0YdS�NrGr�)rr�r@rArr��extractr�r�r*�getcwd�normpathrSr2�encoderTr	)r5rDr�r��writtenfile�correctfilerrrr�test_extract8s
2zExtractTests.test_extractc
Cs�|��t�td���}tD]�\}}|�||�}tj�||�}tj�	|�}|�
tj�||�||f�t|d��$}|�
|��|���Wd�n1s�0Yt|�qWd�n1s�0Ytt�dSr�)r�r@rArr�r�r�r�r*r�r\�samefiler2rSr�rTr	)r5�targetrDr�r�r�r�rrrr�_test_extract_with_targetKs2(z&ExtractTests._test_extract_with_targetcCs4t��}|�|�Wd�n1s&0YdSr)rr��r5�extdirrrr�test_extract_with_target^sz%ExtractTests.test_extract_with_targetcCs:t�� }|�t�|��Wd�n1s,0YdSr)rr�rr�r�rrr�!test_extract_with_target_pathlikebsz.ExtractTests.test_extract_with_target_pathlikecCs�t���|��t�td��~}|��tD]`\}}tj�	t�
�|�}t|d��$}|�|�
�|���Wd�n1sx0Yt|�q*Wd�n1s�0YWd�n1s�0YdSr�)rr�r@rAr�
extractallr�r�r�r*r�r2rSr�rTr	)r5rDr�r��outfilerrrr�test_extract_allfs2zExtractTests.test_extract_allc
Cs�|��t�td��|}|�|�tD]\\}}tj�||�}t	|d��$}|�
|��|���Wd�n1sn0Yt
|�q$Wd�n1s�0Yt
t�dSr�)r�r@rArr�r�r�r�r*r2rSr�rTr	)r5r�rDr�r�r�rrrr�_test_extract_all_with_targetss
2(z*ExtractTests._test_extract_all_with_targetcCs4t��}|�|�Wd�n1s&0YdSr)rr�r�rrr�test_extract_all_with_target�sz)ExtractTests.test_extract_all_with_targetcCs:t�� }|�t�|��Wd�n1s,0YdSr)rr�rr�r�rrr�%test_extract_all_with_target_pathlike�sz2ExtractTests.test_extract_all_with_target_pathlikecCsP|�tj�|��t|d�� }|�|��|�Wd�n1sB0YdS)Nr�)r\r�r��isfiler2rSrT)r5rRr#rrrr�
check_file�szExtractTests.check_filecCsBtjj}|�|dd�d�|�|dd�d�|�|dd�d�dS)	Nz,,?,C:,foo,bar/z�,z_,C_,foo,bar/zza\b,c<d>e|f"g?h*iza\b,c_d_e_f_g_h_i�../../foo../../ba..r�/�	foo/ba..r)r@rAZ_sanitize_windows_namerS)r5Zsanrrr�test_sanitize_windows_name�sz'ExtractTests.test_sanitize_windows_namecCsgd�}|�|�dS)N))z
../foo/bar�foo/bar)z
foo/../barr�)z
foo/../../barr�)z
foo/bar/..r�)z./../foo/barr�)z/foo/barr�)z/foo/../barr�)z/foo/../../barr���_test_extract_hackers_arcnames)r5Zcommon_hacknamesrrr�*test_extract_hackers_arcnames_common_cases�s
z7ExtractTests.test_extract_hackers_arcnames_common_cases�\zRequires \ as path separator.cCsgd�}|�|�dS)z>Test combination of path fixing and windows name sanitization.))z
..\foo\barr�)z..\/foo\/barr�)zfoo/\..\/barr�)zfoo\/../\barr�)z	C:foo/barr�)z
C:/foo/barr�)zC://foo/barr�)z
C:\foo\barr�)z//conky/mountpoint/foo/barr�)z\\conky\mountpoint\foo\barr�)z///conky/mountpoint/foo/bar�conky/mountpoint/foo/bar)z\\\conky\mountpoint\foo\barr�)z//conky//mountpoint/foo/barr�)z\\conky\\mountpoint\foo\barr�)z//?/C:/foo/barr�)z\\?\C:\foo\barr�)zC:/../C:/foo/barz
C_/foo/bar)za:b\c<d>e|f"g?h*izb/c_d_e_f_g_h_i)r�r�Nr�)r5Zwindows_hacknamesrrr�*test_extract_hackers_arcnames_windows_only�sz7ExtractTests.test_extract_hackers_arcnames_windows_onlyr�zRequires / as path separator.cCsgd�}|�|�dS)N))z	//foo/barr�)r�zfoo../ba..r)�
foo/..\barr�r�)r5Zposix_hacknamesrrr�(test_extract_hackers_arcnames_posix_only�sz5ExtractTests.test_extract_hackers_arcnames_posix_onlyc
	Cs>|D�]2\}}d|��}t�tdtj��0}t��}||_d|_|�||�Wd�n1s`0Y|�	t
jd�}t
j�
ddd�}t
jj
|g|�d��R�}t�td��6}|�||�}	|j|	|d	||	|fd
�Wd�n1s�0Y|�||�td�t�td��}|�|�Wd�n1�s60Y|�||�td�t
jj
t
��g|�d��R�}t�td��.}|�|�}	|j|	|d|d
�Wd�n1�s�0Y|�||�t|�d�d�t�td��}|��Wd�n1�s0Y|�||�t|�d�d�tt�qdS)
N�foobarr:r�r�r��subdirZsubsubrGzextract %r: %r != %r)�msgz
extract %rr)r�r@rArr��ZipInforRr�rB�replacer�rkr�r*r[r�rSr�r
r�r�r	)
r5Z	hacknamesZarcnameZ	fixednamer#rDr��
targetpathr�r�rrrr��sH*��$*
�&(z+ExtractTests._test_extract_hackers_arcnamesN)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��unittestZskipIfr�r�rkr�r�r�rrrrr�1s"



r�c@sPeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�dd��Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%dEdF�Z&dGdH�Z'dIdJ�Z(e)�dKdL��Z*dMdN�Z+dOS)P�
OtherTestsc
CsBt�tdtj��h}|�dd�|�t��|�dd�Wd�n1sJ0Y|�|��dgd�Wd�n1s~0Yt�td���}|�	�}d}|D]:}|�
|��}||��7}Wd�q�1s�0Yq�|�|dd	h�d}|D]}||�|�7}q�|�|dd	h�Wd�n1�s40YdS)
Nr:r[r��barr�rGr&r�sbarfoo)
r@rArr�rBr~rrSr`rar2rTrZ)r5rDrlr+rnr�rrr�test_open_via_zip_info�s *4,z!OtherTests.test_open_via_zip_infocCs^t�td��>}dD](}t�|�}|jdO_|�||�qWd�n1sP0YdS)Nr:Zabcdefghijklmnopr/)r@rArr��	flag_bitsrB)r5Zorig_zipr+r�rrr�-test_writestr_extended_local_header_issue1202s

z8OtherTests.test_writestr_extended_local_header_issue1202cCs�t�td��8}tD]"\}}|�||�|�|jd�qWd�n1sJ0Y|�|jd�t�td��}|�|jd�Wd�n1s�0Y|�|jd�dS)z8Check that the zipfile is closed after the 'with' block.r:zzipfp is not openN�zipfp is not closedrG)r@rArr�rBZassertIsNotNoner6�assertIsNoner�rrr�
test_close
s.,zOtherTests.test_closecCs�t�td��*}tD]\}}|�||�qWd�n1s<0Yz8t�td��}t���Wd�n1sr0YWn"tjy�|�|jd�Yn0dS)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.r:NrGr�)r@rArr�rBr>r�r6)r5rDr�r�Zzipfp2rrr�test_close_on_exceptions,*z"OtherTests.test_close_on_exceptioncCs d}|�ttjt�|�d�dS)NsdPKx!p�@xPKxx!p�@�xPK/rG)r��NotImplementedErrorr@rArrr�rrr�test_unsupported_version&s

�z#OtherTests.test_unsupported_versioncCsRtd�}t�|��,}|��D]}|�|���qWd�n1sD0YdS)Nzzip_cp437_header.zip)rr@rAr`r2r�)r5r�rDr[rrr�test_read_unicode_filenames1sz&OtherTests.test_read_unicode_filenamescCs�t�td��>}|�dd�|�dd�|�|��djt�Wd�n1sP0Yt�td��8}|�|j	djd�|�|j	djd�Wd�n1s�0YdS)Nr:�foo.txtzTest for unicode filenameuö.txtrrGrM)
r@rArrBr�rarRr_rS�filelist)r5rHrrr�test_write_unicode_filenames9s4z'OtherTests.test_write_unicode_filenamescCsNt�td��.}|�dd�|�|�d�d�Wd�n1s@0YdS)Nr:uприкладssample)r@rArrBrSrTr�rrr�'test_read_after_write_unicode_filenamesCsz2OtherTests.test_read_after_write_unicode_filenamescCs�tt�d}d}t�tdtj��}|�||�Wd�n1sB0Y|�t�� t�tdtj�Wd�n1s|0Yt�td��4}|�|�	�|g�|�|�
|�|�Wd�n1s�0YdS)z&Test exclusive creating a new zipfile.�testfile.txt�#hello, world. this is some content.�xNrG)r	rr@rAr�rBr��FileExistsErrorrSr`rT)r5rRr#rDrrr�test_exclusive_create_zip_fileHs*.z)OtherTests.test_exclusive_create_zip_filecCs�tj�t�rt�t�d}d}z<t�td��}|�||�Wd�n1sN0YWntyv|�	d�Yn0|�
tj�t��t�td��"}|�|�|�|�Wd�n1s�0YdS)Nr�r�r�z1Could not append data to a non-existent zip file.rG)
r�r��existsrr	r@rArBr��failr\rSrT)r5rRr#rHrrr�(test_create_non_existent_file_for_appendUs
.z3OtherTests.test_create_non_existent_file_for_appendcCs\ttd��}|�d�Wd�n1s*0Yzt�t�}WntjyVYn0dS)Nr:�this is not a legal zip file
)r2rr3r@rAr>)r5r6rHrrr�test_close_erroneous_filegs(z$OtherTests.test_close_erroneous_filecCs�ttd��}|�d�Wd�n1s*0Y|�t�t��|�t�t�t���ttd�� }|�t�|��Wd�n1s�0Yt�	�}|�d�|�t�|��|�
dd�|�t�|��dS)z;Check that is_zipfile() correctly identifies non-zip files.r:r�Nr�sthis is not a legal zip file
r)r2rr3rr@�
is_zipfilerr�rrr�r4rrr�test_is_zip_erroneous_filevs(.
z%OtherTests.test_is_zip_erroneous_filecCs�t��}tj|dd��}|�dd�Wd�n1s80Y|��}tt|��D](}t�|d|��}|�tj	tj|�qVdS)zCCheck that zipfiles with missing bytes at the end raise BadZipFile.r:r>r��O, for a Muse of Fire!N)
rrr@rArBrWr'rYr�r>)r5r6r�r��Nrrr�test_damaged_zipfile�s*zOtherTests.test_damaged_zipfilecCs�tjtdd��}|�dd�Wd�n1s00Y|�t�t��ttd��4}|�t�|��|�dd�|��}Wd�n1s�0Yt	�
�}|�|�|�t�|��|�dd�|�t�|��dS)z7Check that is_zipfile() correctly identifies zip files.r:r>r�r�Nr�r)r@rArrBr\r�r2r�rTrrr3)r5r�r6Zzip_contentsrrr�test_is_zip_valid_file�s*&
z!OtherTests.test_is_zip_valid_filecCs|�ttjt�dSr)r�r�r@rArr�rrr�%test_non_existent_file_raises_OSError�sz0OtherTests.test_non_existent_file_raises_OSErrorcCsnttd�}|��|�tjtjt�ttd��}|�d�Wd�n1sN0Y|�tjtjt�dS)Nr:z
short file)r2rr�r�r@r>rAr3)r5rr6rrr�!test_empty_file_raises_BadZipFile�s
(z,OtherTests.test_empty_file_raises_BadZipFilecCs�t��}tj|dd��}|�dd�Wd�n1s80Y|�t|jd�|�t|jd�|�t|j	�|�t|jdd�tt
d��}|�d�Wd�n1s�0Y|�t|jt
�dS)	z?Verify that testzip() doesn't swallow inappropriate exceptions.r:r>r��O, for a Muse of Fire!Nz	bogus.txtr�zzipfile test data)rrr@rArBr�r�rTr2rdrr3)r5r+r�rrrr�!test_closed_zip_raises_ValueError�s*(z,OtherTests.test_closed_zip_raises_ValueErrorcCs|�ttjtd�dS)z>Check that bad modes passed to ZipFile constructor are caught.�qN)r�r�r@rArr�rrr�test_bad_constructor_mode�sz$OtherTests.test_bad_constructor_modecCs�tjtdd��}|�dd�Wd�n1s00Ytjtdd��P}|�d�|�t|jdd�|�t|jdd�|�t|jdd	�Wd�n1s�0YdS)
z7Check that bad modes passed to ZipFile.open are caught.r:r>r�r�NrGr��UZrU)r@rArrBrTr�r�r2�r5r�rrr�test_bad_open_mode�s*
zOtherTests.test_bad_open_modec	Cs�tjtdd��v}|�dd�|�d��@}tt�D]}|�|�d�d�q0|�|��d�Wd�n1sl0YWd�n1s�0YdS)	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.r:r>r�r�rr&r�N)	r@rArrBr2r'r(rSrT)r5r�rr$rrr�
test_read0�szOtherTests.test_read0cCsDtjtdd��"}|�t|jdd�Wd�n1s60YdS)zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.r:r>r�rGN)r@rArr��KeyErrorr2r�rrr�test_open_non_existent_item�sz&OtherTests.test_open_non_existent_itemcCs|�ttjtdd�dS)zMCheck that bad compression methods passed to ZipFile.open are
        caught.r:r�N)r�r�r@rArr�rrr�test_bad_compression_mode�sz$OtherTests.test_bad_compression_modecCsJd}t�t�|�d�� }|�t|jd�Wd�n1s<0YdS)NsfPK.�C�@xPK..�C�@�xPK/!rGr�)r@rArrr�r�r2)r5r+r�rrr�test_unsupported_compression�sz'OtherTests.test_unsupported_compressioncCsPtjtdd��.}|�dd�|�|��dg�Wd�n1sB0YdS)zLCheck that a filename containing a null byte is properly
        terminated.r:r>zfoo.txtqqqr�r�N)r@rArrBrSr`r�rrr�test_null_byte_in_filenamesz%OtherTests.test_null_byte_in_filenamecCs<|�tjd�|�tjd�|�tjd�|�tjd�dS)zACheck that ZIP internal structure sizes are calculated correctly.��.�8r�N)rSr@ZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locatorr�rrr�test_struct_sizesszOtherTests.test_struct_sizesc	Cs�tjtdd��*}|�|jd�|�dd�Wd�n1s>0Ytjtdd��}|�|jd�Wd�n1sz0Yd}tjtdd��"}||_|�dd�Wd�n1s�0Ytjtdd��}|�|j|�Wd�n1s�0Yd	�d
d�td�D��}|�d
�}tjtdd��"}||_|�dd�Wd�n1�s^0Ytjtdd��}|�|j|�Wd�n1�s�0Ytjtdd��R}|�	t
��|d|_Wd�n1�s�0Y|�dd�Wd�n1�s0Ytjtdd��}|�|j|�Wd�n1�sL0Ytjtdd��"}d|_|�dd�Wd�n1�s�0Ytjtdd��}d|_Wd�n1�s�0Ytjtdd��}|�|jd�Wd�n1�s0Ytjtdd��"}d|_|�dd�Wd�n1�sD0Ytj�
t�}tjtdd��}d|_Wd�n1�s�0Y|�|tj�
t�k�tjtdd��}|�|jd�Wd�n1�s�0YdS)z8Check that comments on the archive are handled properly.r:r>r&r�r�NrGs9Bravely taking to his feet, he beat a very brave retreat.�cSsg|]}d|dd�qS)rrr�rr"rrrr%'r&z,OtherTests.test_comments.<locals>.<listcomp>�r soopssoriginal commentr�san updated commentsoriginal comment that's longersshorter comment)r@rArrSr�rBr*r'r�r~rr�r��getsizer\)r5r�Zzipfrr�Zcomment2Zoriginal_zip_sizerrr�
test_commentssP*,*,
,.*,.,&.,&zOtherTests.test_commentsc	Cspt�tdtj��L}|�dd�|�t��d|_Wd�n1sD0YWd�n1sb0YdS)Nr:r�r�zthis is an error)r@rArr�rBr��	TypeErrorr�r�rrr�test_unicode_commentMszOtherTests.test_unicode_commentcCs�t�tdtj��"}|�|j�d|_Wd�n1s80Yt�td��}|�|jd�Wd�n1sr0YdS)Nr�r�rG)r@rArr�rr�r�rSr�rrr�$test_change_comment_in_empty_archiveSs
$z/OtherTests.test_change_comment_in_empty_archivecCs�t�tdtj��}|�dd�Wd�n1s20Yt�tdtj��"}|�|j�d|_Wd�n1st0Yt�td��}|�|jd�Wd�n1s�0YdS)Nr:r�r�r�r�rG)	r@rArr�rBr\r�r�rSr�rrr�'test_change_comment_in_nonempty_archiveZs*$z2OtherTests.test_change_comment_in_nonempty_archivecCs�tjtdd�}|��ztjtdd�}WntjyF|�d�Yn0tjtdd�}|��ztjtdd�}Wn|�d�Yn0dS)Nr:r>rGz+Unable to create empty ZIP file in 'w' moder�z+Unable to create empty ZIP file in 'a' mode)r@rArr�r>r�r�rrr�test_empty_zipfilecszOtherTests.test_empty_zipfilecCs*ttd�}|��|�tjtjtd�dS)Nr:rG)r2rr�r�r@r>rArqrrr�test_open_empty_filets
zOtherTests.test_open_empty_filecCs|�ttjdd�dS)NZ	seventies)i�rMrMrrr)r�r�r@r�r�rrr�test_create_zipinfo_before_1980|s�z*OtherTests.test_create_zipinfo_before_1980cCs tjdd�}|�t|�d�dS)z=Before bpo-26185, repr() on empty ZipInfo object was failing.�emptyrQz&<ZipInfo filename='empty' file_size=0>N)r@r�rSr��r5�zirrr�test_create_empty_zipinfo_repr�sz)OtherTests.test_create_empty_zipinfo_reprcCs�t��}|�|jd�|�|jd�|�|jd�|�|jtj�|�|jd�|�|j	d�|�
|jd�|�|jtj
�|�|jtj
�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�dS)z'Ensure all required attributes are set.ZNoNamer�r&)rrrN)r@r�rSZ
orig_filenamerRr�r�r�r�r-rZZ
create_systemZcreate_versionZDEFAULT_VERSIONZextract_versionZreservedr�ZvolumeZ
internal_attrr�rbr;rrrr�,test_create_empty_zipinfo_default_attributes�s"z7OtherTests.test_create_empty_zipinfo_default_attributescCsHd}t�t�|�d��}|�|���Wd�n1s:0YdS)z>If an extra field in the header is less than 4 bytes, skip it.snPK���@����abcAPK���@������abcPK3%rGN)r@rArrr�rd�r5r�r�rrr�#test_zipfile_with_short_extra_field�s�	z.OtherTests.test_zipfile_with_short_extra_fieldc
Cs~d}d}d}t�tdtj����}|jddd��}|�|�Wd�n1sN0Y|jddd���.}|�t��|jddd�Wd�n1s�0Y|�t��|jdd	d�Wd�n1s�0Y|�t��|�d
d�Wd�n1�s0Y|�t��|�t	d�Wd�n1�s@0Y|�t��|�
�Wd�n1�st0Y|�|�Wd�n1�s�0Y|jd
dd��}|�|�Wd�n1�s�0YWd�n1�s�0Yt�td	��Z}|�|�d�|�|�|�d�|�|�|�d
�|�|�|�
�gd��Wd�n1�sp0YdS)Ns"It's fun to charter an accountant!s And sail the wide accountant seas#To find, explore the funds offshorer:r�r>r��handlerGr_ZabcderH�baz)r�r�r)r@rArr�r2r3r�r�rBrhr�rSrTr`)r5Zmsg1Zmsg2Zmsg3r�Zw2�w1rrr�test_open_conflicting_handles�s2(,,,,(*Jz(OtherTests.test_open_conflicting_handlesc	Cs�d}|�d�}t�td��}|�d|�Wd�n1s<0Yt�td���}|�dd���}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�Wd�n1�s20YWd�n1�sR0Yt��}tj|dd��}|�d|�Wd�n1�s�0Ytj|dd���}|�dd���}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�Wd�n1�s�0YWd�n1�s�0YdS)	NsWhere's Bruce?sBrucer:r�rGrrIr>)�findr@rArrBr2r�r��SEEK_SETrSr��SEEK_CURrT�SEEK_ENDrYrr)r5�txt�blocr�r6r+rrr�test_seek_tell�sB
*P,zOtherTests.test_seek_tellc	Cs�d}t�|�}tj|dtjd��}|�dd�Wd�n1sB0Yt�dd��Jt�|�� }|�t	|j
d�Wd�n1s�0YWd�n1s�0YdS)NsPKr:)r8r��azzipfile.bz2)rrr@rArrB�mockZpatchr�r�r�)r5r+Zzip_filerHrrr�)test_decompress_without_3rd_party_library�s
*z4OtherTests.test_decompress_without_3rd_party_librarycCstt�tt�dSrr�r�rrrr��szOtherTests.tearDownN),r�r�r�r�r�r�r�r�r
r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr	r
rrrr�rrrrr��sR



	
:	&
	r�c@seZdZdd�Zdd�ZdS)�AbstractBadCrcTestscCsN|j}tjt�|�dd�� }|�d|���Wd�n1s@0YdS)z>Tests that files with bad CRCs return their name from testzip.rGr>�afileN)�zip_with_bad_crcr@rArrrSrdrrrr�test_testzip_with_bad_crc�sz-AbstractBadCrcTests.test_testzip_with_bad_crcc
Csf|j}tjt�|�dd��"}|�tj|jd�Wd�n1sB0Ytjt�|�dd��L}|�dd�� }|�tj|j�Wd�n1s�0YWd�n1s�0Ytjt�|�dd���}|�dd��R}d|_	|�tj��|�d��rq�Wd�n1�s0YWd�n1�s80YWd�n1�sX0YdS)zFTests that files with bad CRCs raise a BadZipFile exception when read.rGr>rNr�)
rr@rArrr�r>rTr2�
MIN_READ_SIZE)r5r�r�Zcorrupt_filerrr�test_read_with_bad_crcs0Lz*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�rrrrrrr�src@seZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�r@r�r8rrrrrrs�rc@seZdZejZdZdS)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�r@r	r8rrrrrr's�rc@seZdZejZdZdS)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�r@rr8rrrrrr 4s�r c@seZdZejZdZdS)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�r@rr8rrrrrr!Ds�r!c@s^eZdZdZdZdZdZdZdd�Zdd	�Z	d
d�Z
dd
�Ze�dd��Z
dd�Zdd�ZdS)�DecryptionTestsz�Check that ZIP decryption works. Since the library does not
    support encryption at the moment, we use a pre-generated encrypted
    ZIP file.s�PKn�i.#y�?&test.txt��gly|�-�=�y�r�Z}Lg���|�䋺�)���lPKn�i.#y�?& ��test.txtPK6Ls�PK	�}38xu��zeroUT	֋�Gڋ�GUx���<M�a�X�Y&�{oEם���PKxu��PK	�}38xu��
��zeroUT֋�GUxPK?[szipfile.py encryption testscCs�ttd��}|�|j�Wd�n1s,0Yt�td�|_ttd��}|�|j�Wd�n1sp0Yt�td�|_	dS)Nr0rG)
r2rr3r+r@rAr�r�data2�zip2r4rrrr7ms**zDecryptionTests.setUpcCs,|j��t�t�|j��t�t�dSr)r�r�r�r	rr$rr�rrrr�us


zDecryptionTests.tearDowncCs(|�t|jjd�|�t|jjd�dS)N�test.txt�zero)r�r�r�rTr$r�rrr�test_no_password{sz DecryptionTests.test_no_passwordcCs@|j�d�|�t|jjd�|j�d�|�t|jjd�dS)Nsperlr%r&)r��setpasswordr�r�rTr$r�rrr�test_bad_password�sz!DecryptionTests.test_bad_passwordcCsH|j�d�|�|j�d�|j�|j�d�|�|j�d�|j�dS)N�pythonr%s12345r&)r�r(rSrT�plainr$�plain2r�rrr�test_good_password�sz"DecryptionTests.test_good_passwordcCsV|�t|jjd�|�t|jjdd�|jt|jjddd�|jt|jjddd�dS)N�unicoder%Zpython)�pwd)r�r�r�r(rTr2r�r�rrr�test_unicode_password�sz%DecryptionTests.test_unicode_passwordcCs�|j�d�|j}d}|�|�}t|�}|j�dd���:}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�|�||||��|j
}d|_
d|_d|_|�dtj�|�	|�
�d�|�|tj�|�	|�|�||||��||_
|�dtj�|�	|�
�t|��|�dtj�|�	|�
�d�|��Wd�n1�sz0YdS)Nr*s
encryptionr%rGrrMr&)r�r(r+rrYr2r�r�rrSr�rrTrZ_readbufferZ_offsetr)r5rZ	test_wordrZbloc_lenr6Z
old_read_sizerrrr�s6
zDecryptionTests.test_seek_tellN)r�r�r��__doc__r+r#r+r,r7r�r'r)r
r-r0rrrrrr"Ss�	�

r"c@s`eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�"AbstractTestsWithRandomBinaryFilescCs6tdd�dtdd�}d�dd�t|�D��|_dS)N��@r�rMr&css&|]}t�dt�tdd��VqdS)z<fi���rN)rr4rrr"rrrr�s�z@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>)rr*r'r+)r-Z	datacountrrrr.�s
�z-AbstractTestsWithRandomBinaryFiles.setUpClasscCs:ttd��}|�|j�Wd�n1s,0YdSr/r1r4rrrr7�sz(AbstractTestsWithRandomBinaryFiles.setUpcCstt�tt�dSrr�r�rrrr��sz+AbstractTestsWithRandomBinaryFiles.tearDowncCsJt�|d|��(}|�td�|�tt�Wd�n1s<0YdS)Nr:r;)r@rAr3rr)rrrrF�sz4AbstractTestsWithRandomBinaryFiles.make_test_archivecCs�|�||�t�|d|��R}|�t�}|�t|�t|j��|�||j�|�|�d�|j�Wd�n1sr0YdS)NrGr;)rFr@rArTrrSrYr+)r5rr8rD�testdatarrrro�s
z+AbstractTestsWithRandomBinaryFiles.zip_testcCs t|�D]}|�||j�qdSrrprqrrr�	test_read�sz,AbstractTestsWithRandomBinaryFiles.test_readc	Cs2|�||�t�|d|���}g}|�t��,}|�d�}|s>qJ|�|�q.Wd�n1s^0Yg}|�d��,}|�d�}|s�q�|�|�qxWd�n1s�0Yd�|�}	|�t	|	�t	|j
��|�|	|j
�d�|�}
|�t	|
�t	|j
��|�|
|j
�Wd�n1�s$0YdSrs)rFr@rAr2rrTrur*rSrYr+)r5rr8rDrvrwrxryrzZ	testdata1Z	testdata2rrrr{�s(
*
*

z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCs t|�D]}|�||j�qdSrr|rqrrrr}�sz,AbstractTestsWithRandomBinaryFiles.test_openc	Cs�|�||�t�|d|���}g}|�t��2}|�tdd��}|sBqN|�|�q,Wd�n1sb0Yd�|�}|�	t
|�t
|j��|�	||j�Wd�n1s�0YdSr�)rFr@rAr2rrTrrur*rSrYr+)r5rr8rDrvrwrxr5rrrr��s*
z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCs t|�D]}|�||j�qdSrr�rqrrrr�	sz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r.r7r�rFror6r{r}r�r�rrrrr2�s

r2c@seZdZejZdS)� StoredTestsWithRandomBinaryFilesNrUrrrrr7	sr7c@seZdZejZdS)�!DeflateTestsWithRandomBinaryFilesNrKrrrrr8	sr8c@seZdZejZdS)�Bzip2TestsWithRandomBinaryFilesNr
rrrrr9	sr9c@seZdZejZdS)�LzmaTestsWithRandomBinaryFilesNrrrrrr:#	sr:c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TellablecCs||_d|_dS�Nr)r6�offsetr4rrr�__init__+	szTellable.__init__cCs|j�|�}|j|7_|Sr)r6r3r=)r5r+�nrrrr3/	szTellable.writecCs|jSr)r=r�rrrr�4	sz
Tellable.tellcCs|j��dSr�r6�flushr�rrrrA7	szTellable.flushN)r�r�r�r>r3r�rArrrrr;*	sr;c@s$eZdZdd�Zdd�Zdd�ZdS)�
UnseekablecCs
||_dSr)r6r4rrrr>;	szUnseekable.__init__cCs|j�|�Sr)r6r3r�rrrr3>	szUnseekable.writecCs|j��dSrr@r�rrrrAA	szUnseekable.flushN)r�r�r�r>r3rArrrrrB:	srBc@s$eZdZdd�Zdd�Zdd�ZdS)�UnseekableTestscCspdd�ttfD�]Z}|j|d���6t��}|�d�t�|�}t�||�dtj	��(}|�
dd�|�
dd	�Wd�n1s�0Y|�|��dd
�d�tj|dd
���}|�
d�� }|�|��d�Wd�n1s�0Y|�
d�� }|�|��d	�Wd�n1�s 0YWd�n1�s@0YWd�q1�s`0YqdS)NcSs|Srr�rrrrrzF	r&z/UnseekableTests.test_writestr.<locals>.<lambda>��wrapper�abcr:�ones�111�twos�222rI�abcPKrGr>)r;rB�subTestrrr3�BufferedWriterr@rAr�rBrSrWr2rT)r5rFr�bfrDr��zopenrrr�
test_writestrE	s

*.zUnseekableTests.test_writestrcCs�dd�ttfD�]�}|j|d����t��}|�d�t�|�}t�||�dtj	���}|�
tt�t
td��}|�d�Wd�n1s�0Y|�td�t
td��}|�d	�Wd�n1s�0Y|�td
�Wd�n1s�0Y|�|��dd�d�tj|d
d���}|�
d�� }|�|��d�Wd�n1�sZ0Y|�
d
�� }|�|��d	�Wd�n1�s�0YWd�n1�s�0YWd�q1�s�0YqdS)NcSs|SrrrDrrrrzV	r&z,UnseekableTests.test_write.<locals>.<lambda>rErGr:r0rIrHrKrJrIrLrGr>)r;rBrMrrr3rNr@rAr��
addCleanupr	rr2rSrWrT)r5rFrrOrD�f2r�rPrrr�
test_writeU	s&

((*0zUnseekableTests.test_writecCsndd�ttfD�]X}|j|d���4t��}|�d�t�|�}t�||�dtj	��|}|�
dd��}|�d�Wd�n1s�0Y|�
dd��}|�d	�Wd�n1s�0YWd�n1s�0Y|�|��dd
�d�t�|��4}|�|�
d�d�|�|�
d�d	�Wd�n1�s>0YWd�q1�s^0YqdS)NcSs|SrrrDrrrrzk	r&z1UnseekableTests.test_open_write.<locals>.<lambda>rErGr:rHrIrJrKrIrL)r;rBrMrrr3rNr@rAr�r2rSrWrT)r5rFrrOr�rPrrr�test_open_writej	s

(FzUnseekableTests.test_open_writeN)r�r�r�rQrTrUrrrrrCD	srCc@sheZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestsWithMultipleOpenscCs dtd�|_dtd�|_dS)NrI�'rK)r�data1r#r,rrrr.}	sz!TestsWithMultipleOpens.setUpClasscCsPt�|dtj��,}|�d|j�|�d|j�Wd�n1sB0YdS)Nr:rHrJ)r@rAr	rBrXr#)r5rrDrrrrF�	sz(TestsWithMultipleOpens.make_test_archivecCs�t|�D]�}|�|�tj|dd���}|�d��f}|�d��<}|�d�}|�d�}||��7}||��7}Wd�n1s~0YWd�n1s�0Y|�||�|�||j�Wd�q1s�0YqdS)NrGr>rH��)rrFr@rAr2rTrSrX�r5rr��zopen1�zopen2rXr#rrr�test_same_file�	s


Hz%TestsWithMultipleOpens.test_same_filecCs�t|�D]�}|�|�tj|dd���}|�d��f}|�d��<}|�d�}|�d�}||��7}||��7}Wd�n1s~0YWd�n1s�0Y|�||j�|�||j�Wd�q1s�0YqdS)NrGr>rHrJrY�	rrFr@rAr2rTrSrXr#rZrrr�test_different_file�	s


Hz*TestsWithMultipleOpens.test_different_filecCs�t|�D]�}|�|�tj|dd���}|�d��f}|�d�}|�d��2}|�d�}||��7}||��7}Wd�n1s~0YWd�n1s�0Y|�||j�|�||j�Wd�q1s�0YqdS)NrGr>rHrYrJr^)r5rr�r[rXr\r#rrr�test_interleaved�	s


Hz'TestsWithMultipleOpens.test_interleavedc
Cs�t|�D]�}|�|�t����}t�|d��0}|�|�d��}|�|�d��}Wd�n1sb0Y|�d�}|�d�}||��7}||��7}Wd�n1s�0Y|�	||j
�|�	||j�qdS)NrGrHrJrY)rrF�
contextlib�	ExitStackr@rA�
enter_contextr2rTrSrXr#)r5r�stackr�r[r\rXr#rrr�test_read_after_close�	s

.

*z,TestsWithMultipleOpens.test_read_after_closec
Cst|�D]�}t�|dtj��`}|�d|j�|�d|j�|�d��}|�d�}Wd�n1sd0YWd�n1s�0Y|�	||jdd��t�|d��$}|�d�}|�d�}Wd�n1s�0Y|�	||j�|�	||j�qdS)Nr:rHrJrYrG)
rr@rAr	rBrXr#r2rTrS�r5rr�r[rXr#rrr�test_read_after_write�	sF
(z,TestsWithMultipleOpens.test_read_after_writec
Cs�t|�D]�}t�|dtj��`}|�d|j�|�d��(}|�d�|�d|j�Wd�n1sd0YWd�n1s�0Yt�|d��$}|�d�}|�d�}Wd�n1s�0Y|�	||j�|�	||j�qdS)Nr:rHrYrJrG)
rr@rAr	rBrXr2rTr#rSrfrrr�test_write_after_read�	s
J
(z,TestsWithMultipleOpens.test_write_after_readc
Cs�|�t�tjtdd��R}td�D]8}|�d�|�d��}Wd�q"1sP0Yq"Wd�n1sp0Yttj�� }|�	|�
�d�Wd�n1s�0YdS)NrGr>r�rH)rFrr@rAr'rTr2r��devnullZ
assertLess�fileno)r5r�r�r[rrrr�test_many_opens�	s

>z&TestsWithMultipleOpens.test_many_opensc
Cs:t�tdtj��}|�d|j�Wd�n1s40Yt�tdtj���}|�dd��^}|�d�}|�dd��}|�|j	�Wd�n1s�0Y||��7}Wd�n1s�0YWd�n1s�0Y|�
||j�t�t��$}|�
|�d�|j	�Wd�n1�s,0YdS)Nr:rHr�rGrYrJ)r@rArr	rBrXr2rTr3r#rS)r5r�Zr1rXrrrr�test_write_while_reading�	s,
*Hz/TestsWithMultipleOpens.test_write_while_readingcCstt�dSrrOr�rrrr��	szTestsWithMultipleOpens.tearDownN)r�r�r�r�r.rFr]r_r`rergrhrkrlr�rrrrrV{	s


rVc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestWithDirectorycCst�t�dSr)r�r�rr�rrrr7�	szTestWithDirectory.setUpc
Cs�t�td���}|�t�Wd�n1s.0Y|�tj�tj�	td���|�tj�tj�	tdd���|�tj�
tj�	tddd���dS)N�
zipdir.zipr��brG)r@rArr�rr\r�r��isdirr*r�r�rrr�test_extract_dir�	s
(z"TestWithDirectory.test_extract_dircCs t�tj�td��|��dS�Nr�)r�r�r�r*rrqr�rrr�
test_bug_6050
szTestWithDirectory.test_bug_6050c	Cs�tj�td�}t�|�t�|�jd@}t�t	d���}|�
|�|jd}|�|j
�d��|�|j|d>dB�|�
|d�|jd}|�|j
d	�|�|j|d>dB�Wd�n1s�0Yt�t	d
���}|jd}|�|j
�d��|�|j|d>dB�|jd}|�|j
d	�|�|j|d>dB�tj�td�}t�|�|�|�|�tj�tj�|d���|�tt�|��d�Wd�n1�s�0YdS)
Nr�r�r:rz/x/r3�yrMzy/rGr�r�)r�r�r*rr�r�st_moder@rArr3r�r\rRrjrSr�r�rprY�listdir)r5�dirpathr?r�r�r�rrr�test_write_dir	
s0



4



z TestWithDirectory.test_write_dirc	Cs t�tj�td��t�td��B}|�dd�|j	d}|�
|jd�|�
|jd�Wd�n1sh0Yt�td���}|j	d}|�
|j�d��|�
|jd�tj�td�}t�|�|�|�|�
tj�tj�|d���|�
t�|�dg�Wd�n1�s0YdS)	Nr�r:zx/r&ri�ArGr�)r�r�r�r*rr@rArrBr�rSrRr�r\rjr�rprv)r5r�r�r�rrr�test_writestr_dir#
s
,


z#TestWithDirectory.test_writestr_dircCs tt�tj�t�rtt�dSr)r
rr�r�r�rr	r�rrrr�4
szTestWithDirectory.tearDownN)	r�r�r�r7rqrsrxryr�rrrrrm�	srmc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ZipInfoTestscCsHtj�t�}|�t�|j�d�|�|�	��|�|j
tj�
t��dS�Nztest_zipfile.py)r@r��	from_filerhrS�	posixpathrrrRr�is_dirrbr�r�r�rrrr�test_from_file;
szZipInfoTests.test_from_filecCsNtj�t�t��}|�t�|j	�d�|�
|���|�|jt
j�t��dSr{)r@r�r|rr�rhrSr}rrrRrr~rbr�r�r�rrrr�test_from_file_pathlikeA
sz$ZipInfoTests.test_from_file_pathlikecCsPtj�t�t�d�}|�t�|j	�d�|�
|���|�|jtj
�t��dS)Nr)r@r�r|r��fsencoderhrSr}rrrRrr~rbr�r�rrrr�test_from_file_bytesG
sz!ZipInfoTests.test_from_file_bytescCsxttd��Z}tj�|��d�}|�t�|j	�d�|�
|���|�|jt
j�t��Wd�n1sj0YdS)Nr�r)r2rhr@r�r|rjrSr}rrrRrr~rbr�r�r�)r5rrrrr�test_from_file_filenoM
s
z"ZipInfoTests.test_from_file_filenocCs`tj�tj�t��}tj�|d�}|�|j	d�|�
|���|�|jtj
�|�|jd�dS)NZstdlib_testsz
stdlib_tests/r)r�r�rg�abspathrhr@r�r|rSrRr\r~r�r�rb)r5rwrrrr�
test_from_dirT
szZipInfoTests.test_from_dirN)r�r�r�rr�r�r�r�rrrrrz:
s
rzc@sJeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�dd��Z	d
d�Z
dS)�CommandLineTestcOs2tjddg|�Ri|��\}}}|�tj��d�S)N�-mr@r)rZassert_python_okr�r��linesepr�)r5�argsrC�rc�out�errrrr�
zipfilecmd_
s�zCommandLineTest.zipfilecmdcGstjddg|�R�S)Nr�r@)rZassert_python_failure)r5r�rrr�zipfilecmd_failured
sz"CommandLineTest.zipfilecmd_failurecCs||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr&susageserrorsrequired�-lr�)r�rSrZr@ZassertNotEqual�strip)r5r�r�r�rrr�test_bad_useg
szCommandLineTest.test_bad_usecCsXtd�}dD] }|�||�}|�|��d�qtd�}|�d|�\}}}|�|d�dS)Nrn)�-tz--testsDone testingztesttar.tarr�r&)rr�rS�rstripr�)r5�zip_name�optr�r�r�rrr�test_test_commandq
sz!CommandLineTest.test_test_commandcCs�td�}t��}t�|d��}|�|�Wd�n1s<0Y|���dd�}dD] }|j||dd�}|�	||�qZdS)NrnrGr �backslashreplace)r�z--listzascii:backslashreplace)ZPYTHONIOENCODING)
rrrUr@rArVrWr�r�rS)r5r�rtZtfZexpectedr�r�rrr�test_list_commandz
s(�z!CommandLineTest.test_list_commandc	Cs\|�tt�ttd��}|�d�Wd�n1s60Yt�t�|�tt�ttj	�
td�d��}|�d�Wd�n1s�0Yttg}ttdtdg}dD]�}z�|j|tg|�R�}|�
|d�t�t��L}|�
|��|�|�
|�|d	�d
�|�
|�|d�d�Wd�n1�s60YWtt�q�tt�0q�dS)
Nr:ztest 1zfile.txtztest 2r�z	/file.txt)z-cz--creater&rstest 1r�stest 2)rRr	rr2r3r�r��	TESTFNDIRr
r�r*r�rrSr@rAr`rT)r5r�filesr`r�r�rHrrr�test_create_command�
s$(
(8z#CommandLineTest.test_create_commandc	Cstd�}dD�]}t���}|�|||�}|�|d�t�|���}|��D]�}tj�	||j
�dtj��}|�
�r�|�tj�|��qH|�tj�|��t|d��&}|�|��|�|��Wd�qH1s�0YqHWd�n1s�0YWd�q1�s
0YqdS)Nrn)z-ez	--extractr&r�r�)rrr�rSr@rArar�r�r*rRr�rkr~r\rpr�r2rT)	r5r�r�r�r�rHrr�rrrr�test_extract_command�
s
�z$CommandLineTest.test_extract_commandN)r�r�r�r�r�r�r�r�r
r�r�rrrrr�]
s
	
r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	e
jd
�e�	e�
dej�d�d
d���Ze�	e
jd
�e�	e�
dej�d�dd���ZdS)�TestExecutablePrependedZipz@Test our ability to open zip files with an executable prepended.cCs tddd�|_tddd�|_dS)NZexe_with_zipZziptestdata)r�Zexe_with_z64)r�exe_zip�	exe_zip64r�rrrr7�
sz TestExecutablePrependedZip.setUpcCsj|�t�|�d|���t�|��4}|��D]}|�|�}|�d|�q,Wd�n1s\0YdS)Nzis_zipfile failed on sFAVORITE_NUMBER)r\r@r�rAr`rTrZ)r5r[rDr?r+rrr�_test_zip_works�
s�
z*TestExecutablePrependedZip._test_zip_workscCs|�|j�dSr)r�r�r�rrr� test_read_zip_with_exe_prepended�
sz;TestExecutablePrependedZip.test_read_zip_with_exe_prependedcCs|�|j�dSr)r�r�r�rrr�"test_read_zip64_with_exe_prepended�
sz=TestExecutablePrependedZip.test_read_zip64_with_exe_prependedzsys.executable required.z	/bin/bashz#Test relies on #!/bin/bash working.cCs"t�|jtjg�}|�d|�dS�Nsnumber in executable: 5)�
subprocess�check_outputr��sys�
executablerZ�r5�outputrrr�test_execute_zip2�
sz,TestExecutablePrependedZip.test_execute_zip2cCs"t�|jtjg�}|�d|�dSr�)r�r�r�r�r�rZr�rrr�test_execute_zip64�
sz-TestExecutablePrependedZip.test_execute_zip64N)r�r�r�r1r7r�r�r�r�Z
skipUnlessr�r�r�r]�X_OKr�r�rrrrr��
s
��r�c@seZdZGdd�d�ZdS)�jaracoc@seZdZGdd�d�ZdS)zjaraco.itertoolsc@s$eZdZdd�Zdd�Zdd�ZdS)zjaraco.itertools.CountercCsd|_t|�|_dSr<)r��iter�
_orig_iter)r5r$rrrr>�
sz!jaraco.itertools.Counter.__init__cCs|Srrr�rrr�__iter__�
sz!jaraco.itertools.Counter.__iter__cCst|j�}|jd7_|Sr�)�nextr�r�)r5�resultrrr�__next__�
s
z!jaraco.itertools.Counter.__next__N)r�r�r�r>r�r�rrrr�Counter�
sr�N)r�r�r�r�rrrrrC�
srCN)r�r�r�rCrrrrr��
sr�cCs&tj�|���D]}|�|d�q|S)z}
    Given a writable zip file zf, inject directory entries for
    any directories implied by the presence of children.
    r&)r@�CompleteDirs�
_implied_dirsr`rB)rHr[rrr�add_dirs�
sr�cCsZt��}t�|d�}|�dd�|�dd�|�dd�|�dd	�|�d
d�d|_|S)
u:
    Create a zip file with this structure:

    .
    ├── a.txt
    ├── b
    │   ├── c.txt
    │   ├── d
    │   │   └── e.txt
    │   └── f.txt
    └── g
        └── h
            └── i.txt

    This fixture has the following key characteristics:

    - a file at the root (a)
    - a file two levels deep (b/d/e)
    - multiple files in a directory (b/c, b/f)
    - a directory containing only a directory (g/h)

    "alpha" because it uses alphabet
    "rep" because it's a representative example
    r:r��content of azb/c.txtscontent of cz	b/d/e.txtscontent of ezb/f.txtscontent of fz	g/h/i.txtscontent of izalpharep.zip)rrr@rArBrR)r+rHrrr�build_alpharep_fixture�
sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdZd d!�Zd"d#�Zd$d%�Zd&S)'�TestPathcCst��|_|�|jj�dSr)rarb�fixturesrRr�r�rrrr7s
zTestPath.setUpccsh|���t�VWd�n1s&0Y|���tt��VWd�n1sZ0YdSr)rMr�r�r�rrr�zipfile_alphareps
&
zTestPath.zipfile_alpharepc	cs|t�|j�t���}|��D]Z}|j}|��||j}|�	d��}|�
|���Wd�n1sf0Y|VqdSr/)rr�r�rcrr�r6r�rRr2r3rW)r5Ztmpdir�alpharep�bufferr��strmrrr�zipfile_ondisk!s
,zTestPath.zipfile_ondiskcCs�|��D]�}t�|�}|��s"J�|��\}}}|��s<J�|��sHJ�|��sTJ�|��\}}}|��rr|��svJ�|��\}	|	��s�J�|��\}
|
��\}|��sJ�qdSr)r�r@r�r~�iterdir�is_file)r5r��rootr�ro�grGrrrA�hr$rrr�test_iterdir_and_types+s



zTestPath.test_iterdir_and_typescCs\|��D]N}t�|�}|d��s&J�|d��s6J�|d��sFJ�|d��sJ�qdS)Nro�b/r�zg/)r�r@r�r~�r5r�r�rrr�test_subdir_is_dir;s
zTestPath.test_subdir_is_dirc	Csf|��D]X}t�|�}|��\}}}|���}|��}Wd�n1sJ0Y|dksJ�qdS)N�content of a)r�r@r�r�r2rT)r5r�r�r�ror�r�r+rrrr}Cs

&zTestPath.test_opencCsJ|��D]<}t�|�}|��\}}}|��dks4J�|��dksJ�qdS)Nr�r�)r�r@r�r��	read_text�
read_bytes)r5r�r�r�ror�rrrr6Ks

zTestPath.test_readcCsX|��D]J}t�|�}|�d�}|��s,J�|�d��d��d�}|��dksJ�qdS�Nr�rorze.txtzcontent of e)r�r@r��joinpathr�r��r5r�r�r�rArrr�
test_joinpathRs

zTestPath.test_joinpathcCsP|��D]B}t�|�}|d}|��s*J�|ddd}|��dksJ�qdSr�)r�r@r�r�r�r�rrr�test_traverse_truedivZs
zTestPath.test_traverse_truedivcCs*|��D]}t�t|��}t�|�qdS)zN
        zipfile.Path should be constructable from a path-like object
        N)r�rr�r_r@)r5r�Zpathlikerrr�test_pathlike_constructionbsz#TestPath.test_pathlike_constructioncCs*|��D]}t�|�}|t�d�qdSrr)r�r@r�rr�rrr�test_traverse_pathlikejs
zTestPath.test_traverse_pathlikecCsH|��D]:}t�|�}|djjdks*J�|ddjjdksJ�qdS)Nr�r�roza/�r�r@r��parentZatr�rrr�test_parentos
zTestPath.test_parentcCsD|��D]6}t�|�}|djjdks*J�|djjdksJ�qdS)Nror�r�r�r�rrr�test_dir_parentus
zTestPath.test_dir_parentcCs0|��D]"}t�|�}|djjdksJ�qdS)Nzmissing dir/r�r�r�rrr�test_missing_dir_parent{s
z TestPath.test_missing_dir_parentcCs�|��D]�}t�|�}|��\}}}|�dd�|�dd�tdd�|��D��sVJ�|d��dksjJ�|d��\}|��dksJ�qdS)	zk
        If the underlying zipfile is changed, the Path object should
        reflect that change.
        r�r�zbar/baz.txtrcss|]}|jdkVqdS)r�N)r[)r#�childrrrr�s�z+TestPath.test_mutability.<locals>.<genexpr>r�N)r�r@r�r�rB�anyr�)r5r�r�r�ror�rrrr�test_mutability�s
�zTestPath.test_mutabilityi cCs@t��}t�|d�}ttt|j��D]}|�||�q$d|_	|S)zACreate a read-only zipfile with a huge number of entries entries.r:rG)
rrr@rA�mapr_r'�HUGE_ZIPFILE_NUM_ENTRIESrBr?)r5r�rH�entryrrr�huge_zipfile�szTestPath.huge_zipfilecCsFt�|���}tj�|���}|D]}|�d�q"|j|j	ksBJ�dS)zE
        Ensure joinpath on items in zipfile is linear time.
        �suffixN)
r@r�r�r�rCr�r�r�r�r�)r5r��entriesr�rrr�test_joinpath_constant_time�s
z$TestPath.test_joinpath_constant_timecCs"dd�td�D�}tj�|�dS)NcSs g|]}d�tjt|���qS)r�)r*�string�ascii_lowercaser_)r#r?rrrr%�r&z:TestPath.test_implied_dirs_performance.<locals>.<listcomp>rW)r'r@r�r�r�rrr�test_implied_dirs_performance�sz&TestPath.test_implied_dirs_performanceN)r�r�r�r7r�r�r�r�r}r6r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s&
	r��__main__)Vra�importlib.utilrnrrCr�rr}r�rr�r�r]r�Z
unittest.mockrr@�tempfilerrrrZtest.supportrrrr	r
rrr
rrrrr�r(Z
DATAFILES_DIRr�rrZTestCaser�rrrrr'rJrLrMrNrTrVrWrXrYr�r�rrrr r!r"r2r7r8r9r:r;rBrCrVrmrzr�r��tupleZconsumer�r�r�r�r��mainrrrr�<module>s�0	�C�������BAg[����
7}A#P'
$


Kontol Shell Bypass