Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_zipfile.cpython-39.opt-2.pyc

a

��g���@sjddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlZddlmZddlmZmZmZddlmZddlmZmZmZmZmZmZmZm Z m!Z!m"Z"edZ#edZ$dZ%d	Z&gd
�Z'dd�Z(Gd
d�d�Z)Gdd�de)ej*�Z+e�Gdd�de)ej*��Z,e �Gdd�de)ej*��Z-e!�Gdd�de)ej*��Z.Gdd�d�Z/Gdd�de/ej*�Z0e�Gdd�de/ej*��Z1e �Gdd�de/ej*��Z2e!�Gdd �d e/ej*��Z3Gd!d"�d"�Z4Gd#d$�d$e4ej*�Z5e�Gd%d&�d&e4ej*��Z6e �Gd'd(�d(e4ej*��Z7e!�Gd)d*�d*e4ej*��Z8Gd+d,�d,ej*�Z9Gd-d.�d.ej*�Z:Gd/d0�d0ej*�Z;Gd1d2�d2�Z<Gd3d4�d4e<ej*�Z=e�Gd5d6�d6e<ej*��Z>e �Gd7d8�d8e<ej*��Z?e!�Gd9d:�d:e<ej*��Z@Gd;d<�d<ej*�ZAGd=d>�d>�ZBGd?d@�d@eBej*�ZCe�GdAdB�dBeBej*��ZDe �GdCdD�dDeBej*��ZEe!�GdEdF�dFeBej*��ZFGdGdH�dH�ZGGdIdJ�dJ�ZHGdKdL�dLej*�ZIe�GdMdN�dNej*��ZJGdOdP�dPej*�ZKGdQdR�dRej*�ZLGdSdT�dTej*�ZMGdUdV�dVej*�ZNeOZPGdWdX�dX�ZQdYdZ�ZRd[d\�ZSGd]d^�d^ej*�ZTGd_d`�d`ejU�ZVeWdak�rfe�X�dS)b�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�-/usr/local/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>1s���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�setUp6s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%jr&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_testFsL
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_test�s 
*
*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)Nr:r<Z12rGrM�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_compresslevel0s�

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_zipfileLs2&
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_reprjs6*
,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)Nr:rMr�Z
compress_1Z
compress_9r�)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)Nr:�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)N�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!r0r��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)Nr:r�)r@rArr3rr2rSrTr�rrr�test_write_default_name5s
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)Nr:r>r�r�rG)	r@rArrBr�r�r3rr2r�rrr�test_write_to_readonlyKs*.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_1980Xs.

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_2107cs$	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)Nr:ZstoremeZ	deflateme)
r@rArr3rr��ZIP_DEFLATEDrcrSr�)r5rD�sinfoZdinforrr�test_per_file_compression�s

z4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�r@r
r8rrrrrr	�sr	c@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@rArr8r r'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_test5s�z5StoredTestZip64InSmallFiles.large_file_exception_testcCsLtj|d|dd��&}|�tj|jd|j�Wd�n1s>0YdSr))r@rAr�r&rBr+r*rrr�large_file_exception_test2:s
�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�Ds�*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_appendLs,
$,
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)N�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_fileZs�






