Your IP : 18.119.135.67


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/zipfile.cpython-310.pyc

o

6��fY`�@sLdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZz	ddlZejZWneyUdZejZYnwzddlZWneygdZYnwzddlZWneyydZYnwgd�ZGdd�de�ZGdd�de�ZeZZdZd	Zd	ZdZd
Z dZ!dZ"d
Z#dZ$dZ%dZ&dZ'dZ(dZ)e�*e(�Z+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3d
Z4dZ5dZ6dZ7e�*e6�Z8dZ9dZ:dZ;dZ<dZ=dZ>dZ?dZ@d
ZAdZBdZCdZDdZEdZFdZGd ZHd!ZId"ZJd#ZKd$ZLd%ZMe�*eL�ZNdZOdZPdZQdZRdZSdZTdZUdZVd
ZWdZXdZYdZZd&Z[d'Z\e�*e[�Z]d(Z^d)Z_e�*e^�Z`dZadZbdZcdZddZedZfdZgdZhd
ZidZjd*Zke�ld+�Zmd,d-�Znd.d/�Zod0d1�Zpd2d3�Zqd4d5�ZrGd6d7�d7es�Ztdaud8d9�Zvd:d;�ZwGd<d=�d=�ZxGd>d?�d?�Zyidd@�ddA�ddB�ddB�ddB�ddB�ddC�ddD�d
dE�ddF�ddC�ddG�ddH�d#dI�dJdK�dLdM�dNdO�ZzdPdQ�Z{dsdRdS�Z|dTdU�Z}GdVdW�dW�Z~GdXdY�dY�ZGdZd[�d[ej��Z�Gd\d]�d]ej��Z�Gd^d_�d_�Z�Gd`da�dae��Z�dbdc�Z�ddde�Z�e�j�Z�	dfdg�Z�Gdhdi�die��Z�Gdjdk�dke��Z�dsdldm�Z�Gdndo�do�Z�dsdpdq�Z�e�drk�r$e��dSdS)tzP
Read and write ZIP files.

XXX references to utf-8 need further investigation.
�N)
�
BadZipFile�
BadZipfile�error�
ZIP_STORED�ZIP_DEFLATED�	ZIP_BZIP2�ZIP_LZMA�
is_zipfile�ZipInfo�ZipFile�	PyZipFile�LargeZipFile�Pathc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�./opt/alt/python310/lib64/python3.10/zipfile.pyr,src@seZdZdZdS)r
zu
    Raised when writing a zipfile, the zipfile requires ZIP64 extensions
    and those extensions are disabled.
    N)rrr�__doc__rrrrr
0sr
i���������-�.�?s<4s4H2LHsPK��������	z<4s4B4HL2L5H2LsPK�
��
����z<4s2B4HL2L2HsPKz<4sLQLsPKz
<4sQ2H2L4QsPKiPK�<HHc
Cs�tj}d}g}d}}|dt|�krD||||d��\}}|d|}	||vr:||kr6|�|||��|	}d}|	}|dt|�ks|sH|S|t|�krW|�||d��d�|�S)NFrr T�)�_EXTRA_FIELD_STRUCT�unpack�len�append�join)
�extraZxidsr/Zmodified�buffer�start�iZxidZxlen�jrrr�_strip_extra�s&�	
r8cCs*z
t|�rWdSWdStyYdSw)NTF)�_EndRecData�OSError��fprrr�_check_zipfile�s���r=cCspd}z+t|d�rt|d�}W|St|d��}t|�}Wd�W|S1s&wYW|Sty7Y|Sw)z�Quickly see if a file is a ZIP file by checking the magic number.

    The filename argument may be a file or file-like object too.
    F�readr;�rbN)�hasattrr=�openr:)�filename�resultr<rrrr	�s
�
����r	c
Csz
|�|td�Wnty|YSw|�t�}t|�tkr#|St�t|�\}}}}|tkr3|S|dks;|dkr?t	d��|�|tt
d�|�t
�}t|�t
krV|St�t|�\
}}}	}
}}}
}}}|tkrl|S||t
<||t<||t<|
|t<||t<||t<||t<|S)zM
    Read the ZIP64 end-of-archive records and use that to update endrec
    rrrz3zipfiles that span multiple disks are not supported)�seek�sizeEndCentDir64Locatorr:r>r0�structr/�structEndArchive64Locator�stringEndArchive64Locatorr�sizeEndCentDir64�structEndArchive64�stringEndArchive64�_ECD_SIGNATURE�_ECD_DISK_NUMBER�_ECD_DISK_START�_ECD_ENTRIES_THIS_DISK�_ECD_ENTRIES_TOTAL�	_ECD_SIZE�_ECD_OFFSET)�fpin�offset�endrec�dataZsigZdisknoZreloffZdisksZsz�create_versionZread_versionZdisk_numZdisk_dirZdircountZ	dircount2ZdirsizeZ	diroffsetrrr�
_EndRecData64�s<�


�rXc	Csb|�dd�|��}z	|�td�Wn
tyYdSw|��}t|�tkrU|dd�tkrU|dd�dkrUt�t	|�}t
|�}|�d�|�|t�t|t|�St
|dtd�}|�|d�|��}|�t�}|dkr�|||t�}t|�tkr�dSt
t�t	|��}|t}||t|t|�}|�|�|�||�t|||||�SdS)	z�Return data from the "End of Central Directory" record, or None.

    The data is a list of the nine items in the ZIP "End of central dir"
    record followed by a tenth item, the file seek offset of this record.rrNr ���sr-i)rD�tell�sizeEndCentDirr:r>r0�stringEndArchiverFr/�structEndArchive�listr1rX�max�rfind�_ECD_COMMENT_SIZE)	rSZfilesizerVrUZmaxCommentStartr5ZrecDataZcommentSize�commentrrrr9sB�


�r9c@s\eZdZdZdZddd�Zdd�Zdd
d�Zdd
�Zdd�Z	e
ddd�dd��Zdd�Zd	S)r
z>Class with attributes describing each file in the ZIP archive.)�
orig_filenamerB�	date_time�
compress_type�_compresslevelrbr3�
create_systemrW�extract_version�reserved�	flag_bits�volume�
internal_attr�
external_attr�
header_offset�CRC�
compress_size�	file_size�	_raw_time�_end_offset�NoName��rrrrrcCs�||_|�td��}|dkr|d|�}tjdkr%tj|vr%|�tjd�}||_||_|ddkr5td��t	|_
d|_d|_d|_
tjdkrJd|_nd|_t|_t|_d|_d|_d|_d|_d|_d|_d|_d|_dS)Nr�/rvz+ZIP does not support timestamps before 1980r-Zwin32r)rc�find�chr�os�sep�replacerBrd�
ValueErrorrrerfrbr3�sys�platformrg�DEFAULT_VERSIONrWrhrirjrkrlrmrprqrs)�selfrBrdZ	null_byterrr�__init__\s6

zZipInfo.__init__cCs�d|jj|jfg}|jtkr|�dt�|j|j��|jd?}|jd@}|r2|�dt	�
|��|r;|�d|�|��}|rD|jrL|�d|j�|rQ|j
rd|jtks\|j|j
krd|�d|j
�|�d	�d
�|�S)Nz<%s filename=%r� compress_type=%sr)rz filemode=%rz external_attr=%#xz
 file_size=%rz compress_size=%r�>�)�	__class__rrBrerr1�compressor_names�getrm�stat�filemode�is_dirrqrpr2)r�rC�hi�lo�isdirrrr�__repr__�s,
