Spade
Mini Shell
3
\�)�2@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
yddlZWnek
rxddl
ZYnXyddlZejZWnek
r�dZe
jZYnXyddlZWnek
r�dZYnXyddlZWnek
r�dZYnXdddddddd d
ddd
gZGdd�de�ZGdd
�d
e�ZeZZdeZdgZdiZdZdZdZdZdZdZ
dZ!dZ"dZ#dZ$dZ%e j&e$�Z'dZ(dZ)dZ*dZ+dZ,dZ-d
Z.d!Z/dZ0d"Z1d#Z2d$Z3e j&e2�Z4dZ5dZ6dZ7dZ8dZ9dZ:d
Z;d!Z<dZ=d"Z>d%Z?d&Z@dZAd'ZBdZCd(ZDdZEd)ZFd*ZGd+ZHd,ZIe j&eH�ZJdZKdZLdZMdZNdZOdZPd
ZQd!ZRdZSd"ZTd%ZUd&ZVd-ZWd.ZXe j&eW�ZYd/ZZd0Z[e j&eZ�Z\dZ]dZ^dZ_dZ`dZadZbd
Zcd!ZddZed"Zfd1Zge jhd2�Zid3d4�Zjd5d6�Zkd7d �Zld8d9�Zmd:d;�ZnGd<d
�d
eo�ZpGd=d>�d>�ZqGd?d@�d@�ZrGdAdB�dB�ZsdCdDdEdEdEdEdFdGdHdIdFdJdKdLdMdNdOdP�ZtdQdR�ZudSdT�ZvdUdV�ZwGdWdX�dX�ZxGdYdZ�dZ�ZyGd[d\�d\ejz�Z{Gd]d^�d^ejz�Z|Gd_d�d�Z}Gd`d�de}�Z~djdadb�Ze�dck�r�e�dS)k�N�
BadZipFile�
BadZipfile�error�
ZIP_STORED�ZIP_DEFLATED� ZIP_BZIP2�ZIP_LZMA�
is_zipfile�ZipInfo�ZipFile� PyZipFile�LargeZipFilec@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�/usr/lib64/python3.6/zipfile.pyr+sc@seZdZdS)r
N)rrrrrrrr
/s��������-�.�?s<4s4H2LHsPK������� z<4s4B4HL2L5H2LsPK�
��
���z<4s2B4HL2L2HsPKz<4sLQLsPKz
<4sQ2H2L4QsPKiPKz<HHc
Cs�tj}d}g}d}}xf|dt|�kr|||||d��\}}|d|} ||krv||krn|j|||��| }d}| }qW|s�|Sdj|�S)NFrrT�)�_EXTRA_FIELD_STRUCT�unpack�len�append�join)
�extraZxidsr,Zmodified�buffer�start�iZxidZxlen�jrrr�_strip_extra�s
r5cCs*yt|�rdSWntk
r$YnXdS)NTF)�_EndRecData�OSError)�fprrr�_check_zipfile�sr9cCsVd}y8t|d�rt|d�}nt|d��}t|�}WdQRXWntk
rPYnX|S)NF�read)r8�rb)�hasattrr9�openr7)�filename�resultr8rrrr �s
cCsy|j|td�Wntk
r(|SX|jt�}t|�tkrD|Stjt|�\}}}}|tkrd|S|dkst|dkr|t d��|j|tt
d�|jt
�}t|�t
kr�|Stjt|�\
}}} }
}}}
}}}|tkr�|S||t
<||t<||t<|
|t<||t<||t<||t<|S)Nrrrz3zipfiles
that span multiple disks are not
supported)�seek�sizeEndCentDir64Locatorr7r:r-�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_versionZread_versionZdisk_numZdisk_dirZdircountZ dircount2ZdirsizeZ diroffsetrrr�
_EndRecData64�s6
rTc Csf|jdd�|j�}y|jtd�Wntk
r:dSX|j�}t|�tkr�|dd�tkr�|dd�dkr�tjt |�}t
|�}|jd�|j|t�t|t|�St
|d td�}|j|d�|j�}|jt�}|dk�rb|||t�}t|�tk�rdSt
tjt |��}|t}||t|t|�}|j|�|j||�t|||||�SdS)
Nrrrsr*rr���i)r@�tell�sizeEndCentDirr7r:r-�stringEndArchiverBr,�structEndArchive�listr.rT�max�rfind�_ECD_COMMENT_SIZE) rOZfilesizerRrQZmaxCommentStartr2ZrecDataZcommentSize�commentrrrr6s>
r6c@sReZdZd'Zd)dd�Zdd�Zd*dd�Zdd
�Zd!d"�Ze d+d#d$��Z
d%d&�ZdS),r
�
orig_filenamer>� date_time�
compress_typer^r0�
create_systemrS�extract_version�reserved� flag_bits�volume�
internal_attr�
external_attr�
header_offset�CRC�
compress_size� file_size� _raw_time�NoName�rrcCs�||_|jtd��}|dkr(|d|�}tjdkrJtj|krJ|jtjd�}||_||_|ddkrjtd��t |_
d|_d|_t
jdkr�d|_nd|_t|_t|_d|_d|_d|_d|_d|_dS)Nr�/i�z+ZIP
does not support timestamps before
1980r*Zwin32r)r_�find�chr�os�sep�replacer>r`�
ValueErrorrrar^r0�sys�platformrb�DEFAULT_VERSIONrSrcrdrerfrgrh)�selfr>r`Z null_byterrr�__init__Ws.
zZipInfo.__init__cCs�d|jj|jfg}|jtkr8|jdtj|j|j��|jd?}|jd@}|rd|jdt j
|��|rv|jd|�|j�}|s�|jr�|jd|j�|s�|j
r�|jtks�|j|j
kr�|jd|j
�|jd �d
j|�S)Nz<%s filename=%rz compress_type=%sri��z
filemode=%rz external_attr=%#xz
file_size=%rz
compress_size=%r�>�)� __class__rr>rarr.�compressor_names�getrh�stat�filemode�is_dirrlrkr/)rzr?�hi�lo�isdirrrr�__repr__�s(
zZipInfo.__repr__NcCs||j}|ddd>|dd>B|dB}|dd>|d d>B|ddB}|jd
@rfd}}}n|j}|j}|j}|j}d} |dkr�|tkp�|tk}|r�d}
|tj|
dtj |
�d ||�}|tks�|tkr�|s�t
d��d
}d
}t} |jt
k�rtt| �} n|jtk�rtt| �} t| |j�|_t| |j�|_|j�\}}tjtt|j|j||j|||||t|�t|��
}
|
||S)Nri�r#rr
rrr%rrz<HHQQz'Filesize would require ZIP64
extensionsl��)r`rerjrkrlr0�ZIP64_LIMITrB�pack�calcsizer
�
ZIP64_VERSIONrarr[�
BZIP2_VERSIONr�LZMA_VERSIONrcrS�_encodeFilenameFlags�structFileHeader�stringFileHeaderrdr-)rz�zip64�dt�dosdate�dostimerjrkrlr0�min_version�fmtr>re�headerrrr�
FileHeader�sF$$
zZipInfo.FileHeadercCs>y|jjd�|jfStk
r8|jjd�|jdBfSXdS)N�asciizutf-8i)r>�encodere�UnicodeEncodeError)rzrrrr��szZipInfo._encodeFilenameFlagscCs(|j}tj}�xt|�dk�r"|d|dd��\}}|dk�r|dkrZ|d|dd��}nV|dkrv|d|dd ��}n:|d
kr�|d|dd��}n|d
kr�f}ntd||f��d
}|jdkr�|||_|d7}|jdkr�|||_|d7}|jdk�r|j}|||_|d7}||dd�}qWdS)Nrz<HHr�z<QQQ�rz<QQrrz<Qrrz"Corrupt
extra field %04x
(size=%d)��������)r�r�)r0rBr,r-rrlrkri)rzr0r,�tp�lnZcounts�idx�oldrrr�_decodeExtra�s4
zZipInfo._decodeExtracCs�t|tj�rtj|�}tj|�}tj|j�}tj|j �}|dd�}|dkrP|}tj
jtj
j|�d�}x$|dtj
tjfkr�|dd�}qjW|r�|d7}|||�}|jd@d>|_|r�d|_|jdO_n|j|_|S)Nrr!rrpi��r)�
isinstancers�PathLike�fspathr��S_ISDIR�st_mode�time� localtime�st_mtime�path�normpath�
splitdrivert�altseprhrl�st_size)�clsr>�arcname�str��mtimer`�zinforrr� from_file�s(
zZipInfo.from_filecCs|jddkS)Nrrp���)r>)rzrrrr�szZipInfo.is_dir)r_r>r`rar^r0rbrSrcrdrerfrgrhrirjrkrlrm�rorrrrr)rnr�)N)N)rrr� __slots__r{r�r�r�r��classmethodr�r�rrrrr
>s6
*
.$!c@s8eZdZdd�ZdZdd�Zdd�Zdd �Zd
d�ZdS)�
_ZipDecryptercCshd}dgd}xTtd�D]H}|}x6td�D]*}|d@rH|d?d@|A}q*|d?d@}q*W|||<qW|S)Nl
q[r�rri���)�range)Zpoly�tabler3�crcr4rrr�_GenerateCRCTable#s
z_ZipDecrypter._GenerateCRCTableNcCs|d?d@|j||Ad@AS)Nri����)�crctable)rzZchr�rrr�_crc327sz_ZipDecrypter._crc32cCsBtjdkrtj�t_d|_d|_d|_x|D]}|j|�q,WdS)NixV4i�gE#i�xV4)r�r�r��key0�key1�key2�_UpdateKeys)rz�pwd�prrrr{;s
z_ZipDecrypter.__init__cCsX|j||j�|_|j|jd@d@|_|jddd@|_|j|jd?d@|j�|_dS)Nr�l��i�rr�)r�r�r�r�)rz�crrrr�Dsz_ZipDecrypter._UpdateKeyscCs0|jdB}|||dAd?d@A}|j|�|S)Nrrrr�)r�r�)rzr��krrr�__call__Js
z_ZipDecrypter.__call__) rrrr�r�r�r{r�r�rrrrr�s
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd S)
�LZMACompressorcCs
d|_dS)N)�_comp)rzrrrr{UszLZMACompressor.__init__cCsFtjdtji�}tjtjtjtj|�gd�|_tjdddt |��|S)N�id)�filtersz<BBHr#r)
�lzmaZ_encode_filter_properties�FILTER_LZMA1r��
FORMAT_RAW�_decode_filter_propertiesr�rBr�r-)rzZpropsrrr�_initXszLZMACompressor._initcCs*|jdkr|j�|jj|�S|jj|�S)N)r�r��compress)rzrRrrrr�_s
zLZMACompressor.compresscCs&|jdkr|j�|jj�S|jj�S)N)r�r��flush)rzrrrr�ds
zLZMACompressor.flushN)rrrr{r�r�r�rrrrr�Ssr�c@seZdZdd�Zdd�ZdS)�LZMADecompressorcCsd|_d|_d|_dS)Nr*F)�_decomp�_unconsumed�eof)rzrrrr{lszLZMADecompressor.__init__cCs�|jdkr�|j|7_t|j�dkr*dStjd|jdd��\}t|j�d|krXdStjtjtjtj |jdd|��gd�|_|jd|d�}|`|jj
|�}|jj|_|S)Nrr*z<Hr)r�)r�r�r-rBr,r�r�r�r�r��
decompressr�)rzrRZpsizer?rrrr�qs
zLZMADecompressor.decompressN)rrrr{r�rrrrr�jsr�ZstoreZshrink�reduceZimplode�tokenizeZdeflateZ deflate64Zbzip2r�ZterseZlz77ZwavpackZppmd)rrrrrr
r!r"rr#r$rrr)��a�bcCsX|tkr
nJ|tkr
tsTtd��n4|tkr6tsTtd��n|tkrLtsTtd��ntd��dS)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�sr�cCs@|tkrtjtjtjd�S|tkr*tj�S|tkr8t �SdSdS)Nr'i�)
rr�ZcompressobjZZ_DEFAULT_COMPRESSIONZDEFLATEDrr�Z
BZ2Compressorrr�)rarrr�_get_compressor�s
r�cCsn|tkrdS|tkrtjd�S|tkr.tj�S|tkr<t�St j
|�}|r\td||f��ntd|f��dS)Nr'zcompression
type %d (%s)zcompression type
%di�)rrr�Z
decompressobjrr�ZBZ2Decompressorrr�rr�r�)raZdescrrrr�_get_decompressor�s
r�c@s&eZdZdd�Zd
dd�Zdd�ZdS)�_SharedFilecCs"||_||_||_||_||_dS)N)�_file�_pos�_close�_lock�_writing)rz�file�pos�close�lockZwritingrrrr{�s
z_SharedFile.__init__rc CsL|j�<|j�rtd��|jj|j�|jj|�}|jj�|_|SQRXdS)NzyCan't
read from the ZIP file while there is an open writing handle on it. Close
the writing handle before trying to
read.)r�r�rvr�r@r�r:rV)rz�nrRrrrr:�sz_SharedFile.readcCs$|jdk r
|j}d|_|j|�dS)N)r�r�)rz�fileobjrrrr��s
z_SharedFile.closeNr�)r�)rrrr{r:r�rrrrr��s
r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd d
�ZdS)� _TellablecCs||_d|_dS)Nr)r8rP)rzr8rrrr{�sz_Tellable.__init__cCs|jj|�}|j|7_|S)N)r8�writerP)rzrRr�rrrr��sz_Tellable.writecCs|jS)N)rP)rzrrrrV�sz_Tellable.tellcCs|jj�dS)N)r8r�)rzrrrr��sz_Tellable.flushcCs|jj�dS)N)r8r�)rzrrrr��sz_Tellable.closeN)rrrr{r�rVr�r�rrrrr��s
r�cs|eZdZdZdZddd�Zdd �Zd d
d�Zd!dd
�Zdd�Z d#dd�Z
dd�Zdd�Zdd�Z
dd�Z�fdd�Z�ZS)$�
ZipExtFilerriNFcCs�||_||_||_|j|_|j|_|j|_t |j�|_
d|_d|_d|_
d|_|jdk rf|jd8_||_|j|_t|d�r�|j|_td�|_nd|_dS)NFr*rrrj)�_fileobj�
_decrypter�_close_fileobjra�_compress_typerk�_compress_leftrl�_leftr��
_decompressor�_eof�_readbuffer�_offset�newlines�moder>�namer<rj�
_expected_crc�crc32�_running_crc)rzr�r�zipinfoZ decrypterZ
close_fileobjrrrr{s&
zZipExtFile.__init__cCsvd|jj|jjfg}|jsX|jd|j|jf�|jtkrb|jdt j
|j|j��n
|jd�|jd�dj|�S)Nz<%s.%sz name=%r mode=%rz
compress_type=%sz
[closed]r|r})r~rr�closedr.rrr�rrr�r/)rzr?rrrr�#s
zZipExtFile.__repr__cCsL|dkr>|jjd|j�d}|dkr>|j|j|�}||_|Stjj||�S)Nr�
r)rrqr�io�BufferedIOBase�readline)rz�limitr3�linerrrr1szZipExtFile.readlinecCsr|t|j�|jkr\|j|�}t|�|jkrJ||j|jd�|_d|_n|jt|�8_|j|j|jd�S)Nri)r-rrr:)rzr��chunkrrr�peekAs
zZipExtFile.peekcCsdS)NTr)rzrrr�readableNszZipExtFile.readablecCs|dks|dkrL|j|jd�}d|_d|_x|jsF||j|j�7}q.W|S||j}|t|j�kr~|j|j|�}||_|S|t|j�}|j|jd�}d|_d|_x^|dko�|j�r|j|�}|t|�kr�||_||_||d|�7}P||7}|t|�8}q�W|S)Nrr*)rrr�_read1�MAX_Nr-)rzr��buf�endrRrrrr:Qs4
zZipExtFile.readcCs@|jdkrdSt||j�|_|jr<|j|jkr<td|j��dS)NzBad
CRC-32 for file
%r)rrr rrr)rz�newdatarrr�_update_crcrs
zZipExtFile._update_crccCs|dks|dkrV|j|jd�}d|_d|_x$|jsP|j|j�}|r.||7}Pq.W|S||j}|t|j�kr�|j|j|�}||_|S|t|j�}|j|jd�}d|_d|_|dk�rxN|j�s
|j|�}|t|�kr�||_||_||d|�7}P|r�||7}Pq�W|S)Nrr*)rrrrrr-)rzr�rrRrrrr�read1|s>
zZipExtFile.read1cCs"|js|dkrdS|jtkrH|jj}|t|�krR||j|t|��7}n
|j|�}|jtkrj|jdk|_nx|jtkr�t ||j
�}|jj||�}|jjp�|jdko�|jj|_|jr�||jj
�7}n
|jj|�}|jjp�|jdk|_|d|j�}|jt|�8_|jdk�rd|_|j|�|S)Nrr*T)rr�rrZunconsumed_tailr-�_read2rr�r[�
MIN_READ_SIZEr�r�r�r�r)rzr�rRrrrr�s2
zZipExtFile._read1cCsj|jdkrdSt||j�}t||j�}|jj|�}|jt|�8_|sLt�|jdk rft t
|j|��}|S)Nrr*)r�r[r�minr�r:r-�EOFErrorr��bytes�map)rzr�rRrrrr�s
zZipExtFile._read2c
s&z|jr|jj�Wdt�j�XdS)N)r�r�r��super)rz)r~rrr��szZipExtFile.close�i@)NFr�)r�)rr�)r�)rrrrrr{r�rrrr:rrrrr��
__classcell__rr)r~rr��s
!
%$r�cs@eZdZdd�Zedd��Zdd�Zdd�Z�fd d
�Z�Z S)�
_ZipWriteFilecCs4||_||_||_t|j�|_d|_d|_d|_dS)Nr) �_zinfo�_zip64�_zipfiler�ra�_compressor�
_file_size�_compress_size�_crc)rz�zfr�r�rrrr{�sz_ZipWriteFile.__init__cCs|jjS)N)r(r8)rzrrrr��sz_ZipWriteFile._fileobjcCsdS)NTr)rzrrr�writable�sz_ZipWriteFile.writablecCsf|jrtd��t|�}|j|7_t||j�|_|jrV|jj|�}|jt|�7_|j j
|�|S)NzI/O operation on closed
file.)rrvr-r*rr,r)r�r+r�r�)rzrR�nbytesrrrr��sz_ZipWriteFile.writecsX|jr
dSt�j�|jrN|jj�}|jt|�7_|jj|�|j|j _
n
|j|j _
|j|j _
|j|j _|j jd@r�|jr�dnd}|jjtj|t|j j
|j j
|j j��|jj�|j_nn|js�|jtkr�td��|jtkr�td��|jj�|j_|jj|j j�|jj|j j|j��|jj|jj�d|j_|jjj|j �|j |jj|j j
<dS)Nrz<LLQQz<LLLLz+File size unexpectedly exceeded ZIP64
limitz1Compressed size unexpectedly exceeded ZIP64
limitF)!rr"r�r)r�r+r-r�r�r&rkr*r,rjrlrer'rBr��
_DD_SIGNATURErVr(� start_dirr�r�r@rir�r��filelistr.�
NameToInfor>)rzrr�)r~rrr��s8
z_ZipWriteFile.close)
rrrr{�propertyr�r.r�r�r$rr)r~rr%�s
r%c@seZdZdZdZdedfdd�Zdd�Zdd �Zd
d�Z dd
�Z
dd�Zdd�Zd;dd�Z
dd�Zdd�Zdd�Zedd��Zejdd��Zd<dd�Zd=dd
�d!d"�Zd>d#d$�Zd?d%d&�Zd@d'd(�Zed)d*��Zd+d,�Zd-d.�ZdAd/d0�ZdBd1d2�Zd3d4�Zd5d6�Z
d7d8�Z!d9d:�Z"dS)CrN�rTcCsF|dkrtd��t|�||_d|_d|_i|_g|_||_||_d|_ d|_
t|tj
�rdtj|�}t|t�r�d|_||_d d
ddd
d
dd�}||}x^ytj||�|_Wn(tk
r�||kr�||}w��YnXPq�Wnd|_||_t|dd�|_d|_tj�|_d|_d|_�y|dk�r*|j�n�|dk�r�d|_y|jj�|_Wn2t
tfk
�r|t!|j�|_d|_d|_Yn6Xy|jj"|j�Wn t tfk
�r�d|_YnXnf|dk�ry|j�|jj"|j�Wn6t#k
�r|jj"dd�d|_|jj�|_YnXntd��Wn$|j}d|_|j$|��YnXdS)Nr5�w�x�az+ZipFile
requires mode 'r', 'w', 'x', or
'a'Frr*r;zw+bzx+bzr+b�wbZxb)r5r6r7r8zr+bzw+bzx+brrTrz"Mode
must be 'r', 'w', 'x', or
'a')r5r6r7r8)r6r7)%rvr��_allowZip64�
_didModify�debugr3r2r�rr��_commentr�rsr�r��str�_filePassedr>r
r=r8r7�getattr�_fileRefCnt� threading�RLockr�� _seekabler��_RealGetContentsrVr1�AttributeErrorr�r@r�_fpclose)rzr�rr��
allowZip64ZmodeDictr�r8rrrr{;s�
zZipFile.__init__cCs|S)Nr)rzrrr� __enter__�szZipFile.__enter__cCs|j�dS)N)r�)rz�type�value� tracebackrrr�__exit__�szZipFile.__exit__cCs�d|jj|jjfg}|jdk rd|jr8|jd|j�n|jdk rR|jd|j�|jd|j�n
|jd�|jd�dj|�S)Nz<%s.%sz file=%rz filename=%rz
mode=%rz [closed]r|r}) r~rrr8r?r.r>rr/)rzr?rrrr��s
zZipFile.__repr__cCs�|j}yt|�}Wntk
r.td��YnX|s<td��|jdkrNt|�|t}|t}|t|_ |t
||}|ttkr�|t
t8}|jdkr�||}td|||�|||_|j|jd�|j|�}tj|�}d}�x�||k�r�|jt�} t| �tk�rtd��tjt| �} | ttk�r0td��|jdk�rDt| �|j| t�}
| d}|d @�rp|
jd
�}
n
|
jd�}
t|
�}|j| t�|_|j| t
�|_!| t"|_#| dd�\|_$|_%|_&|_'|_(|_)}
}|_*|_+|_,|j&t-k�r�t.d
|j&d��| dd�\|_/|_0|_1|
|_2|d?d|d?d@|d@|
d?|
d?d@|
d@df|_3|j4�|j#||_#|j5j6|�||j7|j8<|t| t| t| t
}|jdkr�td|�q�WdS)NzFile is not a zip filerrzgiven,
inferred, offsetrzTruncated central directoryz&Bad magic number for
central directoryr izutf-8�cp437rzzip file version
%.1fr$r'r)r#i�rr%r�total)9r8r6r7rr<�printrMrN�_ECD_COMMENTr=�
_ECD_LOCATIONrHrGrErAr1r@r:r
�BytesIO�sizeCentralDirr-rBr,�structCentralDir�
_CD_SIGNATURE�stringCentralDir�_CD_FILENAME_LENGTH�decoder
�_CD_EXTRA_FIELD_LENGTHr0�_CD_COMMENT_LENGTHr^�_CD_LOCAL_HEADER_OFFSETrirSrbrcrdrerarjrkrl�MAX_EXTRACT_VERSIONr�rfrgrhrmr`r�r2r.r3r>)rzr8rQZsize_cdZ offset_cd�concatZinferredrRrO�centdirr>�flagsr7�t�drrrrE�sp
4
zZipFile._RealGetContentscCsdd�|jD�S)NcSsg|]
}|j�qSr)r>)�.0rRrrr�
<listcomp>�sz$ZipFile.namelist.<locals>.<listcomp>)r2)rzrrr�namelist�szZipFile.namelistcCs|jS)N)r2)rzrrr�infolist�szZipFile.infolistcCsPtdd |d�x:|jD]0}d|jdd�}td|j||jf|d�qWdS)
Nz%-46s %19s %12s� File Name�Modified �Size)r�z%d-%02d-%02d
%02d:%02d:%02dr!z
%-46s %s
%12d)rgrhri)rPr2r`r>rl)rzr�r�Zdaterrr�printdir�szZipFile.printdircCs^d}xT|jD]J}y.|j|jd��}x|j|�r0q$WWdQRXWqtk
rT|jSXqWdS)Nrrr5i)r2r=r>r:r)rzZ
chunk_sizer��frrr�testzipszZipFile.testzipcCs$|jj|�}|dkr
td|��|S)Nz(There is no item named %r in the
archive)r3r��KeyError)rzr�inforrr�getinfos
zZipFile.getinfocCs8|r"t|t�r"tdt|�j��|r.||_nd|_dS)Nzpwd:
expected bytes, got %s)r�r
� TypeErrorrJrr�)rzr�rrr�setpasswords
zZipFile.setpasswordcCs|jS)N)r=)rzrrrr^%szZipFile.commentcCs^t|t�stdt|�j��t|�tkrNddl}|jdtdd�|dt�}||_ d|_
dS)Nzcomment: expected bytes, got %srz3Archive comment is too long;
truncating to %d bytesr)�
stacklevelT)r�r
rprJrr-�ZIP_MAX_COMMENT�warnings�warnr=r;)rzr^rtrrrr^*s
c Cs"|j|d|��
}|j�SQRXdS)Nr5)r=r:)rzrr�r8rrrr:7szZipFile.readF)�force_zip64csv|dkrtd��|r2t|t�r2tdt|�j��|rF|dkrFtd���jsTtd��t|t�rd|}n$|dkr~t|�}�j|_ n
�j
|�}|dkr��j||d�S�jr�td���j
d 7_
t�j|j�j�j�fd
d��}�y~|jt�}t|�tk�r�td��tjt|�}|ttk�r
td
��|j|t�}|t�rF|j|t�|jd@�rZtd��|jd@�rntd��|jd@�r�|jd�} n
|jd�} | |j k�r�td|j |f��|jd @}
d}|
�rL|�sΈj!}|�s�t"d|��t#|�}|jd�}t$t%||dd���}
|jd@�r$|j&d?d@}n|j'd?d@}|
d|k�rLt"d|��t(||||d�S|j)��YnXdS)
Nr5r6zopen() requires mode "r" or "w"zpwd: expected
bytes, got %sz'pwd is only supported for reading filesz2Attempt to use
ZIP archive that was already closed)rvzyCan't read from the ZIP file
while there is an open writing handle on it. Close the writing handle
before trying to
read.rcs�jS)N)r�r)rzrr�<lambda>lszZipFile.open.<locals>.<lambda>zTruncated
file headerz Bad magic number for file header� z$compressed patched data
(flag bit 5)�@zstrong encryption (flag bit 6)izutf-8rNz/File name in
directory %r and header %r differ.z6File %r is encrypted, password required
for extractionrrrr�r�r%zBad password for file
%rT>r5r6)*rvr�r rprJrr8r
r�raro�_open_to_writer�rAr�rirGr�r:�sizeFileHeaderr-rrBr,r��
_FH_SIGNATUREr��_FH_FILENAME_LENGTH�_FH_EXTRA_FIELD_LENGTHrer�rYr_r�r�r�rZr!rmrjr�r�)rzrrr�rvr�Zzef_fileZfheader�fnameZ fname_strZis_encryptedZzdr��hZ
check_byter)rzrr=<s~
zZipFile.opencCs�|r|jrtd��|jr"td��t|d�s2d|_d|_d|_d|_|jt kr\|jdO_|j
sp|jdO_|js|d|_|jo�|p�|jd tk}|j
r�|j
j|j�|j
j�|_|j|�d
|_|j
j|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.rlrrri�rg�������?Ti�)r:rvr�r<rlrkrjrerarrDrhr�r8r@r1rVri�_writecheckr;r�r�r%)rzr�rvr�rrrrz�s4
zZipFile._open_to_writecCs*|dkrtj�}n
tj|�}|j|||�S)N)rs�getcwdr��_extract_member)rz�memberr�r�rrr�extract�s
zZipFile.extractcCsL|dkr|j�}|dkr"tj�}n
tj|�}x|D]}|j|||�q2WdS)N)rersr�r�r�)rzr��membersr�r
rrr�
extractall�s
zZipFile.extractallcCs^|j}|s(d}tj|dt|��}||_|j|�}dd�|j|�D�}|jdd�|D��}|S)Nz:<>|"?*�_css|]}|jd�VqdS)�.N)�rstrip)rcr7rrr� <genexpr>sz1ZipFile._sanitize_windows_name.<locals>.<genexpr>css|]}|r|VqdS)Nr)rcr7rrrr�s)�!_windows_illegal_name_trans_tabler>� maketransr-� translate�splitr/)r�r��pathsepr�Zillegalrrr�_sanitize_windows_name�s
zZipFile._sanitize_windows_namecsNt|t�s|j|�}|jjdtjj�}tjjrB|jtjjtjj�}tjj |�d}dtjj
tjjf�tjjj�fdd�|j
tjj�D��}tjjdkr�|j|tjj�}tjj||�}tjj|�}tjj|�}|r�tjj|�r�tj|�|j��rtjj|��s
tj|�|S|j||d��(}t|d��}tj||�WdQRXWdQRX|S) Nrprr}c3s|]}|�kr|VqdS)Nr)rcr7)�invalid_path_partsrrr�sz*ZipFile._extract_member.<locals>.<genexpr>�\)r�r9)r�r
ror>rursr�rtr�r��curdir�pardirr/r�r�r��dirname�exists�makedirsr�r��mkdirr=�shutil�copyfileobj)rzr�Z
targetpathr�r�Z upperdirs�source�targetr)r�rr�s.
&
zZipFile._extract_membercCs�|j|jkr(ddl}|jd|jdd�|jdkr:td��|jsHtd ��t|j�|j s�d}t
|j�tkrpd
}n|j
tkr�d}n|jtkr�d}|r�t|d
��dS)NrzDuplicate
name: %rr)rrr6r7r8z&write() requires mode 'w',
'x', or 'a'z4Attempt to write ZIP archive that was
already closedzFiles countZFilesizezZipfile sizez would require ZIP64
extensions)r6r7r8)r>r3rtrurrvr8r�rar:r-r2�ZIP_FILECOUNT_LIMITrlr�rir
)rzr�rt�requires_zip64rrrr�/s(
zZipFile._writecheckcCs0|jstd��|jrtd��tj||�}|j�r>d|_d|_n|dk rN||_n|j |_|j�r�|j
��|jrz|jj|j
�|jj�|_|jtkr�|jdO_|j|�d|_|jj|�||j|j<|jj|jd��|jj�|_
WdQRXn<t|d��,}|j|d��}tj||d�WdQRXWdQRXdS)Nz7Attempt
to write to ZIP archive that was already closedz>Can't write to ZIP
archive while an open writing handle existsrrTFr;r6iri )r8rvr�r
r�r�rkrjrar�r�rDr@r1rVrirrer�r;r2r.r3r>r�r�r=r�r�)rzr>r�rar��src�destrrrr�Fs8
z
ZipFile.writecCs�t|t�r|jd�}t|t�spt|tjtj��dd�d�}|j|_|jd
dkrhd|_ |j dO_ qtd|_ n|}|j
s�td ��|jr�td
��|dk r�||_t
|�|_|j�*|j|dd��}|j|�WdQRXWdQRXdS)Nzutf-8r!)r>r`rrpi�Ari�z7Attempt
to write to ZIP archive that was already closedz?Can't write to ZIP
archive while an open writing handle
exists.r6)rr�i�Ai�)r�r>r�r
r�r�r�rar>rhr8rvr�r-rlr�r=r�)rzZzinfo_or_arcnamerRrar�r�rrr�writestrps.
zZipFile.writestrcCs|j�dS)N)r�)rzrrr�__del__�szZipFile.__del__cCs||jdkrdS|jrtd��zB|jdkr\|jr\|j�"|jrJ|jj|j�|j �WdQRXWd|j}d|_|j
|�XdS)NzvCan't close the ZIP file while there is an open writing
handle on it. Close the writing handle before closing the
zip.r6r7r8)r6r7r8)r8r�rvrr;r�rDr@r1�_write_end_recordrG)rzr8rrrr��s
z
ZipFile.closecCsr�xP|jD�]D}|j}|ddd>|dd>B|dB}|dd>|d d>B|ddB}g}|jtksv|jtkr�|j|j�|j|j�d
}d
}n|j}|j}|jtkr�|j|j�d
}n|j}|j} d}
|�rt| d�} t j
ddt|�dd
t|�f|��| } t}
|j
tk�r(tt|
�}
n|j
tk�r>tt|
�}
t|
|j�}t|
|j�}yZ|j�\}
}t j
tt||j||j||j
|||j||t|
�t| �t|j�d|j|j|�}Wnltk
�rttt||j||j|j
|j
|||j||t|j!�t| �t|j�d|j|j|ft"j#d��YnX|j$j%|�|j$j%|
�|j$j%| �|j$j%|j�q
W|j$j&�}t|j�}||j'}|j'}d}|t(k�r�d}n|tk�r�d}n|tk�r�d}|�r*|j)�s�t*|d��t j
t+t,ddddd||||�}|j$j%|�t j
t-t.d|d�}|j$j%|�t/|d�}t/|d
�}t/|d
�}t j
t0t1dd||||t|j2�� }|j$j%|�|j$j%|j2�|j$j3�dS)Nri�r#rr
rrr%rl��z<HH�Qr)r�zFiles countzCentral directory
offsetzCentral directory sizez would require ZIP64
extensions�,ri��)r)4r2r`rlr�rkr.rir0r5rBr�r-r�rarr[r�rr�rcrSr�rUrWrbrdrjr^rgrh�DeprecationWarningrPrer>rw�stderrr8r�rVr1r�r:r
rFrGrCrDrrYrXr=r�)rzr�r�r�r�r0rlrkriZ
extra_datar�rcrSr>rer_Zpos2ZcentDirCountZcentDirSizeZ
centDirOffsetr�Zzip64endrecZzip64locrecrQrrrr��s�$$
zZipFile._write_end_recordcCs*|jd8_|jr&|jr&|j�dS)Nr)rAr?r�)rzr8rrrrGszZipFile._fpclose)N)N)r5N)F)NN)NNN)NN)N)#rrrr8r�rr{rIrMr�rErerfrjrlrorqr4r^�setterr:r=rzr�r�r�r�r�r�r�r�r�r�r�rGrrrrr's:WN
q
+
*
*
$fc@s0eZdZdeddfdd�Zd
dd �Zd
d�ZdS)rr5TrcCstj|||||d�||_dS)N)rr�rH)rr{� _optimize)rzr�rr�rH�optimizerrrr{szPyZipFile.__init__r}NcCs�tj|�}|rF||�rF|jrBtjj|�r.dnd}td||f�dStjj|�\}}tjj|��rntjj|d�}tjj|��r�|r�d||f}n|}|jr�td|d|�|j |dd�|�\}} |jr�td
| �|j
|| �tj|�}
|
jd�x�|
D]�}tjj||�}tjj
|�\}
}tjj|��rRtjjtjj|d���r�|j|||d�q�|dkr�|�r�||��r�|jr�td
|�q�|j |dd�|�\}} |j�r�td
| �|j
|| �q�Wn�|j�r�td|�x�tj|�D]�}tjj||�}tjj
|�\}
}|dk�r�|�r0||��r0|j�r�td
|��q�|j |dd�|�\}} |j�rZtd
| �|j
|| ��q�WnP|dd�dk�r�td��|j |dd�|�\}} |j�r�td| �|j
|| �dS)Nr�r�z%s %r skipped by
filterfuncz__init__.pyz%s/%szAdding package in�asrrZAdding)�
filterfuncz.pyzfile %r skipped by filterfunczAdding files from
directoryz.Files added with writepy() must end with ".py"zAdding
file���r�r�r�r�)rsr�r<r�r�rPr�r/�isfile�
_get_codenamer��listdir�remove�splitext�writepyr�)rz�pathname�basenamer�Zlabel�dirrZinitnamerr�Zdirlistr>r��rootZextrrrr�$sx
zPyZipFile.writepyc
sd�fdd� }|d}|d}tjj|dd�}tjj|dd�}tjj|dd�}�jdk�r\tjj|�r�tj|�jtj|�jkr�|} }
n�tjj|�r�tj|�jtj|�jkr�|}
|} n�tjj|�r�tj|�jtj|�jkr�|}
|} nvtjj|��rtj|�jtj|�jk�r|}
|} nD||��rRt j
jd k�r4|}
nt j
jdk�rH|}
n|}
|} n|}
} n��jd k�rr|}
|} n<|} �jdk�r�|}
n&�jdk�r�|}
nd
j�j�}t
|��tjj|
��o�tj|
�jtj|�jk�s�||�jd��s�|}
} tjj| �d}|�rd||f}|
|fS)Nrcs^ddl}�jrtd|�y|j|d|d�Wn,|jk
rX}zt|j�dSd}~XnXdS)NrZ CompilingT)�doraiser�F)�
py_compiler<rP�compile�PyCompileError�msg)r�r�r��err)rzrr�_compile}s
z)PyZipFile._get_codename.<locals>._compilez.pyz.pycr})�optimizationrrz"invalid
value for 'optimize':
{!r})r�z%s/%sr�)r�r�)� importlib�util�cache_from_sourcer�rsr�r�r�r�rwr`r��formatrvr�)
rzr�r�r�Zfile_pyZfile_pycZpycache_opt0Zpycache_opt1Zpycache_opt2r�rr�Zarchivenamer)rzrr�vs`
zPyZipFile._get_codenamer�)r}N)rrrrr{r�r�rrrrrs
Rcsddl}|jd�}|dkr(tjdd�}|s:|ddkrLt|�tjd�|ddkr�t|�dkrvt|�tjd�t|dd ��}|j�WdQRX�n||ddk�r
t|�dkr�t|�tjd�t|dd ��}|j �}WdQRX|�r�td
j
|��td��n|ddk�rbt|�dk�r8t|�tjd�t|dd ��}|j|d�WdQRXn�|ddk�rt|�dk�r�t|�tjd��fd
d��t|dd��h}x`|dd�D]P}tj
j|�}|�s�tj
jtj
j|��}|dtjtjfk�r�d}�|||��q�WWdQRXdS)NraE
Usage:
zipfile.py -l zipfile.zip # Show listing of a zipfile
zipfile.py -t zipfile.zip # Test if a zipfile is valid
zipfile.py -e zipfile.zip target # Extract zipfile into target
dir
zipfile.py -c zipfile.zip src ... # Create zipfile from sources
r�-l�-c�-e�-trr5z.The following enclosed file is
corrupted: {!r}zDone
testingrcsptjj|�r|j||t�nPtjj|�rl|r8|j||�x2tj|�D]$}�|tjj||�tjj||��qDWdS)N)rsr�r�r�rr�r�r/)r-r��zippathZnm)�addToZiprrr��szmain.<locals>.addToZipr6r})r�r�r�r�)�textwrap�dedentrw�argvrP�exitr-rrjrlr�r�rsr�r�r�r�r�)�argsr�ZUSAGEr-Zbadfiler�r�r)r�r�main�sT
r��__main__li���ii��ii��)N)�r
rs�re�importlib.utilr�rwr�r�r�rBZbinasciirB�ImportErrorZdummy_threadingr�rr�r��__all__� Exceptionrr
rrr�r�rsrrrrryr�r�r�r]rYrXr�rWrHrIrJrKrLrMrNr]rQrRrUrWrTrVZ_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_SIZErXrZr[Z_CD_DISK_NUMBER_STARTZ_CD_INTERNAL_FILE_ATTRIBUTESZ_CD_EXTERNAL_FILE_ATTRIBUTESr\r�r�r{r|Z_FH_EXTRACT_VERSIONZ_FH_EXTRACT_SYSTEMZ_FH_GENERAL_PURPOSE_FLAG_BITSZ_FH_COMPRESSION_METHODZ_FH_LAST_MOD_TIMEZ_FH_LAST_MOD_DATEZ_FH_CRCZ_FH_COMPRESSED_SIZEZ_FH_UNCOMPRESSED_SIZEr}r~rCrDrArFrGrEZ_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_CENTDIRr0ZStructr+r5r9r rTr6�objectr
r�r�r�rr�r�r�r�r�rr�r%rrr�rrrrr�<module>s>
+=Y=fJy/
B