Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.135.208.27
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_zipfile.cpython-310.pyc
o

ab���@slddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlZddlZddlmZddlmZmZmZddlmZddlmZmZmZmZmZddlmZm Z m!Z!m"Z"m#Z#edZ$edZ%d	Z&d
Z'gd�Z(dd
�Z)Gdd�d�Z*Gdd�de*e
j+�Z,e�Gdd�de*e
j+��Z-e�Gdd�de*e
j+��Z.e�Gdd�de*e
j+��Z/Gdd�d�Z0Gdd�de0e
j+�Z1e�Gdd�de0e
j+��Z2e�Gdd�de0e
j+��Z3e�Gd d!�d!e0e
j+��Z4Gd"d#�d#�Z5Gd$d%�d%e5e
j+�Z6e�Gd&d'�d'e5e
j+��Z7e�Gd(d)�d)e5e
j+��Z8e�Gd*d+�d+e5e
j+��Z9Gd,d-�d-e
j+�Z:Gd.d/�d/e
j+�Z;Gd0d1�d1e
j+�Z<Gd2d3�d3�Z=Gd4d5�d5e=e
j+�Z>e�Gd6d7�d7e=e
j+��Z?e�Gd8d9�d9e=e
j+��Z@e�Gd:d;�d;e=e
j+��ZAGd<d=�d=e
j+�ZBGd>d?�d?�ZCGd@dA�dAeCe
j+�ZDe�GdBdC�dCeCe
j+��ZEe�GdDdE�dEeCe
j+��ZFe�GdFdG�dGeCe
j+��ZGGdHdI�dI�ZHGdJdK�dK�ZIGdLdM�dMe
j+�ZJe�GdNdO�dOe
j+��ZKGdPdQ�dQe
j+�ZLGdRdS�dSe
j+�ZMGdTdU�dUe
j+�ZNGdVdW�dWe
j+�ZOePZQGdXdY�dY�ZRdZd[�ZSd\d]�ZTd^d_�ZUGd`da�dae
j+�ZVeWdbk�r4e
�X�dSdS)c�N)�
TemporaryFile)�randint�random�	randbytes)�
script_helper)�findfile�
requires_zlib�requires_bz2�
requires_lzma�captured_stdout)�TESTFN�unlink�rmtree�temp_dir�temp_cwd�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�n1swYt���}|V|�|j�Wd�dS1s9wYdS�N)�TESTFN2r�assertFalse�closed�io�BytesIO)�test�f�r�:/usr/local/python-3.10/lib/python3.10/test/test_zipfile.py�	get_files&s��
"�rc@seZdZedd��Zdd�ZdBdd�ZdBdd	�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)C�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>2s���z:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>�)�range�FIXEDTEST_SIZE�line_gen�join�data��clsrrr�
setUpClass0s�z&AbstractTestsWithSourceFile.setUpClasscC�<ttd��}|�|j�Wd�dS1swYdS�N�wb��openr�writer+��self�fprrr�setUp7�"�z!AbstractTestsWithSourceFile.setUpNc	Cs�||d�}tj|dfi|���F}|�td�|�tt�|�d|j�|jddd��}|jD]}|�|�q.Wd�n1s@wYWd�dSWd�dS1sXwYdS)N)�compression�
compresslevel�w�another.name�strfile�written-open-w��mode)�zipfile�ZipFiler4r�writestrr+r3r))r6rr:r;�kwargs�zipfp�linerrr�make_test_archive<s

���"�z-AbstractTestsWithSourceFile.make_test_archivecCsB|�|||�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]}|�|�}|�|j|�|�|jt|j��q�|��Wd�dS1�swYdS)N�rr=r>)�file��	File Namer�Modified�Size��%Y-%m-%d�%H:%M:%S�r?cS�g|]}|j�qSr��filenamer"rrrr%k�z8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>)rHrBrC�assertEqual�readrr+r�StringIO�printdir�getvalue�
splitlines�len�assertIn�split�
assertTrue�time�strptime�str�namelist�infolist�	file_size�getinforU�testzip)r6rr:r;rFr7�	directory�lines�fn�date�time_�size�names�infosr$�nm�inforrr�zip_testGsN

$�z$AbstractTestsWithSourceFile.zip_testcC� t|�D]	}|�||j�qdSr�rrsr:�r6rrrr�
test_basic}��z&AbstractTestsWithSourceFile.test_basicc		Cs|�||�t�|d|��i}g}|�t��}	|�d�}|sq%|�|�qWd�n1s/wYg}|�d��}	|�d�}|sEqK|�|�q=Wd�n1sUwY|�d�|�|j	�|�d�|�|j	�Wd�dS1sywYdS�NrIT�r=r&)
rHrBrCr3rrX�appendrWr*r+)	r6rr:rF�zipdata1�zipopen1�	read_data�zipdata2�zipopen2rrr�
zip_open_test�s2

��

��"�z)AbstractTestsWithSourceFile.zip_open_testcCrtr�rr�r:rvrrr�	test_open�rxz%AbstractTestsWithSourceFile.test_opencCs\t�t�}|�||j�t�|d|j��}|�|jt	�Wd�dS1s'wYdS�NrI)
�pathlib�Pathrr�r:rBrC�assertIsInstancerUrc)r6�pathrFrrr�test_open_with_pathlike�s

"�z3AbstractTestsWithSourceFile.test_open_with_pathlikec	Cs�|�||�t�|d|��<}g}|�t��}	|�tdd��}|s"q(|�|�qWd�n1s2wY|�d�	|�|j
�Wd�dS1sLwYdS�NrITrO�r&)rHrBrCr3rrXrr{rWr*r+)r6rr:rFr|r}r~rrr�zip_random_open_test�s
��"�z0AbstractTestsWithSourceFile.zip_random_open_testcCrtr�rr�r:rvrrr�test_random_open�rxz,AbstractTestsWithSourceFile.test_random_openc	Cs�|�||�t�|d��.}|�t��}g}	|�d�}|sq$|�|�qWd�n1s.wYWd�n1s=wY|�d�|�|j	�dS)NrIT���r&)
rHrBrCr3r�read1r{rWr*r+�r6rr:rF�zipopen�zipdatar~rrr�zip_read1_test�s"�

���	z*AbstractTestsWithSourceFile.zip_read1_testcCrtr)rr�r:rvrrr�
test_read1�rxz&AbstractTestsWithSourceFile.test_read1c	Cs�|�||�t�|d��6}|�t��!}g}	|�d�}|�t|�d�|s&q,|�|�qWd�n1s6wYWd�n1sEwY|�	d�
|�|j�dS)NrIT�
r&)rHrBrCr3rr�ZassertLessEqualr]r{rWr*r+r�rrr�zip_read1_10_test�s$�

���
z-AbstractTestsWithSourceFile.zip_read1_10_testcCrtr)rr�r:rvrrr�
test_read1_10�rxz)AbstractTestsWithSourceFile.test_read1_10c	Cs�|�||�t�|d��8}|�t��#}d}	|��}|sq.||7}|�d�}|s)q.||7}qWd�n1s8wYWd�n1sGwY|�||j�dS)NrIr&T�d)	rHrBrCr3r�readlinerXrWr+)r6rr:rFr�r+rXrrr�zip_readline_read_test�s*�
����z2AbstractTestsWithSourceFile.zip_readline_read_testcCrtr)rr�r:rvrrr�test_readline_read�s�z.AbstractTestsWithSourceFile.test_readline_readc	Cs�|�||�t�|d��6}|�t��}|jD]}|��}|�||�qWd�n1s-wYWd�dSWd�dS1sEwYdSr�)rHrBrCr3rr)r�rW)r6rr:rFr�rGZlinedatarrr�zip_readline_test�s
���"�z-AbstractTestsWithSourceFile.zip_readline_testcCrtr)rr�r:rvrrr�
test_readlinerxz)AbstractTestsWithSourceFile.test_readlinec	Cs�|�||�t�|d��3}|�t��}|��}Wd�n1s!wYt|j|�D]
\}}|�||�q,Wd�dS1sBwYdSr�)	rHrBrCr3r�	readlines�zipr)rW)r6rr:rFr�ZziplinesrG�ziplinerrr�zip_readlines_tests
��"�z.AbstractTestsWithSourceFile.zip_readlines_testcCrtr)rr�r:rvrrr�test_readlinesrxz*AbstractTestsWithSourceFile.test_readlinesc	Cs�|�||�t�|d��7}|�t��}t|j|�D]
\}}|�||�qWd�n1s.wYWd�dSWd�dS1sFwYdSr�)rHrBrCr3rr�r)rW)r6rr:rFr�rGr�rrr�zip_iterlines_tests���"�z.AbstractTestsWithSourceFile.zip_iterlines_testcCrtr)rr�r:rvrrr�test_iterlinesrxz*AbstractTestsWithSourceFile.test_iterlinesc	Cs�t�td|j��}|�dd�Wd�n1swYt�td|j��8}|�d��}|�|�d�d�|�|�d�d�Wd�n1sIwYWd�dSWd�dS1sawYdS)	z>Check for cases where compressed data is larger than original.r<r>Z12NrIrO�1�2)rBrCrr:rDr3rWrX)r6rFZopenobjrrr�test_low_compressions���"�z0AbstractTestsWithSourceFile.test_low_compressioncCs<t�td�}|jdd|jd�|�d�}|�|j|j�dS)Nr<�b.txt�hello world��
compress_type)rBrCrrDr:rgrWr�)r6rFrrrrr�test_writestr_compression+s
z5AbstractTestsWithSourceFile.test_writestr_compressioncCs�tjtddd�}|jdd|jd�|jdd|jdd	�|�d�}|�|j|j�|�|jd�|�d�}|�|j|j�|�|jd�dS)
Nr<rO�r;�a.txtr�r�r��)r�r;)	rBrCrrDr:rgrWr��_compresslevel)r6rFZa_infoZb_inforrr�test_writestr_compresslevel1s�

z7AbstractTestsWithSourceFile.test_writestr_compresslevelc
Cs�dD]M}|d}t|�}t�t��d|j��1}|�d|�|�dd��}|�|�}|�	t
|�|�Wd�n1s;wYWd�n1sJwYqdS)N)rOi�iii@rOr<�foorI)rrBrCrrr:rDr3rXrWr])r6Z	test_sizerfZjunk�zipfr7�bufrrr�test_read_return_sizeAs
�����z1AbstractTestsWithSourceFile.test_read_return_sizec
Cslt��}tj|dd��}|jd|j|jd�|��}Wd�n1s$wY|��}t�|�}t�|��=}|�	d��(}|�
|d�|�t��|�
�Wd�n1sYwYWd�n1shwYWd�n1swwYt�|�}t�|��D}|�	d��/}|�
|d�|�t��|�
d�r�	|�
d�s�Wd�n1s�wYWd�n1s�wYWd�n1s�wYt�|�}t�|��O}|�	d��0}|�
|d�|�t��|�d�r�	|�d�s�Wd�n	1�swYWd�n1�swYWd�dSWd�dS1�s/wYdS)Nr<r@r>r��r�)rrrBrCrDr+r:�tellr[r3�truncate�assertRaises�EOFErrorrXr�)r6r7r��
end_offset�zipfiledatar�rrr�test_truncated_zipfileMs\
�

�����


�������


���� ��$�z2AbstractTestsWithSourceFile.test_truncated_zipfilec
Cs�d}t|�D]�}t�|d|j��}|�t|�t|�}|�d|�Wd�n1s+wYt�|d���}t|�}t|t	�rI|�d||�n|�d||�|�d|�t|�
|��}|�d||�|�d|�|�d	|�|jtjkr�|�d
|�|�d|�|�|��&}t|�}|�d||�|�d|�|jtjkr�|�d
|�Wd�n1s�wY|�d
t|��Wd�n1s�wY|�d
t|��qdS)Nz	file.namer<zmode='w'rIzfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])
rrBrCr:r4r�reprr^�
isinstancercrg�
ZIP_STOREDr3)r6�fnamerrFrIr�rrr�	test_reprks@�
����z%AbstractTestsWithSourceFile.test_reprcCs$t|�D]}|j||jdd�qdS)N�	r�rurvrrr�test_compresslevel_basic���z4AbstractTestsWithSourceFile.test_compresslevel_basiccCs�tjtddd��/}|�td�|jtddd�|�d�}|�d�}|�|jd�|�|jd�Wd�dS1s:wYdS)zTCheck that files within a Zip archive can have different
        compression levels.r<rOr�Z
compress_1Z
compress_9r�N)rBrCrr4rrgrWr�)r6rFZone_infoZ	nine_inforrr�test_per_file_compresslevel�s

"�z7AbstractTestsWithSourceFile.test_per_file_compresslevelc	s�G��fdd�dtj�}d�	|�}d�t�|d|j��b}|�dd��
}|�d�Wd�n1s3wYd�z9z|�dd��
}|�d	�Wd�n1sRwYWn
tye�d
7�YnwWd�Wd�q�Wd�nd�wWd�n1s�wYt�t�|�����}|�	|�
�dg�|�	|�d�d�Wd�n1s�wYqt�t�|�����%}|�	|�
�ddg�|�	|�d�d�|�	|�d�d	�Wd�dS1s�wYdS)Ncs eZdZ���fdd�Z�ZS)zCAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFilecs,�dur��kr
t��d7�t��|�dS�NrO)�OSError�superr4�r6r+)�	__class__�count�stoprrr4�s
zIAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFile.write)�__name__�
__module__�__qualname__r4�
__classcell__r�r�r�)r�r�
BrokenFile�sr�rTr<Zfile1sdata1Zfile2sdata2rO)rrrBrCr:r3r4r�r[rWrdrX)r6r�ZtestfilerFrrr�r�test_writing_errors�sD	������
��"�z/AbstractTestsWithSourceFile.test_writing_errorscC�tt�tt�dSr�r
rr�r6rrr�tearDown��z$AbstractTestsWithSourceFile.tearDownr)$r�r�r��classmethodr.r8rHrsrwr�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/sD


6

	%rc@s�eZdZejZdZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�StoredTestsWithSourceFileNcCsn|�||�t�|d��!}|�d�}|�|jd�|�d�}|�|jd�Wd�dS1s0wYdS)NrIr>��r?)rHrBrCrgrW�
external_attr)r6rr:rF�zinfoZzinfo2rrr�zip_test_writestr_permissions�s

"�z7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs t|�D]	}|�|tj�qdSr)rr�rBr�rvrrr�test_writestr_permissions�rxz3StoredTestsWithSourceFile.test_writestr_permissionscCs�t�tdtj��}|�td�Wd�n1swYt�tdtj��}|�|��dg�Wd�dS1s;wYdS)Nr<�	/absoluterI�absolute�rBrCrr�r4rrWrd�r6rFrrr�test_absolute_arcnames�s�"�z0StoredTestsWithSourceFile.test_absolute_arcnamescCs�t�tdtj��}|�tt�Wd�n1swYt�tdtj��}|�d|j�|�|�	�tdg�Wd�dS1sCwYdS)z&Test appending to an existing zipfile.r<N�ar>)
rBrCrr�r4rrDr+rWrdr�rrr�test_append_to_zip_file�s�"�z1StoredTestsWithSourceFile.test_append_to_zip_filec	Cs�d}ttd��
}|�|�Wd�n1swYt�tdtj��}|�tt�Wd�n1s5wYttd��8}|�t|��t�|d��}|�	|�
�tg�|�	|�t�|j�Wd�n1skwYWd�n1szwYttd��}|�	|�t|��|�|��}Wd�n1s�wYt
�|��9}t�|��}|�	|�
�tg�|�	|�t�|j�Wd�n1s�wYWd�dSWd�dS1s�wYdS)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!r1Nr��rbrI)r3rr4rBrCr�r�seekr]rWrdrXr+rr)r6r+rrFr��biorrr�test_append_to_non_zip_file�s.�����
�P�z5StoredTestsWithSourceFile.test_append_to_non_zip_filec	Cst���*}t�|dtj��}|�tt�Wd�n1swY|��}Wd�n1s1wYd}tt	d��}|�|�|�|�Wd�n1sRwYt�t	��}|�
|��tg�|�
|�t�|j
�Wd�dS1s{wYdS)Nr<r�r1)rrrBrCr�r4rr[r3rrWrdrXr+�r6r�rFr�r+rrrr�test_read_concatenated_zip_files
�
�
�"�z9StoredTestsWithSourceFile.test_read_concatenated_zip_filec	Cs�t���*}t�|dtj��}|�tt�Wd�n1swY|��}Wd�n1s1wYdd}tt	d��}|�|�|�|�Wd�n1sTwYt�t	d��}|�
|��tg�|�d|j
�Wd�n1szwYtt	d��}|�
|�t|��|�|��}Wd�n1s�wYt�|��D}t�|��&}|�
|��tdg�|�
|�t�|j
�|�
|�d�|j
�Wd�n1s�wYWd�dSWd�dS1s�wYdS)Nr<sI am not a ZipFile!i@Br1r�r>r�)rrrBrCr�r4rr[r3rrWrdrDr+rXr]r�rrr�$test_append_to_concatenated_zip_files0
�
�
��
�P�z>StoredTestsWithSourceFile.test_append_to_concatenated_zip_filecCs�t�tdtj��}|�tt�Wd�n1swYttddd��
}|�d�Wd�n1s5wYt�td��}|�|tj�Wd�dS1sSwYdS)Nr<r��utf-8��encodingz
rI)rBrCrr�r4rr3r��r6rFrrrr�test_ignores_newline_at_end$s��"�z5StoredTestsWithSourceFile.test_ignores_newline_at_endcCs�t�tdtj��}d|_|�tt�Wd�n1swYttddd��
}|�d�Wd�n1s8wYt�td��}|�|tj�|�	|jd�Wd�dS1s]wYdS)Nr<�this is a commentr�r�r�zabcdef
rI)
rBrCrr��commentr4rr3r�rWr�rrr�)test_ignores_stuff_appended_past_comments,s��"�zCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentsc	Cs�t�td��6}|�t�ttd��}|�|�t�|���Wd�n1s'wYWd�dSWd�dS1s?wYdS)z`Check that calling ZipFile.write without arcname specified
        produces the expected result.r<r�N)rBrCrr4rr3rWrXr�rrr�test_write_default_name6s