��






zZipInfo.__repr__NcCsx|j}|ddd>|dd>B|dB}|dd>|d	d>B|ddB}|jd
@r3d}}}n	|j}|j}|j}|j}d}	|durM|tkpL|tk}|rad}
|t�|
dt�	|
�d	||�}|tksi|tkru|sot
d
��d}d}t}	|jt
kr�tt|	�}	n
|jtkr�tt|	�}	t|	|j�|_t|	|j�|_|��\}}t�tt|j|j||j|||||t|�t|��
}
|
||S)z-Return the per-file header as a bytes object.rrvr$rr!rrr&r rNz<HHQQz'Filesize would require ZIP64 extensions���)rdrjrorprqr3�ZIP64_LIMITrF�pack�calcsizer
�
ZIP64_VERSIONrerr_�
BZIP2_VERSIONr�LZMA_VERSIONrhrW�_encodeFilenameFlags�structFileHeader�stringFileHeaderrir0)r��zip64�dt�dosdate�dostimerorprqr3�min_version�fmtrBrj�headerrrr�
FileHeader�sJ$$
�




�zZipInfo.FileHeadercCs>z
|j�d�|jfWSty|j�d�|jdBfYSw)N�ascii�utf-8�)rB�encoderj�UnicodeEncodeError�r�rrrr��s
�zZipInfo._encodeFilenameFlagscCs6|j}tj}t|�dkr�|d|dd��\}}|dt|�kr'td||f��|dkr�|d|d�}zD|jdvrLd}|d|dd��\|_|dd�}|jd	krdd
}|d|dd��\|_|dd�}|jd	krvd}|d|dd��\|_Wntjy�td|�d
��d�w||dd�}t|�dksdSdS)Nr r,z"Corrupt extra field %04x (size=%d)r)l����r�z	File sizez<Qrr�z
Compress sizez
Header offsetzCorrupt zip64 extra field. z not found.)	r3rFr/r0rrqrprnr)r�r3r/�tpZlnrVZfieldrrr�_decodeExtra�s<


�����zZipInfo._decodeExtraT��strict_timestampsc	Cst|tj�rt�|�}t�|�}t�|j�}t�|j	�}|dd�}|s-|ddkr-d}n
|s7|ddkr7d}|dur=|}tj
�tj
�|�d�}|dtj
tjfvrc|dd�}|dtj
tjfvsS|ri|d	7}|||�}|jd
@d>|_|r�d|_|jdO_|S|j|_|S)a_Construct an appropriate ZipInfo for a file on the filesystem.

        filename should be the path to a file or directory on the filesystem.

        arcname is the name which it will have within the archive (by default,
        this will be the same as filename, but without a drive letter and with
        leading path separators removed).
        rr"rvru�;)r�r���;r�Nrrwrr))�
isinstancerz�PathLike�fspathr��S_ISDIR�st_mode�time�	localtime�st_mtime�path�normpath�
splitdriver{�altseprmrq�st_size)	�clsrB�arcnamer��str��mtimerd�zinforrr�	from_file�s4


�
�zZipInfo.from_filecCs|jddkS)z2Return True if this archive member is a directory.���rw�rBr�rrrr�szZipInfo.is_dir)rtru�N)
rrrr�	__slots__r�r�r�r�r��classmethodr�r�rrrrr
As
,
.%r
cCs0td�D]}|d@r|d?dA}q|dL}q|S)Nrrl q[)�range)�crcr7rrr�_gen_crcs

r�csld�d�d�tdurttttd���at��fdd������fdd��|D]}�|�q&��fd	d
�}|S)NixV4i�gE#i�xV4�cs|d?�||Ad@AS)z(Compute the CRC32 primitive on one byte.r�r)Zchr�)�crctablerr�crc329sz_ZipDecrypter.<locals>.crc32cs<�|�����d@d@��ddd@���d?���dS)Nr�r�i�r�r)�c)r��key0�key1�key2rr�update_keys=s
z"_ZipDecrypter.<locals>.update_keyscsNt�}|j}|D]}�dB}|||dAd?d@N}�|�||�qt|�S)zDecrypt a bytes object.rrrr�)�	bytearrayr1�bytes)rVrCr1r��k)r�r�rr�	decrypterGs
z _ZipDecrypter.<locals>.decrypter)�	_crctabler^�mapr�r�)�pwd�pr�r)r�r�r�r�r�r�r�
_ZipDecrypter/s
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�LZMACompressorcCs
d|_dSr�)�_compr�rrrr�Ws
zLZMACompressor.__init__cCsFt�dtji�}tjtjt�tj|�gd�|_t�dddt	|��|S)N�id��filtersz<BBHr$r )
�lzmaZ_encode_filter_properties�FILTER_LZMA1r��
FORMAT_RAW�_decode_filter_propertiesr�rFr�r0)r�Zpropsrrr�_initZs

�zLZMACompressor._initcCs*|jdur|��|j�|�S|j�|�Sr�)r�r��compress)r�rVrrrr�as
zLZMACompressor.compresscCs&|jdur|��|j��S|j��Sr�)r�r��flushr�rrrr�fs

