Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_zipfile.cpython-38.pyc
U

>��g���@s<ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlZddlmZddlmZmZmZddlmZddlmZmZmZmZmZmZmZmZm Z m!Z!edZ"edZ#dZ$d	Z%d
ddd
gZ&dd�Z'dd�Z(Gdd�d�Z)Gdd�de)e
j*�Z+eGdd�de)e
j*��Z,eGdd�de)e
j*��Z-e Gdd�de)e
j*��Z.Gdd�d�Z/Gdd�de/e
j*�Z0eGd d!�d!e/e
j*��Z1eGd"d#�d#e/e
j*��Z2e Gd$d%�d%e/e
j*��Z3Gd&d'�d'�Z4Gd(d)�d)e4e
j*�Z5eGd*d+�d+e4e
j*��Z6eGd,d-�d-e4e
j*��Z7e Gd.d/�d/e4e
j*��Z8Gd0d1�d1e
j*�Z9Gd2d3�d3e
j*�Z:Gd4d5�d5e
j*�Z;Gd6d7�d7�Z<Gd8d9�d9e<e
j*�Z=eGd:d;�d;e<e
j*��Z>eGd<d=�d=e<e
j*��Z?e Gd>d?�d?e<e
j*��Z@Gd@dA�dAe
j*�ZAGdBdC�dC�ZBGdDdE�dEeBe
j*�ZCeGdFdG�dGeBe
j*��ZDeGdHdI�dIeBe
j*��ZEe GdJdK�dKeBe
j*��ZFGdLdM�dM�ZGGdNdO�dO�ZHGdPdQ�dQe
j*�ZIeGdRdS�dSe
j*��ZJGdTdU�dUe
j*�ZKGdVdW�dWe
j*�ZLGdXdY�dYe
j*�ZMGdZd[�d[e
j*�ZNeOZPGd\d]�d]�ZQd^d_�ZRd`da�ZSGdbdc�dce
j*�ZTeUddk�r8e
�V�dS)e�N)�
TemporaryFile)�randint�random�getrandbits)�
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
6y7u8i9o0pcCstd|��|d�S)N��little)r�to_bytes)�size�r�0/opt/cppython/lib/python3.8/test/test_zipfile.py�getrandbytes$src	csTtVt��}|V|�|j�W5QRXt���}|V|�|j�W5QRXdS�N)�TESTFN2r�assertFalse�closed�io�BytesIO)�test�frrr�	get_files's
r#c@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>3s���z:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>�)�range�FIXEDTEST_SIZE�line_gen�join�data��clsrrr�
setUpClass1s�z&AbstractTestsWithSourceFile.setUpClassc	Cs&ttd��}|�|j�W5QRXdS�N�wb��openr�writer0��self�fprrr�setUp8sz!AbstractTestsWithSourceFile.setUpNc
Cs�||d�}tj|df|��\}|�td�|�tt�|�d|j�|jddd��}|jD]}|�|�qXW5QRXW5QRXdS)N)�compression�
compresslevel�w�another.name�strfile�written-open-w��mode)�zipfile�ZipFiler8r�writestrr0r7r.)r:r"r=r>�kwargs�zipfp�linerrr�make_test_archive=s

z-AbstractTestsWithSourceFile.make_test_archivec	Cs.|�|||�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�|��W5QRXdS)N�rr@rA)�file��	File Namer�Modified�Size��%Y-%m-%d�%H:%M:%S�rBcSsg|]
}|j�qSr��filenamer'rrrr*lsz8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>)rKrErF�assertEqual�readrr0r�StringIO�printdir�getvalue�
splitlines�len�assertIn�split�
assertTrue�time�strptime�str�namelist�infolist�	file_size�getinforW�testzip)r:r"r=r>rIr;�	directory�lines�fn�date�time_r�names�infosr)�nm�inforrr�zip_testHsL
z$AbstractTestsWithSourceFile.zip_testcCs t|�D]}|�||j�qdSr�r#rsr=�r:r"rrr�
test_basic~sz&AbstractTestsWithSourceFile.test_basicc	
Cs�|�||�t�|d|���}g}|�t��"}|�d�}|s<qH|�|�q,W5QRXg}|�d��"}|�d�}|srq~|�|�qbW5QRX|�d�|�|j	�|�d�|�|j	�W5QRXdS�NrL�r@r+)
rKrErFr7rrY�appendrXr/r0)	r:r"r=rI�zipdata1�zipopen1�	read_data�zipdata2�zipopen2rrr�
zip_open_test�s 

z)AbstractTestsWithSourceFile.zip_open_testcCs t|�D]}|�||j�qdSr�r#rr=rurrr�	test_open�sz%AbstractTestsWithSourceFile.test_openc	CsFt�t�}|�||j�t�|d|j��}|�|jt	�W5QRXdS�NrL)
�pathlib�Pathrrr=rErF�assertIsInstancerWrd)r:�pathrIrrr�test_open_with_pathlike�s
z3AbstractTestsWithSourceFile.test_open_with_pathlikec
Csz|�||�t�|d|��V}g}|�t��(}|�tdd��}|sBqN|�|�q,W5QRX|�d�	|�|j
�W5QRXdS�NrLrR�r+)rKrErFr7rrYrryrXr/r0)r:r"r=rIrzr{r|rrr�zip_random_open_test�sz0AbstractTestsWithSourceFile.zip_random_open_testcCs t|�D]}|�||j�qdSr�r#r�r=rurrr�test_random_open�sz,AbstractTestsWithSourceFile.test_random_openc
Csr|�||�t�|d��<}|�t��&}g}|�d�}|s:qF|�|�q*W5QRXW5QRX|�d�|�|j	�dS)NrL���r+)
rKrErFr7r�read1ryrXr/r0�r:r"r=rI�zipopen�zipdatar|rrr�zip_read1_test�s�
 z*AbstractTestsWithSourceFile.zip_read1_testcCs t|�D]}|�||j�qdSr)r#r�r=rurrr�
test_read1�sz&AbstractTestsWithSourceFile.test_read1c
Cs�|�||�t�|d��L}|�t��6}g}|�d�}|�t|�d�|sJqV|�|�q*W5QRXW5QRX|�	d�
|�|j�dS)NrL�
r+)rKrErFr7rr�ZassertLessEqualr^ryrXr/r0r�rrr�zip_read1_10_test�s�
 z-AbstractTestsWithSourceFile.zip_read1_10_testcCs t|�D]}|�||j�qdSr)r#r�r=rurrr�
test_read1_10�sz)AbstractTestsWithSourceFile.test_read1_10c
Cs�|�||�t�|d��P}|�t��:}d}|��}|s8qZ||7}|�d�}|sPqZ||7}q*W5QRXW5QRX|�||j�dS)NrLr+�d)	rKrErFr7r�readlinerYrXr0)r:r"r=rIr�r0rYrrr�zip_readline_read_test�s�
z2AbstractTestsWithSourceFile.zip_readline_read_testcCs t|�D]}|�||j�qdSr)r#r�r=rurrr�test_readline_read�sz.AbstractTestsWithSourceFile.test_readline_readc
Cs^|�||�t�|d��<}|�t��&}|jD]}|��}|�||�q,W5QRXW5QRXdSr�)rKrErFr7rr.r�rX)r:r"r=rIr�rJZlinedatarrr�zip_readline_test�s
z-AbstractTestsWithSourceFile.zip_readline_testcCs t|�D]}|�||j�qdSr)r#r�r=rurrr�
test_readlinesz)AbstractTestsWithSourceFile.test_readlinec
Csh|�||�t�|d��F}|�t��}|��}W5QRXt|j|�D]\}}|�||�qDW5QRXdSr�)	rKrErFr7r�	readlines�zipr.rX)r:r"r=rIr�ZziplinesrJ�ziplinerrr�zip_readlines_testsz.AbstractTestsWithSourceFile.zip_readlines_testcCs t|�D]}|�||j�qdSr)r#r�r=rurrr�test_readlinessz*AbstractTestsWithSourceFile.test_readlinesc
Cs`|�||�t�|d��>}|�t��(}t|j|�D]\}}|�||�q2W5QRXW5QRXdSr�)rKrErFr7rr�r.rX)r:r"r=rIr�rJr�rrr�zip_iterlines_tests
z.AbstractTestsWithSourceFile.zip_iterlines_testcCs t|�D]}|�||j�qdSr)r#r�r=rurrr�test_iterlinessz*AbstractTestsWithSourceFile.test_iterlinesc
Cs�t�td|j��}|�dd�W5QRXt�td|j��@}|�d��*}|�|�d�d�|�|�d�d�W5QRXW5QRXdS)	z>Check for cases where compressed data is larger than original.r?rAZ12rLrR�1�2N)rErFrr=rGr7rXrY)r:rIZopenobjrrr�test_low_compression sz0AbstractTestsWithSourceFile.test_low_compressioncCs<t�td�}|jdd|jd�|�d�}|�|j|j�dS)Nr?�b.txt�hello world��
compress_type)rErFrrGr=rhrXr�)r:rIrrrrr�test_writestr_compression,s
z5AbstractTestsWithSourceFile.test_writestr_compressioncCs�tjtddd�}|jdd|jd�|jdd|jdd	�|�d�}|�|j|j�|�|jd�|�d�}|�|j|j�|�|jd�dS)
Nr?rR�r>�a.txtr�r�r��)r�r>)	rErFrrGr=rhrXr��_compresslevel)r:rIZa_infoZb_inforrr�test_writestr_compresslevel2s�

