Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_zipfile.cpython-310.pyc
o

�9j'�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlZddlZddlmZddlZddlZddlmZddlmZmZmZddlmZddlmZmZmZm Z m!Z!ddl"m#Z#m$Z$m%Z%m&Z&m'Z'e#dZ(e#d	Z)d
Z*dZ+gd�Z,d
d�Z-Gdd�d�Z.Gdd�de.ej/�Z0e�Gdd�de.ej/��Z1e�Gdd�de.ej/��Z2e �Gdd�de.ej/��Z3Gdd�d�Z4Gdd�de4ej/�Z5e�Gdd�de4ej/��Z6e�Gdd �d e4ej/��Z7e �Gd!d"�d"e4ej/��Z8Gd#d$�d$�Z9Gd%d&�d&e9ej/�Z:e�Gd'd(�d(e9ej/��Z;e�Gd)d*�d*e9ej/��Z<e �Gd+d,�d,e9ej/��Z=Gd-d.�d.ej/�Z>Gd/d0�d0ej/�Z?Gd1d2�d2ej/�Z@Gd3d4�d4�ZAGd5d6�d6eAej/�ZBe�Gd7d8�d8eAej/��ZCe�Gd9d:�d:eAej/��ZDe �Gd;d<�d<eAej/��ZEGd=d>�d>ej/�ZFGd?d@�d@�ZGGdAdB�dBeGej/�ZHe�GdCdD�dDeGej/��ZIe�GdEdF�dFeGej/��ZJe �GdGdH�dHeGej/��ZKGdIdJ�dJ�ZLGdKdL�dL�ZMGdMdN�dNej/�ZNe�GdOdP�dPej/��ZOGdQdR�dRej/�ZPGdSdT�dTej/�ZQGdUdV�dVej/�ZRGdWdX�dXej/�ZSeTZUGdYdZ�dZ�ZVd[d\�ZWd]d^�ZXd_d`�ZYGdadb�dbej/�ZZGdcdd�ddej[�Z\Gdedf�dfej/�Z]e^dgk�rTe�_�dSdS)h�N)�assert_python_ok)�
TemporaryFile)�randint�random�	randbytes)�
script_helper)�findfile�
requires_zlib�requires_bz2�
requires_lzma�captured_stdout)�TESTFN�unlink�rmtree�temp_dir�temp_cwd�2�d���zipfile_datafiles))�	_ziptest1�
1q2w3e4r5t)zziptest2dir/_ziptest2�
qawsedrftg)z!ziptest2dir/ziptest3dir/_ziptest3�
azsxdcfvgb)z-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3�
6y7u8i9o0pccs��tVt��}|V|�|j�Wd�n1swYt���}|V|�|j�Wd�dS1s9wYdS�N)�TESTFN2r�assertFalse�closed�io�BytesIO)�test�f�r#�(/usr/lib/python3.10/test/test_zipfile.py�	get_files)s��
"�r%c@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�ir#r#r$�
<listcomp>5s���z:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>�)�range�FIXEDTEST_SIZE�line_gen�join�data��clsr#r#r$�
setUpClass3s�z&AbstractTestsWithSourceFile.setUpClasscC�<ttd��}|�|j�Wd�dS1swYdS�N�wb��openr
�writer2��self�fpr#r#r$�setUp:�"�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�ZipFiler;r
�writestrr2r:r0)r=r"rArB�kwargs�zipfp�liner#r#r$�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�rrDrE)�file��	File Namer�Modified�Size��%Y-%m-%d�%H:%M:%S�rFcS�g|]}|j�qSr#��filenamer)r#r#r$r,n�z8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>)rOrIrJ�assertEqual�readr
r2r�StringIO�printdir�getvalue�
splitlines�len�assertIn�split�
assertTrue�time�strptime�str�namelist�infolist�	file_size�getinfor\�testzip)r=r"rArBrMr>�	directory�lines�fn�date�time_�size�names�infosr+�nm�infor#r#r$�zip_testJsN

$�z$AbstractTestsWithSourceFile.zip_testcC� t|�D]	}|�||j�qdSr�r%rzrA�r=r"r#r#r$�
test_basic���z&AbstractTestsWithSourceFile.test_basicc		Cs|�||�t�|d|��i}g}|�t��}	|�d�}|sn|�|�qWd�n1s/wYg}|�d��}	|�d�}|sEn|�|�q=Wd�n1sUwY|�d�|�|j	�|�d�|�|j	�Wd�dS1sywYdS�NrPT�rDr-)
rOrIrJr:r
r_�appendr^r1r2)	r=r"rArM�zipdata1�zipopen1�	read_data�zipdata2�zipopen2r#r#r$�
zip_open_test�s2

��

��"�z)AbstractTestsWithSourceFile.zip_open_testcCr{r�r%r�rAr}r#r#r$�	test_open�rz%AbstractTestsWithSourceFile.test_opencCs\t�t�}|�||j�t�|d|j��}|�|jt	�Wd�dS1s'wYdS�NrP)
�pathlib�Pathrr�rArIrJ�assertIsInstancer\rj)r=�pathrMr#r#r$�test_open_with_pathlike�s

"�z3AbstractTestsWithSourceFile.test_open_with_pathlikec	Cs�|�||�t�|d|��<}g}|�t��}	|�tdd��}|s"n|�|�qWd�n1s2wY|�d�	|�|j
�Wd�dS1sLwYdS�NrPTrV�r-)rOrIrJr:r
r_rr�r^r1r2)r=r"rArMr�r�r�r#r#r$�zip_random_open_test�s
��"�z0AbstractTestsWithSourceFile.zip_random_open_testcCr{r�r%r�rAr}r#r#r$�test_random_open�rz,AbstractTestsWithSourceFile.test_random_openc	Cs�|�||�t�|d��.}|�t��}g}	|�d�}|sn|�|�qWd�n1s.wYWd�n1s=wY|�d�|�|j	�dS)NrPT���r-)
rOrIrJr:r
�read1r�r^r1r2�r=r"rArM�zipopen�zipdatar�r#r#r$�zip_read1_test�s"�

���	z*AbstractTestsWithSourceFile.zip_read1_testcCr{r)r%r�rAr}r#r#r$�
test_read1�rz&AbstractTestsWithSourceFile.test_read1c	Cs�|�||�t�|d��6}|�t��!}g}	|�d�}|�t|�d�|s&n|�|�qWd�n1s6wYWd�n1sEwY|�	d�
|�|j�dS)NrPT�
r-)rOrIrJr:r
r��assertLessEqualrdr�r^r1r2r�r#r#r$�zip_read1_10_test�s$�

���
z-AbstractTestsWithSourceFile.zip_read1_10_testcCr{r)r%r�rAr}r#r#r$�
test_read1_10�rz)AbstractTestsWithSourceFile.test_read1_10c	Cs�|�||�t�|d��8}|�t��#}d}	|��}|sn||7}|�d�}|s)n||7}qWd�n1s8wYWd�n1sGwY|�||j�dS)NrPr-T�d)	rOrIrJr:r
�readliner_r^r2)r=r"rArMr�r2r_r#r#r$�zip_readline_read_test�s*�
����z2AbstractTestsWithSourceFile.zip_readline_read_testcCr{r)r%r�rAr}r#r#r$�test_readline_read�s�z.AbstractTestsWithSourceFile.test_readline_readc	Cs�|�||�t�|d��6}|�t��}|jD]}|��}|�||�qWd�n1s-wYWd�dSWd�dS1sEwYdSr�)rOrIrJr:r
r0r�r^)r=r"rArMr�rN�linedatar#r#r$�zip_readline_test�s
���"�z-AbstractTestsWithSourceFile.zip_readline_testcCr{r)r%r�rAr}r#r#r$�
test_readlinerz)AbstractTestsWithSourceFile.test_readlinec	Cs�|�||�t�|d��3}|�t��}|��}Wd�n1s!wYt|j|�D]
\}}|�||�q,Wd�dS1sBwYdSr�)	rOrIrJr:r
�	readlines�zipr0r^)r=r"rArMr��ziplinesrN�zipliner#r#r$�zip_readlines_tests
��"�z.AbstractTestsWithSourceFile.zip_readlines_testcCr{r)r%r�rAr}r#r#r$�test_readlinesrz*AbstractTestsWithSourceFile.test_readlinesc	Cs�|�||�t�|d��7}|�t��}t|j|�D]
\}}|�||�qWd�n1s.wYWd�dSWd�dS1sFwYdSr�)rOrIrJr:r
r�r0r^)r=r"rArMr�rNr�r#r#r$�zip_iterlines_tests���"�z.AbstractTestsWithSourceFile.zip_iterlines_testcCr{r)r%r�rAr}r#r#r$�test_iterlinesrz*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.rCrE�12NrPrV�1�2)rIrJrrArKr:r^r_)r=rM�openobjr#r#r$�test_low_compression"s���"�z0AbstractTestsWithSourceFile.test_low_compressioncCs<t�td�}|jdd|jd�|�d�}|�|j|j�dS)NrC�b.txt�hello world��
compress_type)rIrJrrKrArnr^r�)r=rMryr#r#r$�test_writestr_compression.s
z5AbstractTestsWithSourceFile.test_writestr_compressioncCs�tjtddd�}|jdd|jd�|jdd|jdd	�|�d�}|�|j|j�|�|jd�|�d�}|�|j|j�|�|jd�dS)
NrCrV�rB�a.txtr�r�r��)r�rB)	rIrJrrKrArnr^r��_compresslevel)r=rM�a_info�b_infor#r#r$�test_writestr_compresslevel4s�

z7AbstractTestsWithSourceFile.test_writestr_compresslevelc
Cs�dD]M}|d}t|�}t�t��d|j��1}|�d|�|�dd��}|�|�}|�	t
|�|�Wd�n1s;wYWd�n1sJwYqdS)N)rVi�iii@rVrC�foorP)rrIrJrr rArKr:r_r^rd)r=�	test_sizerm�junk�zipfr>�bufr#r#r$�test_read_return_sizeDs
�����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)NrCrGrEr��r�)rr rIrJrKr2rA�tellrbr:�truncate�assertRaises�EOFErrorr_r�)r=r>r��
end_offset�zipfiledatar�r#r#r$�test_truncated_zipfilePs\
�

�����


�������


���� ��$�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.namerCzmode='w'rPzfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])
r%rIrJrAr;r
�reprre�
isinstancerjrn�
ZIP_STOREDr:)r=�fnamer"rMrPr�r#r#r$�	test_reprns@�
����z%AbstractTestsWithSourceFile.test_reprcCs$t|�D]}|j||jdd�qdS)N�	r�r|r}r#r#r$�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.rCrVr��
compress_1�
compress_9r�N)rIrJrr;r
rnr^r�)r=rM�one_info�	nine_infor#r#r$�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�nCWd�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�NrV)�OSError�superr;�r=r2)�	__class__�count�stopr#r$r;�s
zIAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFile.write)�__name__�
__module__�__qualname__r;�
__classcell__r#�r�r��r�r$�
BrokenFile�sr�rTrC�file1sdata1�file2sdata2rV)rr rIrJrAr:r;r�rbr^rkr_)r=r��testfilerMr"r#r�r$�test_writing_errors�sD	������
��"�z/AbstractTestsWithSourceFile.test_writing_errorscC�tt�tt�dSr�rr
r�r=r#r#r$�tearDown��z$AbstractTestsWithSourceFile.tearDownr)$r�r�r��classmethodr5r?rOrzr~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&2sD


6

	%r&c@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)NrPrE��rF)rOrIrJrnr^�
external_attr)r=r"rArM�zinfo�zinfo2r#r#r$�zip_test_writestr_permissions�s

"�z7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs t|�D]	}|�|tj�qdSr)r%r�rIr�r}r#r#r$�test_writestr_permissions�rz3StoredTestsWithSourceFile.test_writestr_permissionscCs�t�tdtj��}|�td�Wd�n1swYt�tdtj��}|�|��dg�Wd�dS1s;wYdS)NrC�	/absoluterP�absolute�rIrJrr�r;r
r^rk�r=rMr#r#r$�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.rCN�arE)
rIrJrr�r;r
rKr2r^rkr�r#r#r$�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!r8Nr�rbrP)r:rr;rIrJr�r
�seekrdr^rkr_r2rr )r=r2r"rMr��bior#r#r$�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)NrCrr8)rr rIrJr�r;r
rbr:rr^rkr_r2�r=rrMr�r2r"r#r#r$�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)NrCsI am not a ZipFile!i@Br8rrEr)rr rIrJr�r;r
rbr:rr^rkrKr2r_rdrr#r#r$�$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)NrCr�utf-8��encodingz
rP)rIrJrr�r;r
r:r��r=rMr"r#r#r$�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)NrC�this is a commentrr
rzabcdef
rP)
rIrJrr��commentr;r
r:r�r^r
r#r#r$�)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.rCrN)rIrJrr;r
r:r^r_r
r#r#r$�test_write_default_name9s
��"�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.txtrCrG�bogusrPr)
rIrJrrKr:�closer��
ValueErrorr_rr��readable�seekable)r=r�rM�fidr#r#r$�test_io_on_closed_zipextfileAs ���"�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.rCrGrrNrP)	rIrJrrKr�rr;r
r:r�r#r#r$�test_write_to_readonlyOs����"�z0StoredTestsWithSourceFile.test_write_to_readonlycCs�t�td�t�td��}|�t|jt�Wd�n1swYtjtddd��}|�t�|�	t�}|�
|jd�Wd�dS1sIwYdS)N)rrrCF��strict_timestamps�i�rVrVrrr)�os�utimer
rIrJrr�rr;rnr^�	date_time)r=rMr�r#r#r$�test_add_file_before_1980\s�

"�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=rCFr)i;����;r&)rh�	localtime�
OverflowError�skipTestrr r
�stat�st_mtime_nsrIrJrr��struct�errorr;rnr^r!)r=�ts�mtime_nsrMr�r#r#r$�test_add_file_after_2107gs,��	�

"�z2StoredTestsWithSourceFile.test_add_file_after_2107)r�r�r�rIr�rAr�r�r�r�rrrr	rrrrrr"r0r#r#r#r$r��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.rC�storeme�	deflatemeN)
rIrJrr;r
r��ZIP_DEFLATEDrnr^r�)r=rM�sinfo�dinfor#r#r$�test_per_file_compression�s