zLZMACompressor.flushN)rrrr�r�r�r�rrrrr�Us
r�c@seZdZdd�Zdd�ZdS)�LZMADecompressorcCsd|_d|_d|_dS)Nr-F)�_decomp�_unconsumed�eofr�rrrr�ns
zLZMADecompressor.__init__c	Cs�|jdurM|j|7_t|j�dkrdSt�d|jdd��\}t|j�d|kr,dStjtjt�tj	|jdd|��gd�|_|jd|d�}|`|j�
|�}|jj|_|S)Nr r-z<Hrr�)r�r�r0rFr/r�r�r�r�r��
decompressr�)r�rVZpsizerCrrrr�ss"
�
�
zLZMADecompressor.decompressN)rrrr�r�rrrrr�lsr�ZstoreZshrink�reduceZimplode�tokenizeZdeflateZ	deflate64Zbzip2r�Zterse�Zlz77�aZwavpack�bZppmdcCs\|tkrdS|tkrtstd��dS|tkrtstd��dS|tkr*ts(td��dStd��)Nz.Compression requires the (missing) zlib modulez-Compression requires the (missing) bz2 modulez.Compression requires the (missing) lzma modulez(That compression method is not supported)	rr�zlib�RuntimeErrorr�bz2rr��NotImplementedError)�compressionrrr�_check_compression�s*������r�cCsf|tkr|durt�|tjd�St�tjtjd�S|tkr*|dur&t�|�St��S|tkr1t	�SdS)N��)
rr�ZcompressobjZDEFLATEDZZ_DEFAULT_COMPRESSIONrr�Z
BZ2Compressorrr�)re�
compresslevelrrr�_get_compressor�s
r�cCspt|�|tkr
dS|tkrt�d�S|tkrt��S|tkr"t	�St
�|�}|r1td||f��td|f��)Nr�zcompression type %d (%s)zcompression type %d)
r�rrr�Z
decompressobjrr�ZBZ2Decompressorrr�r�r�r�)reZdescrrrr�_get_decompressor�s

r�c@s8eZdZdd�Zdd�Zddd�Zdd	d
�Zdd�Zd
S)�_SharedFilecCs*||_||_||_||_||_|j|_dSr�)�_file�_pos�_close�_lock�_writing�seekable)r��file�pos�close�lockZwritingrrrr��sz_SharedFile.__init__cC�|jSr�)rr�rrrrZ��z_SharedFile.tellrcCsZ|j� |��rtd��|j�||�|j��|_|jWd�S1s&wYdS)Nz}Can't reposition in the ZIP file while there is an open writing handle on it. Close the writing handle before trying to read.)rrr}r�rDrZr)r�rT�whencerrrrD�s$�z_SharedFile.seekr�cCsd|j�%|��rtd��|j�|j�|j�|�}|j��|_|Wd�S1s+wYdS)N�yCan't read from the ZIP file while there is an open writing handle on it. Close the writing handle before trying to read.)rrr}r�rDrr>rZ�r��nrVrrrr>�s$�z_SharedFile.readcCs(|jdur|j}d|_|�|�dSdSr�)r�r)r��fileobjrrrr�s

�z_SharedFile.closeN�r�r�)rrrr�rZrDr>rrrrrr��s


r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�	_TellablecCs||_d|_dS�Nr)r<rT�r�r<rrrr��s
z_Tellable.__init__cCs|j�|�}|j|7_|Sr�)r<�writerT)r�rVrrrrr�sz_Tellable.writecCr	r�)rTr�rrrrZr
z_Tellable.tellcC�|j��dSr�)r<r�r�rrrr��z_Tellable.flushcCrr�)r<rr�rrrr	rz_Tellable.closeN)rrrr�rrZr�rrrrrr�srcs�eZdZdZdZdZdZ		d(dd�Zd	d
�Zdd�Z	d)dd�Z
d*dd�Zdd�Zd)dd�Z
dd�Zdd�Zdd�Zdd�Z�fdd �Zd!d"�Zd+d$d%�Zd&d'�Z�ZS),�
ZipExtFilezZFile-like object for reading an archive member.
       Is returned by ZipFile.open().
    i@iiNFcCs&||_||_||_|j|_|j|_|j|_t	|j�|_
d|_d|_d|_
d|_||_|j|_t|d�r=|j|_td�|_nd|_d|_z|��r\|��|_|j|_|j|_|j|_d|_Wn	tyfYnwd|_|r�|j d@ry|j!d?d@}n|jd?d@}|�"�}||kr�t#d	|j$��dSdS)
NFr-rroTrr�r�zBad password for file %r)%�_fileobj�_pwd�_close_fileobjre�_compress_typerp�_compress_leftrq�_leftr��
_decompressor�_eof�_readbuffer�_offset�newlines�moderB�namer@ro�
_expected_crcr��_running_crc�	_seekablerrZ�_orig_compress_start�_orig_compress_size�_orig_file_size�_orig_start_crc�AttributeError�
_decrypterrjrr�_init_decrypterr�rc)r�rr$�zipinfor�Z
close_fileobjZ
check_byte�hrrrr�sN

��
�zZipExtFile.__init__cCs4t|j�|_|j�d�}|jd8_|�|�dS)Nrr&)r�rr.rr>r)r�r�rrrr/NszZipExtFile._init_decryptercCsvd|jj|jjfg}|js,|�d|j|jf�|jtkr+|�dt	�
|j|j��n|�d�|�d�d�|�S)N�<%s.%sz name=%r mode=%rr��	 [closed]r�r�)r�rr�closedr1r%r$rrr�r�r2�r�rCrrrr�Ys�
���


zZipExtFile.__repr__r�cCsL|dkr|j�d|j�d}|dkr|j|j|�}||_|Stj�||�S)zrRead and return a line from the stream.

        If limit is specified, at most limit bytes will be read.
        r�
r)r!rxr"�io�BufferedIOBase�readline)r��limitr6�linerrrr9gszZipExtFile.readlinercCsr|t|j�|jkr.|�|�}t|�|jkr%||j|jd�|_d|_n	|jt|�8_|j|j|jd�S)z6Returns buffered bytes without advancing the position.Nri)r0r!r"r>)r�r�chunkrrr�peekws
zZipExtFile.peekcCs|jrtd��dS)N�I/O operation on closed file.T)r4r}r�rrr�readable�szZipExtFile.readablecCs"|jrtd��|dus|dkr-|j|jd�}d|_d|_|js+||�|j�7}|jr |S||j}|t|j�krF|j|j|�}||_|S|t|j�}|j|jd�}d|_d|_|dkr�|js�|�|�}|t|�kr~||_||_||d|�7}	|S||7}|t|�8}|dkr�|jrb|S)z�Read and return up to n bytes.
        If the argument is omitted, None, or negative, data is read and returned until EOF is reached.
        zread from closed file.Nrr-)r4r}r!r"r �_read1�MAX_Nr0)r�r�buf�endrVrrrr>�s>�

��	zZipExtFile.readcCsD|jdurdSt||j�|_|jr|j|jkr td|j��dSdS)NzBad CRC-32 for file %r)r&r�r'r rr%)r��newdatarrr�_update_crc�s
�zZipExtFile._update_crccCs|dus|dkr-|j|jd�}d|_d|_|js+|�|j�}|r(||7}	|S|jr|S||j}|t|j�krF|j|j|�}||_|S|t|j�}|j|jd�}d|_d|_|dkr�|js�|�|�}|t|�kr~||_||_||d|�7}	|S|r�||7}	|S|jrb|S)z7Read up to n bytes with at most one read() system call.Nrr-)r!r"r r@rAr0)r�rrBrVrCrrr�read1�sH�

��
zZipExtFile.read1cCs |js|dkr	dS|jtkr$|jj}|t|�kr#||�|t|��7}n|�|�}|jtkr5|jdk|_n<|jtkrat	||j
�}|j�||�}|jjpT|jdkoT|jj|_|jr`||j�
�7}n|j�|�}|jjpo|jdk|_|d|j�}|jt|�8_|jdkr�d|_|�|�|S)Nrr-T)r rrrZunconsumed_tailr0�_read2rrr_�
MIN_READ_SIZEr�r�r�rrEr
rrrr@�s8
�



��

zZipExtFile._read1cCsd|jdkrdSt||j�}t||j�}|j�|�}|jt|�8_|s&t�|jdur0|�|�}|S)Nrr-)	rr_rH�minrr>r0�EOFErrorr.r
rrrrG�s


zZipExtFile._read2cs>z|jr|j��Wt���dSWt���dSt���wr�)rrr�superr��r�rrrs�zZipExtFile.closecCs|jrtd��|jS�Nr>)r4r}r(r�rrrrszZipExtFile.seekablercCsJ|jrtd��|jst�d��|��}|dkr|}n|dkr#||}n|dkr-|j|}ntd��||jkr9|j}|dkr?d}||}||j}|dkrY|t|j	�krY||_d}n1|dkr�|j
�|j�|j
|_|j|_|j|_d|_	d|_t|j�|_d|_|}|jdur�|��|dkr�t|j|�}|�|�||8}|dks�|��S)	Nzseek on closed file.�!underlying stream is not seekablerrrzCwhence must be os.SEEK_SET (0), os.SEEK_CUR (1), or os.SEEK_END (2)r-F)r4r}r(r7�UnsupportedOperationrZr+r"r0r!rrDr)r,r'r*rrr�rrr r.r/rI�
MAX_SEEK_READr>)r�rTrZcurr_posZnew_posZread_offsetZbuff_offsetZread_lenrrrrDsN