z7AbstractTestsWithSourceFile.test_writestr_compresslevelcCs|dD]r}|d}t|�}t�t��d|j��D}|�d|�|�dd�� }|�|�}|�	t
|�|�W5QRXW5QRXqdS)N)rRi�iii@rRr?�foorL)rrErFrr r=rGr7rYrXr^)r:Z	test_sizergZjunk�zipfr;�bufrrr�test_read_return_sizeBs
z1AbstractTestsWithSourceFile.test_read_return_sizecCs|t��}tj|dd��"}|jd|j|jd�|��}W5QRX|��}t�|�}t�|��H}|�	d��2}|�
|d�|�t��|�
�W5QRXW5QRXW5QRXt�|�}t�|��L}|�	d��6}|�
|d�|�t��|�
d�r�q�W5QRXW5QRXW5QRXt�|�}t�|��P}|�	d��:}|�
|d�|�t��|�d��rZ�qJW5QRXW5QRXW5QRXdS)Nr?rCrAr��r�)rr rErFrGr0r=�tellr\r7�truncate�assertRaises�EOFErrorrYr�)r:r;r�Z
end_offset�zipfiledatar�rrr�test_truncated_zipfileNs2
&

 
z2AbstractTestsWithSourceFile.test_truncated_zipfilecCs|d}t|�D�]h}t�|d|j��&}|�t|�t|�}|�d|�W5QRXt�|d���}t|�}t|t	�r�|�d||�n|�d||�|�d|�t|�
|��}|�d||�|�d|�|�d	|�|jtjkr�|�d
|�|�d|�|�|��D}t|�}|�d||�|�d|�|jtjk�rB|�d
|�W5QRX|�d
t|��W5QRX|�d
t|��qdS)Nz	file.namer?zmode='w'rLzfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])
r#rErFr=r8r�reprr_�
isinstancerdrh�
ZIP_STOREDr7)r:�fnamer"rIrLr�rrr�	test_reprls6
z%AbstractTestsWithSourceFile.test_reprcCs$t|�D]}|j||jdd�qdS)N�	r�rtrurrr�test_compresslevel_basic�sz4AbstractTestsWithSourceFile.test_compresslevel_basicc	Csltjtddd��R}|�td�|jtddd�|�d�}|�d�}|�|jd�|�|jd�W5QRXdS)zTCheck that files within a Zip archive can have different
        compression levels.r?rRr�Z
compress_1Z
compress_9r�N)rErFrr8rrhrXr�)r:rIZone_infoZ	nine_inforrr�test_per_file_compresslevel�s

z7AbstractTestsWithSourceFile.test_per_file_compresslevelc
slG��fdd�dtj�}d�|�}d�t�|d|j���}|�dd��}|�d�W5QRXd�zZz&|�dd��}|�d�W5QRXWntk
r��d	7�YnXW�W5QR��qW5d�XW5QRXt�t�|�����*}|�	|�
�dg�|�	|�d�d�W5QRXqt�t�|�����>}|�	|�
�ddg�|�	|�d�d�|�	|�d�d�W5QRXdS)
Ncs eZdZ���fdd�Z�ZS)zCAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFilecs,�dk	r��krt��d7�t��|�dS�NrR)�OSError�superr8�r:r0)�	__class__�count�stoprrr8�s
zIAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFile.write)�__name__�
__module__�__qualname__r8�
__classcell__r�r�r�)r�r�
BrokenFile�sr�rr?Zfile1sdata1Zfile2sdata2rR)rr rErFr=r7r8r�r\rXrerY)r:r�ZtestfilerIr"rr�r�test_writing_errors�s,	z/AbstractTestsWithSourceFile.test_writing_errorscCstt�tt�dSr�r	rr�r:rrr�tearDown�sz$AbstractTestsWithSourceFile.tearDown)N)N)$r�r�r��classmethodr3r<rKrsrvrr�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$0sB


6

	%r$c@s~eZdZejZdZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�StoredTestsWithSourceFileNc	CsX|�||�t�|d��6}|�d�}|�|jd�|�d�}|�|jd�W5QRXdS)NrLrA��rB)rKrErFrhrX�
external_attr)r:r"r=rI�zinfoZzinfo2rrr�zip_test_writestr_permissions�s

z7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs t|�D]}|�|tj�qdSr)r#r�rEr�rurrr�test_writestr_permissions�sz3StoredTestsWithSourceFile.test_writestr_permissionsc	CsZt�tdtj��}|�td�W5QRXt�tdtj��}|�|��dg�W5QRXdS)Nr?�	/absoluterL�absolute�rErFrr�r8rrXre�r:rIrrr�test_absolute_arcnames�sz0StoredTestsWithSourceFile.test_absolute_arcnamesc	Csjt�tdtj��}|�tt�W5QRXt�tdtj��(}|�d|j�|�|�	�tdg�W5QRXdS)z&Test appending to an existing zipfile.r?�arAN)
rErFrr�r8rrGr0rXrer�rrr�test_append_to_zip_file�s
z1StoredTestsWithSourceFile.test_append_to_zip_filec
Cs8d}ttd��}|�|�W5QRXt�tdtj��}|�tt�W5QRXttd��R}|�t|��t�|d��,}|�	|�
�tg�|�	|�t�|j�W5QRXW5QRXttd��$}|�	|�t|��|�|��}W5QRXt
�|��B}t�|��,}|�	|�
�tg�|�	|�t�|j�W5QRXW5QRXdS)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!r5r��rbrLN)r7rr8rErFr�r�seekr^rXrerYr0rr )r:r0r"rIr��biorrr�test_append_to_non_zip_file�s (z5StoredTestsWithSourceFile.test_append_to_non_zip_filec
Cs�t���6}t�|dtj��}|�tt�W5QRX|��}W5QRXd}tt	d��}|�|�|�|�W5QRXt�t	��,}|�
|��tg�|�
|�t�|j
�W5QRXdS)Nr?r�r5)rr rErFr�r8rr\r7rrXrerYr0�r:r�rIr�r0r"rrr�test_read_concatenated_zip_files

z9StoredTestsWithSourceFile.test_read_concatenated_zip_filec
CsNt���6}t�|dtj��}|�tt�W5QRX|��}W5QRXdd}tt	d��}|�|�|�|�W5QRXt�t	d��&}|�
|��tg�|�d|j
�W5QRXtt	d��$}|�
|�t|��|�|��}W5QRXt�|��X}t�|��B}|�
|��tdg�|�
|�t�|j
�|�
|�d�|j
�W5QRXW5QRXdS)Nr?sI am not a ZipFile!i@Br5r�rAr�)rr rErFr�r8rr\r7rrXrerGr0rYr^r�rrr�$test_append_to_concatenated_zip_files$

z>StoredTestsWithSourceFile.test_append_to_concatenated_zip_filec	Csrt�tdtj��}|�tt�W5QRXttd��}|�d�W5QRXt�td��}|�|tj�W5QRXdS)Nr?r�z
rL)rErFrr�r8rr7r��r:rIr"rrr�test_ignores_newline_at_end%sz5StoredTestsWithSourceFile.test_ignores_newline_at_endc	Cs�t�tdtj��}d|_|�tt�W5QRXttd��}|�d�W5QRXt�td��"}|�|tj�|�	|jd�W5QRXdS)Nr?�this is a commentr�zabcdef
rL)
rErFrr��commentr8rr7r�rXr�rrr�)test_ignores_stuff_appended_past_comments-szCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentsc
CsRt�td��<}|�t�ttd��}|�|�t�|���W5QRXW5QRXdS)z`Check that calling ZipFile.write without arcname specified
        produces the expected result.r?r�N)rErFrr8rr7rXrYr�rrr�test_write_default_name7s
z1StoredTestsWithSourceFile.test_write_default_namec
Cs�tjtdd��}|�dd�W5QRXtjtdd��}|�t|jt�W5QRXtjtdd��*}|�t��|jtdd�W5QRXW5QRXdS)z[Check that trying to call write() on a readonly ZipFile object
        raises a ValueError.r?rCzsomefile.txt�bogusrLN)	rErFrrGr��
ValueErrorr8rr7r�rrr�test_write_to_readonly?sz0StoredTestsWithSourceFile.test_write_to_readonlyc	Csvt�td�t�td��}|�t|jt�W5QRXtjtddd��(}|�t�|�	t�}|�
|jd�W5QRXdS)N)rrr?F�Zstrict_timestamps)i�rRrRrrr)�os�utimerrErFrr�r�r8rhrX�	date_time)r:rIr�rrr�test_add_file_before_1980Ls

z3StoredTestsWithSourceFile.test_add_file_before_1980c	Cs�d}zt�|�Wn&tk
r8|�d|�d��YnXzt�t||f�Wntk
rl|�d�YnXt�t�j}|dkr�|�d|���t	�
td��}|�t
j|jt�W5QRXt	j
tddd	��(}|�t�|�t�}|�|jd
�W5QRXdS)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�)rb�	localtime�
OverflowError�skipTestr�r�r�stat�st_mtime_nsrErFrr��struct�errorr8rhrXr�)r:�tsZmtime_nsrIr�rrr�test_add_file_after_2107Ws$	

z2StoredTestsWithSourceFile.test_add_file_after_2107)r�r�r�rEr�r=r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr��s
	

r�c@seZdZejZdd�ZdS)�DeflateTestsWithSourceFilec	Cspt�td��Z}|�tdtj�|�tdtj�|�d�}|�d�}|�|j	tj�|�|j	tj�W5QRXdS)zUCheck that files within a Zip archive can have different
        compression options.r?ZstoremeZ	deflatemeN)
rErFrr8rr��ZIP_DEFLATEDrhrXr�)r:rI�sinfoZdinforrr�test_per_file_compression}s

z4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�rErr=r	rrrrrxsrc@seZdZejZdS)�Bzip2TestsWithSourceFileN�r�r�r�rE�	ZIP_BZIP2r=rrrrr
�sr
c@seZdZejZdS)�LzmaTestsWithSourceFileN�r�r�r�rE�ZIP_LZMAr=rrrrr
�sr
c@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/r0)r2r.rrrr3�s�z(AbstractTestZip64InSmallFiles.setUpClassc	CsBtj|_tj|_dt_dt_ttd��}|�|j�W5QRXdS)Nrr�r5)	rE�ZIP64_LIMIT�_limit�ZIP_FILECOUNT_LIMIT�_filecount_limitr7rr8r0r9rrrr<�sz#AbstractTestZip64InSmallFiles.setUpc	CsHtj|d|dd��,}|�td�|�tt�|�d|j�W5QRXt�|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�|��W5QRXdS)Nr?T�Z
allowZip64r@rArLrUrOrrPrQrRrSrT�cSsg|]
}|j�qSrrVr'rrrr*�sz:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>)rErFr8rrGr0rXrYrrZr[r\r]r^r_r`rarbrcrdrerfrgrhrWri)r:r"r=rIr;rjrkrlrmrnrrorpr)rqrrrrrrs�sN