"�z4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�rIr4rAr7r#r#r#r$r1�sr1c@�eZdZejZdS)�Bzip2TestsWithSourceFileN�r�r�r�rI�	ZIP_BZIP2rAr#r#r#r$r9��
r9c@r8)�LzmaTestsWithSourceFileN�r�r�r�rI�ZIP_LZMArAr#r#r#r$r=�r<r=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)r#r#r$�	<genexpr>�s��z;AbstractTestZip64InSmallFiles.setUpClass.<locals>.<genexpr>r�
)r.r/r1r2)r4r0r#r#r$r5�s�z(AbstractTestZip64InSmallFiles.setUpClasscCsXtj|_tj|_dt_dt_ttd��}|�|j�Wd�dS1s%wYdS)Nrr�r8)	rI�ZIP64_LIMIT�_limit�ZIP_FILECOUNT_LIMIT�_filecount_limitr:r
r;r2r<r#r#r$r?�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)NrCT��
allowZip64rDrErPrYrSrrTrUrVrWrX�cSrZr#r[r)r#r#r$r,�r]z:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>)rIrJr;r
rKr2r^r_rr`rarbrcrdrerfrgrhrirjrkrlrmrnr\ro)r=r"rArMr>rprqrrrsrtrurvrwr+rxryr#r#r$rz�sR�


$�z&AbstractTestZip64InSmallFiles.zip_testcCr{rr|r}r#r#r$r~�rz(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)NrCTrGr���foo%08d�%drI�9rPr')
rIrJr
rA�debugr.rKr^rdrkrr_�decode)r=r��numfilesr+�zipf2�contentr#r#r$�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)NrCFrGr�r�rKrLrIrMr-rTrJrPr')rIrJr
rArNr.rKr^rdrkr��LargeZipFilerr_rO)r=r�rPr+�	numfiles2rQrRr#r#r$�test_too_many_files_appendsN�����z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs$|jt_|jt_tt�tt�dSr)rDrIrCrFrErr
rr�r#r#r$r�.sz&AbstractTestZip64InSmallFiles.tearDownN)r�r�r�r�r5r?rzr~rSrVr�r#r#r#r$r@�s

9'r@c@sveZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
					
ddd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd
S)�StoredTestZip64InSmallFilescCsLtj|d|dd��}|�tj|jtd�Wd�dS1swYdS�NrCFrGrD)rIrJr�rTr;r
�r=r"rArMr#r#r$�large_file_exception_test9s
�"�z5StoredTestZip64InSmallFiles.large_file_exception_testcCsNtj|d|dd��}|�tj|jd|j�Wd�dS1s wYdSrX)rIrJr�rTrKr2rYr#r#r$�large_file_exception_test2>s

�"�z6StoredTestZip64InSmallFiles.large_file_exception_test2cCs.t|�D]}|�|tj�|�|tj�qdSr)r%rZrIr�r[r}r#r#r$�test_large_file_exceptionCs�z5StoredTestZip64InSmallFiles.test_large_file_exceptioncCs�tjtdtjdd��}|�td�Wd�n1swYt�tdtj��}|�|��dg�Wd�dS1s=wYdS)NrCTrGr�rPr�r�r�r#r#r$r�Hs��"�z2StoredTestZip64InSmallFiles.test_absolute_arcnamescCs
tjtddd��}|�d|j�Wd�n1swYtjtddd��}|�d�}|j}Wd�n1s:wYtjtddd��}|�d|j�Wd�n1sYwYtjtddd��}|�d�}|�|j|�Wd�dS1s~wYdS)NrCTrGrErPr�strfile2)rIrJrrKr2rn�extrar^)r=rMr�r^r#r#r$�test_appendPs�
��
"�z'StoredTestZip64InSmallFiles.test_appendFr-Nc
Cs"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|��}|dur�dt|�}|	dur�d
dt|�dt|
�}	t�dddt|��}t�dddt|
��}d}d}t�dt|��}d|||||||d||||d|||dt�d|�dd|||dt�d|	�ddd}|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
        �r����<L�<HH�QrVz<Q�:�2N�,�lz<HrYstest.txt�test1234sPK!�%��sPK--!�%��s
��PKs--s
sPKssPK:2�)r�r,�packrd)r=�file_size_64_set�file_size_extra�compress_size_64_set�compress_size_extra�header_offset_64_set�header_offset_extra�extensible_data�end_of_central_dir_size�offset_to_end_of_central_dir�actual_size�actual_header_offset�local_zip64_fields�central_zip64_fieldsrm�
compress_size�
header_offset�local_extra�
central_extra�central_dir_size�offset_to_central_dir�local_extra_length�central_extra_lengthr\rR�filename_length�zip64_contentsr#r#r$�make_zip64_file^s�





��
��
�
��������	�
���
������
�������
��� ��$z+StoredTestZip64InSmallFiles.make_zip64_filecCsR|jdd�}|�tj��}t�t�|��Wd�n1swY|�dt|j	��
��|�t�t�|���|jdddd�}|�tj��}t�t�|��Wd�n1s[wY|�dt|j	��
��|�t�t�|���|jdd�}|�tj��}t�t�|��Wd�n1s�wY|�dt|j	��
��|�t�t�|���|jdddddd�}|�tj��}t�t�|��Wd�n1s�wY|�d	t|j	��
��|�t�t�|���|jd
dddd�}|�tj��}t�t�|��Wd�n	1�swY|�d	t|j	��
��|�t�t�|���|jddd
dd�}|�tj��}t�t�|��Wd�n	1�sOwY|�d	t|j	��
��|�t�t�|���|jd
d
dd
�}|�tj��}t�t�|��Wd�n	1�s�wY|�d	t|j	��
��|�t�t�|���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)rmNz	file size)rmrnroz
compress size)ro)rmrnrorprqz
header offsetF)rmrorprq)rmrnrorq)rmrorq)
r�r�rI�
BadZipFilerJrr rerj�	exception�lowerrg�
is_zipfile)r=�missing_file_size_extra�e�missing_compress_size_extra�missing_header_offset_extrar#r#r$�test_bad_zip64_extra�s���������������z0StoredTestZip64InSmallFiles.test_bad_zip64_extracCs�|jdd�}|�tjd��t�t�|��Wd�n1s wY|�t�t�|���|jdd�}|�tjd��t�t�|��Wd�n1sPwY|�t�t�|���|jdd�}|�tjd��t�t�|��Wd�n1s�wY|�t�t�|���|jdd�}|�tjd��t�t�|��Wd�n1s�wY|�t�t�|���dS)Nr)rtzCorrupt.*recordr�)rurzCorrupt.*locator)	r��assertRaisesRegexrIr�rJrr rr��r=r�r#r#r$�!test_bad_zip64_end_of_central_dir1s(����z=StoredTestZip64InSmallFiles.test_bad_zip64_end_of_central_dircCs�|��}|�dd�}|�tjd��t�t�|��Wd�n1s$wY|�t�	t�|���|jdd�}|�dd�}|�tjd��t�t�|��Wd�n1sZwY|�t�	t�|���dS)Nrjrk�record not found�
�data�rs)
r��replacer�rIr�rJrr rr�r�r#r#r$�.test_zip64_end_of_central_dir_record_not_foundFs���zJStoredTestZip64InSmallFiles.test_zip64_end_of_central_dir_record_not_foundcCs
d}d}d}d}|jdd�}t�t�|���,}|��d}|�|j|�|�|j|�|�|j	|�|�|�
|�|�Wd�n1sEwY|�t�t�|���|�
tjd��t�t�d|��Wd�n1sqwY|�t�t�d|���dS)Nr`rrir�r�r�s	prepended)r�rIrJrr rlr^rmrzr{r_rgr�r�r�r)r=�expected_file_size�expected_compress_size�expected_header_offset�expected_contentr��zfr�r#r#r$�test_zip64_extensible_dataTs&���z6StoredTestZip64InSmallFiles.test_zip64_extensible_datac
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`rriT)rmrn)rorp)rqrrrVr#)r.rd�	itertools�combinations�updaterIrJrr r�rlr^rmrzr{r_)r=r�r�r�r��paramsrP�comborL�cr�r�r#r#r$� test_generated_valid_zip64_extrais.�����z<StoredTestZip64InSmallFiles.test_generated_valid_zip64_extra)	FFFFFFr-NN)r�r�r�rIr�rArZr[r\r�r_r�r�r�r�r�r�r#r#r#r$rW5s$
�nerWc@r8)�DeflateTestZip64InSmallFilesN�r�r�r�rIr4rAr#r#r#r$r��r<r�c@r8)�Bzip2TestZip64InSmallFilesNr:r#r#r#r$r��r<r�c@r8)�LzmaTestZip64InSmallFilesNr>r#r#r#r$r��r<r�c@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�AbstractWriterTestscC�tt�dSr�rrr�r#r#r$r���zAbstractWriterTests.tearDowncCs�d}t�td|j��1}|�dd�}|�|�|��|�|j�|��|�|j�|�	|�
d�|�Wd�dS1s>wYdS)N�contentrCr!)rIrJrrAr:r;rrgrr^r_�r=r2r�rCr#r#r$�test_close_after_close�s
"�z*AbstractWriterTests.test_close_after_closecCs�d}t�td|j��/}|�dd�}|�|�|��|�|j�|�	t
|jd�|�|�d�|�Wd�dS1s<wYdS)Nr�rCr!r-)
rIrJrrAr:r;rrgrr�rr^r_r�r#r#r$�test_write_after_close�s
"�z*AbstractWriterTests.test_write_after_closec	Cs�t�dgd��}t|�|j}t�t��d|j��2}|�dd��}|�	|�
|�|�Wd�n1s4wY|�	|�d�j|�Wd�dS1sNwYdS)Nrd)rVr�rIrYrRrCr2)
�arrayrd�itemsizerIrJrr rAr:r^r;rnrm)r=�q�LENGTHr�r2r#r#r$�test_issue44439�s�"�z#AbstractWriterTests.test_issue44439N)r�r�r�r�r�r�r�r#r#r#r$r��s

r�c@r8)�StoredWriterTestsN�r�r�r�rIr�rAr#r#r#r$r��s
r�c@r8)�DeflateWriterTestsNr�r#r#r#r$r���
r�c@r8)�Bzip2WriterTestsNr:r#r#r#r$r��r�r�c@r8)�LzmaWriterTestsNr>r#r#r#r$r��r�r�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�PyZipFileTestscCs$|d|vr|�|d|�dSdS)N�or�)re)r=�namerkr#r#r$�assertCompiledIn�r�zPyZipFileTests.assertCompiledIncCs~tj|tjtjtjvd�s|�d�tj�|d�}zt�|tjtj	B�}t�
|�Wnty8|�d�Ynwt|�dS)N)�
effective_idsz/requires write access to the installed locationztest_zipfile.try)
r�access�W_OK�supports_effective_idsr)r�r1r:�O_WRONLY�O_CREATr�	Exceptionr)r=r�r\�fdr#r#r$�requiresWriteAccess�s

�
�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)NrC�.pyc�__pycache__r��testpackagez%s/%s)r�rr��dirname�__file__rrI�	PyZipFile�endswithrf�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInrkr�)r=�trMrr�
path_split�bnr#r#r$�test_write_pyfile�s4


��
P�z PyZipFileTests.test_write_pyfilec	Cs�ddl}tj�|j�}|�|�t��<}t�|d��}|�	|�|�
�}|�d|�|�d|�Wd�n1s:wYWd�dSWd�dS1sRwYdS)NrrCzemail/__init__.pyzemail/mime/text.py)�emailrr�r�r�r�rrIr�r�rkr�)r=r��
packagedirr�rMrvr#r#r$�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)	NrrC�SyntaxErrorcSsdS)NFr#)�whateverr#r#r$�<lambda>�zCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>��
filterfunccSstj�|��d�S)N�bad)rr�r��
startswith)r�r#r#r$�filter�zAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)r!rr�r�r�r�rrIr�rr�rbrg�assertWarns�UserWarning�print)r=r!r�r�rM�	reportSIO�	reportStrr�r#r#r$�"test_write_filtered_python_packages2
����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)	NrTrVr�rC)�optimizezemail/__init__zemail/mime/text)r�rr�r�r�r�rrIr�r�rkre)r=r�r��optlevel�extr�rMrvr#r#r$�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.pyrCr
r�
print(42)
�mod2.py�print(42 * 42)
zmod2.txtzbla bla bla
�r�mkdirrr:r�r1r;rrIr�r�rkr�r�r�r=r>r�rMrvr#r#r$�test_write_python_directory2s.
���
��	�	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�rCr
rr�r�r�cSs|�d�S)Nr�)r�)rrr#r#r$r�Sr�zEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>r�r�r�r#r#r$�$test_write_python_directory_filteredIs&
����	�	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)NrCr
rz!most definitely not a python file)
rrIr�r:r
r;r��RuntimeErrorr�r)r=r�rMr"r#r#r$�test_write_non_pyfile]s�
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�rCr
rzBad syntax in python file
r�zmod1.pyc)rr�rr:r�r1r;rrIr�rr�rerbrkr�r)r=r>r�rM�srvr#r#r$�test_write_pyfile_bad_syntaxds&
�����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�rCr
rr�)rr�rr:r�r1r;rrIr�r�r�r�rkr�rr�r#r#r$�test_write_pathlikezs
����z"PyZipFileTests.test_write_pathlikeN)r�r�r�r�r�r�r�r�r�r�r�r�r�rr#r#r#r$r��s
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Ze�ejjdkd�dd��Ze�ejjdkd�dd ��Zd!d"�Zd#S)$�ExtractTestscCsPt�tdtj��}tD]
\}}|�||�qWd�dS1s!wYdS)NrC)rIrJrr��SMALL_TEST_DATArK�r=rM�fpath�fdatar#r#r$�make_test_file�s
�"�zExtractTests.make_test_filecCs�t��o|��t�td��L}tD]A\}}|�|�}tj�	t�
�|�}tj�|�}|�||�t
|d��}|�|��|���Wd�n1sIwYt|�qWd�n1s]wYWd�dSWd�dS1suwYdS�NrPr)rrrIrJrr�extractrr�r1�getcwd�normpathr^r:�encoder_r)r=rMrr�writtenfile�correctfiler"r#r#r$�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)rrIrJrrrrr�r1r
rg�samefiler:r^rr_r)r=�targetrMrrrr
r"r#r#r$�_test_extract_with_target�s�
��z&ExtractTests._test_extract_with_targetcC�6t��}|�|�Wd�dS1swYdSr)rr�r=�extdirr#r#r$�test_extract_with_target��"�z%ExtractTests.test_extract_with_targetcC�<t��}|�t�|��Wd�dS1swYdSr)rrr�r�rr#r#r$�!test_extract_with_target_pathlike��"�z.ExtractTests.test_extract_with_target_pathlikecCs�t��b|��t�td��?}|��tD]0\}}tj�	t�
�|�}t|d��}|�|�
�|���Wd�n1s<wYt|�qWd�n1sPwYWd�dSWd�dS1shwYdSr)rrrIrJr�
extractallrrr�r1r	r:r^rr_r)r=rMrr�outfiler"r#r#r$�test_extract_all�s�
���"�zExtractTests.test_extract_allc
Cs�|��t�td��>}|�|�tD].\}}tj�||�}t	|d��}|�
|��|���Wd�n1s7wYt
|�qWd�n1sKwYt
t�dSr)rrIrJrrrrr�r1r:r^rr_r)r=rrMrrrr"r#r#r$�_test_extract_all_with_target�s
�
��
z*ExtractTests._test_extract_all_with_targetcCrr)rrrr#r#r$�test_extract_all_with_target�rz)ExtractTests.test_extract_all_with_targetcCrr)rrr�r�rr#r#r$�%test_extract_all_with_target_pathlike�rz2ExtractTests.test_extract_all_with_target_pathlikecCsR|�tj�|��t|d��}|�|��|�Wd�dS1s"wYdS)Nr)rgrr��isfiler:r^r_)r=r\rRr"r#r#r$�
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)rIrJ�_sanitize_windows_namer^)r=�sanr#r#r$�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)r=�common_hacknamesr#r#r$�*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\barr0)z//conky//mountpoint/foo/barr0)z\\conky\\mountpoint\foo\barr0)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=�windows_hacknamesr#r#r$�*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/..\barr3r+)r=�posix_hacknamesr#r#r$�(test_extract_hackers_arcnames_posix_onlysz5ExtractTests.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�foobarrCr�r$r�subdir�subsubrPzextract %r: %r != %r)�msgz
extract %rr)rrIrJrr��ZipInfor\r�rKr�rr�r�r1rfrr^r!rrr	r)
r=�	hacknames�arcname�	fixednamerRrMr��
targetpathr
rr#r#r$r,sT�����
��
�
�z+ExtractTests._test_extract_hackers_arcnamesN)r�r�r�rrrrrrrrrr!r(r.�unittest�skipIfrr�r�r2r5r,r#r#r#r$r�s$


rc@steZdZdd�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(dKdL�Z)e*�dMdN��Z+e�dOdP��Z,e�dQdR��Z-dSdT�Z.dUS)V�
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)
NrCr�r��barr�rPr-r6sbarfoo)
rIrJrr�rKr�r�r^rkrlr:r_re)r=rMrwr2ryr�r#r#r$�test_open_via_zip_infoIs*����"�z!OtherTests.test_open_via_zip_infocCs`t�td�� }dD]}t�|�}|jdO_|�||�q	Wd�dS1s)wYdS)NrC�abcdefghijklmnopr`)rIrJrr:�	flag_bitsrK)r=�orig_zipr2r�r#r#r$�-test_writestr_extended_local_header_issue1202]s
�"�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.rCzzipfp is not openN�zipfp is not closedrP)rIrJrrrK�assertIsNotNoner>�assertIsNonerr#r#r$�
test_closeds���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.rCNrPrH)rIrJrrrKr�rJr>)r=rMrr�zipfp2r#r#r$�test_close_on_exceptionps����z"OtherTests.test_close_on_exceptioncCs d}|�ttjt�|�d�dS)NsdPKx!p�@xPKxx!p�@�xPK/rP)r��NotImplementedErrorrIrJrr r�r#r#r$�test_unsupported_version}s

�z#OtherTests.test_unsupported_versioncCsTtd�}t�|��}|��D]	}|�|���qWd�dS1s#wYdS)Nzzip_cp437_header.zip)rrIrJrkr:r)r=r�rMr�r#r#r$�test_read_unicode_filenames�s�"�z&OtherTests.test_read_unicode_filenamescCs�t�td��}|�dd�|�dd�|�|��djt�Wd�n1s(wYt�td��}|�|j	djd�|�|j	djd�Wd�dS1sSwYdS)NrC�foo.txtzTest for unicode filenameuö.txtrrPrV)
rIrJr
rKr�rlr\rjr^�filelist�r=r�r#r#r$�test_write_unicode_filenames�s�"�z'OtherTests.test_write_unicode_filenamescCsPt�td��}|�dd�|�|�d�d�Wd�dS1s!wYdS)NrCuприкладssample)rIrJrrKr^r_r�r#r#r$�'test_read_after_write_unicode_filenames�s"�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.�xNrP)rrrIrJr�rKr��FileExistsErrorr^rkr_)r=r\rRrMr#r#r$�test_exclusive_create_zip_file�s��"�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)NrVrWrz1Could not append data to a non-existent zip file.rP)
rr��existsr
rrIrJrKr��failrgr^r_)r=r\rRr�r#r#r$�(test_create_non_existent_file_for_append�s 
���"�z3OtherTests.test_create_non_existent_file_for_appendcCs`ttddd��
}|�d�Wd�n1swYzt�t�}WdStjy/YdSw)NrCr
r�this is not a legal zip file
)r:r
r;rIrJr�)r=r>r�r#r#r$�test_close_erroneous_file�s��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.rCr
rr^Nrsthis is not a legal zip file
r)r:r
r;rrIr�r�r�rr rr<r#r#r$�test_is_zip_erroneous_file�s��
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.rCrGrQ�O, for a Muse of Fire!N)
rr rIrJrKrbr.rdr�r�)r=r>r�r��Nr#r#r$�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.rCrGrQraNrr)rIrJr
rKrgr�r:rr_rr r;)r=r�r>�zip_contentsr#r#r$�test_is_zip_valid_file�s�
�
z!OtherTests.test_is_zip_valid_filecCs|�ttjt�dSr)r�r�rIrJr
r�r#r#r$�%test_non_existent_file_raises_OSErrorsz0OtherTests.test_non_existent_file_raises_OSErrorcCsvttddd�}|��|�tjtjt�ttddd��
}|�d�Wd�n1s+wY|�tjtjt�dS)NrCr
rz
short file)r:r
rr�rIr�rJr;)r=r"r>r#r#r$�!test_empty_file_raises_BadZipFiles�z,OtherTests.test_empty_file_raises_BadZipFilecCsFtd�}dD]}t�d|�|dd�<t�|�}|�tjtj|�qdS)N�PK)rVrarbr#�)	�	bytearrayr,rlrr r�rIr�rJ)r=�buffer�dirsizer"r#r#r$�8test_negative_central_directory_offset_raises_BadZipFiles
�zCOtherTests.test_negative_central_directory_offset_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.rCrGrQ�O, for a Muse of Fire!Nz	bogus.txtrr
rzzipfile test data)rr rIrJrKr�rr_r:ror
r;)r=r2r�r"r#r#r$�!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.r�N)r�rrIrJr
r�r#r#r$�test_bad_constructor_mode4sz$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.rCrGrQrnNrPr��U�rU)rIrJr
rKr_r�rr:�r=r�r#r#r$�test_bad_open_mode8s�
"�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.rCrGrQrnrr-raN)	rIrJr
rKr:r.r/r^r_)r=r�r"r+r#r#r$�
test_read0Es��"�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.rCrGrQrPN)rIrJr
r��KeyErrorr:rsr#r#r$�test_open_non_existent_itemQs"�z&OtherTests.test_open_non_existent_itemcCs|�ttjtdd�dS)zMCheck that bad compression methods passed to ZipFile.open are
        caught.rCr�N)r�rNrIrJr