�zZipExtFile.seekcCs>|jrtd��|jst�d��|j|jt|j�|j	}|S)Nztell on closed file.rN)
r4r}r(r7rOr+rr0r!r")r�ZfileposrrrrZMs
zZipExtFile.tell)NFr�rr)rrrrrArHrPr�r/r�r9r=r?r>rErFr@rGrrrDrZ�
__classcell__rrrLrr
s,
�3


#
%$
2rcs@eZdZdd�Zedd��Zdd�Zdd�Z�fd	d
�Z�Z	S)�
_ZipWriteFilecCs8||_||_||_t|j|j�|_d|_d|_d|_	dSr)
�_zinfo�_zip64�_zipfiler�rerf�_compressor�
_file_size�_compress_size�_crc)r��zfr�r�rrrr�Ws�
z_ZipWriteFile.__init__cCs|jjSr�)rVr<r�rrrrasz_ZipWriteFile._fileobjcCsdS)NTrr�rrr�writablee�z_ZipWriteFile.writablecCs�|jrtd��t|ttf�rt|�}nt|�}|j}|j|7_t	||j
�|_
|jr:|j�|�}|j
t|�7_
|j�|�|SrM)r4r}r�r�r�r0�
memoryview�nbytesrXr�rZrWr�rYrr)r�rVr_rrrrhs
z_ZipWriteFile.writec	sf|jrdSz�t���|jr(|j��}|jt|�7_|j�|�|j|j	_
n|j|j	_
|j|j	_
|j|j	_|j	jd@r_|jrBdnd}|j�t�|t|j	j
|j	j
|j	j��|j��|j_n7|jst|jtkrktd��|jtkrttd��|j��|j_|j�|j	j�|j�|j	�|j��|j�|jj�|jj�|j	�|j	|jj|j	j<Wd|j_ dSd|j_ w)Nrz<LLQQz<LLLLz+File size unexpectedly exceeded ZIP64 limitz1Compressed size unexpectedly exceeded ZIP64 limitF)!r4rKrrWr�rYr0rrrTrprXrZrorqrjrUrFr��
_DD_SIGNATURErZrV�	start_dirr�r�rDrnr��filelistr1�
NameToInforBr)r�rBr�rLrrr{sD




�
�
�z_ZipWriteFile.close)
rrrr��propertyrr\rrrRrrrLrrSVs

rSc@s*eZdZdZdZdZdeddfdd�dd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
d=dd�Zdd�Zdd�Zdd�Zedd��Zejdd��Zd=dd �Zd>d!d"�d#d$�Zd?d%d&�Zd@d'd(�ZdAd)d*�Zed+d,��Zd-d.�Zd/d0�Z		dAd1d2�Z	d@d3d4�Zd5d6�Z d7d8�Z!d9d:�Z"d;d<�Z#dS)Brai Class with methods to open, read, write, close, list zip files.

    z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True,
                compresslevel=None)

    file: Either the path to the file, or a file-like object.
          If it is a path, the file will be opened and closed by ZipFile.
    mode: The mode can be either read 'r', write 'w', exclusive create 'x',
          or append 'a'.
    compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),
                 ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).
    allowZip64: if True ZipFile will create files with ZIP64 extensions when
                needed, otherwise it will raise an exception when this would
                be necessary.
    compresslevel: None (default for the given compression type) or an integer
                   specifying the level to pass to the compressor.
                   When using ZIP_STORED or ZIP_LZMA this keyword has no effect.
                   When using ZIP_DEFLATED integers 0 through 9 are accepted.
                   When using ZIP_BZIP2 integers 1 through 9 are accepted.

    N�rTr�c
	Cs@|dvrtd��t|�||_d|_d|_i|_g|_||_||_||_	d|_
d|_||_t
|tj�r8t�|�}t
|t�rpd|_||_ddd	d
dddd
�}||}	z	t�||�|_Wntym||vrl||}YqQ�w	n
d|_||_t|dd�|_d|_t��|_d|_d|_z�|dkr�|��WdS|dvr�d|_z|j� �|_!Wnt"tfy�t#|j�|_d|_!d|_YWdSwz|j�$|j!�WWdSt"tfy�d|_YWdSw|dk�r
z|��|j�$|j!�WWdSt%�y|j�$dd�d|_|j� �|_!YWdSwtd��|j}	d|_|�&|	��)z]Open the ZIP file with mode read 'r', write 'w', exclusive create 'x',
        or append 'a'.)re�w�x�az+ZipFile requires mode 'r', 'w', 'x', or 'a'FrNr-r?�w+b�x+b�r+b�wbZxb)rerfrgrhrkrirjTrr%re)rfrgrhrz"Mode must be 'r', 'w', 'x', or 'a')'r}r��_allowZip64�
_didModify�debugrcrbr�r�r$r��_comment�_strict_timestampsr�rzr�r��str�_filePassedrBr7rAr<r:�getattr�_fileRefCnt�	threading�RLockrr(r�_RealGetContentsrZrar-rrDr�_fpclose)
r�rr$r��
allowZip64r�r�ZmodeDictr�r<rrrr��s�

��
��
�	
zZipFile.__init__cCs|Sr�rr�rrr�	__enter__r]zZipFile.__enter__cCs|��dSr��r)r��type�value�	tracebackrrr�__exit__"�zZipFile.__exit__cCs�d|jj|jjfg}|jdur2|jr|�d|j�n
|jdur)|�d|j�|�d|j�n|�d�|�d�d�|�S)Nr2z file=%rz filename=%rz mode=%rr3r�r�)	r�rrr<rsr1rBr$r2r5rrrr�%s�




zZipFile.__repr__cCs�|j}zt|�}Wntytd��w|std��|jdkr$t|�|t}|t}|t|_	|t
||}|ttkrE|t
t8}|jdkrU||}td|||�|||_|jdkrctd��|�|jd�|�|�}t�|�}d}||k�r_|�t�}	t|	�tkr�td��t�t|	�}	|	ttkr�td��|jdkr�t|	�|�|	t�}
|	d	}|d
@r�|
�d�}
n|
�d�}
t|
�}|�|	t�|_|�|	t �|_!|	t"|_#|	dd
�\|_$|_%|_&|_'|_(|_)}
}|_*|_+|_,|j&t-kr�t.d|j&d��|	dd�\|_/|_0|_1|
|_2|d?d|d	?d@|d@|
d?|
d	?d@|
d@df|_3|�4�|j#||_#|j5�6|�||j7|j8<|t|	t|	t|	t }|jdk�r[td|�||ks{|j}t9|j5dd�dd�D]	}||_:|j#}�qldS)z/Read in the table of contents for the ZIP file.zFile is not a zip filerrzgiven, inferred, offsetrz Bad offset for central directoryzTruncated central directoryz&Bad magic number for central directoryr!r�r��cp437rzzip file version %.1fr%r(r+r$rvr�r&r�totalcSr	r�)rn)r�rrr�<lambda>��z*ZipFile._RealGetContents.<locals>.<lambda>T)�key�reverseN);r<r9r:rro�printrQrR�_ECD_COMMENTrp�
_ECD_LOCATIONrLrKrIrErarDr>r7�BytesIO�sizeCentralDirr0rFr/�structCentralDir�
_CD_SIGNATURE�stringCentralDir�_CD_FILENAME_LENGTH�decoder
�_CD_EXTRA_FIELD_LENGTHr3�_CD_COMMENT_LENGTHrb�_CD_LOCAL_HEADER_OFFSETrnrWrgrhrirjrerorprq�MAX_EXTRACT_VERSIONr�rkrlrmrrrdr�rbr1rcrB�sortedrs)r�r<rUZsize_cdZ	offset_cd�concatZinferredrVr��centdirrB�flagsrg�t�d�
end_offsetr�rrrrx3s��












�
����
�/
�
�zZipFile._RealGetContentscCsdd�|jD�S)z+Return a list of file names in the archive.cSsg|]}|j�qSrr�)�.0rVrrr�
<listcomp>�sz$ZipFile.namelist.<locals>.<listcomp>�rbr�rrr�namelist�szZipFile.namelistcCr	)zJReturn a list of class ZipInfo instances for files in the
        archive.r�r�rrr�infolist��zZipFile.infolistcCsLtdd|d�|jD]}d|jdd�}td|j||jf|d�qdS)z+Print a table of contents for the zip file.z%-46s %19s %12s)z	File NamezModified    ZSize)rz%d-%02d-%02d %02d:%02d:%02dNr"z
%-46s %s %12d)r�rbrdrBrq)r�rr��daterrr�printdir�s�
��zZipFile.printdirc	Csxd}|jD]4}z$|�|jd��}|�|�r	|�|�sWd�n1s%wYWqty9|jYSwdS)z%Read all the files and check the CRC.ireN)rbrArBr>r)r�Z
chunk_sizer��frrr�testzip�s


������zZipFile.testzipcCs$|j�|�}|durtd|��|S)z,Return the instance of ZipInfo given 'name'.Nz(There is no item named %r in the archive)rcr��KeyError)r�r%�inforrr�getinfo�s�zZipFile.getinfocCs8|rt|t�stdt|�j��|r||_dSd|_dS)z)Set default password for encrypted files.�pwd: expected bytes, got %sN)r�r��	TypeErrorr}rr�)r�r�rrr�setpassword�s


zZipFile.setpasswordcCr	)z.The comment text associated with the ZIP file.)rpr�rrrrb�r�zZipFile.commentcCs^t|t�stdt|�j��t|�tkr'ddl}|jdtdd�|dt�}||_	d|_
dS)Nzcomment: expected bytes, got %srz3Archive comment is too long; truncating to %d bytesr��
stacklevelT)r�r�r�r}rr0�ZIP_MAX_COMMENT�warnings�warnrprn)r�rbr�rrrrb�s
��
cCs:|�|d|��}|��Wd�S1swYdS)zReturn file bytes for name.reN�rAr>)r�r%r�r<rrrr>�s$�zZipFile.readF��force_zip64cs*|dvrtd��|rt|t�stdt|�j��|r"|dkr"td���js)td��t|t�r1|}n|dkrBt|�}�j|_	�j
|_n��|�}|dkrR�j
||d�S�jrYtd���jd	7_t�j|j�j�j�fd
d��}z�|�t�}t|�tkr�td��t�t|�}|ttkr�td
��|�|t�}|tr�|�|t�|jd@r�t d��|jd@r�t d��|t!d@r�|�"d�}	n|�"d�}	|	|j#kr�td|j#|f��|j$dur�|�%�|j&|j$kr�td|j#�d���|jd	@}
|
�r|s��j'}|�st(d|��nd}t)||||d�WS|�*��)auReturn file-like object for 'name'.

        name is a string for the file name within the ZIP file, or a ZipInfo
        object.

        mode should be 'r' to read a file already in the ZIP file, or 'w' to
        write to a file newly added to the archive.

        pwd is the password to decrypt files (only used for reading).

        When writing, if the file size is not known in advance but may exceed
        2 GiB, pass force_zip64 to use the ZIP64 format, which can handle large
        files.  If the size is known in advance, it is best to pass a ZipInfo
        instance for name, with zinfo.file_size set.
        >rfrezopen() requires mode "r" or "w"r�rfz'pwd is only supported for reading filesz2Attempt to use ZIP archive that was already closedr�rrcs�jSr�)rrr�rrr�r�zZipFile.open.<locals>.<lambda>zTruncated file headerz Bad magic number for file header� z$compressed patched data (flag bit 5)�@zstrong encryption (flag bit 6)r�r�r�z/File name in directory %r and header %r differ.NzOverlapped entries: z (possible zip bomb)z6File %r is encrypted, password required for extractionT)+r}r�r�r�r}rr<r
r�rer�rfr��_open_to_writerrur�rnryrr>�sizeFileHeaderr0rrFr/r��
_FH_SIGNATUREr��_FH_FILENAME_LENGTH�_FH_EXTRA_FIELD_LENGTHrjr��_FH_GENERAL_PURPOSE_FLAG_BITSr�rcrsrZrpr�r�rr)r�r%r$r�r�r�Zzef_fileZfheader�fnameZ	fname_strZis_encryptedrr�rrA�s��



�




��

��zZipFile.opencCs�|r	|js	td��|jrtd��d|_d|_d|_|jtkr%|jdO_|js/|jdO_|j	s5d|_	|jo@|p@|j
dtk}|jrK|j�
|j�|j��|_|�|�d|_|j�|�|��d|_t|||�S)	NzHforce_zip64 is True, but allowZip64 was False when opening the ZIP file.zzCan't write to the ZIP file while there is another write handle open on it. Close the first handle before opening another.rrr��g�������?T)rmr}rrprorjrerr(rmrqr�r<rDrarZrn�_writecheckrnrr�rS)r�r�r�r�rrrr�7s4
�
�
zZipFile._open_to_writecCs*|dur	t��}nt�|�}|�|||�S)a#Extract a member from the archive to the current working directory,
           using its full name. Its file information is extracted as accurately
           as possible. `member' may be a filename or a ZipInfo object. You can
           specify a different directory using `path'.
        N)rz�getcwdr��_extract_member)r��memberr�r�rrr�extract`s

zZipFile.extractcCsH|dur|��}|durt��}nt�|�}|D]	}|�|||�qdS)z�Extract all members from the archive to the current working
           directory. `path' specifies a different directory to extract to.
           `members' is optional and must be a subset of the list returned
           by namelist().
        N)r�rzr�r�r�)r�r��membersr�r0rrr�
extractallms

�zZipFile.extractallcCs^|j}|sd}t�|dt|��}||_|�|�}dd�|�|�D�}|�dd�|D��}|S)z;Replace bad characters and remove trailing dots from parts.z:<>|"?*�_css�|]}|�d�VqdS)�.N)�rstrip�r�rgrrr�	<genexpr>���z1ZipFile._sanitize_windows_name.<locals>.<genexpr>css�|]}|r|VqdSr�rr�rrrr��s�)�!_windows_illegal_name_trans_tablerr�	maketransr0�	translate�splitr2)r�r��pathsep�tableZillegalrrr�_sanitize_windows_name~s
zZipFile._sanitize_windows_namec	s�t|t�s
|�|�}|j�dtjj�}tjjr!|�tjjtjj�}tj�	|�d}dtjj
tjjf�tjj��fdd�|�
tjj�D��}tjjdkrS|�|tjj�}tj�||�}tj�|�}tj�|�}|rstj�|�sst�|�|��r�tj�|�s�t�|�|S|j||d��,}t|d��}t�||�Wd	�n1s�wYWd	�|SWd	�|S1s�wY|S)
zbExtract the ZipInfo object 'member' to a physical
           file on the path targetpath.
        rwrr�c3s�|]	}|�vr|VqdSr�rr��Zinvalid_path_partsrrr��s���z*ZipFile._extract_member.<locals>.<genexpr>�\�r�rlN)r�r
r�rBr|rzr�r{r�r��curdir�pardirr2r�r�r��dirname�exists�makedirsr�r��mkdirrA�shutil�copyfileobj)r�r�Z
targetpathr�r�Z	upperdirs�source�targetrr�rr��s<

&

�(���zZipFile._extract_membercCs�|j|jvrddl}|jd|jdd�|jdvrtd��|js$td��t|j�|j	sOd}t
|j�tkr8d	}n|j
tkr@d
}n|jtkrGd}|rQt|d��dSdS)
z6Check for errors before writing a file to the archive.rNzDuplicate name: %rrr��rfrgrhz&write() requires mode 'w', 'x', or 'a'z4Attempt to write ZIP archive that was already closed�Files countZFilesizezZipfile size� would require ZIP64 extensions)rBrcr�r�r$r}r<r�rermr0rb�ZIP_FILECOUNT_LIMITrqr�rnr
)r�r�r��requires_zip64rrrr��s0
�


��zZipFile._writecheckc	Cs�|jstd��|jrtd��tj|||jd�}|��r"d|_d|_n|dur*||_	n|j
|_	|dur6||_n|j|_|��r�|j
�H|jrL|j�|j�|j��|_|j	tkr^|jdO_|�|�d|_|j�|�||j|j<|j�|�d��|j��|_Wd�dS1s�wYdSt|d	��.}|�|d
��}t�||d�Wd�n1s�wYWd�dSWd�dS1s�wYdS)zLPut the bytes from filename into the archive under the name
        arcname.�7Attempt to write to ZIP archive that was already closedz>Can't write to ZIP archive while an open writing handle existsr�rNrTFr?rfi ) r<r}rr
r�rqr�rprorer�rfr�rr(rDrarZrnrrjr�rnrbr1rcrBrr�rAr�r�)r�rBr�rer�r��src�destrrrr�sJ���

"�P�z
ZipFile.writec	Cs2t|t�r
|�d�}t|t�s<t|t�t���dd�d�}|j|_|j|_	|j
ddkr8d|_|jdO_nd	|_n|}|jsEt
d
��|jrLt
d��|durS||_|durZ||_	t|�|_|j�-|j|dd
��
}|�|�Wd�n1szwYWd�dSWd�dS1s�wYdS)aWrite a file into the archive.  The contents is 'data', which
        may be either a 'str' or a 'bytes' instance; if it is a 'str',
        it is encoded as UTF-8 first.
        'zinfo_or_arcname' is either a ZipInfo instance or
        the name of the file in the archive.r�Nr")rBrdr�rwi�Ar)r�r�z?Can't write to ZIP archive while an open writing handle exists.rf)r$)r�rrr�r
r�r�r�rer�rfrBrmr<r}rr0rqrrAr)r�Zzinfo_or_arcnamerVrer�r�r�rrr�writestr�sB


���
��"�zZipFile.writestrcCs|��dS)z2Call the "close()" method in case the user forgot.Nr|r�rrr�__del__(szZipFile.__del__c	Cs�|jdurdS|jrtd��za|jdvrF|jrT|j�|jr%|j�|j�|�	�Wd�n21s3wYW|j}d|_|�
|�dSW|j}d|_|�
|�dSW|j}d|_|�
|�dSW|j}d|_|�
|�dS|j}d|_|�
|�w)zOClose the file, and for mode 'w', 'x' and 'a' write the ending
        records.NzvCan't close the ZIP file while there is an open writing handle on it. Close the writing handle before closing the zip.r�)r<rr}r$rnrr(rDra�_write_end_recordryrrrrr,s:

�����z
ZipFile.closecCs
|jD]�}|j}|ddd>|dd>B|dB}|dd>|d	d>B|ddB}g}|jtks8|jtkrI|�|j�|�|j�d
}d
}n|j}|j}|jtkr]|�|j�d
}n|j}|j}	d}
|r�t|	d�}	t	j
dd
t|�ddt|�g|�R�|	}	t}
|j
tkr�tt|
�}
n
|j
tkr�tt|
�}
t|
|j�}t|
|j�}|��\}
}t	�
tt||j||j||j
|||j||t|
�t|	�t|j�d|j|j|�}|j�|�|j�|
�|j�|	�|j�|j�q|j� �}t|j�}||j!}|j!}d}|t"k�rd}n|tk�rd}n|tk�rd}|�rV|j#�s#t$|d��t	�
t%t&ddddd||||�}|j�|�t	�
t't(d|d�}|j�|�t)|d�}t)|d
�}t)|d
�}t	�
t*t+dd||||t|j,��	}|j�|�|j�|j,�|j-dk�r~|j�.�|j�/�dS)Nrrvr$rr!rrr&r r�rQr,�Qrr�zCentral directory offsetzCentral directory sizer��,rrrh)0rbrdrqr�rpr1rnr3r8rFr�r0r�rerr_r�rr�rhrWr�r�r�rgrirorbrlrmr<rrZrar�rmr
rJrKrGrHrIr]r\rpr$�truncater�)r�r�r�r�r�r3rqrprnZ
extra_datar�rhrWrBrjr�Zpos2ZcentDirCountZcentDirSizeZ
centDirOffsetr�Zzip64endrecZzip64locrecrUrrrr�Bs�
$$



���





�





���


�
zZipFile._write_end_recordcCs<|jdksJ�|jd8_|js|js|��dSdSdS)Nrr)rursrrrrrry�s
�zZipFile._fpcloser�)reN)F)NN)NNN)$rrrrr<r�rr�r{r�r�rxr�r�r�r�r�r�rdrb�setterr>rAr�r�r�r�r�r�r�rr�r�rr�ryrrrrr�sR��ZV
	
		



f
)


*
�2
�)^rc@s4eZdZdZdeddfdd�Zd
d	d
�Zdd�ZdS)rzDClass to create ZIP archives with Python library files and packages.reTr�cCstj|||||d�||_dS)N)r$r�rz)rr��	_optimize)r�rr$r�rz�optimizerrrr��s�
zPyZipFile.__init__r�NcCs�t�|�}|r"||�s"|jr tj�|�rdnd}td||f�dStj�|�\}}tj�|��r-tj�|d�}tj�|�r�|rGd||f}n|}|jrStd|d|�|�	|d	d
�|�\}}	|jrgtd|	�|�
||	�tt�|��}
|
�
d�|
D]Y}tj�||�}tj�|�\}
}tj�|�r�tj�tj�|d��r�|j|||d�q{|d
kr�|r�||�s�|jr�td|�q{|�	|d	d
�|�\}}	|jr�td|	�|�
||	�q{dS|jr�td|�tt�|��D]D}tj�||�}tj�|�\}
}|d
k�r*|�r||��s|j�rtd|�q�|�	|d	d
�|�\}}	|j�r$td|	�|�
||	�q�dS|d
d�d
k�r:td��|�	|d	d
�|�\}}	|j�rOtd|	�|�
||	�dS)a�Add all files from "pathname" to the ZIP archive.

        If pathname is a package directory, search the directory and
        all package subdirectories recursively for all *.py and enter
        the modules into the archive.  If pathname is a plain
        directory, listdir *.py and enter all modules.  Else, pathname
        must be a Python *.py file and the module will be put into the
        archive.  Added modules are always module.pyc.
        This method will compile the module.py into module.pyc if
        necessary.
        If filterfunc(pathname) is given, it is called with every argument.
        When it is False, the file or directory is skipped.
        r�rz%s %r skipped by filterfuncNz__init__.py�%s/%szAdding package in�asr���ZAdding)�
filterfunc�.pyzfile %r skipped by filterfunczAdding files from directoryz.Files added with writepy() must end with ".py"zAdding file)rzr�ror�r�r�r�r2�isfile�
_get_codenamerr��listdir�remove�splitext�writepyr�)r��pathname�basenamer�Zlabel�dirr%Zinitnamer�r�ZdirlistrBr��rootZextrrrr��s�


���
��

�
���
zPyZipFile.writepyc
s�d�fdd�	}|d}|d}tjj|dd�}tjj|dd�}tjj|d	d�}�jdkr�tj�|�rCt�|�jt�|�jkrC|}	}
n�tj�|�rZt�|�jt�|�jkrZ|}
|}	n�tj�|�rqt�|�jt�|�jkrq|}
|}	nztj�|�r�t�|�jt�|�jkr�|}
|}	nc||�r�t	j
jd
kr�|}
nt	j
jdkr�|}
n|}
|}	nH|}
}	nC�jd
kr�|}
|}	n|}	�jdkr�|}
n�jd	kr�|}
n
d��j�}t
|��tj�|
�r�t�|
�jt�|�jks�||�jd�s�|}
}	tj�|	�d}|r�d
||f}|
|fS)aReturn (filename, archivename) for the path.

        Given a module name path, return the correct file path and
        archive name, compiling if necessary.  For example, given
        /python/lib/string, return (/python/lib/string.pyc, string).
        r�c
sbddl}�jrtd|�z|j|d|d�WdS|jy0}zt|j�WYd}~dSd}~ww)NrZ	CompilingT)�doraiser�F)�
py_compileror��compile�PyCompileError�msg)rr�r�errr�rr�_compile	s
�
��z)PyZipFile._get_codename.<locals>._compiler�z.pycr�)�optimizationrrrz"invalid value for 'optimize': {!r})r�r�Nr)�	importlib�util�cache_from_sourcer�rzr�r�r�r�r~r�r��formatr}r�)
r�r�r�rZfile_pyZfile_pycZpycache_opt0Zpycache_opt1Zpycache_opt2r�r�rZarchivenamerr�rr�s`