��"�z1StoredTestsWithSourceFile.test_write_default_namec	Cs�d}tjtdd��}|�|d�Wd�n1swYtjtdd��N}|�|��0}|��|�t|j�|�t|j	d�|�t|j
�|�t|j�|�t|j�Wd�n1s_wYWd�dSWd�dS1swwYdS)N�somefile.txtr<r@�bogusrIr)
rBrCrrDr3�closer��
ValueErrorrXr�r��readable�seekable)r6r�rFZfidrrr�test_io_on_closed_zipextfile>s ���"�z6StoredTestsWithSourceFile.test_io_on_closed_zipextfilec	Cs�tjtdd��}|�dd�Wd�n1swYtjtdd��}|�t|jt�Wd�n1s7wYtjtdd��-}|�t��|jtdd�Wd�n1s[wYWd�dSWd�dS1sswYdS)z[Check that trying to call write() on a readonly ZipFile object
        raises a ValueError.r<r@r�r�NrI)	rBrCrrDr�r�r4rr3r�rrr�test_write_to_readonlyLs����"�z0StoredTestsWithSourceFile.test_write_to_readonlycCs�t�td�t�td��}|�t|jt�Wd�n1swYtjtddd��}|�t�|�	t�}|�
|jd�Wd�dS1sIwYdS)N)rrr<F�Zstrict_timestamps�i�rOrOrrr)�os�utimerrBrCrr�r�r4rgrW�	date_time)r6rFr�rrr�test_add_file_before_1980Ys�

"�z3StoredTestsWithSourceFile.test_add_file_before_1980cCs$d}zt�|�Wnty|�d|�d��Ynwz
t�t||f�Wnty4|�d�Ynwt�t�j}|dkrG|�d|���t	�
td��}|�t
j|jt�Wd�n1sawYt	j
tddd	��}|�t�|�t�}|�|jd
�Wd�dS1s�wYdS)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)ra�	localtime�
OverflowError�skipTestrrr�stat�st_mtime_nsrBrCrr��struct�errorr4rgrWr)r6�tsZmtime_nsrFr�rrr�test_add_file_after_2107ds,��	�

"�z2StoredTestsWithSourceFile.test_add_file_after_2107)r�r�r�rBr�r:r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr��s"
	

r�c@seZdZejZdd�ZdS)�DeflateTestsWithSourceFilecCs�t�td��3}|�tdtj�|�tdtj�|�d�}|�d�}|�|j	tj�|�|j	tj�Wd�dS1s<wYdS)zUCheck that files within a Zip archive can have different
        compression options.r<ZstoremeZ	deflatemeN)
rBrCrr4rr��ZIP_DEFLATEDrgrWr�)r6rF�sinfoZdinforrr�test_per_file_compression�s

"�z4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�rBrr:rrrrrr�src@�eZdZejZdS)�Bzip2TestsWithSourceFileN�r�r�r�rB�	ZIP_BZIP2r:rrrrr��
rc@r)�LzmaTestsWithSourceFileN�r�r�r�rB�ZIP_LZMAr:rrrrr�rrc@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.setUpClasscCsXtj|_tj|_dt_dt_ttd��}|�|j�Wd�dS1s%wYdS)Nrr�r1)	rB�ZIP64_LIMIT�_limit�ZIP_FILECOUNT_LIMIT�_filecount_limitr3rr4r+r5rrrr8�s"�z#AbstractTestZip64InSmallFiles.setUpcCsptj|d|dd��}|�td�|�tt�|�d|j�Wd�n1s'wYt�|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]}|�|�}|�|j|�|�|jt
|j���q|��Wd�dS1�s1wYdS)Nr<T�Z
allowZip64r=r>rIrRrLrrMrNrOrPrQ�cSrSrrTr"rrrr%�rVz:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>)rBrCr4rrDr+rWrXrrYrZr[r\r]r^r_r`rarbrcrdrerfrgrUrh)r6rr:rFr7rirjrkrlrmrnrorpr$rqrrrrrrs�sR�


$�z&AbstractTestZip64InSmallFiles.zip_testcCrtrrurvrrrrw�rxz(AbstractTestZip64InSmallFiles.test_basiccCs�tjtd|jdd�}d|_d}t|�D]}|�d|d|dd	�q|�t|�	��|�|�
�t�td
|j�}|�t|�	��|�t|�D]}|�d|��d�}|�|d|dd	�qH|�
�dS)Nr<Tr(r���foo%08d�%dr)�9rIr )
rBrCrr:�debugr'rDrWr]rdr�rX�decode)r6r��numfilesr$�zipf2�contentrrr�test_too_many_files�s�z1AbstractTestZip64InSmallFiles.test_too_many_filescCstjtd|jdd�}d|_d}t|�D]}|�d|d|dd	�q|�t|�	��|�|�
tj��|�d|d
�Wd�n1sGwY|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�|�
tj��|�d|d
�Wd�n1s�wY|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�d
}t||�D]}|�d|d|dd	�q�|�t|�	��|�|��t�td|j�}|�t|�	��|�t|�D]}|�
d|��d�}|�|d|dd	�q�|��dS)Nr<Fr(r�r�r+r,r)r-r&r�Tr*rIr )rBrCrr:r.r'rDrWr]rdr��LargeZipFiler�rXr/)r6r�r0r$Z	numfiles2r1r2rrr�test_too_many_files_appendsN�����z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs$|jt_|jt_tt�tt�dSr)r%rBr$r'r&r
rrr�rrrr�+sz&AbstractTestZip64InSmallFiles.tearDownN)r�r�r�r�r.r8rsrwr3r5r�rrrrr!�s

9'r!c@sZeZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
			ddd
�Zdd�Zdd�Z
dS)�StoredTestZip64InSmallFilescCsLtj|d|dd��}|�tj|jtd�Wd�dS1swYdS�Nr<Fr(r=)rBrCr�r4r4r�r6rr:rFrrr�large_file_exception_test6s
�"�z5StoredTestZip64InSmallFiles.large_file_exception_testcCsNtj|d|dd��}|�tj|jd|j�Wd�dS1s wYdSr7)rBrCr�r4rDr+r8rrr�large_file_exception_test2;s

�"�z6StoredTestZip64InSmallFiles.large_file_exception_test2cCs.t|�D]}|�|tj�|�|tj�qdSr)rr9rBr�r:rvrrr�test_large_file_exception@s�z5StoredTestZip64InSmallFiles.test_large_file_exceptioncCs�tjtdtjdd��}|�td�Wd�n1swYt�tdtj��}|�|��dg�Wd�dS1s=wYdS)Nr<Tr(r�rIr�r�r�rrrr�Es��"�z2StoredTestZip64InSmallFiles.test_absolute_arcnamescCs
tjtddd��}|�d|j�Wd�n1swYtjtddd��}|�d�}|j}Wd�n1s:wYtjtddd��}|�d|j�Wd�n1sYwYtjtddd��}|�d�}|�|j|�Wd�dS1s~wYdS)Nr<Tr(r>rIr�Zstrfile2)rBrCrrDr+rg�extrarW)r6rFr�r<rrr�test_appendMs�
��
"�z'StoredTestZip64InSmallFiles.test_appendFcCs�d}d}g}	g}
|}|rd}|r|	�|�|
�|�t�d|�}|}|r2d}|r2|	�|�|
�|�t�d|�}|}
|rEd}
|rE|
�|�t�d|
�}
tjddt|	�ddt|	�g|	�R�}tjddt|
�ddt|
�g|
�R�}t�dd	dt|
��}t�dd
dt|	��}t�dddt|	��}t�dddt|
��}d
}d}t�dt|��}d|||||||d||||d|
||ddd||dddd}|S)z�Generate bytes sequence for a zip with (incomplete) zip64 data.

        The actual values (not the zip 64 0xffffffff values) stored in the file
        are:
        file_size: 8
        compress_size: 8
        header_offset: 0
        �rl��z<Lz<HH�QrOz<Q�:�2z<HrRstest.txt�test1234sPK!�%��sPK--!�%��s
�sPK,--ss
sPKlssPK:2s)r{r�packr])r6�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_fieldsrf�
compress_size�
header_offsetZlocal_extraZ
central_extraZcentral_dir_sizeZoffset_to_central_dirZlocal_extra_lengthZcentral_extra_lengthrUr2Zfilename_lengthZzip64_contentsrrr�make_zip64_file[s�






��
���������	�
���
���������������!z+StoredTestZip64InSmallFiles.make_zip64_filecCs�|jdd�}|�tj��}t�t�|��Wd�n1swY|�dt|j	��
��|jdddd�}|�tj��}t�t�|��Wd�n1sPwY|�dt|j	��
��|jdd�}|�tj��}t�t�|��Wd�n1swY|�dt|j	��
��|jdddddd�}|�tj��}t�t�|��Wd�n1s�wY|�d	t|j	��
��|jd
dddd�}|�tj��}t�t�|��Wd�n1s�wY|�d	t|j	��
��|jddd
dd�}|�tj��}t�t�|��Wd�n	1�swY|�d	t|j	��
��|jd
d
dd
�}|�tj��}t�t�|��Wd�n	1�sIwY|�d	t|j	��
��dS)a
Missing zip64 extra records raises an exception.

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

        If the zip64 extra content doesn't contain enough entries for the
        number of fields marked with 0xFFFF or 0xFFFFFFFF, we raise an error.
        This test mismatches the length of the zip64 extra field and the number
        of fields set to indicate the presence of zip64 data.
        T)rDNz	file size)rDrErFz
compress size)rF)rDrErFrGrHz
header offsetF)rDrFrGrH)rDrErFrH)rDrFrH)rLr�rB�
BadZipFilerCrrr^rc�	exception�lower)r6Zmissing_file_size_extra�eZmissing_compress_size_extraZmissing_header_offset_extrarrr�test_bad_zip64_extra�s~��������������z0StoredTestZip64InSmallFiles.test_bad_zip64_extrac
Cs�d}d}d}d}ddd�ddd�ddd�f}tdt|�d�D]Y}t�||�D]P}i}|D]}	|�|	�q-t�t�|j	d	i|�����,}
|
�
�d}|�|j|�|�|j
|�|�|j|�|�|
�|�|�Wd�n1srwYq'qdS)
Nr>rrBT)rDrE)rFrG)rHrIrOr)r'r]�	itertools�combinations�updaterBrCrrrLrerWrfrJrKrX)r6Zexpected_file_sizeZexpected_compress_sizeZexpected_header_offsetZexpected_content�paramsrIZcomborE�c�zfr�rrr� test_generated_valid_zip64_extras.�����z<StoredTestZip64InSmallFiles.test_generated_valid_zip64_extraN)FFFFFF)r�r�r�rBr�r:r9r:r;r�r=rLrQrXrrrrr62s
�c^r6c@r)�DeflateTestZip64InSmallFilesN�r�r�r�rBrr:rrrrrY8rrYc@r)�Bzip2TestZip64InSmallFilesNrrrrrr[=rr[c@r)�LzmaTestZip64InSmallFilesNrrrrrr\Brr\c@�$eZdZdd�Zdd�Zdd�ZdS)�AbstractWriterTestscC�tt�dSr�r
rr�rrrr�J�zAbstractWriterTests.tearDowncCs�d}t�td|j��1}|�dd�}|�|�|��|�|j�|��|�|j�|�	|�
d�|�Wd�dS1s>wYdS)N�contentr<r)rBrCrr:r3r4r�r`rrWrX�r6r+r�r<rrr�test_close_after_closeMs
"�z*AbstractWriterTests.test_close_after_closecCs�d}t�td|j��/}|�dd�}|�|�|��|�|j�|�	t
|jd�|�|�d�|�Wd�dS1s<wYdS)Nrbr<rr&)
rBrCrr:r3r4r�r`rr�r�rWrXrcrrr�test_write_after_closeXs
"�z*AbstractWriterTests.test_write_after_closeN)r�r�r�r�rdrerrrrr^Hsr^c@r)�StoredWriterTestsN�r�r�r�rBr�r:rrrrrfbs
rfc@r)�DeflateWriterTestsNrZrrrrrhe�
rhc@r)�Bzip2WriterTestsNrrrrrrjirirjc@r)�LzmaWriterTestsNrrrrrrkmrirkc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�PyZipFileTestscCs$|d|vr|�|d|�dSdS)N�orV)r^)r6�namerdrrr�assertCompiledInsr�zPyZipFileTests.assertCompiledIncCs~tj|tjtjtjvd�s|�d�tj�|d�}zt�|tjtj	B�}t�
|�Wnty8|�d�Ynwt|�dS)N)Z
effective_idsz/requires write access to the installed locationztest_zipfile.try)
r�access�W_OK�supports_effective_idsrr�r*r3�O_WRONLY�O_CREATr��	Exceptionr
)r6r�rU�fdrrr�requiresWriteAccessws

�
�z"PyZipFileTests.requiresWriteAccessc	Cs�|�tj�t��t��e}t�|d��O}t}|�d�r@|�	tj
�}tjdur/|�|�	tj��d|vr:t
j�|�}n|dd�}|�|�tj�|�}|�||���|�||���Wd�n1sewYWd�n1stwYt��T}t�|d��5}t}|�d�r�|dd�}|�|d�ddtj�|�f}|�||���|�||���Wd�n1s�wYWd�dSWd�dS1s�wYdS)Nr<�.pyc�__pycache__r�Ztestpackagez%s/%s)rwrr��dirname�__file__rrB�	PyZipFile�endswithr_�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInrdro)r6�trFrkZ
path_splitZbnrrr�test_write_pyfile�s4


��
P�z PyZipFileTests.test_write_pyfilec	Cs�ddl}tj�|j�}|�|�t��<}t�|d��}|�	|�|�
�}|�d|�|�d|�Wd�n1s:wYWd�dSWd�dS1sRwYdS)Nrr<zemail/__init__.pyzemail/mime/text.py)�emailrr�rzr{rwrrBr|r�rdro)r6r��
packagedirr�rFrorrr�test_write_python_package�s