r�r#r#r$�test_bad_compression_modeWsz$OtherTests.test_bad_compression_modecCsLd}t�t�|�d��}|�t|jd�Wd�dS1swYdS)NsfPK.�C�@xPK..�C�@�xPK/!rPrX)rIrJrr r�rNr:)r=r2r�r#r#r$�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.rCrGzfoo.txtqqqrarQN)rIrJr
rKr^rkrsr#r#r$�test_null_byte_in_filenamegs"�z%OtherTests.test_null_byte_in_filenamecCs<|�tjd�|�tjd�|�tjd�|�tjd�dS)zACheck that ZIP internal structure sizes are calculated correctly.��.�8r�N)r^rI�sizeEndCentDir�sizeCentralDir�sizeEndCentDir64�sizeEndCentDir64Locatorr�r#r#r$�test_struct_sizesnszOtherTests.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.rCrGr-rQrnNrPs9Bravely taking to his feet, he beat a very brave retreat.�cSsg|]
}d|dd�qS)rLrIr�r#r)r#r#r$r,�sz,OtherTests.test_comments.<locals>.<listcomp>�r'soopssoriginal commentrsan updated commentsoriginal comment that's longersshorter comment)rIrJr
r^rrKr1r.rr�r�rr��getsizerg)r=r��zipfrr�comment2�original_zip_sizer#r#r$�
test_commentsusn����
����������$�zOtherTests.test_commentsc	Cs�t�tdtj��/}|�dd�|�t��d|_Wd�n1s"wYWd�dSWd�dS1s:wYdS)NrCrQrnzthis is an error)rIrJr
r�rKr��	TypeErrorrrsr#r#r$�test_unicode_comment�s��"�zOtherTests.test_unicode_commentcCs�t�tdtj��}|�|j�d|_Wd�n1swYt�td��}|�|jd�Wd�dS1s:wYdS)NrrrP)rIrJr
r�rrRrr^rsr#r#r$�$test_change_comment_in_empty_archive�s�"�z/OtherTests.test_change_comment_in_empty_archivecCs�t�tdtj��}|�dd�Wd�n1swYt�tdtj��}|�|j�d|_Wd�n1s:wYt�td��}|�|jd�Wd�dS1sXwYdS)NrCrQrnrrrP)	rIrJr
r�rKrgrRrr^rsr#r#r$�'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)NrCrGrPz+Unable to create empty ZIP file in 'w' moderz+Unable to create empty ZIP file in 'a' mode)rIrJr
rr�r\rsr#r#r$�test_empty_zipfile�s�zOtherTests.test_empty_zipfilecCs.ttddd�}|��|�tjtjtd�dS)NrCr
rrP)r:r
rr�rIr�rJr}r#r#r$�test_open_empty_file�szOtherTests.test_open_empty_filecCs|�ttjdd�dS)N�	seventies)i�rVrVrrr)r�rrIr:r�r#r#r$�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.�emptyr[z&<ZipInfo filename='empty' file_size=0>N)rIr:r^r��r=�zir#r#r$�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.�NoNamerr-)rrIrN)rIr:r^�
orig_filenamer\r!r�r�rr^re�
create_system�create_version�DEFAULT_VERSION�extract_version�reservedrE�volume�
internal_attrr�rmrzr�r#r#r$�,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%rPN)rIrJrr rJro�r=r�r�r#r#r$�#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 offshorerCr�rGrB�handlerPrj�abcderQ�baz)r�rBr�)rIrJrr�r:r;r�rrKr�rr^r_rk)r=�msg1�msg2�msg3r��w2�w1r#r#r$�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?sBrucerCrQrPrrRrG)�findrIrJr
rKr:rr�SEEK_SETr^r��SEEK_CURr_�SEEK_ENDrdrr )r=�txt�blocr�r>r2r#r#r$�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)NrhrC)rAr��azzipfile.bz2)rr rIrJr;rK�mock�patchr�r�r)r=r2�zip_filer�r#r#r$�)test_decompress_without_3rd_party_libraryOs
���"�z4OtherTests.test_decompress_without_3rd_party_libraryc	Csd}t�t�|�d��v}|�|��ddg�|�d�}|�|jd�|�|jd�|�|j	d�|�d�}|�|jd�|�|jd�|�|j	d�|�t
|�d��d�|�tj
d��
|�d�Wd�n1slwYWd�dSWd�dS1s�wYdS)	Ns�PK�lH�8�	a��0�K\d`PK�lH�8�	aPK�lH�8�	bPK^/rPr�brri�	zFile name.*differ)rIrJrr r^rkrnr{rzrmrdr_r�r��r=r2r�r�r#r#r$�test_full_overlapYs&�


��"�zOtherTests.test_full_overlapc	Csd}t�t�|�d��n}|�|��ddg�|�d�}|�|jd�|�|jd�|�|j	d�|�d�}|�|jd�|�|jd	�|�|j	d
�|�
tjd��
|�d�Wd�n1sawY|�t
|�d��d
�Wd�dS1s|wYdS)Ns�PK�lHY�84(a�PK�lH�8�	b��0�K\d`PK�lHY�84(aPK�lH�8�	$bPK^SrPrr�r�4i(�$rir�zOverlapped entries)rIrJrr r^rkrnr{rzrmr�r�r_rdr�r#r#r$�test_quoted_overlapvs"�

�"�zOtherTests.test_quoted_overlapcCr�rr�r�r#r#r$r��r�zOtherTests.tearDownN)/r�r�r�rCrGrKrMrOr	rPrTrUrZr]r_r`rcrerfrgrmrorprtrurwrxryrzr�r�r�r�r�r�r�r�r�r�r�r�r�r
r�r�r�r�r#r#r#r$rAHs^



	
:	&
	

rAc@seZdZdd�Zdd�ZdS)�AbstractBadCrcTestscCsP|j}tjt�|�dd��}|�d|���Wd�dS1s!wYdS)z>Tests that files with bad CRCs return their name from testzip.rPrG�afileN)�zip_with_bad_crcrIrJrr r^ror�r#r#r$�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.rPrGr�Nr�)
r�rIrJrr r�r�r_r:�
MIN_READ_SIZE)r=r�r��corrupt_filer#r#r$�test_read_with_bad_crc�s0����

������"�z*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�r�r�r#r#r#r$r��sr�c@�eZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�rIr�rAr�r#r#r#r$r��s�r�c@r�)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�rIr4rAr�r#r#r#r$r����r�c@r�)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�rIr;rAr�r#r#r#r$r��r�r�c@r�)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�rIr?rAr�r#r#r#r$r��r�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)Nr8rP)
r:r
r;r2rIrJr�r�data2�zip2r<r#r#r$r?	s��zDecryptionTests.setUpcCs,|j��t�t�|j��t�t�dSr)r�rrrr
r�rr�r#r#r$r�	s


zDecryptionTests.tearDowncCs(|�t|jjd�|�t|jjd�dS)N�test.txt�zero)r�r�r�r_r�r�r#r#r$�test_no_password	sz DecryptionTests.test_no_passwordcCs@|j�d�|�t|jjd�|j�d�|�t|jjd�dS)Nsperlr�r�)r��setpasswordr�r�r_r�r�r#r#r$�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�r^r_�plainr��plain2r�r#r#r$�test_good_password%	sz"DecryptionTests.test_good_passwordcCsV|�t|jjd�|�t|jjdd�|jt|jjddd�|jt|jjddd�dS)N�unicoder��python)�pwd)r�r�r�r�r_r:rr�r#r#r$�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)Nr�s
encryptionr�rPrrVr-)r�r�r�r�rdr:rrr�r^r�r�r_r��_readbuffer�_offsetr�)r=r��	test_wordr��bloc_lenr>�
old_read_sizer#r#r$r�2	s8

"�zDecryptionTests.test_seek_tellN)r�r�r��__doc__r2r�r�r�r?r�r�r�r	r�r�r�r#r#r#r$r��s �	�

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)Nri�@r�rVr-css(�|]}t�dt�tdd��VqdS)z<fi���rN)r,rlrrr)r#r#r$rA\	s� �z@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>)rr1r.r2)r4�	datacountr#r#r$r5Y	s
�z-AbstractTestsWithRandomBinaryFiles.setUpClasscCr6r7r9r<r#r#r$r?_	r@z(AbstractTestsWithRandomBinaryFiles.setUpcCr�rr�r�r#r#r$r�d	r�z+AbstractTestsWithRandomBinaryFiles.tearDowncCsLt�|d|��}|�td�|�tt�Wd�dS1swYdS)NrCrD)rIrJr;r
rYr#r#r$rOh	s"�z4AbstractTestsWithRandomBinaryFiles.make_test_archivecCs�|�||�t�|d|��*}|�t�}|�t|�t|j��|�||j�|�|�d�|j�Wd�dS1s:wYdS)NrPrD)rOrIrJr_r
r^rdr2)r=r"rArM�testdatar#r#r$rzn	s
"�z+AbstractTestsWithRandomBinaryFiles.zip_testcCr{rr|r}r#r#r$�	test_readx	rz,AbstractTestsWithRandomBinaryFiles.test_readc	Cs4|�||�t�|d|���}g}|�t��}	|�d�}|sn|�|�qWd�n1s/wYg}|�d��}	|�d�}|sEn|�|�q=Wd�n1sUwYd�|�}	|�t	|	�t	|j
��|�|	|j
�d�|�}
|�t	|
�t	|j
��|�|
|j
�Wd�dS1s�wYdSr�)rOrIrJr:r
r_r�r1r^rdr2)r=r"rArMr�r�r�r�r��	testdata1�	testdata2r#r#r$r�|	s:

��

��

"�z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCr{rr�r}r#r#r$r��	rz,AbstractTestsWithRandomBinaryFiles.test_openc	Cs�|�||�t�|d|��I}g}|�t��}	|�tdd��}|s"n|�|�qWd�n1s2wYd�|�}|�	t
|�t
|j��|�	||j�Wd�dS1sYwYdSr�)rOrIrJr:r
r_rr�r1r^rdr2)r=r"rArMr�r�r�r�r#r#r$r��	s 
��
"�z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCr{rr�r}r#r#r$r��	rz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r5r?r�rOrzr�r�r�r�r�r#r#r#r$r�X	s

r�c@r8)� StoredTestsWithRandomBinaryFilesNr�r#r#r#r$r��	r�r�c@r8)�!DeflateTestsWithRandomBinaryFilesNr�r#r#r#r$r��	r<r�c@r8)�Bzip2TestsWithRandomBinaryFilesNr:r#r#r#r$r��	r<r�c@r8)�LzmaTestsWithRandomBinaryFilesNr>r#r#r#r$r��	r<r�c@r�)
�TellablecCs||_d|_dS�Nr)r>�offsetr<r#r#r$�__init__�	s
zTellable.__init__cCs|j�|�}|j|7_|Sr)r>r;r�)r=r2�nr#r#r$r;�	szTellable.writecCs|jSr)r�r�r#r#r$r��	sz
Tellable.tellcC�|j��dSr�r>�flushr�r#r#r$r��	�zTellable.flushN)r�r�r�r�r;r�r�r#r#r#r$r��	s
r�c@�$eZdZdd�Zdd�Zdd�ZdS)�
UnseekablecCs
||_dSr)r>r<r#r#r$r��	s
zUnseekable.__init__cCs|j�|�Sr)r>r;r�r#r#r$r;�	r�zUnseekable.writecCr�rr�r�r#r#r$r��	r�zUnseekable.flushN)r�r�r�r�r;r�r#r#r#r$r��	sr�c@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#�r"r#r#r$r��	r�z/UnseekableTests.test_writestr.<locals>.<lambda>��wrapper�abcrC�ones�111�twos�222rR�abcPKrPrG)r�r��subTestrr r;�BufferedWriterrIrJr�rKr^rbr:r_)r=r�r"�bfrMr��zopenr#r#r$�
test_writestr�	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)NcSr�rr#r�r#r#r$r��	r�z,UnseekableTests.test_write.<locals>.<lambda>r�r�rCr8r�r�rr�rRrrPrG)r�r�rrr r;rrIrJr��
addCleanuprr
r:r^rbr_)r=r�r"rrM�f2r�rr#r#r$�
test_write�	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)NcSr�rr#r�r#r#r$r�	
r�z1UnseekableTests.test_open_write.<locals>.<lambda>r�r�rCr�r�r�rrRr)r�r�rrr r;rrIrJr�r:r^rbr_)r=r�r"rr�rr#r#r$�test_open_write
s.

���������zUnseekableTests.test_open_writeN)r�r�r�rr	r
r#r#r#r$r��	sr�c@sheZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestsWithMultipleOpenscCs dtd�|_dtd�|_dS)Nr��'r)r�data1r�r3r#r#r$r5
sz!TestsWithMultipleOpens.setUpClasscCsRt�|dtj��}|�d|j�|�d|j�Wd�dS1s"wYdS)NrCr�r�)rIrJr4rKr
r�)r=r"rMr#r#r$rO 
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)NrPrGr���)r%rOrIrJr:r_r^r
�r=r"r��zopen1�zopen2r
r�r#r#r$�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)NrPrGr�r�r�	r%rOrIrJr:r_r^r
r�rr#r#r$�test_different_file4
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)NrPrGr�rr�r)r=r"r�rr
rr�r#r#r$�test_interleavedB
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)NrPr�r�r)r%rO�
contextlib�	ExitStackrIrJ�
enter_contextr:r_r^r
r�)r=r"�stackr�rrr
r�r#r#r$�test_read_after_closeQ
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)NrCr�r�rrP)
r%rIrJr4rKr
r�r:r_r^�r=r"r�rr
r�r#r#r$�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)NrCr�rr�rP)
r%rIrJr4rKr
r:r_r�r^rr#r#r$�test_write_after_readm
s 
���
��z,TestsWithMultipleOpens.test_write_after_readc
Cs�|�t�tjtdd��)}td�D]}|�d�|�d��}Wd�n1s(wYqWd�n1s8wYttjd��}|�	|�
�d�Wd�dS1sWwYdS)NrPrGr�r�r)rOrrIrJr.r_r:r�devnull�
assertLess�fileno)r=r�rXrr"r#r#r$�test_many_opensz
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)NrCr�rrPrr�)rIrJrr4rKr
r:r_r;r�r^)r=r��r1r
r�r#r#r$�test_write_while_reading�
s"�
����"�z/TestsWithMultipleOpens.test_write_while_readingcCr�rr�r�r#r#r$r��
r�zTestsWithMultipleOpens.tearDownN)r�r�r�r�r5rOrrrrrrr!r#r�r#r#r#r$r
s


rc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestWithDirectorycCst�t�dSr)rr�rr�r#r#r$r?�
r�zTestWithDirectory.setUpc
Cs�t�td���
}|�t�Wd�n1swY|�tj�tj�	td���|�tj�tj�	tdd���|�tj�
tj�	tddd���dS)N�
zipdir.ziprr�r�)rIrJrrrrgrr��isdirr1r[rsr#r#r$�test_extract_dir�
s�$z"TestWithDirectory.test_extract_dircCs t�tj�td��|��dS�Nr)rr�r�r1rr'r�r#r#r$�
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)
NrXr�rCrz/x/ri�yrVzy/rPrr�)rr�r1rr�r*�st_moderIrJr
r;rRrgr\r�r^r�rr&rd�listdir)r=�dirpathrHr�r�rr#r#r$�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)	NrXrCzx/r-ri�ArPr)rr�r�r1rrIrJr
rKrRr^r\r�rgr�rr&r,)r=r�r�rr#r#r$�test_writestr_dir�
s"
�


"�z#TestWithDirectory.test_writestr_dircCs$tt�tj�t�rtt�dSdSr)rrrr�r[r
rr�r#r#r$r��
s�zTestWithDirectory.tearDownN)	r�r�r�r?r'r)r.r/r�r#r#r#r$r$�
sr$c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ZipInfoTestscCsHtj�t�}|�t�|j�d�|�|�	��|�|j
tj�
t��dS�Nztest_zipfile.py)rIr:�	from_filer�r^�	posixpathr�r\r�is_dirrmrr�r�r�r#r#r$�test_from_file�
szZipInfoTests.test_from_filecCsNtj�t�t��}|�t�|j	�d�|�
|���|�|jt
j�t��dSr1)rIr:r2r�r�r�r^r3r�r\rr4rmrr�r�r�r#r#r$�test_from_file_pathlike�
sz$ZipInfoTests.test_from_file_pathlikecCsPtj�t�t�d�}|�t�|j	�d�|�
|���|�|jtj
�t��dS)Nr!)rIr:r2r�fsencoder�r^r3r�r\rr4rmr�r�r�r#r#r$�test_from_file_bytes�
sz!ZipInfoTests.test_from_file_bytescCszttd��.}tj�|��d�}|�t�|j	�d�|�
|���|�|jt
j�t��Wd�dS1s6wYdS)Nrr!)r:r�rIr:r2r r^r3r�r\rr4rmrr�r�)r=r"r�r#r#r$�test_from_file_fileno�
s"�z"ZipInfoTests.test_from_file_filenocCs`tj�tj�t��}tj�|d�}|�|j	d�|�
|���|�|jtj
�|�|jd�dS)N�stdlib_testsz
stdlib_tests/r)rr�r��abspathr�rIr:r2r^r\rgr4r�r�rm)r=r-r�r#r#r$�
test_from_dir�
szZipInfoTests.test_from_dirN)r�r�r�r5r6r8r9r<r#r#r#r$r0�
sr0c@sJeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�dd��Z	d
d�Z
dS)�CommandLineTestcOs2tjddg|�Ri|��\}}}|�tj��d�S)N�-mrIrB)rrr�r�linesepr)r=�argsrL�rc�out�errr#r#r$�
zipfilecmd�
s�zCommandLineTest.zipfilecmdcGstjddg|�R�S)Nr>rI)r�assert_python_failure)r=r@r#r#r$�zipfilecmd_failurer�z"CommandLineTest.zipfilecmd_failurecCs||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr-susageserrorsrequired�-lr�)rFr^rer��assertNotEqual�strip)r=rArBrCr#r#r$�test_bad_useszCommandLineTest.test_bad_usecCsXtd�}dD]}|�||�}|�|��d�qtd�}|�d|�\}}}|�|d�dS)Nr%)�-tz--testsDone testingztesttar.tarrKr-)rrDr^�rstriprF)r=�zip_name�optrBrArCr#r#r$�test_test_commandsz!CommandLineTest.test_test_commandcCs�td�}t��}t�|d��
}|�|�Wd�n1swY|���dd�}dD]}|j||dd�}|�	||�q-dS)Nr%rPr'�backslashreplace)rGz--listzascii:backslashreplace)�PYTHONIOENCODING)
rrr`rIrJrarbrrDr^)r=rMr��tf�expectedrNrBr#r#r$�test_list_commands���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)NrCr
rztest 1�file.txtztest 2r$z	/file.txt)�-cz--creater-rstest 1r�stest 2)rrr
r:r;rr��	TESTFNDIRrr�r1rDrr^rIrJrkr_)r=r"�filesrkrNrBr�r#r#r$�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)rrrDr^rIrJrlrr�r1r\r�r�r4rgr&r r:r_)	r=rMrNrrBr�r�r�r"r#r#r$�test_extract_command9s.���������z$CommandLineTest.test_extract_commandN)r�r�r�rDrFrJrOrTr	rYrZr#r#r#r$r=�
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)N�exe_with_zip�ziptestdata)r7�exe_with_z64)r�exe_zip�	exe_zip64r�r#r#r$r?Nsz TestExecutablePrependedZip.setUpcCsl|�t�|�d|���t�|��}|��D]
}|�|�}|�d|�qWd�dS1s/wYdS)Nzis_zipfile failed on sFAVORITE_NUMBER)rgrIr�rJrkr_re)r=r�rMr�r2r#r#r$�_test_zip_worksRs�
�"�z*TestExecutablePrependedZip._test_zip_workscC�|�|j�dSr)rar_r�r#r#r$� test_read_zip_with_exe_prepended\�z;TestExecutablePrependedZip.test_read_zip_with_exe_prependedcCrbr)rar`r�r#r#r$�"test_read_zip64_with_exe_prepended_rdz=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�
executablere�r=�outputr#r#r$�test_execute_zip2b�z,TestExecutablePrependedZip.test_execute_zip2cCrfrg)rhrir`rjrkrerlr#r#r$�test_execute_zip64iroz-TestExecutablePrependedZip.test_execute_zip64N)r�r�r�r�r?rarcrer?�
skipUnlessrjrkrr��X_OKrnrpr#r#r#r$r[Ks 
��r[c@�eZdZGdd�d�ZdS)�jaracoc@rs)zjaraco.itertoolsc@r�)zjaraco.itertools.CountercCsd|_t|�|_dSr�)r��iter�
_orig_iter)r=r+r#r#r$r�ysz!jaraco.itertools.Counter.__init__cCr�rr#r�r#r#r$�__iter__}sz!jaraco.itertools.Counter.__iter__cCst|j�}|jd7_|Sr�)�nextrvr�)r=�resultr#r#r$�__next__�s
z!jaraco.itertools.Counter.__next__N)r�r�r�r�rwrzr#r#r#r$�Counterxsr{N)r�r�r�r{r#r#r#r$r�w�r�N)r�r�r�r�r#r#r#r$rtvr|rtcCs&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-)rI�CompleteDirs�
_implied_dirsrkrK)r�r�r#r#r$�add_dirs�srcCsZt��}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
    rCr��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)rr rIrJrKr\)r2r�r#r#r$�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)r=r���methr#r$r��s�zpass_alpharep.<locals>.wrapper)�	functools�wraps)r�r�r#r�r$�
pass_alpharep�sr�c@s�eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Zedd��Z	ed
d��Z
edd��Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd��Zdd�Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zed)d*��Zed+d,��Zed-d.��Zed/d0��Zed1d2��Zed3d4��Zd5Zd6d7�Zd8d9�Z d:d;�Z!ed<d=��Z"ed>d?��Z#ed@dA��Z$edBdC��Z%edDdE��Z&edFdG��Z'edHdI��Z(edJdK��Z)dLdM�Z*e+�,e-�.�dNkdO�dPdQ��Z/e+�,e-�.�dNkdO�dRdS��Z0dTS)U�TestPathcCst��|_|�|jj�dSr)rr�fixturesrrr�r#r#r$r?�s
zTestPath.setUpccsl�|���t�VWd�n1swY|���tt��VWd�dS1s/wYdSr)rr�rr�r#r#r$r��s�

�
"�zTestPath.zipfile_alpharepcCsjt�|j�t���}|j}|��||j}|�d��}|�	|�
��Wd�|S1s.wY|Sr7)r�r�r�rrr>rr\r:r;rb)r=r��tmpdirrkr��strmr#r#r$�zipfile_ondisk�s

��zTestPath.zipfile_ondiskcCs�t�|�}|��sJ�|��\}}}|��sJ�|��sJ�|��s$J�|��\}}}|��r3|��s5J�|��\}	|	��s@J�|��\}
|
��\}|��sPJ�dSr)rIr�r4�iterdir�is_file)r=r��rootrr��gr�r"rr��hr+r#r#r$�test_iterdir_and_types�s



zTestPath.test_iterdir_and_typescCs t�|�}|�d���rJ�dS)Nzmissing.txt)rIr��joinpathr��r=r�r�r#r#r$�test_is_file_missing�s
zTestPath.test_is_file_missingcCsPt�|�}|��\}}}|�t��
|��Wd�dS1s!wYdSr)rIr�r�r�r�r=r�r�rr�r�r#r#r$�test_iterdir_on_file�s


"�zTestPath.test_iterdir_on_filecCsNt�|�}|d��s
J�|d��sJ�|d��sJ�|d��s%J�dS)Nr��b/r�zg/)rIr�r4r�r#r#r$�test_subdir_is_dir�s

zTestPath.test_subdir_is_dircCs�t�|�}|��\}}}|jdd��}|��}Wd�n1s!wY|�|d�|�dd��}|��}Wd�n1sAwY|�|d�dS)Nr
r�content of arP)rIr�r�r:r_r^)r=r�r�rr�r�r�r2r#r#r$r��s

�
�zTestPath.test_opencCs�t��}t�|d�}|�dd�d��d|_t�|�}|��\}|�	d�}|�
dd��}|��}Wd�n1s:wY|�|d�|j
dd��}|��}Wd�n1sZwY|�|d�dS)	NrCzpath/16.txtzThis was utf-16zutf-16ztest_open_utf16.zipz16.txtrPr)
rr rIrJrKrr\r�r�r�r:r_r^)r=�in_memory_filer�r�r��u16r�r2r#r#r$�test_open_encoding_utf16s



�
�z!TestPath.test_open_encoding_utf16c	CsPt��}t�|d�}|�dd�d|_t�|�}|��\}|�d�}|j	ddd�}|�
|d	�|jd
ddd��}|�
|��d�Wd�n1sJwY|�
td
��|j	ddd�}Wd�n1sgwY|jd
ddd��*}|�t��|��Wd�n1s�wYWd�dSWd�dS1s�wYdS)NrCzpath/bad-utf8.binsinvalid utf-8: ��.z"test_read_text_encoding_errors.zipzbad-utf8.binr
�ignore)�errorszinvalid utf-8: .rP�surrogateescapeuinvalid utf-8: ��.rr�strict)rr�)rr rIrJrKr\r�r�r��	read_textr^r:r_r�r�r��UnicodeDecodeError)r=r�r�r�r�r�r2r"r#r#r$�test_open_encoding_errorss,


��
��"�z"TestPath.test_open_encoding_errorscCsTd}tddd|�}|j��}|�t|�d|j�|�|dd�|�|dd	�d
S)z8EncodingWarning must blame the read_text and open calls.aimport io, zipfile
with zipfile.ZipFile(io.BytesIO(), "w") as zf:
    zf.filename = '<test_encoding_warnings in memory zip file>'
    zf.writestr("path/file.txt", b"Spanish Inquisition")
    root = zipfile.Path(zf)
    (path,) = root.iterdir()
    file_path = path.joinpath("file.txt")
    unused = file_path.read_text()  # should warn
    file_path.open("r").close()  # should warn
z-X�warn_default_encodingrVr�rs^<string>:8: EncodingWarning:rVs^<string>:9: EncodingWarning:N)rrCrcr^rd�assertRegex)r=�code�proc�warningsr#r#r$�test_encoding_warnings-s
zTestPath.test_encoding_warningscCs�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.
        rCrGzfile.binr8sbinary contentsNrUr
rz	text file)rIr�rJrr r�r:r;)r=r�r�r#r#r$r
@s�"�zTestPath.test_open_writecC�Nt�tt���}|�t��|�d���Wd�dS1s wYdS)zJ
        Attempting to open a directory raises IsADirectoryError.
        r�N)rIr�rr�r��IsADirectoryErrorr�r:rSr#r#r$�test_open_extant_directoryK�"�z#TestPath.test_open_extant_directorycCs�t�|�}|�t��|�d�jddd�Wd�n1swY|�t��|�d��dd�Wd�dS1s>wYdS)Nr�rr
r)rIr�r�rr�r:r�r#r#r$�test_open_binary_invalid_argsSs
�"�z&TestPath.test_open_binary_invalid_argscCr�)zR
        Attempting to open a missing directory raises FileNotFoundError.
        �zN)rIr�rr�r��FileNotFoundErrorr�r:rSr#r#r$�test_open_missing_directory[r�z$TestPath.test_open_missing_directorycCsJt�|�}|��\}}}|jdd�dksJ�|�d�|��dks#J�dS)Nr