zPyZipFile._get_codename)r�N)rrrrrr�r�r�rrrrr�s
�
RrcCst�t|�dd�S)a2
    Given a path with elements separated by
    posixpath.sep, generate all parents of that path.

    >>> list(_parents('b/d'))
    ['b']
    >>> list(_parents('/b/d/'))
    ['/b']
    >>> list(_parents('b/d/f/'))
    ['b/d', 'b']
    >>> list(_parents('b'))
    []
    >>> list(_parents(''))
    []
    rN)�	itertools�islice�	_ancestry)r�rrr�_parentsUsrccsB�|�tj�}|�tj�r|Vt�|�\}}|�tj�s
dSdS)a�
    Given a path with elements separated by
    posixpath.sep, generate all elements of that path.

    >>> list(_ancestry('b/d'))
    ['b/d', 'b']
    >>> list(_ancestry('/b/d/'))
    ['/b/d', '/b']
    >>> list(_ancestry('b/d/f/'))
    ['b/d/f', 'b/d', 'b']
    >>> list(_ancestry('b'))
    ['b']
    >>> list(_ancestry(''))
    []

    Multiple separators are treated like a single.

    >>> list(_ancestry('//b//d///f//'))
    ['//b//d///f', '//b//d', '//b']
    N)r��	posixpathr{r�)r��tailrrrrhs��rcCst�t|�j|�S)zZ
    Return items in minuend not in subtrahend, retaining order
    with O(1) lookup.
    )r�filterfalse�set�__contains__)ZminuendZ
subtrahendrrr�_difference�srcsTeZdZdZedd��Z�fdd�Zdd�Zdd	�Z�fd
d�Z	e
dd
��Z�ZS)�CompleteDirszk
    A ZipFile subclass that ensures that implied directories
    are always included in the namelist.
    cCs.tj�tt|��}dd�|D�}tt||��S)Ncss�|]}|tjVqdSr�)rr{)r�r�rrrr��r�z-CompleteDirs._implied_dirs.<locals>.<genexpr>)r�chain�
from_iterabler�r�_deduper)�names�parentsZas_dirsrrr�
_implied_dirs�szCompleteDirs._implied_dirscs tt|���}|t|�|��Sr�)rKrr�r^r)r�rrLrrr��szCompleteDirs.namelistcCst|���Sr�)rr�r�rrr�	_name_set�r�zCompleteDirs._name_setcCs,|��}|d}||vo||v}|r|S|S)zx
        If the name represents a directory, return that name
        as a directory (with the trailing slash).
        rw)r)r�r%rr�Z	dir_matchrrr�resolve_dir�szCompleteDirs.resolve_dircsDzt��|�WSty!|�d�r||��vr�t|d�YSw)z6
        Supplement getinfo for implied dirs.
        rwr�)rKr�r��endswithrr
)r�r%rLrrr��s�zCompleteDirs.getinfocCs8t|t�r|St|t�s||�Sd|jvrt}||_|S)zl
        Given a source (filename or zipfile), return an
        appropriate CompleteDirs subclass.
        re)r�rrr$r�)r�r�rrr�make�s


zCompleteDirs.make)
rrrr�staticmethodrr�rrr�r�r rRrrrLrr�s

rcs,eZdZdZ�fdd�Z�fdd�Z�ZS)�
FastLookupzV
    ZipFile subclass to ensure implicit
    dirs exist and are resolved rapidly.
    c�Ft�t��|jWd�S1swYtt|���|_|jSr�)�
contextlib�suppressr-Z_FastLookup__namesrKr"r�r�rLrrr���
 �zFastLookup.namelistcr#r�)r$r%r-Z_FastLookup__lookuprKr"rr�rLrrr�r&zFastLookup._name_set)rrrrr�rrRrrrLrr"�sr"cOst�|d�||fS)Nr)r7�
text_encoding)�encoding�args�kwargsrrr�_extract_text_encoding�sr+c@s�eZdZdZdZd'dd�Zd(dd�d	d
�Zedd��Zed
d��Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZeZed%d&��ZdS))ru,
    A pathlib-compatible interface for zip files.

    Consider a zip file with this structure::

        .
        ├── a.txt
        └── b
            ├── c.txt
            └── d
                └── e.txt

    >>> data = io.BytesIO()
    >>> zf = ZipFile(data, 'w')
    >>> zf.writestr('a.txt', 'content of a')
    >>> zf.writestr('b/c.txt', 'content of c')
    >>> zf.writestr('b/d/e.txt', 'content of e')
    >>> zf.filename = 'mem/abcde.zip'

    Path accepts the zipfile object itself or a filename

    >>> root = Path(zf)

    From there, several path operations are available.

    Directory iteration (including the zip file itself):

    >>> a, b = root.iterdir()
    >>> a
    Path('mem/abcde.zip', 'a.txt')
    >>> b
    Path('mem/abcde.zip', 'b/')

    name property:

    >>> b.name
    'b'

    join with divide operator:

    >>> c = b / 'c.txt'
    >>> c
    Path('mem/abcde.zip', 'b/c.txt')
    >>> c.name
    'c.txt'

    Read text:

    >>> c.read_text()
    'content of c'

    existence:

    >>> c.exists()
    True
    >>> (b / 'missing.txt').exists()
    False

    Coercion to string:

    >>> import os
    >>> str(c).replace(os.sep, posixpath.sep)
    'mem/abcde.zip/b/c.txt'

    At the root, ``name``, ``filename``, and ``parent``
    resolve to the zipfile. Note these attributes are not
    valid and will raise a ``ValueError`` if the zipfile
    has no filename.

    >>> root.name
    'abcde.zip'
    >>> str(root.filename).replace(os.sep, posixpath.sep)
    'mem/abcde.zip'
    >>> str(root.parent)
    'mem'
    z>{self.__class__.__name__}({self.root.filename!r}, {self.at!r})r�cCst�|�|_||_dS)aX
        Construct a Path from a ZipFile or filename.

        Note: When the source is an existing ZipFile object,
        its type (__class__) will be mutated to a
        specialized type. If the caller wishes to retain the
        original type, the caller should either create a
        separate ZipFile object or pass a filename.
        N)r"r r��at)r�r�r,rrrr�3	s