P�z(PyZipFileTests.test_write_python_packagecCs�ddl}tj�|j�}|�|�t���}t�|d���}t	��
}|�
|�Wd�n1s.wY|��}|�d|v�t	��}|j
|dd�d�Wd�n1sUwY|��}|�d|v�dd�}t	��$}|�
t��|j
||d�Wd�n1s�wYWd�n1s�wY|��}|r�t|�|�d|v�Wd�n1s�wYWd�dSWd�dS1s�wYdS)	Nrr<�SyntaxErrorcSsdS)NFr)Zwhateverrrr�<lambda>��zCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>�Z
filterfunccSstj�|��d�S)NZbad)rr�r��
startswith)r�rrr�filter��zAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)rrr�rzr{rwrrBr|rr�r[r`�assertWarns�UserWarning�print)r6rr�r�rFZ	reportSIOZ	reportStrr�rrr�"test_write_filtered_python_package�s2
����P�z1PyZipFileTests.test_write_filtered_python_packagec	Cs�ddl}tj�|j�}|�|�d}d}t��B}tj|d|d��!}|�	|�|�
�}|�d||�|�d||�Wd�n1sDwYWd�dSWd�dS1s\wYdS)	NrTrOrxr<)�optimizezemail/__init__zemail/mime/text)r�rr�rzr{rwrrBr|r�rdr^)r6r�r�Zoptlevel�extr�rFrorrr�test_write_with_optimization�s
�
P�z+PyZipFileTests.test_write_with_optimizationc	Cs�t�t�z�ttj�td�ddd��
}|�d�Wd�n1s"wYttj�td�ddd��
}|�d�Wd�n1sCwYttj�td�ddd��
}|�d	�Wd�n1sdwYt��9}t�	|d��#}|�
t�|��}|�d|�|�d|�|�
d|�Wd�n1s�wYWd�n1s�wYWtt�dSWtt�dStt�w)
N�mod1.pyr<r�r��
print(42)
�mod2.py�print(42 * 42)
zmod2.txtzbla bla bla
�r�mkdirrr3r�r*r4rrBr|r�rdror�r�r6r7r�rFrorrr�test_write_python_directory�s.
���
��	�	z*PyZipFileTests.test_write_python_directoryc	Cs:t�t�z�ttj�td�ddd��
}|�d�Wd�n1s"wYttj�td�ddd��
}|�d�Wd�n1sCwYt��7}t�	|d��!}|j
tdd	�d
�|��}|�d|�|�
d|�Wd�n1svwYWd�n1s�wYWtt�dSWtt�dStt�w)Nr�r<r�r�r�r�r�cSs|�d�S)Nr�)r})rkrrrr��razEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>r�r�r�rrr�$test_write_python_directory_filtered�s&
����	�	z3PyZipFileTests.test_write_python_directory_filteredc
Cs�t��O}t�|d��0}ttddd��
}|�d�Wd�n1s"wY|�t|jt�t	t�Wd�n1s=wYWd�dSWd�dS1sUwYdS)Nr<r�r�z!most definitely not a python file)
rrBr|r3rr4r��RuntimeErrorr�r
)r6r�rFrrrr�test_write_non_pyfiles�
P�z$PyZipFileTests.test_write_non_pyfilec
Cs0t�t�z�ttj�td�ddd��
}|�d�Wd�n1s"wYt��S}t�	|d��=}t
��}|�tj�td��Wd�n1sJwY|�d|�
��|��}|�d|�|�d|�Wd�n1sqwYWd�n1s�wYWtt�dSWtt�dStt�w)Nr�r<r�r�zBad syntax in python file
r�zmod1.pyc)rr�rr3r�r*r4rrBr|rr�r^r[rdr�r)r6r7r�rF�srorrr�test_write_pyfile_bad_syntaxs&
�����z+PyZipFileTests.test_write_pyfile_bad_syntaxc	Cs�t�t�zlttj�td�ddd��
}|�d�Wd�n1s"wYt��2}t�	|d��}|�
t�t�d�|�
�}|�d|�Wd�n1sPwYWd�n1s_wYWtt�dSWtt�dStt�w)Nr�r<r�r�r�)rr�rr3r�r*r4rrBr|r�r�r�rdrorr�rrr�test_write_pathlike%s
����z"PyZipFileTests.test_write_pathlikeN)r�r�r�rorwr�r�r�r�r�r�r�r�r�rrrrrlrs
rlc@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)$�ExtractTestscCsPt�tdtj��}tD]
\}}|�||�qWd�dS1s!wYdS)Nr<)rBrCrr��SMALL_TEST_DATArD�r6rF�fpath�fdatarrr�make_test_file5s
�"�zExtractTests.make_test_filecCs�t��o|��t�td��L}tD]A\}}|�|�}tj�	t�
�|�}tj�|�}|�||�t
|d��}|�|��|���Wd�n1sIwYt|�qWd�n1s]wYWd�dSWd�dS1suwYdS�NrIr�)rr�rBrCrr��extractrr�r*�getcwd�normpathrWr3�encoderXr
)r6rFr�r��writtenfile�correctfilerrrr�test_extract:s"
�
���"�zExtractTests.test_extractc
Cs�|��t�td��R}tD]G\}}|�||�}tj�||�}tj�	|�}|�
tj�||�||f�t|d��}|�
|��|���Wd�n1sKwYt|�q
Wd�n1s_wYtt�dSr�)r�rBrCrr�r�rr�r*r�r`�samefiler3rWr�rXr
)r6�targetrFr�r�r�r�rrrr�_test_extract_with_targetMs�
��z&ExtractTests._test_extract_with_targetcC�6t��}|�|�Wd�dS1swYdSr)rr��r6�extdirrrr�test_extract_with_target`�"�z%ExtractTests.test_extract_with_targetcC�<t��}|�t�|��Wd�dS1swYdSr)rr�r�r�r�rrr�!test_extract_with_target_pathliked�"�z.ExtractTests.test_extract_with_target_pathlikecCs�t��b|��t�td��?}|��tD]0\}}tj�	t�
�|�}t|d��}|�|�
�|���Wd�n1s<wYt|�qWd�n1sPwYWd�dSWd�dS1shwYdSr�)rr�rBrCr�
extractallr�rr�r*r�r3rWr�rXr
)r6rFr�r��outfilerrrr�test_extract_allhs�
���"�zExtractTests.test_extract_allc
Cs�|��t�td��>}|�|�tD].\}}tj�||�}t	|d��}|�
|��|���Wd�n1s7wYt
|�qWd�n1sKwYt
t�dSr�)r�rBrCrr�r�rr�r*r3rWr�rXr
)r6r�rFr�r�r�rrrr�_test_extract_all_with_targetus
�
��
z*ExtractTests._test_extract_all_with_targetcCr�r)rr�r�rrr�test_extract_all_with_target�r�z)ExtractTests.test_extract_all_with_targetcCr�r)rr�r�r�r�rrr�%test_extract_all_with_target_pathlike�r�z2ExtractTests.test_extract_all_with_target_pathlikecCsR|�tj�|��t|d��}|�|��|�Wd�dS1s"wYdS)Nr�)r`rr��isfiler3rWrX)r6rUr2rrrr�
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)rBrCZ_sanitize_windows_namerW)r6Zsanrrr�test_sanitize_windows_name�sz'ExtractTests.test_sanitize_windows_namecC�gd�}|�|�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)r6Zcommon_hacknamesrrr�*test_extract_hackers_arcnames_common_cases�s
z7ExtractTests.test_extract_hackers_arcnames_common_cases�\zRequires \ as path separator.cCsgd�}|�|�dS)z>Test combination of path fixing and windows name sanitization.))z
..\foo\barr�)z..\/foo\/barr�)zfoo/\..\/barr�)zfoo\/../\barr�)z	C:foo/barr�)z
C:/foo/barr�)zC://foo/barr�)z
C:\foo\barr�)z//conky/mountpoint/foo/barr�)z\\conky\mountpoint\foo\barr�)z///conky/mountpoint/foo/bar�conky/mountpoint/foo/bar)z\\\conky\mountpoint\foo\barr�)z//conky//mountpoint/foo/barr�)z\\conky\\mountpoint\foo\barr�)z//?/C:/foo/barr�)z\\?\C:\foo\barr�)zC:/../C:/foo/barz
C_/foo/bar)za:b\c<d>e|f"g?h*izb/c_d_e_f_g_h_i)r�r�Nr�)r6Zwindows_hacknamesrrr�*test_extract_hackers_arcnames_windows_only�sz7ExtractTests.test_extract_hackers_arcnames_windows_onlyr�zRequires / as path separator.cCr�)N))z	//foo/barr�)r�zfoo../ba..r)�
foo/..\barr�r�)r6Zposix_hacknamesrrr�(test_extract_hackers_arcnames_posix_only�sz5ExtractTests.test_extract_hackers_arcnames_posix_onlyc
	Cs:|D�]\}}d|��}t�tdtj��}t��}||_d|_|�||�Wd�n1s0wY|�	t
jd�}t
j�
ddd�}t
jj
|g|�d��R�}t�td��}|�||�}	|j|	|d	||	|fd
�Wd�n1suwY|�||�td�t�td��
}|�|�Wd�n1s�wY|�||�td�t
jj
t
��g|�d��R�}t�td��}|�|�}	|j|	|d|d
�Wd�n1s�wY|�||�t|�d�d�t�td��}|��Wd�n	1�swY|�||�t|�d�d�tt�qdS)
N�foobarr<r�r�r��subdirZsubsubrIzextract %r: %r != %r)�msgz
extract %rr)r�rBrCrr��ZipInforUr�rD�replacerr~r�r*r_r�rWr�rr�r�r
)
r6Z	hacknamesZarcnameZ	fixednamer2rFr��
targetpathr�r�rrrr��sT�����
��
�
�z+ExtractTests._test_extract_hackers_arcnamesN)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��unittestZskipIfrr�r~r�r�r�rrrrr�3s$


r�c@sPeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�dd��Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%dEdF�Z&dGdH�Z'dIdJ�Z(e)�dKdL��Z*dMdN�Z+dOS)P�
OtherTestsc
CsBt�tdtj��4}|�dd�|�t��|�dd�Wd�n1s%wY|�|��dgd�Wd�n1s?wYt�td��M}|�	�}d}|D]}|�
|��}||��7}Wd�n1skwYqS|�|dd	h�d}|D]	}||�|�7}q}|�|dd	h�Wd�dS1s�wYdS)
Nr<rnr��barr�rIr&r�sbarfoo)
rBrCrr�rDr�r�rWrdrer3rXr^)r6rFrpr+rrr�rrr�test_open_via_zip_info�s*����"�z!OtherTests.test_open_via_zip_infocCs`t�td�� }dD]}t�|�}|jdO_|�||�q	Wd�dS1s)wYdS)Nr<Zabcdefghijklmnopr>)rBrCrr��	flag_bitsrD)r6Zorig_zipr+r�rrr�-test_writestr_extended_local_header_issue1202s
�"�z8OtherTests.test_writestr_extended_local_header_issue1202cCs�t�td��}tD]\}}|�||�|�|jd�q	Wd�n1s%wY|�|jd�t�td��}|�|jd�Wd�n1sIwY|�|jd�dS)z8Check that the zipfile is closed after the 'with' block.r<zzipfp is not openN�zipfp is not closedrI)rBrCrr�rDZassertIsNotNoner7�assertIsNoner�rrr�
test_closes���zOtherTests.test_closecCs�t�td��}tD]
\}}|�||�q	Wd�n1swYzt�td��}t���1s2wYWdStjyK|�|jd�YdSw)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.r<NrIr�)rBrCrr�rDrMr�r7)r6rFr�r�Zzipfp2rrr�test_close_on_exceptions����z"OtherTests.test_close_on_exceptioncCs d}|�ttjt�|�d�dS)NsdPKx!p�@xPKxx!p�@�xPK/rI)r��NotImplementedErrorrBrCrrr�rrr�test_unsupported_version(s

�z#OtherTests.test_unsupported_versioncCsTtd�}t�|��}|��D]	}|�|���qWd�dS1s#wYdS)Nzzip_cp437_header.zip)rrBrCrdr3r�)r6r�rFrnrrr�test_read_unicode_filenames3s�"�z&OtherTests.test_read_unicode_filenamescCs�t�td��}|�dd�|�dd�|�|��djt�Wd�n1s(wYt�td��}|�|j	djd�|�|j	djd�Wd�dS1sSwYdS)Nr<�foo.txtzTest for unicode filenameuö.txtrrIrO)
rBrCrrDr�rerUrcrW�filelist�r6rWrrr�test_write_unicode_filenames;s�"�z'OtherTests.test_write_unicode_filenamescCsPt�td��}|�dd�|�|�d�d�Wd�dS1s!wYdS)Nr<uприкладssample)rBrCrrDrWrXr�rrr�'test_read_after_write_unicode_filenamesEs"�z2OtherTests.test_read_after_write_unicode_filenamescCs�tt�d}d}t�tdtj��}|�||�Wd�n1s!wY|�t��t�tdtj�Wd�n1s>wYt�td��}|�|�	�|g�|�|�
|�|�Wd�dS1sgwYdS)z&Test exclusive creating a new zipfile.�testfile.txt�#hello, world. this is some content.�xNrI)r
rrBrCr�rDr��FileExistsErrorrWrdrX)r6rUr2rFrrr�test_exclusive_create_zip_fileJs��"�z)OtherTests.test_exclusive_create_zip_filecCs�tj�t�rt�t�d}d}zt�td��}|�||�Wd�n1s'wYWnty;|�	d�Ynw|�
tj�t��t�td��}|�|�|�|�Wd�dS1s`wYdS)Nr�r�r�z1Could not append data to a non-existent zip file.rI)
rr��existsrr
rBrCrDr��failr`rWrX)r6rUr2rWrrr�(test_create_non_existent_file_for_appendWs 
���"�z3OtherTests.test_create_non_existent_file_for_appendcCs`ttddd��
}|�d�Wd�n1swYzt�t�}WdStjy/YdSw)Nr<r�r��this is not a legal zip file
)r3rr4rBrCrM)r6r7rWrrr�test_close_erroneous_fileis��z$OtherTests.test_close_erroneous_filecCs�ttddd��
}|�d�Wd�n1swY|�t�t��|�t�t�t���ttd��}|�t�|��Wd�n1sGwYt�	�}|�d�|�t�|��|�
dd�|�t�|��dS)	z;Check that is_zipfile() correctly identifies non-zip files.r<r�r�r�Nr�sthis is not a legal zip file
r)r3rr4rrB�
is_zipfiler�r�rrr�r5rrr�test_is_zip_erroneous_filexs��
z%OtherTests.test_is_zip_erroneous_filecCs�t��}tj|dd��}|�dd�Wd�n1swY|��}tt|��D]}t�|d|��}|�tj	tj|�q+dS)zCCheck that zipfiles with missing bytes at the end raise BadZipFile.r<r@r��O, for a Muse of Fire!N)
rrrBrCrDr[r'r]r�rM)r6r7r�r��Nrrr�test_damaged_zipfile�s��zOtherTests.test_damaged_zipfilecCs�tjtdd��}|�dd�Wd�n1swY|�t�t��ttd��}|�t�|��|�dd�|��}Wd�n1sGwYt	�
�}|�|�|�t�|��|�dd�|�t�|��dS)z7Check that is_zipfile() correctly identifies zip files.r<r@r�r�Nr�r)rBrCrrDr`r�r3r�rXrrr4)r6r�r7Zzip_contentsrrr�test_is_zip_valid_file�s�
�
z!OtherTests.test_is_zip_valid_filecCs|�ttjt�dSr)r�r�rBrCrr�rrr�%test_non_existent_file_raises_OSError�sz0OtherTests.test_non_existent_file_raises_OSErrorcCsvttddd�}|��|�tjtjt�ttddd��
}|�d�Wd�n1s+wY|�tjtjt�dS)Nr<r�r�z
short file)r3rr�r�rBrMrCr4)r6rr7rrr�!test_empty_file_raises_BadZipFile�s�z,OtherTests.test_empty_file_raises_BadZipFilecCs�t��}tj|dd��}|�dd�Wd�n1swY|�t|jd�|�t|jd�|�t|j	�|�t|jdd�tt
ddd	��
}|�d
�Wd�n1sXwY|�t|jt
�dS)z?Verify that testzip() doesn't swallow inappropriate exceptions.r<r@r��O, for a Muse of Fire!Nz	bogus.txtr�r�r�zzipfile test data)rrrBrCrDr�r�rXr3rhrr4)r6r+r�rrrr�!test_closed_zip_raises_ValueError�s��z,OtherTests.test_closed_zip_raises_ValueErrorcCs|�ttjtd�dS)z>Check that bad modes passed to ZipFile constructor are caught.�qN)r�r�rBrCrr�rrr�test_bad_constructor_mode�sz$OtherTests.test_bad_constructor_modecCs�tjtdd��}|�dd�Wd�n1swYtjtdd��)}|�d�|�t|jdd�|�t|jdd�|�t|jdd	�Wd�dS1sPwYdS)
z7Check that bad modes passed to ZipFile.open are caught.r<r@r�rNrIr�UZrU)rBrCrrDrXr�r�r3�r6r�rrr�test_bad_open_mode�s�
"�zOtherTests.test_bad_open_modec	Cs�tjtdd��D}|�dd�|�d�� }tt�D]}|�|�d�d�q|�|��d�Wd�n1s6wYWd�dSWd�dS1sNwYdS)	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.r<r@r�rrr&r�N)	rBrCrrDr3r'r(rWrX)r6r�rr$rrr�
test_read0�s��"�zOtherTests.test_read0cCsFtjtdd��}|�t|jdd�Wd�dS1swYdS)zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.r<r@r�rIN)rBrCrr��KeyErrorr3rrrr�test_open_non_existent_item�s"�z&OtherTests.test_open_non_existent_itemcCs|�ttjtdd�dS)zMCheck that bad compression methods passed to ZipFile.open are
        caught.r<r�N)r�r�rBrCrr�rrr�test_bad_compression_mode�sz$OtherTests.test_bad_compression_modecCsLd}t�t�|�d��}|�t|jd�Wd�dS1swYdS)NsfPK.�C�@xPK..�C�@�xPK/!rIr�)rBrCrrr�r�r3)r6r+r�rrr�test_unsupported_compression�s"�z'OtherTests.test_unsupported_compressioncCsRtjtdd��}|�dd�|�|��dg�Wd�dS1s"wYdS)zLCheck that a filename containing a null byte is properly
        terminated.r<r@zfoo.txtqqqr�r�N)rBrCrrDrWrdrrrr�test_null_byte_in_filenames"�z%OtherTests.test_null_byte_in_filenamecCs<|�tjd�|�tjd�|�tjd�|�tjd�dS)zACheck that ZIP internal structure sizes are calculated correctly.��.�8r�N)rWrBZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locatorr�rrr�test_struct_sizesszOtherTests.test_struct_sizesc	Cs�tjtdd��}|�|jd�|�dd�Wd�n1swYtjtdd��}|�|jd�Wd�n1s=wYd}tjtdd��}||_|�dd�Wd�n1s_wYtjtdd��}|�|j|�Wd�n1s}wYd	�d
d�td�D��}|�d
�}tjtdd��}||_|�dd�Wd�n1s�wYtjtdd��}|�|j|�Wd�n1s�wYtjtdd��(}|�	t
��
|d|_Wd�n1s�wY|�dd�Wd�n	1�swYtjtdd��}|�|j|�Wd�n	1�s#wYtjtdd��}d|_|�dd�Wd�n	1�sDwYtjtdd��}d|_Wd�n	1�s_wYtjtdd��}|�|jd�Wd�n	1�s~wYtjtdd��}d|_|�dd�Wd�n	1�s�wYtj�
t�}tjtdd��}d|_Wd�n	1�s�wY|�|tj�
t�k�tjtdd��}|�|jd�Wd�dS1�s�wYdS)z8Check that comments on the archive are handled properly.r<r@r&r�rNrIs9Bravely taking to his feet, he beat a very brave retreat.�cSsg|]
}d|dd�qS)r,r)r�rr"rrrr%)sz,OtherTests.test_comments.<locals>.<listcomp>�r soopssoriginal commentr�san updated commentsoriginal comment that's longersshorter comment)rBrCrrWr�rDr*r'r�r�r�rr��getsizer`)r6r�Zzipfrr�Zcomment2Zoriginal_zip_sizerrr�
test_commentssn����
����������$�zOtherTests.test_commentsc	Cs�t�tdtj��/}|�dd�|�t��d|_Wd�n1s"wYWd�dSWd�dS1s:wYdS)Nr<r�rzthis is an error)rBrCrr�rDr��	TypeErrorr�rrrr�test_unicode_commentOs��"�zOtherTests.test_unicode_commentcCs�t�tdtj��}|�|j�d|_Wd�n1swYt�td��}|�|jd�Wd�dS1s:wYdS)Nr�r�rI)rBrCrr�rr�r�rWrrrr�$test_change_comment_in_empty_archiveUs�"�z/OtherTests.test_change_comment_in_empty_archivecCs�t�tdtj��}|�dd�Wd�n1swYt�tdtj��}|�|j�d|_Wd�n1s:wYt�td��}|�|jd�Wd�dS1sXwYdS)Nr<r�rr�r�rI)	rBrCrr�rDr`r�r�rWrrrr�'test_change_comment_in_nonempty_archive\s��"�z2OtherTests.test_change_comment_in_nonempty_archivecCs�tjtdd�}|��z	tjtdd�}Wntjy#|�d�Ynwtjtdd�}|��z
tjtdd�}WdS|�d�YdS)Nr<r@rIz+Unable to create empty ZIP file in 'w' moder�z+Unable to create empty ZIP file in 'a' mode)rBrCrr�rMr�rrrr�test_empty_zipfilees�zOtherTests.test_empty_zipfilecCs.ttddd�}|��|�tjtjtd�dS)Nr<r�r�rI)r3rr�r�rBrMrCrvrrr�test_open_empty_filevszOtherTests.test_open_empty_filecCs|�ttjdd�dS)NZ	seventies)i�rOrOrrr)r�r�rBr�r�rrr�test_create_zipinfo_before_1980~s�z*OtherTests.test_create_zipinfo_before_1980cCs tjdd�}|�t|�d�dS)z=Before bpo-26185, repr() on empty ZipInfo object was failing.�emptyrTz&<ZipInfo filename='empty' file_size=0>N)rBr�rWr��r6�zirrr�test_create_empty_zipinfo_repr�sz)OtherTests.test_create_empty_zipinfo_reprcCs�t��}|�|jd�|�|jd�|�|jd�|�|jtj�|�|jd�|�|j	d�|�
|jd�|�|jtj
�|�|jtj
�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�dS)z'Ensure all required attributes are set.ZNoNamerr&)rr)rN)rBr�rWZ
orig_filenamerUrr�r�r�r<r^Z
create_systemZcreate_versionZDEFAULT_VERSIONZextract_versionZreservedr�ZvolumeZ
internal_attrr�rfrJrrrr�,test_create_empty_zipinfo_default_attributes�s"z7OtherTests.test_create_empty_zipinfo_default_attributescCsJd}t�t�|�d��}|�|���Wd�dS1swYdS)z>If an extra field in the header is less than 4 bytes, skip it.snPK���@����abcAPK���@������abcPK3%rIN)rBrCrrr�rh�r6r�r�rrr�#test_zipfile_with_short_extra_field�s
�	"�z.OtherTests.test_zipfile_with_short_extra_fieldc
Cspd}d}d}t�tdtj���}|jddd��
}|�|�Wd�n1s&wY|jddd���}|�t��|jddd�Wd�n1sJwY|�t��|jdd	d�Wd�n1sfwY|�t��|�d
d�Wd�n1s�wY|�t��|�t	d�Wd�n1s�wY|�t��|�
�Wd�n1s�wY|�|�Wd�n1s�wY|jd
dd��
}|�|�Wd�n1s�wYWd�n1s�wYt�td	��.}|�|�d�|�|�|�d�|�|�|�d
�|�|�|�
�gd��Wd�dS1�s1wYdS)Ns"It's fun to charter an accountant!s And sail the wide accountant seas#To find, explore the funds offshorer<r�r@r��handlerIrcZabcderJ�baz)r�r�r&)rBrCrr�r3r4r�r�rDr{r�rWrXrd)r6Zmsg1Zmsg2Zmsg3r�Zw2�w1rrr�test_open_conflicting_handles�sH�����
�����$�z(OtherTests.test_open_conflicting_handlesc	Cs�d}|�d�}t�td��}|�d|�Wd�n1swYt�td��{}|�dd��e}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�Wd�n1s�wYWd�n1s�wYt��}tj|dd��}|�d|�Wd�n1s�wYtj|dd���}|�dd��e}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�Wd�n1�sDwYWd�dSWd�dS1�s]wYdS)	NsWhere's Bruce?sBrucer<r�rIrrKr@)�findrBrCrrDr3r�r�SEEK_SETrWr��SEEK_CURrX�SEEK_ENDr]rr)r6�txt�blocr�r7r+rrr�test_seek_tell�sT
����� ��$�zOtherTests.test_seek_tellc	Cs�d}t�|�}tj|dtjd��}|�dd�Wd�n1s!wYt�dd��.t�|��}|�t	|j
d�Wd�n1sEwYWd�dSWd�dS1s]wYdS)NsPKr<)r:r��azzipfile.bz2)rrrBrCrrD�mockZpatchr�r�r�)r6r+Zzip_filerWrrr�)test_decompress_without_3rd_party_library�s
���"�z4OtherTests.test_decompress_without_3rd_party_librarycCr�rr�r�rrrr��r�zOtherTests.tearDownN),r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�rrrrrr	rrr
rrrrrrrrrr!r"r$r(r/r	r2r�rrrrr��sT



	
:	&
	r�c@seZdZdd�Zdd�ZdS)�AbstractBadCrcTestscCsP|j}tjt�|�dd��}|�d|���Wd�dS1s!wYdS)z>Tests that files with bad CRCs return their name from testzip.rIr@�afileN)�zip_with_bad_crcrBrCrrrWrhr#rrr�test_testzip_with_bad_crc�s"�z-AbstractBadCrcTests.test_testzip_with_bad_crcc