z&AbstractTestZip64InSmallFiles.zip_testcCs t|�D]}|�||j�qdSrrtrurrrrv�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�9rLr%)
rErFrr=�debugr,rGrXr^re�closerY�decode)r:r��numfilesr)�zipf2�contentrrr�test_too_many_files�s�z1AbstractTestZip64InSmallFiles.test_too_many_filesc	Cs�tjtd|jdd�}d|_d}t|�D] }|�d|d|dd	�q&|�t|�	��|�|�
tj��|�d|d
�W5QRX|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�|�
tj��|�d|d
�W5QRX|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�d
}t||�D]"}|�d|d|dd	��qN|�t|�	��|�|��t�td|j�}|�t|�	��|�t|�D]2}|�
d|��d�}|�|d|dd	��q�|��dS)Nr?Frr�r�rrrrr+r�TrrLr%)rErFrr=rr,rGrXr^rer��LargeZipFilerrYr)r:r�r r)Z	numfiles2r!r"rrr�test_too_many_files_append�sJ��� z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs$|jt_|jt_tt�tt�dSr)rrErrrr	rrr�rrrr�sz&AbstractTestZip64InSmallFiles.tearDownN)r�r�r�r�r3r<rsrvr#r%r�rrrrr�s

9'rc@sTeZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
ddd
�Zdd�Zdd�Z
dS)�StoredTestZip64InSmallFilesc	Cs6tj|d|dd��}|�tj|jtd�W5QRXdS�Nr?Frr@)rErFr�r$r8r�r:r"r=rIrrr�large_file_exception_test)s�z5StoredTestZip64InSmallFiles.large_file_exception_testc	Cs8tj|d|dd��}|�tj|jd|j�W5QRXdSr')rErFr�r$rGr0r(rrr�large_file_exception_test2.s�z6StoredTestZip64InSmallFiles.large_file_exception_test2cCs.t|�D] }|�|tj�|�|tj�qdSr)r#r)rEr�r*rurrr�test_large_file_exception3sz5StoredTestZip64InSmallFiles.test_large_file_exceptionc	Cs^tjtdtjdd��}|�td�W5QRXt�tdtj��}|�|��dg�W5QRXdS)Nr?Trr�rLr�r�r�rrrr�8s�z2StoredTestZip64InSmallFiles.test_absolute_arcnamesc	Cs�tjtddd��}|�d|j�W5QRXtjtddd��}|�d�}|j}W5QRXtjtddd��}|�d|j�W5QRXtjtddd��}|�d�}|�|j|�W5QRXdS)Nr?TrrArLr�Zstrfile2)rErFrrGr0rh�extrarX)r:rIr�r,rrr�test_append@s

z'StoredTestZip64InSmallFiles.test_appendFcCs�d}d}g}	g}
|}|r4d}|r4|	�|�|
�|�t�d|�}|}|rdd}|rd|	�|�|
�|�t�d|�}|}
|r�d}
|r�|
�|�t�d|
�}
tjddt|	�ddt|	�f|	��}tjddt|
�ddt|
�f|
��}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
        rrl��z<Lz<HH�QrRz<Q�:�2z<HrUstest.txt�test1234sPK!�%��sPK--!�%��s
�sPK,--ss
sPKlssPK:2s)ryr�packr^)r:�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_fieldsrg�
compress_size�
header_offsetZlocal_extraZ
central_extraZcentral_dir_sizeZoffset_to_central_dirZlocal_extra_lengthZcentral_extra_lengthrWr"Zfilename_lengthZzip64_contentsrrr�make_zip64_fileNs�






��
���������	�
���
���������������!z+StoredTestZip64InSmallFiles.make_zip64_filec	Cs&|jdd�}|�tj��}t�t�|��W5QRX|�dt|j	��
��|jdddd�}|�tj��}t�t�|��W5QRX|�dt|j	��
��|jdd�}|�tj��}t�t�|��W5QRX|�dt|j	��
��|jdddddd�}|�tj��}t�t�|��W5QRX|�dt|j	��
��|jd	dddd
�}|�tj��}t�t�|��W5QRX|�dt|j	��
��|jddd	dd�}|�tj��}t�t�|��W5QRX|�dt|j	��
��|jd	d	dd�}|�tj��}t�t�|��W5QRX|�dt|j	��
��d
S)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)r3z	file size)r3r4r5z
compress size)r5)r3r4r5r6r7z
header offsetF)r3r5r6r7)r3r4r5r7)r3r5r7N)r;r�rE�
BadZipFilerFrr r_rd�	exception�lower)r:Zmissing_file_size_extra�eZmissing_compress_size_extraZmissing_header_offset_extrarrr�test_bad_zip64_extra�sp�������z0StoredTestZip64InSmallFiles.test_bad_zip64_extracCs�d}d}d}d}ddd�ddd�ddd�f}tdt|�d�D]�}t�||�D]�}i}|D]}	|�|	�qZt�t�|j	f|����N}
|
�
�d}|�|j|�|�|j
|�|�|j|�|�|
�|�|�W5QRXqNq>dS)	Nrrr1T)r3r4)r5r6)r7r8rR)r,r^�	itertools�combinations�updaterErFrr r;rfrXrgr9r:rY)r:Zexpected_file_sizeZexpected_compress_sizeZexpected_header_offsetZexpected_content�paramsrLZcomborH�c�zfr�rrr� test_generated_valid_zip64_extras&�z<StoredTestZip64InSmallFiles.test_generated_valid_zip64_extraN)FFFFFF)r�r�r�rEr�r=r)r*r+r�r-r;r@rGrrrrr&%s�
c^r&c@seZdZejZdS)�DeflateTestZip64InSmallFilesN�r�r�r�rErr=rrrrrH+srHc@seZdZejZdS)�Bzip2TestZip64InSmallFilesNrrrrrrJ0srJc@seZdZejZdS)�LzmaTestZip64InSmallFilesNrrrrrrK5srKc@s$eZdZdd�Zdd�Zdd�ZdS)�AbstractWriterTestscCstt�dSr�r	rr�rrrr�=szAbstractWriterTests.tearDownc	Cstd}t�td|j��V}|�dd�}|�|�|��|�|j�|��|�|j�|�	|�
d�|�W5QRXdS)N�contentr?r!)rErFrr=r7r8rrarrXrY�r:r0r�r?rrr�test_close_after_close@s
z*AbstractWriterTests.test_close_after_closec	Cspd}t�td|j��R}|�dd�}|�|�|��|�|j�|�	t
|jd�|�|�d�|�W5QRXdS)NrNr?r!r+)
rErFrr=r7r8rrarr�r�rXrYrOrrr�test_write_after_closeKs
z*AbstractWriterTests.test_write_after_closeN)r�r�r�r�rPrQrrrrrL;srLc@seZdZejZdS)�StoredWriterTestsN�r�r�r�rEr�r=rrrrrRUsrRc@seZdZejZdS)�DeflateWriterTestsNrIrrrrrTXsrTc@seZdZejZdS)�Bzip2WriterTestsNrrrrrrU\srUc@seZdZejZdS)�LzmaWriterTestsNrrrrrrV`srVc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�PyZipFileTestscCs |d|kr|�|d|�dS)N�orE)r_)r:�namererrr�assertCompiledInfszPyZipFileTests.assertCompiledIncCs�tj|tjtjtjkd�s$|�d�tj�|d�}z"t�|tjtj	B�}t�
|�Wntk
rr|�d�YnXt|�dS)N)Z
effective_idsz/requires write access to the installed locationztest_zipfile.try)
r��access�W_OK�supports_effective_idsr�r�r/r7�O_WRONLY�O_CREATr�	Exceptionr	)r:r�rW�fdrrr�requiresWriteAccessjs

�
z"PyZipFileTests.requiresWriteAccessc
CsR|�tj�t��t���}t�|d���}t}|�d�r�|�	tj
�}tjdk	r^|�|�	tj��d|krtt
j�|�}n|dd�}|�|�tj�|�}|�||���|�||���W5QRXW5QRXt��x}t�|d��`}t}|�d�r�|dd�}|�|d�ddtj�|�f}|�||���|�||���W5QRXW5QRXdS)Nr?�.pyc�__pycache__r�Ztestpackagez%s/%s)rbr�r��dirname�__file__rrE�	PyZipFile�endswithr`�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInrerZ)r:�trIrlZ
path_splitZbnrrr�test_write_pyfilews,


$
z PyZipFileTests.test_write_pyfilec
Csxddl}tj�|j�}|�|�t��H}t�|d��0}|�	|�|�
�}|�d|�|�d|�W5QRXW5QRXdS)Nrr?zemail/__init__.pyzemail/mime/text.py)�emailr�r�rerfrbrrErgrorerZ)r:rt�
packagedirrrrIrorrr�test_write_python_package�s

z(PyZipFileTests.test_write_python_packagecCsddl}tj�|j�}|�|�t���}t�|d���}t	��}|�
|�W5QRX|��}|�d|k�t	��}|j
|dd�d�W5QRX|��}|�d|k�dd�}t	��*}|�
t��|j
||d�W5QRXW5QRX|��}|r�t|�|�d|k�W5QRXW5QRXdS)	Nrr?�SyntaxErrorcSsdS)NFr)Zwhateverrrr�<lambda>�r+zCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>�Z
filterfunccSstj�|��d�S)NZbad)r�r�rp�
startswith)r�rrr�filter�szAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)r!r�r�rerfrbrrErgrror\ra�assertWarns�UserWarning�print)r:r!rurrrIZ	reportSIOZ	reportStrr{rrr�"test_write_filtered_python_package�s&
"z1PyZipFileTests.test_write_filtered_python_packagec
Cs�ddl}tj�|j�}|�|�dnd}d}t��T}tj|d|d��8}|�	|�|�
�}|�d||�|�d||�W5QRXW5QRXdS)	NrTrRrcr?)�optimizezemail/__init__zemail/mime/text)rtr�r�rerfrbrrErgrorer_)r:rtruZoptlevel�extrrrIrorrr�test_write_with_optimization�s
�
z+PyZipFileTests.test_write_with_optimizationc
Cs�t�t�z�ttj�td�d��}|�d�W5QRXttj�td�d��}|�d�W5QRXttj�td�d��}|�d�W5QRXt��T}t	�
|d��<}|�t�|��}|�
d|�|�
d|�|�d|�W5QRXW5QRXW5tt�XdS)N�mod1.pyr?�
print(42)
�mod2.py�print(42 * 42)
zmod2.txtzbla bla bla
�r��mkdirrr
r7r�r/r8rrErgrorerZrq�r:r;rrrIrorrr�test_write_python_directory�s

$z*PyZipFileTests.test_write_python_directoryc
Cs�t�t�z�ttj�td�d��}|�d�W5QRXttj�td�d��}|�d�W5QRXt��P}t	�
|d��8}|jtdd�d�|��}|�
d|�|�d|�W5QRXW5QRXW5tt�XdS)	Nr�r?r�r�r�cSs|�d�S)Nr�)rh)rlrrrrx�szEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>ryr�r�rrr�$test_write_python_directory_filtered�s
$z3PyZipFileTests.test_write_python_directory_filteredcCsft��V}t�|d��>}ttd��}|�d�W5QRX|�t|jt�t	t�W5QRXW5QRXdS)Nr?z!most definitely not a python file)
rrErgr7rr8r��RuntimeErrorror	)r:rrrIr"rrr�test_write_non_pyfile�s
z$PyZipFileTests.test_write_non_pyfilecCs�t�t�z�ttj�td�d��}|�d�W5QRXt��t}t	�
|d��\}t��}|�tj�td��W5QRX|�
d|���|��}|�
d|�|�d|�W5QRXW5QRXW5tt�XdS)Nr�r?zBad syntax in python file
rwzmod1.pyc)r�r�rr
r7r�r/r8rrErgrror_r\rerq)r:r;rrrI�srorrr�test_write_pyfile_bad_syntaxs
$z+PyZipFileTests.test_write_pyfile_bad_syntaxc
Cs�t�t�z�ttj�td�d��}|�d�W5QRXt��F}t	�
|d��.}|�t�
t�d�|��}|�d|�W5QRXW5QRXW5tt�XdS)Nr�r?r�)r�r�rr
r7r�r/r8rrErgror�r�rerZr�rrr�test_write_pathlikes
$z"PyZipFileTests.test_write_pathlikeN)r�r�r�rZrbrsrvrr�r�r�r�r�r�rrrrrWes
rWc@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)$�ExtractTestsc	Cs:t�tdtj�� }tD]\}}|�||�qW5QRXdS)Nr?)rErFrr��SMALL_TEST_DATArG�r:rI�fpath�fdatarrr�make_test_file(szExtractTests.make_test_filecCs�t���|��t�td��z}tD]n\}}|�|�}tj�	t�
�|�}tj�|�}|�||�t
|d��}|�|��|���W5QRXt|�q"W5QRXW5QRXdS�NrLr�)rr�rErFrr��extractr�r�r/�getcwd�normpathrXr7�encoderYr	)r:rIr�r��writtenfile�correctfiler"rrr�test_extract-s
zExtractTests.test_extractcCs�|��t�td���}tD]z\}}|�||�}tj�||�}tj�	|�}|�
tj�||�||f�t|d��}|�
|��|���W5QRXt|�qW5QRXtt�dSr�)r�rErFrr�r�r�r�r/r�ra�samefiler7rXr�rYr	)r:�targetrIr�r�r�r�r"rrr�_test_extract_with_target@sz&ExtractTests._test_extract_with_targetc	Cs t��}|�|�W5QRXdSr)rr��r:�extdirrrr�test_extract_with_targetSsz%ExtractTests.test_extract_with_targetc	Cs&t��}|�t�|��W5QRXdSr)rr�r�r�r�rrr�!test_extract_with_target_pathlikeWsz.ExtractTests.test_extract_with_target_pathlikecCs�t���|��t�td��`}|��tD]L\}}tj�	t�
�|�}t|d��}|�|�
�|���W5QRXt|�q*W5QRXW5QRXdSr�)rr�rErFr�
extractallr�r�r�r/r�r7rXr�rYr	)r:rIr�r��outfiler"rrr�test_extract_all[szExtractTests.test_extract_allcCs�|��t�td��^}|�|�tD]H\}}tj�||�}t	|d��}|�
|��|���W5QRXt
|�q$W5QRXt
t�dSr�)r�rErFrr�r�r�r�r/r7rXr�rYr	)r:r�rIr�r�r�r"rrr�_test_extract_all_with_targeths
z*ExtractTests._test_extract_all_with_targetc	Cs t��}|�|�W5QRXdSr)rr�r�rrr�test_extract_all_with_targetvsz)ExtractTests.test_extract_all_with_targetc	Cs&t��}|�t�|��W5QRXdSr)rr�r�r�r�rrr�%test_extract_all_with_target_pathlikezsz2ExtractTests.test_extract_all_with_target_pathlikec	Cs<|�tj�|��t|d��}|�|��|�W5QRXdS)Nr�)rar�r��isfiler7rXrY)r:rWr"r"rrr�
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)rErFZ_sanitize_windows_namerX)r:Zsanrrr�test_sanitize_windows_name�sz'ExtractTests.test_sanitize_windows_namecCs"ddddddddg}|�|�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)r:Zcommon_hacknamesrrr�*test_extract_hackers_arcnames_common_cases�s�
z7ExtractTests.test_extract_hackers_arcnames_common_cases�\zRequires \ as path separator.cCs8ddddddddd	d
ddd
ddddddg}|�|�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�)r:Zwindows_hacknamesrrr�*test_extract_hackers_arcnames_windows_only�s*�z7ExtractTests.test_extract_hackers_arcnames_windows_onlyr�zRequires / as path separator.cCsdddg}|�|�dS)N)z	//foo/barr�)r�zfoo../ba..r)�
foo/..\barr�r�)r:Zposix_hacknamesrrr�(test_extract_hackers_arcnames_posix_only�s
�z5ExtractTests.test_extract_hackers_arcnames_posix_onlyc

Cs�|D�]�\}}d|��}t�tdtj��&}t��}||_d|_|�||�W5QRX|�	t
jd�}t
j�
ddd�}t
jj
|f|�d���}t�td��,}|�||�}	|j|	|d	||	|fd
�W5QRX|�||�td�t�td��}|�|�W5QRX|�||�td�t
jj
t
��f|�d���}t�td��$}|�|�}	|j|	|d|d
�W5QRX|�||�t|�d�d�t�td��}|��W5QRX|�||�t|�d�d�tt�qdS)
N�foobarr?r�r�r��subdirZsubsubrLzextract %r: %r != %r)�msgz
extract %rr)r�rErFrr��ZipInforWr�rG�replacer�rir�r/r`r�rXr�r
r�r�r	)
r:Z	hacknamesZarcnameZ	fixednamer"rIr�Z
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�rir�r�r�rrrrr�&s"



r�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zedd��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&e'dGdH��Z(edIdJ��Z)edKdL��Z*dMdN�Z+dOS)P�
OtherTestscCs�t�tdtj��J}|�dd�|�t��|�dd�W5QRX|�|��dgd�W5QRXt�td��z}|�	�}d}|D]&}|�
|��}||��7}W5QRXq~|�|dd	h�d}|D]}||�|�7}q�|�|dd	h�W5QRXdS)
Nr?rYr��barr�rLr+r�sbarfoo)
rErFrr�rGr|r}rXrerfr7rYr_)r:rIrpr0rrr�rrr�test_open_via_zip_info�s  z!OtherTests.test_open_via_zip_infoc	CsJt�td��4}dD](}t�|�}|jdO_|�||�qW5QRXdS)Nr?Zabcdefghijklmnopr)rErFrr�Z	flag_bitsrG)r:Zorig_zipr0r�rrr�-test_writestr_extended_local_header_issue1202�s

z8OtherTests.test_writestr_extended_local_header_issue1202c	Cs�t�td��.}tD]"\}}|�||�|�|jd�qW5QRX|�|jd�t�td��}|�|jd�W5QRX|�|jd�dS)z8Check that the zipfile is closed after the 'with' block.r?zzipfp is not open�zipfp is not closedrLN)rErFrr�rGZassertIsNotNoner;�assertIsNoner�rrr�
test_closeszOtherTests.test_closec	Cs�t�td�� }tD]\}}|�||�qW5QRXz$t�td��}t���W5QRXWn$tjk
rz|�|jd�YnXdS)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.r?rLr�N)rErFrr�rGr<r�r;)r:rIr�r�Zzipfp2rrr�test_close_on_exceptionsz"OtherTests.test_close_on_exceptioncCs d}|�ttjt�|�d�dS)NsdPKx!p�@xPKxx!p�@�xPK/rL)r��NotImplementedErrorrErFrr r�rrr�test_unsupported_versions

�z#OtherTests.test_unsupported_versionc	Cs>td�}t�|��"}|��D]}|�|���qW5QRXdS)Nzzip_cp437_header.zip)rrErFrer7r)r:r�rIrYrrr�test_read_unicode_filenames&sz&OtherTests.test_read_unicode_filenamesc	Cs�t�td��4}|�dd�|�dd�|�|��djt�W5QRXt�td��.}|�|j	djd�|�|j	djd�W5QRXdS)Nr?�foo.txtzTest for unicode filenameuö.txtrrLrR)
rErFrrGr�rfrWrdrX�filelist)r:rFrrr�test_write_unicode_filenames.s z'OtherTests.test_write_unicode_filenamesc	Cs:t�td��$}|�dd�|�|�d�d�W5QRXdS)Nr?uприкладssample)rErFrrGrXrYr�rrr�'test_read_after_write_unicode_filenames8sz2OtherTests.test_read_after_write_unicode_filenamesc	Cs�tt�d}d}t�tdtj��}|�||�W5QRX|�t��t�tdtj�W5QRXt�td��*}|�|�	�|g�|�|�
|�|�W5QRXdS)z&Test exclusive creating a new zipfile.�testfile.txt�#hello, world. this is some content.�xrLN)r	rrErFr�rGr��FileExistsErrorrXrerY)r:rWr"rIrrr�test_exclusive_create_zip_file=sz)OtherTests.test_exclusive_create_zip_filec	Cs�tj�t�rt�t�d}d}z(t�td��}|�||�W5QRXWntk
rd|�	d�YnX|�
tj�t��t�td��}|�|�|�|�W5QRXdS)Nr�r�r�z1Could not append data to a non-existent zip file.rL)
r�r��existsrr	rErFrGr��failrarXrY)r:rWr"rFrrr�(test_create_non_existent_file_for_appendJs
z3OtherTests.test_create_non_existent_file_for_appendc	CsJttd��}|�d�W5QRXzt�t�}Wntjk
rDYnXdS)Nr?�this is not a legal zip file
)r7rr8rErFr<)r:r;rFrrr�test_close_erroneous_file\sz$OtherTests.test_close_erroneous_filec	Cs�ttd��}|�d�W5QRX|�t�t��|�t�t�t���ttd��}|�t�|��W5QRXt�	�}|�d�|�t�|��|�
dd�|�t�|��dS)z;Check that is_zipfile() correctly identifies non-zip files.r?r�r�sthis is not a legal zip file
rN)r7rr8rrE�
is_zipfiler�r�rr r�r9rrr�test_is_zip_erroneous_fileks
z%OtherTests.test_is_zip_erroneous_filec	Cspt��}tj|dd��}|�dd�W5QRX|��}tt|��D](}t�|d|��}|�tj	tj|�qBdS)zCCheck that zipfiles with missing bytes at the end raise BadZipFile.r?rCr��O, for a Muse of Fire!N)
rr rErFrGr\r,r^r�r<)r:r;r�r��Nrrr�test_damaged_zipfile}szOtherTests.test_damaged_zipfilec	Cs�tjtdd��}|�dd�W5QRX|�t�t��ttd��*}|�t�|��|�dd�|��}W5QRXt	�
�}|�|�|�t�|��|�dd�|�t�|��dS)z7Check that is_zipfile() correctly identifies zip files.r?rCr�r�r�rN)rErFrrGrar�r7r�rYrr r8)r:r�r;Zzip_contentsrrr�test_is_zip_valid_file�s
z!OtherTests.test_is_zip_valid_filecCs|�ttjt�dSr)r�r�rErFrr�rrr�%test_non_existent_file_raises_OSError�sz0OtherTests.test_non_existent_file_raises_OSErrorc	CsZttd�}|��|�tjtjt�ttd��}|�d�W5QRX|�tjtjt�dS)Nr?z
short file)r7rrr�rEr<rFr8)r:r"r;rrr�!test_empty_file_raises_BadZipFile�s
z,OtherTests.test_empty_file_raises_BadZipFilec	Cs�t��}tj|dd��}|�dd�W5QRX|�t|jd�|�t|jd�|�t|j	�|�t|jdd�tt
d��}|�d�W5QRX|�t|jt
�dS)	z?Verify that testzip() doesn't swallow inappropriate exceptions.r?rCr��O, for a Muse of Fire!z	bogus.txtr�zzipfile test dataN)rr rErFrGr�r�rYr7rirr8)r:r0r�r"rrr�!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�rErFrr�rrr�test_bad_constructor_mode�sz$OtherTests.test_bad_constructor_modec	Cs�tjtdd��}|�dd�W5QRXtjtdd��F}|�d�|�t|jdd�|�t|jdd�|�t|jdd�W5QRXd	S)
z7Check that bad modes passed to ZipFile.open are caught.r?rCr�r�rLr��UZrUN)rErFrrGrYr�r�r7�r:r�rrr�test_bad_open_mode�s
zOtherTests.test_bad_open_modec
Csptjtdd��X}|�dd�|�d��6}tt�D]}|�|�d�d�q0|�|��d�W5QRXW5QRXdS)	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.r?rCr�r�rr+r�N)	rErFrrGr7r,r-rXrY)r:r�r"r)rrr�
test_read0�szOtherTests.test_read0c	Cs0tjtdd��}|�t|jdd�W5QRXdS)zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.r?rCr�rLN)rErFrr��KeyErrorr7r�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�rErFrr�rrr�test_bad_compression_mode�sz$OtherTests.test_bad_compression_modec	Cs6d}t�t�|�d��}|�t|jd�W5QRXdS)NsfPK.�C�@xPK..�C�@�xPK/!rLr�)rErFrr r�r�r7)r:r0r�rrr�test_unsupported_compression�sz'OtherTests.test_unsupported_compressionc	Cs<tjtdd��$}|�dd�|�|��dg�W5QRXdS)zLCheck that a filename containing a null byte is properly
        terminated.r?rCzfoo.txtqqqr�r�N)rErFrrGrXrer�rrr�test_null_byte_in_filename�sz%OtherTests.test_null_byte_in_filenamecCs<|�tjd�|�tjd�|�tjd�|�tjd�dS)zACheck that ZIP internal structure sizes are calculated correctly.��.�8r�N)rXrEZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locatorr�rrr�test_struct_sizesszOtherTests.test_struct_sizesc
Cs�tjtdd�� }|�|jd�|�dd�W5QRXtjtdd��}|�|jd�W5QRXd}tjtdd��}||_|�dd�W5QRXtjtdd��}|�|j|�W5QRXd�d	d
�td�D��}|�d�}tjtdd��}||_|�dd�W5QRXtjtdd��}|�|j|�W5QRXtjtdd��2}|�	t
��|d
|_W5QRX|�dd�W5QRXtjtdd��}|�|j|�W5QRXtjtdd��}d|_|�dd�W5QRXtjtdd��}d|_W5QRXtjtdd��}|�|jd�W5QRXtjtdd��}d|_|�dd�W5QRXtj�
t�}tjtdd��}d|_W5QRX|�|tj�
t�k�tjtdd��}|�|jd�W5QRXdS)z8Check that comments on the archive are handled properly.r?rCr+r�r�rLs9Bravely taking to his feet, he beat a very brave retreat.�cSsg|]}d|dd�qS)rrr�rr'rrrr*sz,OtherTests.test_comments.<locals>.<listcomp>�r%soopssoriginal commentr�san updated commentsoriginal comment that's longersshorter commentN)rErFrrXr�rGr/r,r�r|r}r�r��getsizera)r:r�Zzipfrr�Zcomment2Zoriginal_zip_sizerrr�
test_commentssP
zOtherTests.test_commentsc
CsHt�tdtj��.}|�dd�|�t��d|_W5QRXW5QRXdS)Nr?r�r�zthis is an error)rErFrr�rGr��	TypeErrorr�r�rrr�test_unicode_commentBszOtherTests.test_unicode_commentc	CsXt�tdtj��}|�|j�d|_W5QRXt�td��}|�|jd�W5QRXdS)Nr�r�rL)rErFrr�rr�r�rXr�rrr�$test_change_comment_in_empty_archiveHs
z/OtherTests.test_change_comment_in_empty_archivec	Cs�t�tdtj��}|�dd�W5QRXt�tdtj��}|�|j�d|_W5QRXt�td��}|�|jd�W5QRXdS)Nr?r�r�r�r�rL)	rErFrr�rGrar�r�rXr�rrr�'test_change_comment_in_nonempty_archiveOsz2OtherTests.test_change_comment_in_nonempty_archivecCs�tjtdd�}|��ztjtdd�}Wn tjk
rH|�d�YnXtjtdd�}|��ztjtdd�}Wn|�d�YnXdS)Nr?rCrLz+Unable to create empty ZIP file in 'w' moder�z+Unable to create empty ZIP file in 'a' mode)rErFrrr<r�r�rrr�test_empty_zipfileXszOtherTests.test_empty_zipfilecCs*ttd�}|��|�tjtjtd�dS)Nr?rL)r7rrr�rEr<rFrurrr�test_open_empty_fileis
zOtherTests.test_open_empty_filecCs|�ttjdd�dS)NZ	seventies)i�rRrRrrr)r�r�rEr�r�rrr�test_create_zipinfo_before_1980qs
�z*OtherTests.test_create_zipinfo_before_1980c	Cs4d}t�t�|�d��}|�|���W5QRXdS)z>If an extra field in the header is less than 4 bytes, skip it.snPK���@����abcAPK���@������abcPK3%rLN)rErFrr r�ri�r:r�r�rrr�#test_zipfile_with_short_extra_fieldus�	z.OtherTests.test_zipfile_with_short_extra_fieldcCs�d}d}d}t�tdtj���}|jddd��}|�|�W5QRX|jddd���}|�t��|jddd�W5QRX|�t��|jdd	d�W5QRX|�t��|�d
d�W5QRX|�t��|�t	d�W5QRX|�t��|�
�W5QRX|�|�W5QRX|jd
dd��}|�|�W5QRXW5QRXt�td	��R}|�|�d�|�|�|�d�|�|�|�d
�|�|�|�
�ddd
g�W5QRXdS)Ns"It's fun to charter an accountant!s And sail the wide accountant seas#To find, explore the funds offshorer?r�rCr��handlerLrdZabcderM�baz)rErFrr�r7r8r�r�rGrfrrXrYre)r:Zmsg1Zmsg2Zmsg3r�Zw2�w1rrr�test_open_conflicting_handles�s2z(OtherTests.test_open_conflicting_handlesc
Cs:d}|�d�}t�td��}|�d|�W5QRXt�td���}|�dd���}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�W5QRXW5QRXt��}tj|dd��}|�d|�W5QRXtj|dd���}|�dd���}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�W5QRXW5QRXdS)	NsWhere's Bruce?sBrucer?r�rLrrNrC)�findrErFrrGr7r�r��SEEK_SETrXr��SEEK_CURrY�SEEK_ENDr^rr )r:�txt�blocr�r;r0rrr�test_seek_tell�sB
$zOtherTests.test_seek_tellc
Cszd}t�|�}tj|dtjd��}|�dd�W5QRXt�dd��,t�|��}|�t	|j
d�W5QRXW5QRXdS)NsPKr?)r=r��azzipfile.bz2)rr rErFrrG�mockZpatchr�r�r�)r:r0Zzip_filerFrrr�)test_decompress_without_3rd_party_library�s
z4OtherTests.test_decompress_without_3rd_party_libraryc
Cs�d}t�t�|�d���}|�|��ddg�|�d�}|�|jd�|�|jd�|�|j	d�|�d�}|�|jd�|�|jd�|�|j	d�|�t
|�d��d�|�tj
d��|�d�W5QRXW5QRXdS)	Ns�PK�lH�8�	a��0�K\d`PK�lH�8�	aPK�lH�8�	bPK^/rLr��br��	zFile name.*differ)rErFrr rXrerhr:r9rgr^rY�assertRaisesRegexr<�r:r0r��zirrr�test_full_overlap�s�


zOtherTests.test_full_overlapc
Cs�d}t�t�|�d���}|�|��ddg�|�d�}|�|jd�|�|jd�|�|j	d�|�d�}|�|jd�|�|jd	�|�|j	d
�|�
tjd��|�d�W5QRX|�t
|�d��d
�W5QRXdS)Ns�PK�lHY�84(a�PK�lH�8�	b��0�K\d`PK�lHY�84(aPK�lH�8�	$bPK^SrLr�rr�4i(�$rrzOverlapped entries)rErFrr rXrerhr:r9rgrr<rYr^rrrr�test_quoted_overlap�s�

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�r�r�r�r�r�r�rrrrrrrr�rrrrr��sV



	
:	&
	

r�c@seZdZdd�Zdd�ZdS)�AbstractBadCrcTestsc	Cs:|j}tjt�|�dd��}|�d|���W5QRXdS)z>Tests that files with bad CRCs return their name from testzip.rLrC�afileN)�zip_with_bad_crcrErFrr rXrir�rrr�test_testzip_with_bad_crcsz-AbstractBadCrcTests.test_testzip_with_bad_crccCs�|j}tjt�|�dd��}|�tj|jd�W5QRXtjt�|�dd��.}|�dd��}|�tj|j�W5QRXW5QRXtjt�|�dd��H}|�dd��0}d|_	|�tj��|�d�r�q�W5QRXW5QRXW5QRXdS)zFTests that files with bad CRCs raise a BadZipFile exception when read.rLrCrr�N)
rrErFrr r�r<rYr7�
MIN_READ_SIZE)r:r�r�Zcorrupt_filerrr�test_read_with_bad_crcs$
z*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�rrrrrrrsrc@seZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�rEr�r=rrrrrr1s�rc@seZdZejZdZdS)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�rErr=rrrrrr =s�r c@seZdZejZdZdS)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�rErr=rrrrrr!Js�r!c@seZdZejZdZdS)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�rErr=rrrrrr"Zs�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 testsc	Csdttd��}|�|j�W5QRXt�td�|_ttd��}|�|j�W5QRXt�td�|_	dS)Nr5rL)
r7rr8r0rErFr�r�data2�zip2r9rrrr<�szDecryptionTests.setUpcCs,|j��t�t�|j��t�t�dSr)r�rr�r	rr%rr�rrrr��s


zDecryptionTests.tearDowncCs(|�t|jjd�|�t|jjd�dS)N�test.txt�zero)r�r�r�rYr%r�rrr�test_no_password�sz DecryptionTests.test_no_passwordcCs@|j�d�|�t|jjd�|j�d�|�t|jjd�dS)Nsperlr&r')r��setpasswordr�r�rYr%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)rXrY�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)rYr7r�r�rrr�test_unicode_password�sz%DecryptionTests.test_unicode_passwordc	Csr|j�d�|j}d}|�|�}t|�}|j�dd���0}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�|�||||��|j
}d|_
d|_d|_|�dtj�|�	|�
�d�|�|tj�|�	|�|�||||��||_
|�dtj�|�	|�
�t|��|�dtj�|�	|�
�d�|��W5QRXdS)Nr+s
encryptionr&rLrrRr+)r�r)r,rr^r7r�r�rrXr�rrYrZ_readbufferZ_offsetr)r:r	Z	test_wordr
Zbloc_lenr;Z
old_read_sizerrrr�s6
zDecryptionTests.test_seek_tellN)r�r�r��__doc__r0r$r,r-r<r�r(r*r
r.r1rrrrrr#is�	�

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)Nr�@r�rRr+css&|]}t�dt�tdd��VqdS)z<fi���rN)rr2rrr'rrrr�s�z@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>)rr/r,r0)r2Z	datacountrrrr3�s
�z-AbstractTestsWithRandomBinaryFiles.setUpClassc	Cs&ttd��}|�|j�W5QRXdSr4r6r9rrrr<�sz(AbstractTestsWithRandomBinaryFiles.setUpcCstt�tt�dSrr�r�rrrr��sz+AbstractTestsWithRandomBinaryFiles.tearDownc	Cs6t�|d|��}|�td�|�tt�W5QRXdS)Nr?r@)rErFr8rr(rrrrK�sz4AbstractTestsWithRandomBinaryFiles.make_test_archivec	Csl|�||�t�|d|��H}|�t�}|�t|�t|j��|�||j�|�|�d�|j�W5QRXdS)NrLr@)rKrErFrYrrXr^r0)r:r"r=rI�testdatarrrrs�s
z+AbstractTestsWithRandomBinaryFiles.zip_testcCs t|�D]}|�||j�qdSrrtrurrr�	test_read�sz,AbstractTestsWithRandomBinaryFiles.test_readc
Cs�|�||�t�|d|���}g}|�t��"}|�d�}|s<qH|�|�q,W5QRXg}|�d��"}|�d�}|srq~|�|�qbW5QRXd�|�}	|�t	|	�t	|j
��|�|	|j
�d�|�}
|�t	|
�t	|j
��|�|
|j
�W5QRXdSrw)rKrErFr7rrYryr/rXr^r0)r:r"r=rIrzr{r|r}r~Z	testdata1Z	testdata2rrrr�s(



z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCs t|�D]}|�||j�qdSrr�rurrrr�	sz,AbstractTestsWithRandomBinaryFiles.test_openc
Cs�|�||�t�|d|��p}g}|�t��(}|�tdd��}|sBqN|�|�q,W5QRXd�|�}|�	t
|�t
|j��|�	||j�W5QRXdSr�)rKrErFr7rrYrryr/rXr^r0)r:r"r=rIrzr{r|r5rrrr�	s
z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCs t|�D]}|�||j�qdSrr�rurrrr�&	sz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r3r<r�rKrsr6rr�r�r�rrrrr3�s

r3c@seZdZejZdS)� StoredTestsWithRandomBinaryFilesNrSrrrrr7+	sr7c@seZdZejZdS)�!DeflateTestsWithRandomBinaryFilesNrIrrrrr8/	sr8c@seZdZejZdS)�Bzip2TestsWithRandomBinaryFilesNrrrrrr94	sr9c@seZdZejZdS)�LzmaTestsWithRandomBinaryFilesNrrrrrr:9	sr:c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TellablecCs||_d|_dS�Nr)r;�offsetr9rrr�__init__A	szTellable.__init__cCs|j�|�}|j|7_|Sr)r;r8r=)r:r0�nrrrr8E	szTellable.writecCs|jSr)r=r�rrrr�J	sz
Tellable.tellcCs|j��dSr�r;�flushr�rrrrAM	szTellable.flushN)r�r�r�r>r8r�rArrrrr;@	sr;c@s$eZdZdd�Zdd�Zdd�ZdS)�
UnseekablecCs
||_dSr)r;r9rrrr>Q	szUnseekable.__init__cCs|j�|�Sr)r;r8r�rrrr8T	szUnseekable.writecCs|j��dSrr@r�rrrrAW	szUnseekable.flushN)r�r�r�r>r8rArrrrrBP	srBc@s$eZdZdd�Zdd�Zdd�ZdS)�UnseekableTestscCsdd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��}|�
dd�|�
dd	�W5QRX|�|��dd
�d�tj|dd
��R}|�
d��}|�|��d�W5QRX|�
d��}|�|��d	�W5QRXW5QRXW5QRXqdS)NcSs|Srr�r"rrrrx\	r+z/UnseekableTests.test_writestr.<locals>.<lambda>��wrapper�abcr?�ones�111�twos�222rN�abcPKrLrC)r;rB�subTestrr r8�BufferedWriterrErFr�rGrXr\r7rY)r:rFr"�bfrIr��zopenrrr�
test_writestr[	s

zUnseekableTests.test_writestrcCsRdd�ttfD�]<}|j|d���$t��}|�d�t�|�}t�||�dtj	��j}|�
tt�t
td��}|�d�W5QRX|�td�t
td��}|�d	�W5QRX|�td
�W5QRX|�|��dd�d�tj|d
d��R}|�
d��}|�|��d�W5QRX|�
d
��}|�|��d	�W5QRXW5QRXW5QRXqdS)NcSs|SrrrDrrrrxl	r+z,UnseekableTests.test_write.<locals>.<lambda>rErGr?r5rIrHrKrJrNrLrLrC)r;rBrMrr r8rNrErFr��
addCleanupr	rr7rXr\rY)r:rFr"rOrI�f2r�rPrrr�
test_writek	s&

zUnseekableTests.test_writecCsdd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��J}|�
dd��}|�d�W5QRX|�
dd��}|�d	�W5QRXW5QRX|�|��dd
�d�t�|��*}|�|�
d�d�|�|�
d�d	�W5QRXW5QRXqdS)NcSs|SrrrDrrrrx�	r+z1UnseekableTests.test_open_write.<locals>.<lambda>rErGr?rHrIrJrKrNrL)r;rBrMrr r8rNrErFr�r7rXr\rY)r:rFr"rOr�rPrrr�test_open_write�	s

zUnseekableTests.test_open_writeN)r�r�r�rQrTrUrrrrrCZ	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$r1rrrr3�	sz!TestsWithMultipleOpens.setUpClassc	Cs<t�|dtj��"}|�d|j�|�d|j�W5QRXdS)Nr?rHrJ)rErFrrGrXr$)r:r"rIrrrrK�	sz(TestsWithMultipleOpens.make_test_archivecCs�t|�D]�}|�|�tj|dd��x}|�d��H}|�d��2}|�d�}|�d�}||��7}||��7}W5QRXW5QRX|�||�|�||j�W5QRXqdS)NrLrCrH��)r#rKrErFr7rYrXrX�r:r"r��zopen1�zopen2rXr$rrr�test_same_file�	s


 z%TestsWithMultipleOpens.test_same_filecCs�t|�D]�}|�|�tj|dd��z}|�d��H}|�d��2}|�d�}|�d�}||��7}||��7}W5QRXW5QRX|�||j�|�||j�W5QRXqdS)NrLrCrHrJrY�	r#rKrErFr7rYrXrXr$rZrrr�test_different_file�	s


 z*TestsWithMultipleOpens.test_different_filecCs�t|�D]�}|�|�tj|dd��z}|�d��H}|�d�}|�d��(}|�d�}||��7}||��7}W5QRXW5QRX|�||j�|�||j�W5QRXqdS)NrLrCrHrYrJr^)r:r"r�r[rXr\r$rrr�test_interleaved�	s


 z'TestsWithMultipleOpens.test_interleavedcCs�t|�D]�}|�|�t���j}t�|d��&}|�|�d��}|�|�d��}W5QRX|�d�}|�d�}||��7}||��7}W5QRX|�	||j
�|�	||j�qdS)NrLrHrJrY)r#rK�
contextlib�	ExitStackrErF�
enter_contextr7rYrXrXr$)r:r"�stackr�r[r\rXr$rrr�test_read_after_close�	s



z,TestsWithMultipleOpens.test_read_after_closecCs�t|�D]�}t�|dtj��B}|�d|j�|�d|j�|�d��}|�d�}W5QRXW5QRX|�	||jdd��t�|d��}|�d�}|�d�}W5QRX|�	||j�|�	||j�qdS)Nr?rHrJrYrL)
r#rErFrrGrXr$r7rYrX�r:r"r�r[rXr$rrr�test_read_after_write�	s
z,TestsWithMultipleOpens.test_read_after_writecCs�t|�D]�}t�|dtj��B}|�d|j�|�d��}|�d�|�d|j�W5QRXW5QRXt�|d��}|�d�}|�d�}W5QRX|�	||j�|�	||j�qdS)Nr?rHrYrJrL)
r#rErFrrGrXr7rYr$rXrfrrr�test_write_after_read�	s
"
z,TestsWithMultipleOpens.test_write_after_readcCs||�t�tjtdd��4}td�D]$}|�d�|�d��}W5QRXq"W5QRXttj��}|�	|�
�d�W5QRXdS)NrLrCr�rH)rKrrErFr,rYr7r��devnullZ
assertLess�fileno)r:r�r�r[r"rrr�test_many_opens�	s

z&TestsWithMultipleOpens.test_many_openscCs�t�tdtj��}|�d|j�W5QRXt�tdtj��X}|�dd��@}|�d�}|�dd��}|�|j	�W5QRX||��7}W5QRXW5QRX|�
||j�t�t��}|�
|�d�|j	�W5QRXdS)Nr?rHr�rLrYrJ)rErFrrrGrXr7rYr8r$rX)r:r�Zr1rXrrrr�test_write_while_reading�	s
 z/TestsWithMultipleOpens.test_write_while_readingcCstt�dSrrMr�rrrr�
szTestsWithMultipleOpens.tearDownN)r�r�r�r�r3rKr]r_r`rergrhrkrlr�rrrrrV�	s


rVc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestWithDirectorycCst�t�dSr)r�r�rr�rrrr<
szTestWithDirectory.setUpc
Cs�t�td���}|�t�W5QRX|�tj�tj�	td���|�tj�tj�	tdd���|�tj�
tj�	tddd���dS)N�
zipdir.zipr�rrE)rErFrr�rrar�r��isdirr/r�r�rrr�test_extract_dir
s
z"TestWithDirectory.test_extract_dircCs t�tj�td��|��dS�Nr�)r�r�r�r/rrpr�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�W5QRXt�t	d
���}|jd}|�|j
�d��|�|j|d>dB�|jd}|�|j
d	�|�|j|d>dB�tj�td�}t�|�|�|�|�tj�tj�|d���|�tt�|��d�W5QRXdS)
Nr�r�r?rz/x/r�yrRzy/rLr�r�)r�r�r/rr�r�st_moderErFrr8r�rarWrhrXr�r�ror^�listdir)r:�dirpathrDr�r�r�rrr�test_write_dir
s0



 