��
���������	�
���
���������������!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|�dt|j	��
��|jd	dddd
�}|�tj�� }t�t�|��Wd�n1�s�0Y|�dt|j	��
��|jddd	dd�}|�tj�� }t�t�|��Wd�n1�s20Y|�dt|j	��
��|jd	d	dd�}|�tj�� }t�t�|��Wd�n1�s�0Y|�dt|j	��
��dS)
NT)r6z	file size)r6r7r8z
compress size)r8)r6r7r8r9r:z
header offsetF)r6r8r9r:)r6r7r8r:)r6r8r:)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)	Nr0rr4T)r6r7)r8r9)r:r;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>rCrJrrrrr(1s�
c^r(c@seZdZejZdS)�DeflateTestZip64InSmallFilesN�r�r�r�r@r
r8rrrrrK7srKc@seZdZejZdS)�Bzip2TestZip64InSmallFilesNrrrrrrM<srMc@seZdZejZdS)�LzmaTestZip64InSmallFilesNrrrrrrNAsrNc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�AbstractWriterTestscCstt�dSr�r	rr�rrrr�IszAbstractWriterTests.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_closeLs
z*AbstractWriterTests.test_close_after_closecCs�d}t�td|j��\}|�dd�}|�|�|��|�|j�|�	t
|jd�|�|�d�|�Wd�n1sv0YdS)NrQr:rr&)
r@rArr8r2r3r�r\rr�r�rSrTrRrrr�test_write_after_closeWs
z*AbstractWriterTests.test_write_after_closec	Cs�t�dgd��}t|�|j}t�t��d|j��b}|�dd��"}|�	|�
|�|�Wd�n1sh0Y|�	|�d�j|�Wd�n1s�0YdS)Nr1)rMr�rrPrIr:r+)
�arrayrY�itemsizer@rArrr8r2rSr3rcrb)r5�qZLENGTHr�r+rrr�test_issue44439as0z#AbstractWriterTests.test_issue44439N)r�r�r�r�rSrTrXrrrrrOGs
rOc@seZdZejZdS)�StoredWriterTestsN�r�r�r�r@r�r8rrrrrYisrYc@seZdZejZdS)�DeflateWriterTestsNrLrrrrr[lsr[c@seZdZejZdS)�Bzip2WriterTestsNrrrrrr\psr\c@seZdZejZdS)�LzmaWriterTestsNrrrrrr]tsr]c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�PyZipFileTestscCs |d|vr|�|d|�dS)N�orH)rZ)r5�namer`rrr�assertCompiledInzs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�requiresWriteAccess~s

�
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)rir�r��dirname�__file__rr@�	PyZipFile�endswithr[�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInr`ra)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�rlrmrirr@rnrvr`ra)r5r{�
packagedirryrDrkrrr�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�rw�
startswith)r�rrr�filter�szAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)rr�r�rlrmrirr@rnrrvrWr\�assertWarns�UserWarning�print)r5rr|ryrDZ	reportSIOZ	reportStrr�rrr�"test_write_filtered_python_package�s&
(0Nz1PyZipFileTests.test_write_filtered_python_packagec	Cs�ddl}tj�|j�}|�|�dr(dnd}d}t��r}tj|d|d��B}|�	|�|�
�}|�d||�|�d||�Wd�n1s�0YWd�n1s�0YdS)	NrFrMrjr:)�optimizezemail/__init__zemail/mime/text)r{r�r�rlrmrirr@rnrvr`rZ)r5r{r|Zoptlevel�extryrDrkrrr�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@rnrvr`rarxr
�r5r6ryrDrkrrr�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�)ro)rgrrrrszEPyZipFileTests.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@rnr2rr3r��RuntimeErrorrvr	)r5ryrDrrrr�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
r~zmod1.pyc)r�r�rr2r�r*r3rr@rnrrvrZrWr`rxr
)r5r6ryrD�srkrrr�test_write_pyfile_bad_syntaxs
(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@rnrvrr�r`rar
r�rrr�test_write_pathlike,s
(Jz"PyZipFileTests.test_write_pathlikeN)r�r�r�rarirzr}r�r�r�r�r�r�r�rrrrr^ys
r^c@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_file<s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_extractAs
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_targetTs2(z&ExtractTests._test_extract_with_targetcCs4t��}|�|�Wd�n1s&0YdSr)rr��r5�extdirrrr�test_extract_with_targetgsz%ExtractTests.test_extract_with_targetcCs:t�� }|�t�|��Wd�n1s,0YdSr)rr�rr�r�rrr�!test_extract_with_target_pathlikeksz.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_allos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_target|s
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)N))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�r�)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�rpr�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�rpr�r�r�rrrrr�:s"



r�c@sleZdZdd�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*e�dMdN��Z+e�dOdP��Z,dQdR�Z-dSS)T�
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�r�rSr`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:Zabcdefghijklmnopr0)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)Nr:zzipfp is not open�zipfp is not closedrG)r@rArr�rBZassertIsNotNoner6�assertIsNoner�rrr�
test_closes.,zOtherTests.test_closecCs�t�td��*}tD]\}}|�||�qWd�n1s<0Yz8t�td��}t���Wd�n1sr0YWn"tjy�|�|jd�Yn0dS)Nr:rGr�)r@rArr�rBr?r�r6)r5rDr�r�Zzipfp2rrr�test_close_on_exception"s,*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_filenames:s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)r5rIrrr�test_write_unicode_filenamesBs4z'OtherTests.test_write_unicode_filenamescCsNt�td��.}|�dd�|�|�d�d�Wd�n1s@0YdS)Nr:uприкладssample)r@rArrBrSrTr�rrr�'test_read_after_write_unicode_filenamesLs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)N�testfile.txt�#hello, world. this is some content.�xrG)r	rr@rAr�rBr��FileExistsErrorrSr`rT)r5rRr$rDrrr�test_exclusive_create_zip_fileQs*.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$rIrrr�(test_create_non_existent_file_for_append^s
.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?)r5r6rIrrr�test_close_erroneous_fileps(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)Nr:r�r�sthis is not a legal zip file
r)r2rr3rr@�
is_zipfilerr�rrr�r4rrr�test_is_zip_erroneous_files(.
z%OtherTests.test_is_zip_erroneous_filecCs�t��}tj|dd��}|�dd�Wd�n1s80Y|��}tt|��D](}t�|d|��}|�tj	tj|�qVdS)Nr:r>r��O, for a Muse of Fire!)
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)Nr:r>r�r�r�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)Nr:r>r��O, for a Muse of Fire!z	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)NrW)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)	Nr:r>r�r�rGrW�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)Nr:r>r�r�rr&r�)	r@rArrBr2r'r(rSrT)r5r�rr$rrr�
test_read0�szOtherTests.test_read0cCsDtjtdd��"}|�t|jdd�Wd�n1s60YdS)Nr:r>r�rG)r@rArr��KeyErrorr2r�rrr�test_open_non_existent_item�sz&OtherTests.test_open_non_existent_itemcCs|�ttjtdd�dS)Nr:r�)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_compressionsz'OtherTests.test_unsupported_compressioncCsPtjtdd��.}|�dd�|�|��dg�Wd�n1sB0YdS)Nr:r>zfoo.txtqqqr�r�)r@rArrBrSr`r�rrr�test_null_byte_in_filenamesz%OtherTests.test_null_byte_in_filenamecCs<|�tjd�|�tjd�|�tjd�|�tjd�dS)N��.�8r�)rSr@ZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locatorr�rrr�test_struct_sizesszOtherTests.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)Nr:r>r&r�r�rGs9Bravely taking to his feet, he beat a very brave retreat.�cSsg|]}d|dd�qS)rrr�rr"rrrr%0r&z,OtherTests.test_comments.<locals>.<listcomp>�r soopssoriginal commentr�san updated commentsoriginal comment that's longersshorter comment)r@rArrSr�rBr*r'r�r�r�r�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_commentVs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_archive\s
$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_archivecs*$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_zipfilelszOtherTests.test_empty_zipfilecCs*ttd�}|��|�tjtjtd�dS�Nr:rG)r2rr�r�r@r?rArqrrr�test_open_empty_file}s
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)N�emptyrQz&<ZipInfo filename='empty' file_size=0>)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)NZNoNamer�r&)rrr)r@r�rSZ
orig_filenamerRr�r�r�r�r.rZZ
create_systemZcreate_versionZDEFAULT_VERSIONZextract_versionZreservedr�ZvolumeZ
internal_attrr�rbr<r	rrr�,test_create_empty_zipinfo_default_attributes�s"z7OtherTests.test_create_empty_zipinfo_default_attributescCsHd}t�t�|�d��}|�|���Wd�n1s:0YdS)NsnPK���@����abcAPK���@������abcPK3%rG)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�rBrmr�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_filerIrrr�)test_decompress_without_3rd_party_library�s
*z4OtherTests.test_decompress_without_3rd_party_libraryc	Csd}t�t�|�d���}|�|��ddg�|�d�}|�|jd�|�|jd�|�|j	d�|�d�}|�|jd�|�|jd�|�|j	d�|�t
|�d��d�|�tj
d��|�d�Wd�n1s�0YWd�n1s�0YdS)	Ns�PK�lH�8�	a��0�K\d`PK�lH�8�	aPK�lH�8�	bPK^/rGr��br��	zFile name.*differ)r@rArrrSr`rcr=r<rbrYrT�assertRaisesRegexr?�r5r+r�r
rrr�test_full_overlaps�


zOtherTests.test_full_overlapc	Csd}t�t�|�d���}|�|��ddg�|�d�}|�|jd�|�|jd�|�|j	d�|�d�}|�|jd�|�|jd	�|�|j	d
�|�
tjd��|�d�Wd�n1s�0Y|�t
|�d��d
�Wd�n1s�0YdS)Ns�PK�lHY�84(a�PK�lH�8�	b��0�K\d`PK�lHY�84(aPK�lH�8�	$bPK^SrGr�rr�4i(�$rrzOverlapped entries)r@rArrrSr`rcr=r<rbr r?rTrYr!rrr�test_quoted_overlaps�

(zOtherTests.test_quoted_overlapcCstt�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�rrrrrrrrrrrrrr"r%r�rrrrr��sZ



	
:	&
	

r�c@seZdZdd�Zdd�ZdS)�AbstractBadCrcTestscCsN|j}tjt�|�dd�� }|�d|���Wd�n1s@0YdS)NrGr>�afile)�zip_with_bad_crcr@rArrrSrdr
rrr�test_testzip_with_bad_crcBsz-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)NrGr>r'r�)
r(r@rArrr�r?rTr2�
MIN_READ_SIZE)r5r�r�Zcorrupt_filerrr�test_read_with_bad_crcJs0Lz*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�r)r+rrrrr&Asr&c@seZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�r@r�r8r(rrrrr,`s�r,c@seZdZejZdZdS)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�r@r
r8r(rrrrr-ls�r-c@seZdZejZdZdS)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�r@rr8r(rrrrr.ys�r.c@seZdZejZdZdS)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�r@rr8r(rrrrr/�s�r/c@sZeZdZdZdZdZdZdd�Zdd�Zd	d
�Z	dd�Z
e�d
d��Zdd�Z
dd�ZdS)�DecryptionTestss�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�zip2r4rrrr7�s**zDecryptionTests.setUpcCs,|j��t�t�|j��t�t�dSr)r�r�r�r	rr2rr�rrrr��s


zDecryptionTests.tearDowncCs(|�t|jjd�|�t|jjd�dS)N�test.txt�zero)r�r�r�rTr2r�rrr�test_no_password�sz DecryptionTests.test_no_passwordcCs@|j�d�|�t|jjd�|j�d�|�t|jjd�dS)Nsperlr3r4)r��setpasswordr�r�rTr2r�rrr�test_bad_password�sz!DecryptionTests.test_bad_passwordcCsH|j�d�|�|j�d�|j�|j�d�|�|j�d�|j�dS)N�pythonr3s12345r4)r�r6rSrT�plainr2�plain2r�rrr�test_good_password�sz"DecryptionTests.test_good_passwordcCsV|�t|jjd�|�t|jjdd�|jt|jjddd�|jt|jjddd�dS)N�unicoder3Zpython)�pwd)r�rr�r6rTr2r�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)Nr8s
encryptionr3rGrrMr&)r�r6r9rrYr2r�r�rrSr�rrTr*Z_readbufferZ_offsetr)r5rZ	test_wordrZbloc_lenr6Z
old_read_sizerrrr�s6
zDecryptionTests.test_seek_tellN)r�r�r�r+r1r9r:r7r�r5r7r
r;r>rrrrrr0�s�	�

r0c@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)Nr�@r�rMr&css&|]}t�dt�tdd��VqdS)z<fi���rN)rr5rrr"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+)r5rr8rDrvrwrxrArrrr�D	s*
z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCs t|�D]}|�||j�qdSrr�rqrrrr�U	sz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r.r7r�rFrorBr{r}r�r�rrrrr?�s

r?c@seZdZejZdS)� StoredTestsWithRandomBinaryFilesNrZrrrrrCZ	srCc@seZdZejZdS)�!DeflateTestsWithRandomBinaryFilesNrLrrrrrD^	srDc@seZdZejZdS)�Bzip2TestsWithRandomBinaryFilesNrrrrrrEc	srEc@seZdZejZdS)�LzmaTestsWithRandomBinaryFilesNrrrrrrFh	srFc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TellablecCs||_d|_dS�Nr)r6�offsetr4rrr�__init__p	szTellable.__init__cCs|j�|�}|j|7_|Sr)r6r3rI)r5r+�nrrrr3t	szTellable.writecCs|jSr)rIr�rrrr�y	sz
Tellable.tellcCs|j��dSr�r6�flushr�rrrrM|	szTellable.flushN)r�r�r�rJr3r�rMrrrrrGo	srGc@s$eZdZdd�Zdd�Zdd�ZdS)�
UnseekablecCs
||_dSr)r6r4rrrrJ�	szUnseekable.__init__cCs|j�|�Sr)r6r3r�rrrr3�	szUnseekable.writecCs|j��dSrrLr�rrrrM�	szUnseekable.flushN)r�r�r�rJr3rMrrrrrN	srNc@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�rrrrr�	r&z/UnseekableTests.test_writestr.<locals>.<lambda>��wrapper�abcr:�ones�111�twos�222rI�abcPKrGr>)rGrN�subTestrrr3�BufferedWriterr@rAr�rBrSrWr2rT)r5rRr�bfrDr��zopenrrr�
test_writestr�	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|SrrrPrrrr�	r&z,UnseekableTests.test_write.<locals>.<lambda>rQrSr:r0rUrTrWrVrIrXrGr>)rGrNrYrrr3rZr@rAr��
addCleanupr	rr2rSrWrT)r5rRrr[rD�f2r�r\rrr�
test_write�	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|SrrrPrrrr�	r&z1UnseekableTests.test_open_write.<locals>.<lambda>rQrSr:rTrUrVrWrIrX)rGrNrYrrr3rZr@rAr�r2rSrWrT)r5rRrr[r�r\rrr�test_open_write�	s

(FzUnseekableTests.test_open_writeN)r�r�r�r]r`rarrrrrO�	srOc@sheZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestsWithMultipleOpenscCs dtd�|_dtd�|_dS)NrU�'rW)r�data1r1r,rrrr.�	sz!TestsWithMultipleOpens.setUpClasscCsPt�|dtj��,}|�d|j�|�d|j�Wd�n1sB0YdS)Nr:rTrV)r@rAr
rBrdr1)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>rT��)rrFr@rAr2rTrSrd�r5rr��zopen1�zopen2rdr1rrr�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>rTrVre�	rrFr@rAr2rTrSrdr1rfrrr�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>rTrerVrj)r5rr�rgrdrhr1rrr�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)NrGrTrVre)rrF�
contextlib�	ExitStackr@rA�
enter_contextr2rTrSrdr1)r5r�stackr�rgrhrdr1rrr�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:rTrVrerG)
rr@rAr
rBrdr1r2rTrS�r5rr�rgrdr1rrr�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:rTrerVrG)
rr@rAr
rBrdr2rTr1rSrrrrr�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�rT)rFrr@rAr'rTr2r��devnullZ
assertLess�fileno)r5r�r�rgrrrr�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:rTr�rGrerV)r@rArr
rBrdr2rTr3r1rS)r5r�Zr1rdrrrr�test_write_while_reading-
s,
*Hz/TestsWithMultipleOpens.test_write_while_readingcCstt�dSrrPr�rrrr�:
szTestsWithMultipleOpens.tearDownN)r�r�r�r�r.rFrirkrlrqrsrtrwrxr�rrrrrb�	s