rr�r�)rIr�r�r��
read_bytesr�r#r#r$r�cs


zTestPath.test_readcCsNt�|�}|�d�}|��sJ�|�d��d��d�}|jdd�dks%J�dS�Nr�r�r�e.txtr
r�content of e)rIr�r�r�r��r=r�r�rr�r#r#r$�
test_joinpathks


zTestPath.test_joinpathcCs0t�|�}|�ddd�}|jdd�dksJ�dS)Nr�rr�r
rr�)rIr�r�r�)r=r�r�r�r#r#r$�test_joinpath_multipless
zTestPath.test_joinpath_multiplecCsFt�|�}|d}|��sJ�|ddd}|jdd�dks!J�dSr�)rIr�r�r�r�r#r#r$�test_traverse_truedivys

zTestPath.test_traverse_truedivcCstddddd�}t|�dS)zI
        Disable the __future__.division when testing traversal.
        zzipfile.Path(alpharep) / 'a'z(test)�evalT)�sourcer\rH�dont_inheritN)�compiler�)r=r�r�r#r#r$�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�rjrI)r=r�r��pathliker#r#r$�test_pathlike_construction�s
z#TestPath.test_pathlike_constructioncCst�|�}|t�d�dSr()rIr�r�r�r#r#r$�test_traverse_pathlike�s
zTestPath.test_traverse_pathlikecCs:t�|�}|djjdksJ�|ddjjdksJ�dS)Nrr�r�za/�rIr��parent�atr�r#r#r$�test_parent�s
zTestPath.test_parentcCs6t�|�}|djjdksJ�|djjdksJ�dS)Nr�r�r�r�r�r#r#r$�test_dir_parent�s
zTestPath.test_dir_parentcCs"t�|�}|djjdksJ�dS)Nzmissing dir/r�r�r�r#r#r$�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.
        rQr�zbar/baz.txtr�css�|]}|jdkVqdS)rQN)r�)r*�childr#r#r$rA�s�z+TestPath.test_mutability.<locals>.<genexpr>r
rrBN)rIr�r�rK�anyr�)r=r�r�rr�r�r�r#r#r$�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.rCrP)
rr rIrJ�maprjr.�HUGE_ZIPFILE_NUM_ENTRIESrKrH)r=r�r��entryr#r#r$�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)
rIr�r�rtr�r{r�r�r�r�)r=r��entriesr�r#r#r$�test_joinpath_constant_time�s
z$TestPath.test_joinpath_constant_timecCs"dd�td�D�}tj�|�dS)NcSs g|]}d�tjt|���qS)r$)r1�string�ascii_lowercaserj)r*r�r#r#r$r,�s z:TestPath.test_implied_dirs_performance.<locals>.<listcomp>r)r.rIr}r~r�r#r#r$�test_implied_dirs_performance�sz&TestPath.test_implied_dirs_performancecCs\|�|�}t�|��}td�D]}t�|d�jdd�qWd�dS1s'wYdS)Nr�r�r
r)r�rIrJr.r�r�)r=r�rQ�repr#r#r$�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�r#r#r#r$�Subclass�sr�r�)rIr�r�)r=r�r�r�r#r#r$�
test_subclass�szTestPath.test_subclasscCs"t�|�}|jt�d�ksJ�dS)Nr�)rIr�r\r�r�r#r#r$�
test_filename�r�zTestPath.test_filenamecCs0t�|�}|jdkr|jjksJ�J�dS)zH
        The name of the root should be the name of the zipfile
        r�N)rIr�r�r\r�r#r#r$�test_root_name�s
&zTestPath.test_root_namecCs>t�|�}|jt�d�ksJ�d|j_|jt�d�ksJ�dS)N�.zfoo/bar.zipr�)rIr�r�r�r�r\r�r#r#r$�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�)r\rIr�r�r�r�r�)r=r�r��subr#r#r$�test_root_unnamed�s
��zTestPath.test_root_unnamedcCs@tdtjfi�}|��D]}||��d�j}t||�sJ�qdS)N�	PathChildzsome dir)�typerIr�r�r�r�r�)r=r�r4rQr#r#r$�test_inheritance
s
�zTestPath.test_inheritancecCs.|�|�}t�|�}t�|�|�|j�dS)zU
        A zip file wrapped in a Path should extract even with implied dirs.
        N)r�rIrJr�rr�)r=r��source_pathr�r#r#r$�#test_extract_orig_with_implied_dirs
s


z,TestPath.test_extract_orig_with_implied_dirscCs�t��}t�|d�}|�dd�|�dd�|�dd�d|_t�|�}ttt	|�
���dgks2J�|�d��d	���dks@J�d
S)z�
        Path should handle malformed paths gracefully.

        Paths with leading slashes are not visible.

        Paths with dots are treated like regular files.
        rCz/one-slash.txtr�z//two-slash.txtz
../parent.txtr�z../z..z
parent.txtN)
rr rIrJrKr\r��listr�rjr�r�r�)r=r2r�r�r#r#r$�test_malformed_paths
s
 zTestPath.test_malformed_paths�Windowsz	GH-123693cCs�t��}t�|d�}|�dd�|�dd�d|_t�|�}|��}t|�j	dks+J�t|�}|j	dks9J|j	��|�
d���dksDJ�dS)z�
        Path segments with special characters are readable.

        On some platforms or file systems, characters like
        ``:`` and ``?`` are not allowed, but they are valid
        in the zip file.
        rCzpath?r�zV: NMS.flacsfLaC...r�N)rr rIrJrKr\r�r�rxr�r�r�)r=r2r�r��contents�itemr#r#r$�test_unsupported_names0
s	
zTestPath.test_unsupported_namescCsft��}t�|d�}|�t�d|�d�d|_t�|�}|�	�\}|�
�r'J�|jdks1J|j��dS)z@
        In a zip file, backslashes are not separators.
        rCzfoo\barr�r�N)rr rIrJrK�DirtyZipInfo�for_namer\r�r�r4r�)r=r2r�r��firstr#r#r$�test_backslash_not_separatorE
s

z%TestPath.test_backslash_not_separatorN)1r�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�r�r�r�r�r�r�r?r@�platform�systemr�r�r#r#r#r$r��s�	

















	









r�cs,eZdZdZ�fdd�Zedd��Z�ZS)r�z#
    Bypass name sanitization.
    cs$t�j|g|�Ri|��||_dSr)r�r�r\)r=r\r@rLr�r#r$r�Y
s
zDirtyZipInfo.__init__cCs\||t�t���dd�d�}|j|_|j|_|j�d�r)d|_|jdO_|Sd|_|S)zy
        Construct the same way that ZipFile.writestr does.

        TODO: extract this functionality and re-use
        N�)r\r!r$i�Arir�)	rhr'rAr�rB�compress_levelr\r�r�)r4r��archiver=r#r#r$r�]
s�zDirtyZipInfo.for_name)r�r�r�r�r�r�r�r�r#r#r�r$r�T
s
r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�StripExtraTestsrVcCs�t�d�}|�|jd�}|�dd�}|�dd�}|�dt�||jf��|�|t�||jf��|�|dt�|d|jf��|�||t�||||jf��|�||t�||||jf��|�||t�||||jf��dS)Nrcrr�rIr-�z�r,�Structrl�ZIP64_EXTRAr^rI�_strip_extra�r=r�rr�r�r#r#r$�test_no_datav
s
�$$(zStripExtraTests.test_no_datacCs�t�d�}|�|jd�d}|�dd�d}|�dd�d}|�dt�||jf��|�|t�||jf��|�|d	t�|d	|jf��|�||t�||||jf��|�||t�||||jf��|�||t�||||jf��dS)
NrcrVr�r��bbrIscccr-r�r�r�r#r#r$�test_with_data�
s
�$$(zStripExtraTests.test_with_datacCst�d�}|�|jd�d}|�dd�d}|�dt�|||jf��|�dt�||||jf��|�dt�||d|jf��|�|dt�|||d|jf��|�|t�||||jf��|�|t�||||jf��|�|t�||||jf��dS)NrcrVr�r�r�r-r�r�)r=r�rr�r#r#r$�test_multiples�
s
 � �  $zStripExtraTests.test_multiplescCsd|�dt�d|jf��|�dt�d|jf��|�dt�d|jf��|�dt�d|jf��dS)Nr-r�szzszzz)r^rIr�r�r�r#r#r$�test_too_short�
s��zStripExtraTests.test_too_shortN)r�r�r�r�r�rrrr#r#r#r$r�o
sr��__main__)`r�r�importlib.utilr�rr�rr�r�r3r�r,rhrj�test.support.script_helperrrhr?�
unittest.mockr�rIr��tempfilerrrr�test.supportrrr	r
rr�test.support.os_helperr
rrrrrrWr/�
DATAFILES_DIRrr%r&�TestCaser�r1r9r=r@rWr�r�r�r�r�r�r�r�r�rrAr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr$r0r=r[�tuple�consumertrr�r�r�r:r�r�r��mainr#r#r#r$�<module>s	�C����R���"BAVg[����
7}A#P'
$
>�

Youez - 2016 - github.com/yon3zu
LinuXploit