z TestWithDirectory.test_write_dirc	Cs�t�tj�td��t�td��8}|�dd�|j	d}|�
|jd�|�
|jd�W5QRXt�td���}|j	d}|�
|j�d��|�
|jd�tj�td�}t�|�|�|�|�
tj�tj�|d���|�
t�|�dg�W5QRXdS)	Nr�r?zx/r+ri�ArLr�)r�r�r�r/rrErFrrGr�rXrWr�rarhr�roru)r:r�r�r�rrr�test_writestr_dir9
s



z#TestWithDirectory.test_writestr_dircCs tt�tj�t�rtt�dSr)r
rr�r�r�rr	r�rrrr�J
szTestWithDirectory.tearDownN)	r�r�r�r<rprrrwrxr�rrrrrm
srmc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ZipInfoTestscCsHtj�t�}|�t�|j�d�|�|�	��|�|j
tj�
t��dS�Nztest_zipfile.py)rEr��	from_filerfrX�	posixpathrprWr�is_dirrgr�r�r��r:rrrr�test_from_fileQ
szZipInfoTests.test_from_filecCsNtj�t�t��}|�t�|j	�d�|�
|���|�|jt
j�t��dSrz)rEr�r{r�r�rfrXr|rprWrr}rgr�r�r�r~rrr�test_from_file_pathlikeW
sz$ZipInfoTests.test_from_file_pathlikecCsPtj�t�t�d�}|�t�|j	�d�|�
|���|�|jtj
�t��dS)Nr!)rEr�r{r��fsencoderfrXr|rprWrr}rgr�r�r~rrr�test_from_file_bytes]
sz!ZipInfoTests.test_from_file_bytesc	Csdttd��P}tj�|��d�}|�t�|j	�d�|�
|���|�|jt
j�t��W5QRXdS)Nr�r!)r7rfrEr�r{rjrXr|rprWrr}rgr�r�r�)r:r"rrrr�test_from_file_filenoc
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�re�abspathrfrEr�r{rXrWrar}r�r�rg)r:rvrrrr�
test_from_dirj
szZipInfoTests.test_from_dirN)r�r�r�rr�r�r�r�rrrrryP
s
ryc@sHeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zedd��Z	d
d�Z
dS)�CommandLineTestcOs(tjd|�|�\}}}|�tj��d�S)N�-mrEr)r�rE)rZassert_python_okr�r��linesepr�)r:�argsrH�rc�out�errrrr�
zipfilecmdu
s
�
zCommandLineTest.zipfilecmdcGstjd|��S)Nr�rE)r�rE)rZassert_python_failure)r:r�rrr�zipfilecmd_failurez
sz"CommandLineTest.zipfilecmd_failurecCs||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr+susageserrorsrequired�-lr�)r�rXr_r>ZassertNotEqual�strip)r:r�r�r�rrr�test_bad_use}
szCommandLineTest.test_bad_usecCsXtd�}dD] }|�||�}|�|��d�qtd�}|�d|�\}}}|�|d�dS)Nrn)�-tz--testsDone testingztesttar.tarr�r+)rr�rX�rstripr�)r:�zip_name�optr�r�r�rrr�test_test_command�
sz!CommandLineTest.test_test_commandc	Csltd�}t��}t�|d��}|�|�W5QRX|���dd�}dD] }|j||dd�}|�	||�qFdS)NrnrLr%�backslashreplace)r�z--listzascii:backslashreplace)ZPYTHONIOENCODING)
rrrZrErFr[r\r�r�rX)r:r�rrZtfZexpectedr�r�rrr�test_list_command�
s�z!CommandLineTest.test_list_commandc
Cs|�tt�ttd��}|�d�W5QRXt�t�|�tt�ttj	�
td�d��}|�d�W5QRXttg}ttdtdg}dD]�}zt|j|tf|��}|�
|d�t�t��B}|�
|��|�|�
|�|d	�d
�|�
|�|d�d�W5QRXW5tt�Xq�dS)
Nr?ztest 1zfile.txtztest 2r�z	/file.txt)z-cz--creater+rstest 1r�stest 2)rRr	rr7r8r�r��	TESTFNDIRr
r�r/rr�rXrErFrerY)r:r"�filesrer�r�rFrrr�test_create_command�
s$
$z#CommandLineTest.test_create_commandc	
Cs�td�}dD]�}t���}|�|||�}|�|d�t�|���}|��D]x}tj�	||j
�dtj��}|�
�r�|�tj�|��qF|�tj�|��t|d��}|�|��|�|��W5QRXqFW5QRXW5QRXqdS)Nrn)z-ez	--extractr+r�r�)rrr�rXrErFrfr�r�r/rWr�rir}raror�r7rY)	r:r�r�r�r�rFrr�r"rrr�test_extract_command�
s�z$CommandLineTest.test_extract_commandN)r�r�r�r�r�r�r�r�r
r�r�rrrrr�s
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�rrrr<�
sz TestExecutablePrependedZip.setUpc	CsV|�t�|�d|���t�|��*}|��D]}|�|�}|�d|�q,W5QRXdS)Nzis_zipfile failed on sFAVORITE_NUMBER)rarEr�rFrerYr_)r:rYrIr?r0rrr�_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�
executabler_�r:�outputrrr�test_execute_zip2�
sz,TestExecutablePrependedZip.test_execute_zip2cCs"t�|jtjg�}|�d|�dSr�)r�r�r�r�r�r_r�rrr�test_execute_zip64�
sz-TestExecutablePrependedZip.test_execute_zip64N)r�r�r�r2r<r�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)r:r)rrrr>�
sz!jaraco.itertools.Counter.__init__cCs|Srrr�rrr�__iter__�
sz!jaraco.itertools.Counter.__iter__cCst|j�}|jd7_|Sr�)�nextr�r�)r:�resultrrr�__next__�
s
z!jaraco.itertools.Counter.__next__N)r�r�r�r>r�r�rrrr�Counter�
sr�N)r�r�r�r�rrrrrA�
srAN)r�r�r�rArrrrr��
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+)rE�CompleteDirs�
_implied_dirsrerG)rFrYrrr�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)rr rErFrGrW)r0rFrrr�build_alpharep_fixtures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�fixturesrRrr�rrrr<-s
zTestPath.setUpc	cs@|���t�VW5QRX|���tt��VW5QRXdSr)rMr�r�r�rrr�zipfile_alpharep1s

zTestPath.zipfile_alpharepc
csht�|j�t���}|��D]F}|j}|��||j}|�	d��}|�
|���W5QRX|VqdSr4)r�r�r�rcrr�r;rrWr7r8r\)r:Ztmpdir�alpharep�bufferr��strmrrr�zipfile_ondisk7s
zTestPath.zipfile_ondiskcCs�|��D]�}t�|�}|��s"t�|��\}}}|��s<t�|��sHt�|��sTt�|��\}}}|��rr|��svt�|��\}	|	��s�t�|��\}
|
��\}|��st�qdSr)r�rEr�r}�AssertionError�iterdir�is_file)r:r��rootr�r�grEr"rr?�hr)rrr�test_iterdir_and_typesAs



zTestPath.test_iterdir_and_typescCs\|��D]N}t�|�}|d��s&t�|d��s6t�|d��sFt�|d��st�qdS)Nr�b/r�zg/)r�rEr�r}r��r:r�r�rrr�test_subdir_is_dirQs
zTestPath.test_subdir_is_dirc
CsR|��D]D}t�|�}|��\}}}|���}|��}W5QRX|dkst�qdS)Nr�)r�rEr�r�r7rYr�)r:r�r�r�rr�r�r0rrrr�Ys

zTestPath.test_opencCsJ|��D]<}t�|�}|��\}}}|��dks4t�|��dkst�qdS)Nzcontent of ar�)r�rEr�r��	read_textr�Z
read_bytes)r:r�r�r�rr�rrrr6as

zTestPath.test_readcCsX|��D]J}t�|�}|�d�}|��s,t�|�d��d��d�}|��dkst�qdS�Nr�rrze.txtzcontent of e)r�rEr��joinpathr�r�r��r:r�r�r�r?rrr�
test_joinpathhs

zTestPath.test_joinpathcCsP|��D]B}t�|�}|d}|��s*t�|ddd}|��dkst�qdSr�)r�rEr�r�r�r�r�rrr�test_traverse_truedivps
zTestPath.test_traverse_truedivcCs*|��D]}t�t|��}t�|�qdS)zN
        zipfile.Path should be constructable from a path-like object
        N)r�r�r�rdrE)r:r�Zpathlikerrr�test_pathlike_constructionxsz#TestPath.test_pathlike_constructioncCs*|��D]}t�|�}|t�d�qdSrq)r�rEr�r�r�rrr�test_traverse_pathlike�s
zTestPath.test_traverse_pathlikecCsH|��D]:}t�|�}|djjdks*t�|ddjjdkst�qdS)Nr�r�rza/�r�rEr��parentZatr�r�rrr�test_parent�s
zTestPath.test_parentcCsD|��D]6}t�|�}|djjdks*t�|djjdkst�qdS)Nrr�r�r�r�rrr�test_dir_parent�s
zTestPath.test_dir_parentcCs0|��D]"}t�|�}|djjdkst�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��sVt�|d��dksjt�|d��\}|��dkst�qdS)	zk
        If the underlying zipfile is changed, the Path object should
        reflect that change.
        r�r�zbar/baz.txtrcss|]}|jdkVqdS)r�N)rY)r(Zchildrrrr�s�z+TestPath.test_mutability.<locals>.<genexpr>r�N)r�rEr�r�rG�anyr�r�)r:r�r�r�rr�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?rL)
rr rErF�maprdr,�HUGE_ZIPFILE_NUM_ENTRIESrGrD)r:r�rF�entryrrr�huge_zipfile�szTestPath.huge_zipfilecCsFt�|���}tj�|���}|D]}|�d�q"|j|j	ksBt
�dS)zE
        Ensure joinpath on items in zipfile is linear time.
        �suffixN)rEr�r�r�rAr�r�r�r�r�r�)r:r��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_lowercaserd)r(r?rrrr*�sz:TestPath.test_implied_dirs_performance.<locals>.<listcomp>rW)r,rEr�r�r�rrr�test_implied_dirs_performance�sz&TestPath.test_implied_dirs_performanceN)r�r�r�r<r�r�r�r�r�r6r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�,s&
	r��__main__)Wra�importlib.utilrlrrAr�r�r|r�rr�r�rbr�Z
unittest.mockr
rE�tempfilerrrrZtest.supportrrrr	r
rrr
rrrrr�r-Z
DATAFILES_DIRr�rr#r$ZTestCaser�rr
r
rr&rHrJrKrLrRrTrUrVrWr�r�rrr r!r"r#r3r7r8r9r:r;rBrCrVrmryr�r��tupleZconsumer�r�r�r�r��mainrrrr�<module>s�0�	�5�������BA0g[����
7}A#P'
$


F1le Man4ger