rbc@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�rrH)r@rArr�rr\r�r��isdirr*r�r�rrr�test_extract_dirB
s
(z"TestWithDirectory.test_extract_dircCs t�tj�td��|��dS�Nr�)r�r�r�r*rr|r�rrr�
test_bug_6050I
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/r�yrMzy/rGr�r�)r�r�r*rr�r�st_moder@rArr3r�r\rRrorSr�r�r{rY�listdir)r5�dirpathr?r�r�r�rrr�test_write_dirN
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\ror�r{r�)r5r�r�r�rrr�test_writestr_dirh
s
,


z#TestWithDirectory.test_writestr_dircCs tt�tj�t�rtt�dSr)r
rr�r�r�rr	r�rrrr�y
szTestWithDirectory.tearDownN)	r�r�r�r7r|r~r�r�r�rrrrry>
sryc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ZipInfoTestscCsHtj�t�}|�t�|j�d�|�|�	��|�|j
tj�
t��dS�Nztest_zipfile.py)r@r��	from_filermrS�	posixpathrwrRr�is_dirrbr�r�r�r	rrr�test_from_file�
szZipInfoTests.test_from_filecCsNtj�t�t��}|�t�|j	�d�|�
|���|�|jt
j�t��dSr�)r@r�r�rr�rmrSr�rwrRrr�rbr�r�r�r	rrr�test_from_file_pathlike�
sz$ZipInfoTests.test_from_file_pathlikecCsPtj�t�t�d�}|�t�|j	�d�|�
|���|�|jtj
�t��dS)Nr)r@r�r�r��fsencodermrSr�rwrRrr�rbr�r�r	rrr�test_from_file_bytes�
sz!ZipInfoTests.test_from_file_bytescCsxttd��Z}tj�|��d�}|�t�|j	�d�|�
|���|�|jt
j�t��Wd�n1sj0YdS)Nr�r)r2rmr@r�r�rvrSr�rwrRrr�rbr�r�r�)r5rr
rrr�test_from_file_fileno�
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�rl�abspathrmr@r�r�rSrRr\r�r�r�rb)r5r�r
rrr�
test_from_dir�
szZipInfoTests.test_from_dirN)r�r�r�r�r�r�r�r�rrrrr�
s
r�c@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_failure�
sz"CommandLineTest.zipfilecmd_failurecCs||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr&susageserrorsrequired�-lr�)r�rSrZrAZassertNotEqual�strip)r5r�r�r�rrr�test_bad_use�
szCommandLineTest.test_bad_usecCsXtd�}dD] }|�||�}|�|��d�qtd�}|�d|�\}}}|�|d�dS)Nrz)�-tz--testsDone testingztesttar.tarr�r&)rr�rS�rstripr�)r5�zip_name�optr�r�r�rrr�test_test_command�
sz!CommandLineTest.test_test_commandcCs�td�}t��}t�|d��}|�|�Wd�n1s<0Y|���dd�}dD] }|j||dd�}|�	||�qZdS)NrzrGr �backslashreplace)r�z--listzascii:backslashreplace)ZPYTHONIOENCODING)
rrrUr@rArVrWr�r�rS)r5r�ryZtfZexpectedr�r�rrr�test_list_command�
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)r^r	rr2r3r�r��	TESTFNDIRr
r�r*r�rrSr@rAr`rT)r5r�filesr`r�r�rIrrr�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)Nrz)z-ez	--extractr&r�r�)rrr�rSr@rArar�r�r*rRr�rpr�r\r{r�r2rT)	r5r�r�r�r�rIr
r�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�eZdZdd�Zdd�Zdd�Zdd�Ze�e	j
d	�e�e�d
ej
�d�dd
���Ze�e	j
d	�e�e�d
ej
�d�dd���ZdS)�TestExecutablePrependedZipcCs 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`rDrKr+rrr�_test_zip_works�
s�
z*TestExecutablePrependedZip._test_zip_workscCs|�|j�dSr)r�r�r�rrr� test_read_zip_with_exe_prependedsz;TestExecutablePrependedZip.test_read_zip_with_exe_prependedcCs|�|j�dSr)r�r�r�rrr�"test_read_zip64_with_exe_prependedsz=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_zip64sz-TestExecutablePrependedZip.test_execute_zip64N)r�r�r�r7r�r�r�r�Z
skipUnlessr�r�r�rb�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|�|_dSrH)r��iter�
_orig_iter)r5r$rrrrJ 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�rJr�r�rrrr�Countersr�N)r�r�r�r�rrrrrDsrDN)r�r�r�rDrrrrr�sr�cCs&tj�|���D]}|�|d�q|S)Nr&)r@�CompleteDirs�
_implied_dirsr`rB)rIr`rrr�add_dirs-sr�cCsZt��}t�|d�}|�dd�|�dd�|�dd�|�dd	�|�d
d�d|_|S)
Nr:r�s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+rIrrr�build_alpharep_fixture7s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&d'�Zd(d)�Zd*d+�Zd,S)-�TestPathcCst��|_|�|jj�dSr)rmrn�fixturesr^r�r�rrrr7\s
zTestPath.setUpccsh|���t�VWd�n1s&0Y|���tt��VWd�n1sZ0YdSr)rYr�r�r�rrr�zipfile_alpharep`s
&
zTestPath.zipfile_alpharepc	cs|t�|j�t���}|��D]Z}|j}|��||j}|�	d��}|�
|���Wd�n1sf0Y|VqdSr/)rr�r�rorr�r6r�rRr2r3rW)r5Ztmpdir�alpharep�bufferr��strmrrr�zipfile_ondiskfs
,zTestPath.zipfile_ondiskcCsV|��D]H}t�|�}|��\}}}|��\}}}|��\}	|��\}
|
��\}qdSr�r�r@r��iterdir)r5r��rootr�r�grHrrrB�hr$rrr�test_iterdir_and_typesps