z
Path.__init__reNr�cOs�|��rt|��|d}|��s|dkrt|��|jj|j||d�}d|vr0|s*|r.td��|St|i|��\}}}t	j
||g|�Ri|��S)z�
        Open this entry as text or binary following the semantics
        of ``pathlib.Path.open()`` by passing arguments through
        to io.TextIOWrapper().
        rrer��bz*encoding args invalid for binary operation)r��IsADirectoryErrorr��FileNotFoundErrorr�rAr,r}r+r7�
TextIOWrapper)r�r$r�r)r*Zzip_mode�streamr(rrrrA@	sz	Path.opencCst�|j�jp
|jjSr�)�pathlibZ
PurePosixPathr,r%rBr�rrrr%T	�z	Path.namecCst�|jj��|j�Sr�)r2rr�rB�joinpathr,r�rrrrBX	r3z
Path.filenamecOsZt|i|��\}}}|jd|g|�Ri|���}|��Wd�S1s&wYdS)Nre)r+rAr>)r�r)r*r(�strmrrr�	read_text\	s$�zPath.read_textcCs6|�d��}|��Wd�S1swYdS)Nr?r�)r�r5rrr�
read_bytesa	s$�zPath.read_bytescCst�|j�d��|j�d�kS�Nrw)rr�r,r�)r�r�rrr�	_is_childe	szPath._is_childcCs|�|j|�Sr�)r�r�)r�r,rrr�_nexth	rz
Path._nextcCs|jp	|j�d�Sr8)r,rr�rrrr�k	szPath.is_dircCs|��o|��Sr�)r�r�r�rrr�is_filen	�zPath.is_filecCs|j|j��vSr�)r,r�rr�rrrr�q	szPath.existscCs.|��std��t|j|j���}t|j|�S)NzCan't listdir a file)r�r}r�r:r�r��filterr9)r�Zsubsrrr�iterdirt	szPath.iterdircCst�|jj|j�Sr�)rr2r�rBr,r�rrr�__str__z	r<zPath.__str__cCs|jj|d�S)Nr�)�_Path__reprrr�rrrr�}	rz
Path.__repr__cGs&tj|jg|�R�}|�|j�|��Sr�)rr2r,r:r�r)r��other�nextrrrr4�	sz
Path.joinpathcCs6|js|jjSt�|j�d��}|r|d7}|�|�Sr8)r,rB�parentrr�r�r:)r�Z	parent_atrrrrC�	s
zPath.parent)r�)re)rrrrr@r�rArdr%rBr6r7r9r:r�r;r�r>r?r�r4�__truediv__rCrrrrr�s.M



rc
s ddl}d}|j|d�}|jdd�}|jdddd	d
�|jddd
ddd�|jdddddd�|jddddd
�|�|�}|jdurm|j}t|d��}|��}Wd�n1sYwY|rgtd�	|��td�dS|j
dur�|j
}t|d��
}|��Wd�dS1s�wYdS|jdur�|j\}}t|d��}|�
|�Wd�dS1s�wYdS|jdu�r|j�d�}	|j}
�fdd��t|	d��1}|
D]%}tj�|�}|s�tj�tj�|��}|dtjtjfvr�d}�|||�q�Wd�dS1�swYdSdS) Nrz3A simple command-line interface for zipfile module.)�descriptionT)Zrequiredz-lz--list�	<zipfile>zShow listing of a zipfile)�metavar�helpz-ez	--extractr)rFz<output_dir>zExtract zipfile into target dir)�nargsrGrHz-cz--create�+)z<name>z<file>zCreate zipfile from sourcesz-tz--testzTest if a zipfile is validrez.The following enclosed file is corrupted: {!r}zDone testingcsvtj�|�r|�||t�dStj�|�r7|r|�||�tt�|��D]}�|tj�||�tj�||��q$dSdSr�)	rzr�r�rrr�r�r�r2)r[r��zippathZnm��addToZiprrrM�	s��zmain.<locals>.addToZiprfr�)�argparse�ArgumentParserZadd_mutually_exclusive_group�add_argument�
parse_args�testrr�r�rr^r�r�r�Zcreate�poprzr�r�r�r�r�)
r)rNrE�parser�groupr�r[Zbadfiler�Zzip_name�filesr�rKrrLr�main�	sh
�
�
�
�


�

"�

"��$��rW�__main__r�)�rZbinascii�importlib.utilrr7rrzr�rer�r�rFr~rvr�r$r2r�r��ImportErrorr�r��__all__�	Exceptionrr
rrr�r�r�rrrrr�r�r�r�r�r]r\r�r[rLrMrNrOrPrQrRrar�r�r�r�r�r�Z_CD_CREATE_VERSIONZ_CD_CREATE_SYSTEMZ_CD_EXTRACT_VERSIONZ_CD_EXTRACT_SYSTEMZ
_CD_FLAG_BITSZ_CD_COMPRESS_TYPEZ_CD_TIMEZ_CD_DATEZ_CD_CRCZ_CD_COMPRESSED_SIZEZ_CD_UNCOMPRESSED_SIZEr�r�r�Z_CD_DISK_NUMBER_STARTZ_CD_INTERNAL_FILE_ATTRIBUTESZ_CD_EXTERNAL_FILE_ATTRIBUTESr�r�r�r�r�Z_FH_EXTRACT_VERSIONZ_FH_EXTRACT_SYSTEMr�Z_FH_COMPRESSION_METHODZ_FH_LAST_MOD_TIMEZ_FH_LAST_MOD_DATEZ_FH_CRCZ_FH_COMPRESSED_SIZEZ_FH_UNCOMPRESSED_SIZEr�r�rGrHrErJrKrIZ_CD64_SIGNATUREZ_CD64_DIRECTORY_RECSIZEZ_CD64_CREATE_VERSIONZ_CD64_EXTRACT_VERSIONZ_CD64_DISK_NUMBERZ_CD64_DISK_NUMBER_STARTZ_CD64_NUMBER_ENTRIES_THIS_DISKZ_CD64_NUMBER_ENTRIES_TOTALZ_CD64_DIRECTORY_SIZEZ_CD64_OFFSET_START_CENTDIRr`ZStructr.r8r=r	rXr9�objectr
r�r�r�r�r�r�r�r�r�r�rr8rrSrrrr�dict�fromkeysrrrr"r+rrWrrrrr�<module>s�

���






+=^&��������	�
���
�����
(KU/<

.
=
�

?>