Csz|j}tjt�|�dd��}|�tj|jd�Wd�n1s!wYtjt�|�dd��&}|�dd��}|�tj|j�Wd�n1sJwYWd�n1sYwYtjt�|�dd��K}|�dd��,}d|_	|�tj��|�d�r�	|�d�sWd�n1s�wYWd�n1s�wYWd�dSWd�dS1s�wYdS)zFTests that files with bad CRCs raise a BadZipFile exception when read.rIr@r4Nr�)
r5rBrCrrr�rMrXr3�
MIN_READ_SIZE)r6r�r�Zcorrupt_filerrr�test_read_with_bad_crcs0����

������"�z*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�r6r8rrrrr3�sr3c@�eZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�rBr�r:r5rrrrr:s�r:c@r9)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�rBrr:r5rrrrr;)��r;c@r9)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�rBrr:r5rrrrr=6r<r=c@r9)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�rBr r:r5rrrrr>Fr<r>c@s^eZdZdZdZdZdZdZdd�Zdd	�Z	d
d�Z
dd
�Ze�dd��Z
dd�Zdd�ZdS)�DecryptionTestsz�Check that ZIP decryption works. Since the library does not
    support encryption at the moment, we use a pre-generated encrypted
    ZIP file.s�PKn�i.#y�?&test.txt��gly|�-�=�y�r�Z}Lg���|�䋺�)���lPKn�i.#y�?& ��test.txtPK6Ls�PK	�}38xu��zeroUT	֋�Gڋ�GUx���<M�a�X�Y&�{oEם���PKxu��PK	�}38xu��
��zeroUT֋�GUxPK?[szipfile.py encryption testscCs�ttd��}|�|j�Wd�n1swYt�td�|_ttd��}|�|j�Wd�n1s8wYt�td�|_	dS)Nr1rI)
r3rr4r+rBrCr�r�data2�zip2r5rrrr8os��zDecryptionTests.setUpcCs,|j��t�t�|j��t�t�dSr)r�r�rr
rrArr�rrrr�ws


zDecryptionTests.tearDowncCs(|�t|jjd�|�t|jjd�dS)N�test.txt�zero)r�r�r�rXrAr�rrr�test_no_password}sz DecryptionTests.test_no_passwordcCs@|j�d�|�t|jjd�|j�d�|�t|jjd�dS)NsperlrBrC)r��setpasswordr�r�rXrAr�rrr�test_bad_password�sz!DecryptionTests.test_bad_passwordcCsH|j�d�|�|j�d�|j�|j�d�|�|j�d�|j�dS)N�pythonrBs12345rC)r�rErWrX�plainrA�plain2r�rrr�test_good_password�sz"DecryptionTests.test_good_passwordcCsV|�t|jjd�|�t|jjdd�|jt|jjddd�|jt|jjddd�dS)N�unicoderBZpython)�pwd)r�rr�rErXr3r�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�dS1s�wYdS)NrGs
encryptionrBrIrrOr&)r�rErHr)r]r3r�rr*rWr�r+rXr7Z_readbufferZ_offsetr,)r6r-Z	test_wordr.Zbloc_lenr7Z
old_read_sizerrrr/�s8

"�zDecryptionTests.test_seek_tellN)r�r�r��__doc__r+r@rHrIr8r�rDrFrrJrMr/rrrrr?Us �	�

r?c@s`eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�"AbstractTestsWithRandomBinaryFilescCs6tdd�dtdd�}d�dd�t|�D��|_dS)N��@r�rOr&css(�|]}t�dt�tdd��VqdS)z<fi���rN)rrCrrr"rrrr"�s� �z@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>)rr*r'r+)r-Z	datacountrrrr.�s
�z-AbstractTestsWithRandomBinaryFiles.setUpClasscCr/r0r2r5rrrr8�r9z(AbstractTestsWithRandomBinaryFiles.setUpcCr�rr�r�rrrr��r�z+AbstractTestsWithRandomBinaryFiles.tearDowncCsLt�|d|��}|�td�|�tt�Wd�dS1swYdS)Nr<r=)rBrCr4rr8rrrrH�s"�z4AbstractTestsWithRandomBinaryFiles.make_test_archivecCs�|�||�t�|d|��*}|�t�}|�t|�t|j��|�||j�|�|�d�|j�Wd�dS1s:wYdS)NrIr=)rHrBrCrXrrWr]r+)r6rr:rF�testdatarrrrs�s
"�z+AbstractTestsWithRandomBinaryFiles.zip_testcCrtrrurvrrr�	test_read�rxz,AbstractTestsWithRandomBinaryFiles.test_readc	Cs4|�||�t�|d|���}g}|�t��}	|�d�}|sq%|�|�qWd�n1s/wYg}|�d��}	|�d�}|sEqK|�|�q=Wd�n1sUwYd�|�}	|�t	|	�t	|j
��|�|	|j
�d�|�}
|�t	|
�t	|j
��|�|
|j
�Wd�dS1s�wYdSry)rHrBrCr3rrXr{r*rWr]r+)r6rr:rFr|r}r~rr�Z	testdata1Z	testdata2rrrr��s:

��

��

"�z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCrtrr�rvrrrr��rxz,AbstractTestsWithRandomBinaryFiles.test_openc	Cs�|�||�t�|d|��I}g}|�t��}	|�tdd��}|s"q(|�|�qWd�n1s2wYd�|�}|�	t
|�t
|j��|�	||j�Wd�dS1sYwYdSr�)rHrBrCr3rrXrr{r*rWr]r+)r6rr:rFr|r}r~rRrrrr�	s 
��
"�z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCrtrr�rvrrrr�	rxz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r.r8r�rHrsrSr�r�r�r�rrrrrO�s

rOc@r)� StoredTestsWithRandomBinaryFilesNrgrrrrrT	rirTc@r)�!DeflateTestsWithRandomBinaryFilesNrZrrrrrU	rrUc@r)�Bzip2TestsWithRandomBinaryFilesNrrrrrrV 	rrVc@r)�LzmaTestsWithRandomBinaryFilesNrrrrrrW%	rrWc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TellablecCs||_d|_dS�Nr)r7�offsetr5rrr�__init__-	s
zTellable.__init__cCs|j�|�}|j|7_|Sr)r7r4rZ)r6r+�nrrrr41	szTellable.writecCs|jSr)rZr�rrrr�6	sz
Tellable.tellcC�|j��dSr�r7�flushr�rrrr_9	�zTellable.flushN)r�r�r�r[r4r�r_rrrrrX,	s
rXc@r])�
UnseekablecCs
||_dSr)r7r5rrrr[=	s
zUnseekable.__init__cCs|j�|�Sr)r7r4r�rrrr4@	razUnseekable.writecCr]rr^r�rrrr_C	r`zUnseekable.flushN)r�r�r�r[r4r_rrrrra<	srac@r])�UnseekableTestscCsfdd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��}|�
dd�|�
dd	�Wd�n1s?wY|�|��dd
�d�tj|dd
��B}|�
d��}|�|��d�Wd�n1spwY|�
d��}|�|��d	�Wd�n1s�wYWd�n1s�wYWd�n1s�wYqdS)NcS�|Srr�rrrrr�H	r�z/UnseekableTests.test_writestr.<locals>.<lambda>��wrapper�abcr<�ones�111�twos�222rK�abcPKrIr@)rXra�subTestrrr4�BufferedWriterrBrCr�rDrWr[r3rX)r6rfr�bfrFr��zopenrrr�
test_writestrG	s.

���������zUnseekableTests.test_writestrcCs�dd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��N}|�
tt�t
td��
}|�d�Wd�n1sDwY|�td�t
td��
}|�d	�Wd�n1sdwY|�td
�Wd�n1sywY|�|��dd�d�tj|d
d��B}|�
d��}|�|��d�Wd�n1s�wY|�
d
��}|�|��d	�Wd�n1s�wYWd�n1s�wYWd�n1s�wYqdS)NcSrcrrrdrrrr�X	r�z,UnseekableTests.test_write.<locals>.<lambda>rergr<r1rirhrkrjrKrlrIr@)rXrarmrrr4rnrBrCr��
addCleanupr
rr3rWr[rX)r6rfrrorF�f2r�rprrr�
test_writeW	s<

�����������zUnseekableTests.test_writecCsfdd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��>}|�
dd��
}|�d�Wd�n1s?wY|�
dd��
}|�d	�Wd�n1sZwYWd�n1siwY|�|��dd
�d�t�|��}|�|�
d�d�|�|�
d�d	�Wd�n1s�wYWd�n1s�wYqdS)NcSrcrrrdrrrr�m	r�z1UnseekableTests.test_open_write.<locals>.<lambda>rergr<rhrirjrkrKrl)rXrarmrrr4rnrBrCr�r3rWr[rX)r6rfrror�rprrr�test_open_writel	s.

���������zUnseekableTests.test_open_writeN)r�r�r�rqrtrurrrrrbF	srbc@sheZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestsWithMultipleOpenscCs dtd�|_dtd�|_dS)Nri�'rk)r�data1r@r,rrrr.	sz!TestsWithMultipleOpens.setUpClasscCsRt�|dtj��}|�d|j�|�d|j�Wd�dS1s"wYdS)Nr<rhrj)rBrCrrDrxr@)r6rrFrrrrH�	s"�z(TestsWithMultipleOpens.make_test_archivecCs�t|�D]k}|�|�tj|dd��U}|�d��3}|�d��}|�d�}|�d�}||��7}||��7}Wd�n1s?wYWd�n1sNwY|�||�|�||j�Wd�n1sjwYqdS)NrIr@rh��)rrHrBrCr3rXrWrx�r6rr��zopen1�zopen2rxr@rrr�test_same_file�	s 


�����z%TestsWithMultipleOpens.test_same_filecCs�t|�D]l}|�|�tj|dd��V}|�d��3}|�d��}|�d�}|�d�}||��7}||��7}Wd�n1s?wYWd�n1sNwY|�||j�|�||j�Wd�n1skwYqdS)NrIr@rhrjry�	rrHrBrCr3rXrWrxr@rzrrr�test_different_file�	s 


�����z*TestsWithMultipleOpens.test_different_filecCs�t|�D]l}|�|�tj|dd��V}|�d��3}|�d�}|�d��}|�d�}||��7}||��7}Wd�n1s?wYWd�n1sNwY|�||j�|�||j�Wd�n1skwYqdS)NrIr@rhryrjr~)r6rr�r{rxr|r@rrr�test_interleaved�	s"


������z'TestsWithMultipleOpens.test_interleavedc
Cs�t|�D]e}|�|�t���D}t�|d��}|�|�d��}|�|�d��}Wd�n1s1wY|�d�}|�d�}||��7}||��7}Wd�n1sVwY|�	||j
�|�	||j�qdS)NrIrhrjry)rrH�
contextlib�	ExitStackrBrC�
enter_contextr3rXrWrxr@)r6r�stackr�r{r|rxr@rrr�test_read_after_close�	s

�

��z,TestsWithMultipleOpens.test_read_after_closec
Cst|�D]{}t�|dtj��0}|�d|j�|�d|j�|�d��
}|�d�}Wd�n1s2wYWd�n1sAwY|�	||jdd��t�|d��}|�d�}|�d�}Wd�n1slwY|�	||j�|�	||j�qdS)Nr<rhrjryrI)
rrBrCrrDrxr@r3rXrW�r6rr�r{rxr@rrr�test_read_after_write�	s"���
��z,TestsWithMultipleOpens.test_read_after_writec
Cs�t|�D]p}t�|dtj��0}|�d|j�|�d��}|�d�|�d|j�Wd�n1s2wYWd�n1sAwYt�|d��}|�d�}|�d�}Wd�n1sawY|�	||j�|�	||j�qdS)Nr<rhryrjrI)
rrBrCrrDrxr3rXr@rWr�rrr�test_write_after_read�	s 
���
��z,TestsWithMultipleOpens.test_write_after_readc
Cs�|�t�tjtdd��)}td�D]}|�d�|�d��}Wd�n1s(wYqWd�n1s8wYttjd��}|�	|�
�d�Wd�dS1sWwYdS)NrIr@r�rhr�)rHrrBrCr'rXr3r�devnullZ
assertLess�fileno)r6r�r�r{rrrr�test_many_opens�	s

����"�z&TestsWithMultipleOpens.test_many_opensc
Cs:t�tdtj��}|�d|j�Wd�n1swYt�tdtj��E}|�dd��/}|�d�}|�dd��}|�|j	�Wd�n1sKwY||��7}Wd�n1s`wYWd�n1sowY|�
||j�t�t��}|�
|�d�|j	�Wd�dS1s�wYdS)Nr<rhr�rIryrj)rBrCrrrDrxr3rXr4r@rW)r6r�Zr1rxr'rrr�test_write_while_reading�	s"�
����"�z/TestsWithMultipleOpens.test_write_while_readingcCr_rr`r�rrrr��	razTestsWithMultipleOpens.tearDownN)r�r�r�r�r.rHr}rr�r�r�r�r�r�r�rrrrrv}	s


rvc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestWithDirectorycCst�t�dSr)rr�rr�rrrr8�	r`zTestWithDirectory.setUpc
Cs�t�td���
}|�t�Wd�n1swY|�tj�tj�	td���|�tj�tj�	tdd���|�tj�
tj�	tddd���dS)N�
zipdir.zipr��brV)rBrCrr�rr`rr��isdirr*r�rrrr�test_extract_dir�	s�$z"TestWithDirectory.test_extract_dircCs t�tj�td��|��dS�Nr�)rr�r�r*rr�r�rrr�
test_bug_6050
szTestWithDirectory.test_bug_6050c	Cs�tj�td�}t�|�t�|�jd@}t�t	d��C}|�
|�|jd}|�|j
�d��|�|j|d>dB�|�
|d�|jd}|�|j
d	�|�|j|d>dB�Wd�n1s`wYt�t	d
��c}|jd}|�|j
�d��|�|j|d>dB�|jd}|�|j
d	�|�|j|d>dB�tj�td�}t�|�|�|�|�tj�tj�|d���|�tt�|��d�Wd�dS1s�wYdS)
Nr�rr<rz/x/rP�yrOzy/rIr�r�)rr�r*rr�r�st_moderBrCrr4r�r`rUr}rWr�r�r�r]�listdir)r6�dirpathrAr�r�r�rrr�test_write_dir
s4



�	



"�z TestWithDirectory.test_write_dirc	Cs t�tj�td��t�td��!}|�dd�|j	d}|�
|jd�|�
|jd�Wd�n1s4wYt�td��G}|j	d}|�
|j�d��|�
|jd�tj�td�}t�|�|�|�|�
tj�tj�|d���|�
t�|�dg�Wd�dS1s�wYdS)	Nr�r<zx/r&ri�ArIr�)rr�r�r*rrBrCrrDr�rWrUr�r`r}r�r�r�)r6r�r�r�rrr�test_writestr_dir%
s"
�


"�z#TestWithDirectory.test_writestr_dircCs$tt�tj�t�rtt�dSdSr)rrrr�r�rr
r�rrrr�6
s�zTestWithDirectory.tearDownN)	r�r�r�r8r�r�r�r�r�rrrrr��	sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ZipInfoTestscCsHtj�t�}|�t�|j�d�|�|�	��|�|j
tj�
t��dS�Nztest_zipfile.py)rBr��	from_filer{rW�	posixpathr�rUr�is_dirrfrr�rrrrr�test_from_file=
szZipInfoTests.test_from_filecCsNtj�t�t��}|�t�|j	�d�|�
|���|�|jt
j�t��dSr�)rBr�r�r�r�r{rWr�r�rUrr�rfrr�rrrrr�test_from_file_pathlikeC
sz$ZipInfoTests.test_from_file_pathlikecCsPtj�t�t�d�}|�t�|j	�d�|�
|���|�|jtj
�t��dS)Nr)rBr�r�r�fsencoder{rWr�r�rUrr�rfr�rrrrr�test_from_file_bytesI
sz!ZipInfoTests.test_from_file_bytescCszttd��.}tj�|��d�}|�t�|j	�d�|�
|���|�|jt
j�t��Wd�dS1s6wYdS)Nr�r)r3r{rBr�r�r�rWr�r�rUrr�rfrr�r)r6rr rrr�test_from_file_filenoO
s"�z"ZipInfoTests.test_from_file_filenocCs`tj�tj�t��}tj�|d�}|�|j	d�|�
|���|�|jtj
�|�|jd�dS)NZstdlib_testsz
stdlib_tests/r)rr�rz�abspathr{rBr�r�rWrUr`r�r�r�rf)r6r�r rrr�
test_from_dirV
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�-mrBr#)rZassert_python_okr�r�linesepr�)r6�argsrE�rc�out�errrrr�
zipfilecmda
s�zCommandLineTest.zipfilecmdcGstjddg|�R�S)Nr�rB)rZassert_python_failure)r6r�rrr�zipfilecmd_failuref
r�z"CommandLineTest.zipfilecmd_failurecCs||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr&susageserrorsrequired�-lr)r�rWr^rOZassertNotEqual�strip)r6r�r�r�rrr�test_bad_usei
szCommandLineTest.test_bad_usecCsXtd�}dD]}|�||�}|�|��d�qtd�}|�d|�\}}}|�|d�dS)Nr�)�-tz--testsDone testingztesttar.tarr�r&)rr�rW�rstripr�)r6�zip_name�optr�r�r�rrr�test_test_commands
sz!CommandLineTest.test_test_commandcCs�td�}t��}t�|d��
}|�|�Wd�n1swY|���dd�}dD]}|j||dd�}|�	||�q-dS)Nr�rIr �backslashreplace)r�z--listzascii:backslashreplace)ZPYTHONIOENCODING)
rrrYrBrCrZr[r�r�rW)r6r�r�ZtfZexpectedr�r�rrr�test_list_command|
s���z!CommandLineTest.test_list_commandc	Cs`|�tt�ttddd��
}|�d�Wd�n1swYt�t�|�tt�ttj	�
td�ddd��
}|�d�Wd�n1sIwYttg}ttdtdg}d	D]P}zI|j|tg|�R�}|�
|d
�t�t��&}|�
|��|�|�
|�|d�d�|�
|�|d
�d�Wd�n1s�wYWtt�q]tt�wdS)Nr<r�r�ztest 1�file.txtztest 2r�z	/file.txt)z-cz--creater&rstest 1r�stest 2)rrr
rr3r4rr��	TESTFNDIRrr�r*r�rrWrBrCrdrX)r6r�filesrdr�r�rWrrr�test_create_command�
s.�
����z#CommandLineTest.test_create_commandc	Cstd�}dD]�}t��u}|�|||�}|�|d�t�|��S}|��D]F}tj�	||j
�dtj��}|�
�r@|�tj�|��q#|�tj�|��t|d��}|�|��|�|��Wd�n1sdwYq#Wd�n1stwYWd�n1s�wYqdS)Nr�)z-ez	--extractr&r�r�)rrr�rWrBrCrerr�r*rUr�r~r�r`r�r�r3rX)	r6r�r�r�r�rWr r�rrrr�test_extract_command�
s.���������z$CommandLineTest.test_extract_commandN)r�r�r�r�r�r�r�r�rr�r�rrrrr�_
s
	
r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	e
jd
�e�	e�
dej�d�d
d���Ze�	e
jd
�e�	e�
dej�d�dd���ZdS)�TestExecutablePrependedZipz@Test our ability to open zip files with an executable prepended.cCs tddd�|_tddd�|_dS)NZexe_with_zipZziptestdata)r�Zexe_with_z64)r�exe_zip�	exe_zip64r�rrrr8�
sz TestExecutablePrependedZip.setUpcCsl|�t�|�d|���t�|��}|��D]
}|�|�}|�d|�qWd�dS1s/wYdS)Nzis_zipfile failed on sFAVORITE_NUMBER)r`rBr�rCrdrXr^)r6rnrFr\r+rrr�_test_zip_works�
s�
�"�z*TestExecutablePrependedZip._test_zip_workscC�|�|j�dSr)r�r�r�rrr� test_read_zip_with_exe_prepended�
�z;TestExecutablePrependedZip.test_read_zip_with_exe_prependedcCr�r)r�r�r�rrr�"test_read_zip64_with_exe_prepended�
r�z=TestExecutablePrependedZip.test_read_zip64_with_exe_prependedzsys.executable required.z	/bin/bashz#Test relies on #!/bin/bash working.cC�"t�|jtjg�}|�d|�dS�Nsnumber in executable: 5)�
subprocess�check_outputr��sys�
executabler^�r6�outputrrr�test_execute_zip2�
�z,TestExecutablePrependedZip.test_execute_zip2cCr�r�)r�r�r�r�r�r^r�rrr�test_execute_zip64�
r�z-TestExecutablePrependedZip.test_execute_zip64N)r�r�r�rNr8r�r�r�r�Z
skipUnlessr�r�rrp�X_OKr�r�rrrrr��
s 
��r�c@�eZdZGdd�d�ZdS)�jaracoc@r�)zjaraco.itertoolsc@r])zjaraco.itertools.CountercCsd|_t|�|_dSrY)r��iter�
_orig_iter)r6r$rrrr[�
sz!jaraco.itertools.Counter.__init__cCrcrrr�rrr�__iter__�
sz!jaraco.itertools.Counter.__iter__cCst|j�}|jd7_|Sr�)�nextr�r�)r6�resultrrr�__next__�
s
z!jaraco.itertools.Counter.__next__N)r�r�r�r[r�r�rrrr�Counter�
sr�N)r�r�r�r�rrrrrR�
�rRN)r�r�r�rRrrrrr��
r�r�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&)rB�CompleteDirs�
_implied_dirsrdrD)rWrnrrr�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 i�alpharep.zip)rrrBrCrDrU)r+rWrrr�build_alpharep_fixture�
sr�cst����fdd��}|S)zZ
    Given a method, wrap it in a for loop that invokes method
    with each subtest.
    cs|��D]}�||d�qdS)N)�alpharep)�zipfile_alpharep)r6r���methrrrfs�zpass_alpharep.<locals>.wrapper)�	functools�wraps)r�rfrr�r�
pass_alpharepsr�c@sxeZdZdd�Zdd�Zdd�Zedd��Zed	d
��Zedd��Z	ed
d��Z
edd��Zdd�Zdd�Z
edd��Zdd�Zedd��Zedd��Zedd��Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zed)d*��Zed+d,��Zed-d.��Zd/Zd0d1�Zd2d3�Zd4d5�Zed6d7��Zed8d9��Z ed:d;��Z!ed<d=��Z"ed>d?��Z#ed@dA��Z$edBdC��Z%dDS)E�TestPathcCst��|_|�|jj�dSr)r�r��fixturesrrr�r�rrrr8's
zTestPath.setUpccsl�|���t�VWd�n1swY|���tt��VWd�dS1s/wYdSr)rmr�r�r�rrrr�+s�

�
"�zTestPath.zipfile_alpharepcCsjt�|j�t���}|j}|��||j}|�d��}|�	|�
��Wd�|S1s.wY|Sr0)r�r�r�r�rr7r�rUr3r4r[)r6r�Ztmpdir�bufferr��strmrrr�zipfile_ondisk1s

��zTestPath.zipfile_ondiskcCs�t�|�}|��sJ�|��\}}}|��sJ�|��sJ�|��s$J�|��\}}}|��r3|��s5J�|��\}	|	��s@J�|��\}
|
��\}|��sPJ�dSr)rBr�r��iterdir�is_file)r6r��rootr�r��grVrrrP�hr$rrr�test_iterdir_and_types:s



zTestPath.test_iterdir_and_typescCs t�|�}|�d���rJ�dS)Nzmissing.txt)rBr��joinpathr��r6r�r�rrr�test_is_file_missingJs
zTestPath.test_is_file_missingcCsPt�|�}|��\}}}|�t��
|��Wd�dS1s!wYdSr)rBr�r�r�r��r6r�r�r�r�r�rrr�test_iterdir_on_fileOs


"�zTestPath.test_iterdir_on_filecCsNt�|�}|d��s
J�|d��sJ�|d��sJ�|d��s%J�dS)Nr��b/r�zg/)rBr�r�r�rrr�test_subdir_is_dirVs

zTestPath.test_subdir_is_dircCs\t�|�}|��\}}}|jdd��}|��}Wd�n1s!wY|dks,J�dS)Nr�r��content of a)rBr�r�r3rX)r6r�r�r�r�r�r�r+rrrr�^s

�zTestPath.test_opencCs�t�tjt��dd��}|�d��d��
}|�d�Wd�n1s$wY|�d�jddd	��}|�d
�Wd�dS1sDwYdS)zo
        If the zipfile is open for write, it should be possible to
        write bytes or text to it.
        r<r@zfile.binr1sbinary contentsNr�r�r�z	text file)rBr�rCrrr�r3r4)r6rWr�rrrrufs�"�zTestPath.test_open_writecC�Nt�tt���}|�t��|�d���Wd�dS1s wYdS)zJ
        Attempting to open a directory raises IsADirectoryError.
        r�N)rBr�r�r�r��IsADirectoryErrorr�r3r�rrr�test_open_extant_directoryq�"�z#TestPath.test_open_extant_directorycCs�t�|�}|�t��|�d�jddd�Wd�n1swY|�t��|�d��dd�Wd�dS1s>wYdS)Nr�r�r�r�)rBr�r�r�r�r3r�rrr�test_open_binary_invalid_argsys
�"�z&TestPath.test_open_binary_invalid_argscCr�)zR
        Attempting to open a missing directory raises FileNotFoundError.
        �zN)rBr�r�r�r��FileNotFoundErrorr�r3r�rrr�test_open_missing_directory�r�z$TestPath.test_open_missing_directorycCs@t�|�}|��\}}}|jdd�dksJ�|��dksJ�dS)Nr�r�r�r�)rBr�r��	read_text�
read_bytesr�rrrrS�s
zTestPath.test_readcCsNt�|�}|�d�}|��sJ�|�d��d��d�}|jdd�dks%J�dS�Nr�r�r�e.txtr�r��content of e)rBr�r�r�r�r6r�r�r�rPrrr�
test_joinpath�s


zTestPath.test_joinpathcCs0t�|�}|�ddd�}|jdd�dksJ�dS)Nr�rrr�r�r)rBr�r�r)r6r�r�rPrrr�test_joinpath_multiple�s
zTestPath.test_joinpath_multiplecCsFt�|�}|d}|��sJ�|ddd}|jdd�dks!J�dSr)rBr�r�rr	rrr�test_traverse_truediv�s

zTestPath.test_traverse_truedivcCstddddd�}t|�dS)zI
        Disable the __future__.division when testing traversal.
        zzipfile.Path(alpharep) / 'a'z(test)�evalT)�sourcerUrA�dont_inheritN)�compiler
)r6r��coderrr�test_traverse_simplediv�s�z TestPath.test_traverse_simpledivcCs&|�|�}t�t|��}t�|�dS)zN
        zipfile.Path should be constructable from a path-like object
        N)r�r�r�rcrB)r6r�r�Zpathlikerrr�test_pathlike_construction�s
z#TestPath.test_pathlike_constructioncCst�|�}|t�d�dSr�)rBr�r�r�rrr�test_traverse_pathlike�s
zTestPath.test_traverse_pathlikecCs:t�|�}|djjdksJ�|ddjjdksJ�dS)Nr�rr�za/�rBr��parentZatr�rrr�test_parent�s
zTestPath.test_parentcCs6t�|�}|djjdksJ�|djjdksJ�dS)Nr�rr�rr�rrr�test_dir_parent�s
zTestPath.test_dir_parentcCs"t�|�}|djjdksJ�dS)Nzmissing dir/rrr�rrr�test_missing_dir_parent��
z TestPath.test_missing_dir_parentcCs�t�|�}|��\}}}|�dd�|�dd�tdd�|��D��s%J�|djdd�dks1J�|d	��\}|jdd�dksBJ�d
S)zk
        If the underlying zipfile is changed, the Path object should
        reflect that change.
        r�r�zbar/baz.txtr&css�|]}|jdkVqdS)r�N)rn)r#�childrrrr"�s�z+TestPath.test_mutability.<locals>.<genexpr>r�r�r�N)rBr�r�rD�anyr)r6r�r�r�r�r�r&rrr�test_mutability�s
zTestPath.test_mutabilityi cCs@t��}t�|d�}ttt|j��D]}|�||�qd|_	|S)zACreate a read-only zipfile with a huge number of entries entries.r<rI)
rrrBrC�maprcr'�HUGE_ZIPFILE_NUM_ENTRIESrDrA)r6r�rW�entryrrr�huge_zipfile�szTestPath.huge_zipfilecCsFt�|���}tj�|���}|D]}|�d�q|j|j	ks!J�dS)zE
        Ensure joinpath on items in zipfile is linear time.
        �suffixN)
rBr�r!r�rRr�r�r�r�r)r6r��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_lowercaserc)r#r\rrrr%�s z:TestPath.test_implied_dirs_performance.<locals>.<listcomp>rw)r'rBr�r�r�rrr�test_implied_dirs_performance�sz&TestPath.test_implied_dirs_performancecCs\|�|�}t�|��}td�D]}t�|d�jdd�qWd�dS1s'wYdS)Nr�r�r�r�)r�rBrCr'r�r)r6r�rJZreprrr�test_read_does_not_close�s
�"�z!TestPath.test_read_does_not_closecCs0Gdd�dtj�}||�}t|d|�sJ�dS)Nc@seZdZdS)z(TestPath.test_subclass.<locals>.SubclassN)r�r�r�rrrr�Subclasssr)r�)rBr�r�)r6r�r)r�rrr�
test_subclassszTestPath.test_subclasscCs"t�|�}|jt�d�ksJ�dS)Nr�)rBr�rUr�r�rrr�
test_filenamerzTestPath.test_filenamecCs0t�|�}|jdkr|jjksJ�J�dS)zH
        The name of the root should be the name of the zipfile
        r�N)rBr�rnrUr�rrr�test_root_names
&zTestPath.test_root_namecCs>t�|�}|jt�d�ksJ�d|j_|jt�d�ksJ�dS)N�.zfoo/bar.zipr�)rBr�rr�r�rUr�rrr�test_root_parents
zTestPath.test_root_parentcCs�d|_t�|�}|�t��|jWd�n1swY|�t��|jWd�n1s3wY|d}|jdksCJ�|jsHJ�dS)zd
        It is an error to attempt to get the name
        or parent of an unnamed zipfile.
        Nr�)rUrBr�r�rrnr)r6r�r��subrrr�test_root_unnameds
��zTestPath.test_root_unnamedcCs@tdtjfi�}|��D]}||��d�j}t||�sJ�qdS)NZ	PathChildzsome dir)�typerBr�r�r�rr�)r6r�r-rJrrr�test_inheritance1s
�zTestPath.test_inheritanceN)&r�r�r�r8r�r�r�r�r�r�r�r�rur�rrrSr
rrrrrrrrrrr!r$r'r(r*r+r,r.r0r2rrrrr�&sv	
















	





r��__main__)Yr��importlib.utilr�rrRrr�r�r%rr�r�rar�Z
unittest.mockr1rBr��tempfilerrrrZtest.supportrrrr	r
rZtest.support.os_helperrr
rrrrr�r(Z
DATAFILES_DIRr�rrZTestCaser�rrrr!r6rYr[r\r^rfrhrjrkrlr�r�r3r:r;r=r>r?rOrTrUrVrWrXrarbrvr�r�r�r��tupleZconsumer�r�r�r�r�r��mainrrrr�<module>s	�C�������BAg[����
7}A#P'
$
�
© 2025 GrazzMean