zTestPath.test_iterdir_and_typescCs|��D]}t�|�}qdSr�r�r@r��r5r�r�rrr�test_subdir_is_dir�s
zTestPath.test_subdir_is_dirc	CsZ|��D]L}t�|�}|��\}}}|���}|��}Wd�q1sJ0YqdSr)r�r@r�r�r2rT)r5r�r�r�rr�r�r+rrrr}�s

&zTestPath.test_opencCs*|��D]}t�|�}|��\}}}qdSrr�)r5r�r�r�rr�rrrrB�s
zTestPath.test_readcCs<|��D].}t�|�}|�d�}|�d��d��d�}qdS�Nr�rrze.txt)r�r@r��joinpath�r5r�r�r�rBrrr�
test_joinpath�s


zTestPath.test_joinpathcCs4|��D]&}t�|�}|d}|ddd}qdSr�r�r�rrr�test_traverse_truediv�s

zTestPath.test_traverse_truedivcCs*|��D]}t�t|��}t�|�qdSr)r�rr�r_r@)r5r�Zpathlikerrr�test_pathlike_construction�sz#TestPath.test_pathlike_constructioncCs*|��D]}t�|�}|t�d�qdSr})r�r@r�rr�rrr�test_traverse_pathlike�s
zTestPath.test_traverse_pathlikecCs|��D]}t�|�}qdSrr�r�rrr�test_parent�s
zTestPath.test_parentcCs|��D]}t�|�}qdSrr�r�rrr�test_dir_parent�s
zTestPath.test_dir_parentcCs|��D]}t�|�}qdSrr�r�rrr�test_missing_dir_parent�s
z TestPath.test_missing_dir_parentcCsP|��D]B}t�|�}|��\}}}|�dd�|�dd�|d��\}qdS)Nr�r�zbar/baz.txtrr�)r�r@r�r�rB)r5r�r�r�rr�rrrr�test_mutability�s
zTestPath.test_mutabilityi cCs@t��}t�|d�}ttt|j��D]}|�||�q$d|_	|Sr)
rrr@rA�mapr_r'�HUGE_ZIPFILE_NUM_ENTRIESrBr?)r5r�rI�entryrrr�huge_zipfile�szTestPath.huge_zipfilecCs6t�|���}tj�|���}|D]}|�d�q"dS)N�suffix)r@r�r�r�rDr�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#rKrrrr%�r&z:TestPath.test_implied_dirs_performance.<locals>.<listcomp>rc)r'r@r�r�r�rrr�test_implied_dirs_performance�sz&TestPath.test_implied_dirs_performancecCsLt��}t�|d�}|�dd�|�dd�|�dd�d|_t�|�}dS)Nr:z/one-slash.txtrQz//two-slash.txtz
../parent.txtr�)rrr@rArBrRr�)r5r+rIr�rrr�test_malformed_paths�s
zTestPath.test_malformed_pathscCsHt��}t�|d�}|�dd�|�dd�d|_t�|�}|��}dS)Nr:zpath?rQzV: NMS.flacsfLaC...r�)rrr@rArBrRr�r�)r5r+rIr��contentsrrr�test_unsupported_namess
zTestPath.test_unsupported_namescCsFt��}t�|d�}|�t�d|�d�d|_t�|�}|�	�\}dS)Nr:zfoo\barrQr�)
rrr@rArB�DirtyZipInfo�for_namerRr�r�)r5r+rIr��firstrrr�test_backslash_not_separators

z%TestPath.test_backslash_not_separatorN)r�r�r�r7r�r�r�r�r}rBr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�[s,
	r�cs(eZdZ�fdd�Zedd��Z�ZS)r�cs$t�j|g|�Ri|��||_dSr)r�rJrR)r5rRr�rCr�rrrJ)szDirtyZipInfo.__init__cCsZ||t�t���dd�d�}|j|_|j|_|j�d�rPd|_|jdO_nd|_|S)N�)rRr�r�i�Arr�)	r]rr8r�r9Zcompress_levelrRror�)r-r`�archiver5rrrr�-szDirtyZipInfo.for_name)r�r�r�rJr�r�r�rrr�rr�$sr��__main__)YrUrm�importlib.utilrsrrDr�rr�r�rr�r�r]r�Z
unittest.mockrr@�tempfilerrrrZtest.supportrrrr	r
rrr
rrrrr�r(Z
DATAFILES_DIRr�rrZTestCaser�r	r
rrr(rKrMrNrOrYr[r\r]r^r�r�r&r,r-r.r/r0r?rCrDrErFrGrNrOrbryr�r�r��tupleZconsumer�r�r�r�r�r�r��mainrrrr�<module>s�0	�C�������"BAKg[����
7}A#P'
$J


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists