Your IP : 3.135.247.24


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/zipfile.cpython-35.pyc



��Yf��B@sXdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZyddlZWne
k
r�ddlZYnXyddlZejZWn!e
k
r�dZejZYnXyddlZWne
k
rdZYnXyddlZWne
k
rAdZYnXddddddd	d
ddd
dgZGdd�de�ZGdd�de�ZeZZdd>dZdd>dZdd>dZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&e
j'e%�Z(dZ)dZ*dZ+dZ,dZ-d Z.d!Z/d"Z0dZ1d#Z2d$Z3d%Z4e
j'e3�Z5dZ6dZ7dZ8dZ9dZ:d Z;d!Z<d"Z=dZ>d#Z?d&Z@d'ZAdZBd(ZCdZDd)ZEdZFd*ZGd+ZHd,ZId-ZJe
j'eI�ZKdZLdZMdZNdZOdZPd ZQd!ZRd"ZSdZTd#ZUd&ZVd'ZWd.ZXd/ZYe
j'eX�ZZd0Z[d1Z\e
j'e[�Z]dZ^dZ_dZ`dZadZbd Zcd!Zdd"ZedZfd#Zgd2d3�Zhd4d
�Zid5d6�Zjd7d8�ZkGd9d�del�ZmGd:d;�d;�ZnGd<d=�d=�ZoGd>d?�d?�Zpdd@ddAddBddBddBd dBd!dCd"dDddEd#dFd&dCddGddHd+dIdJdKdLdMdNdOiZqdPdQ�ZrdRdS�ZsdTdU�ZtGdVdW�dW�ZuGdXdY�dY�ZvGdZd[�d[ejw�ZxGd\d�d�ZyGd]d
�d
ey�Zzdd^d_�Z{e|d`krTe{�dS)azP
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�LargeZipFilec@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�,/opt/alt/python35/lib64/python3.5/zipfile.pyr+sc@seZdZdZdS)r
zu
    Raised when writing a zipfile, the zipfile requires ZIP64 extensions
    and those extensions are disabled.
    N)rrr�__doc__rrrrr
/s��������-�.�?s<4s4H2LHsPK�������	z<4s4B4HL2L5H2LsPK�
��
���z<4s2B4HL2L2HsPKz<4sLQLsPKz
<4sQ2H2L4QsPKcCs-yt|�rdSWntk
r(YnXdS)NTF)�_EndRecData�OSError)�fprrr�_check_zipfile�s
r.cCsid}yJt|d�r*td|�}n%t|d��}t|�}WdQRXWntk
rdYnX|S)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
cCsoy|j|td�Wntk
r0|SYnX|jt�}t|�tkrV|Stjt|�\}}}}|tkr�|S|dks�|dkr�t	d��|j|tt
d�|jt
�}t|�t
kr�|Stjt|�\
}}}	}
}}}
}}}|tkr%|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/�len�struct�unpack�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�s6
	0






rKc	Cs�|jdd�|j�}y|jtd�Wntk
rIdSYnX|j�}t|�tkr�|dd�tkr�|d	d�dkr�tjt	|�}t
|�}|jd�|j|t�t|t|�St
|d
td�}|j|d�|j�}|jt�}|dkr�|||t�}t|�tkrYdSt
tjt	|��}|t}||t|t|�}|j|�|j||�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 s�rr���i)r5�tell�sizeEndCentDirr,r/r7�stringEndArchiver8r9�structEndArchive�list�appendrK�max�rfind�_ECD_COMMENT_SIZE)	rFZfilesizerIrHZmaxCommentStart�startZrecDataZcommentSize�commentrrrr+�s>
	


r+c@saeZdZdZd$Zdd%dd�Zdd�Zddd�Zd d!�Zd"d#�Z	dS)&r
z>Class with attributes describing each file in the ZIP archive.�
orig_filenamer3�	date_time�
compress_typerX�extra�
create_systemrJ�extract_version�reserved�	flag_bits�volume�
internal_attr�
external_attr�
header_offset�CRC�
compress_size�	file_size�	_raw_timeZNoName�rrcCs||_|jtd��}|dkr:|d|�}tjdkrmtj|krm|jtjd�}||_||_|ddkr�td��t	|_
d|_d|_t
jdkr�d|_n	d|_t|_t|_d|_d|_d|_d|_d|_dS)Nr�/i�z+ZIP does not support timestamps before 1980rL�win32r)rY�find�chr�os�sep�replacer3rZ�
ValueErrorrr[rXr\�sys�platformr]�DEFAULT_VERSIONrJr^r_r`rarbrc)�selfr3rZZ	null_byterrr�__init__@s.													zZipInfo.__init__cCs;d|jj|jfg}|jtkrN|jdtj|j|j��|jd?}|jd@}|r�|jdt	j
|��|r�|jd|�|jd
d�dk}|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=%#xrrjz
 file_size=%rz compress_size=%r�>����)�	__class__rr3r[rrS�compressor_names�getrc�stat�filemodergrf�join)rur4�hi�lo�isdirrrr�__repr__js(	


zZipInfo.__repr__NcCs|j}|ddd>|dd>B|dB}|dd>|d	d>B|ddB}|jd
@rsd}}}n|j}|j}|j}|j}d}	|dkr�|tkp�|tk}|r�d}
|tj|
dtj	|
�d	||�}|tks|tkr5|s#t
d
��d}d}t}	|jt
krVtt|	�}	n|jtkrttt|	�}	t|	|j�|_t|	|j�|_|j�\}}tjtt|j|j||j|||||t|�t|��
}
|
||S)z'Return the per-file header as a string.ri�r$rr!rrr&r rNz<HHQQz'Filesize would require ZIP64 extensionsl��)rZr`rerfrgr\�ZIP64_LIMITr8�pack�calcsizer
�
ZIP64_VERSIONr[rrT�
BZIP2_VERSIONr�LZMA_VERSIONr^rJ�_encodeFilenameFlags�structFileHeader�stringFileHeaderr_r7)ru�zip64�dt�dosdate�dostimererfrgr\�min_version�fmtr3r`�headerrrr�
FileHeader�sF	&&
				 zZipInfo.FileHeadercCsSy|jjd�|jfSWn/tk
rN|jjd�|jdBfSYnXdS)N�asciizutf-8i)r3�encoder`�UnicodeEncodeError)rurrrr��s
zZipInfo._encodeFilenameFlagscCs�|j}tj}xvt|�dkr�|d|dd��\}}|dkrs|dkrz|d|dd��}nx|dkr�|d|dd	��}nP|d
kr�|d|dd��}n(|d
kr�f}ntd|f��d
}|jdkr|||_|d7}|jdkrD|||_|d7}|jdkrs|j}|||_|d7}||dd�}qWdS)Nr z<HHr�z<QQQ�rz<QQrrz<QrrzCorrupt extra field %s��������)r�r�)r\r8r9r7�RuntimeErrorrgrfrd)rur\r9�tp�lnZcounts�idx�oldrrr�_decodeExtra�s4			



	

zZipInfo._decodeExtra)rYr3rZr[rXr\r]rJr^r_r`rarbrcrdrerfrgrh)rirrrrr)
rrrr�	__slots__rvr�r�r�r�rrrrr
's2*.c@sXeZdZdZdd�ZdZdd�Zdd�Zd	d
�Zdd�Z	dS)
�
_ZipDecrypteraClass to handle decryption of files stored within a ZIP archive.

    ZIP supports a password-based form of encryption. Even though known
    plaintext attacks have been found against it, it is still useful
    to be able to get data out of such a file.

    Usage:
        zd = _ZipDecrypter(mypwd)
        plain_char = zd(cypher_char)
        plain_text = map(zd, cypher_text)
    cCs�d}dgd}xhtd�D]Z}|}xAtd�D]3}|d@r^|d?d@|A}q9|d?d@}q9W|||<q W|S)z�Generate a CRC-32 table.

        ZIP encryption uses the CRC32 one-byte primitive for scrambling some
        internal keys. We noticed that a direct implementation is faster than
        relying on binascii.crc32().
        l q[r�rri���)�range)Zpoly�table�i�crc�jrrr�_GenerateCRCTable�s

z_ZipDecrypter._GenerateCRCTableNcCs|d?d@|j||Ad@AS)z(Compute the CRC32 primitive on one byte.ri����)�crctable)ruZchr�rrr�_crc32�sz_ZipDecrypter._crc32cCs[tjdkrtj�t_d|_d|_d|_x|D]}|j|�q@WdS)NixV4i�gE#i�xV4)r�r�r��key0�key1�key2�_UpdateKeys)ru�pwd�prrrrv�s			
z_ZipDecrypter.__init__cCsr|j||j�|_|j|jd@d@|_|jddd@|_|j|jd?d@|j�|_dS)Nr�l��i�rr�)r�r�r�r�)ru�crrrr�sz_ZipDecrypter._UpdateKeyscCsMt|t�st�|jdB}|||dAd?d@A}|j|�|S)zDecrypt a single character.rrrr�)�
isinstance�int�AssertionErrorr�r�)rur��krrr�__call__
s


z_ZipDecrypter.__call__)
rrrrr�r�r�rvr�r�rrrrr��s	r�c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�LZMACompressorcCs
d|_dS)N)�_comp)rurrrrvszLZMACompressor.__init__cCsetjdtji�}tjtjdtjtj|�g�|_tjdddt	|��|S)N�id�filtersz<BBHr$r )
�lzmaZ_encode_filter_properties�FILTER_LZMA1r��
FORMAT_RAW�_decode_filter_propertiesr�r8r�r7)ruZpropsrrr�_initszLZMACompressor._initcCs9|jdkr)|j�|jj|�S|jj|�S)N)r�r��compress)rurIrrrr�"szLZMACompressor.compresscCs3|jdkr&|j�|jj�S|jj�S)N)r�r��flush)rurrrr�'szLZMACompressor.flushN)rrrrvr�r�r�rrrrr�sr�c@s(eZdZdd�Zdd�ZdS)�LZMADecompressorcCsd|_d|_d|_dS)NrLF)�_decomp�_unconsumed�eof)rurrrrv/s		zLZMADecompressor.__init__c	Cs�|jdkr�|j|7_t|j�dkr7dStjd|jdd��\}t|j�d|krvdStjtjdtjtj	|jdd|��g�|_|jd|d�}|`|jj
|�}|jj|_|S)Nr rLz<Hrr�)r�r�r7r8r9r�r�r�r�r��
decompressr�)rurIZpsizer4rrrr�4s"#zLZMADecompressor.decompressN)rrrrvr�rrrrr�-sr�ZstoreZshrink�reduceZimplode�tokenizeZdeflateZ	deflate64Zbzip2r�Zterse�Zlz77�aZwavpack�bZppmdcCs�|tkrno|tkr0ts~td��nN|tkrQts~td��n-|tkrrts~td��ntd��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�zlibr�r�bz2rr�)�compressionrrr�_check_compression]sr�cCsV|tkr%tjtjtjd�S|tkr;tj�S|tkrNt	�SdSdS)Nr(i�)
rr�ZcompressobjZZ_DEFAULT_COMPRESSIONZDEFLATEDrr�Z
BZ2Compressorrr�)r[rrr�_get_compressorps

r�cCs�|tkrdS|tkr)tjd�S|tkr?tj�S|tkrRt�St	j
|�}|r�td||f��ntd|f��dS)Nr(zcompression type %d (%s)zcompression type %di�)rrr�Z
decompressobjrr�ZBZ2Decompressorrr�r{r|�NotImplementedError)r[Zdescrrrr�_get_decompressor|s

r�c@s7eZdZdd�Zd	dd�Zdd�ZdS)
�_SharedFilecCs(||_||_||_||_dS)N)�_file�_pos�_close�_lock)ru�file�pos�close�lockrrrrv�s			z_SharedFile.__init__rc	CsP|j�@|jj|j�|jj|�}|jj�|_|SWdQRXdS)N)r�r�r5r�r/rN)ru�nrIrrrr/�s

z_SharedFile.readcCs2|jdk	r.|j}d|_|j|�dS)N)r�r�)ru�fileobjrrrr��s		z_SharedFile.closeNry)rrrrvr/r�rrrrr��sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�	_TellablecCs||_d|_dS)Nr)r-rG)rur-rrrrv�s	z_Tellable.__init__cCs%|jj|�}|j|7_|S)N)r-�writerG)rurIr�rrrr��sz_Tellable.writecCs|jS)N)rG)rurrrrN�sz_Tellable.tellcCs|jj�dS)N)r-r�)rurrrr��sz_Tellable.flushcCs|jj�dS)N)r-r�)rurrrr��sz_Tellable.closeN)rrrrvr�rNr�r�rrrrr��s
r�cs�eZdZdZdZdZejd�Zdddd	�Z	d
d�Z
d dd
�Zddd�Zdd�Z
d!dd�Zdd�Zdd�Zdd�Zdd�Z�fdd�Z�S)"�
ZipExtFilezZFile-like object for reading an archive member.
       Is returned by ZipFile.open().
    rris*^(?P<chunk>[^\r\n]+)|(?P<newline>\n|\r\n?)NFcCs�||_||_||_|j|_|j|_|j|_t	|j�|_
d|_d|_d|_
d|k|_d|_|jdk	r�|jd8_||_|j|_t|d�r�|j|_td�|_n	d|_dS)NFrLr�Urre)�_fileobj�
_decrypter�_close_fileobjr[�_compress_typerf�_compress_leftrg�_leftr��
_decompressor�_eof�_readbuffer�_offset�
_universal�newlines�moder3�namer1re�
_expected_crc�crc32�_running_crc)rur�r��zipinfoZ	decrypterZ
close_fileobjrrrrv�s(								zZipExtFile.__init__cCs�d|jj|jjfg}|jsz|jd|j|jf�|jtkr�|jdt	j
|j|j��n
|jd�|jd�dj|�S)Nz<%s.%sz name=%r mode=%rz compress_type=%sz	 [closed]rwrx)rzrr�closedrSr�r�r�rr{r|r)rur4rrrr��s		

zZipExtFile.__repr__cCs�|jra|dkra|jjd|j�d}|dkra|j|j|�}||_|S|js}tjj||�Sd}x|dks�t|�|kr�|jd�}|dkr�|S|j	j
|�}|jd�}|dk	rD|jdkrg|_||jkr'|jj
|�|jt|�7_|dS|jd�}|dkry|d|t|��}|jt|�7_||7}q�W|S)	zrRead and return a line from the stream.

        If limit is specified, at most limit bytes will be read.
        rs
rrLr�newlineN�chunk)r�r�rlr��io�BufferedIOBase�readliner7�peek�PATTERN�search�groupr�rS)ru�limitr��lineZ	readahead�matchr�r�rrrr��s8		!
	zZipExtFile.readlinecCs�|t|j�|jkr~|j|�}t|�|jkri||j|jd�|_d|_n|jt|�8_|j|j|jd�S)z6Returns buffered bytes without advancing the position.Nri)r7r�r�r/)rur�r�rrrr�%szZipExtFile.peekcCsdS)NTr)rurrr�readable2szZipExtFile.readablecCsm|dks|dkrj|j|jd�}d|_d|_x#|jse||j|j�7}qCW|S||j}|t|j�kr�|j|j|�}||_|S|t|j�}|j|jd�}d|_d|_x||dkrh|jrh|j|�}|t|�krK||_||_||d|�7}P||7}|t|�8}q�W|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..
        NrrL)r�r�r��_read1�MAX_Nr7)rur��buf�endrIrrrr/5s4		
					
zZipExtFile.readcCsZ|jdkrdSt||j�|_|jrV|j|jkrVtd|j��dS)NzBad CRC-32 for file %r)r�r�r�r�rr�)ru�newdatarrr�_update_crcVs
zZipExtFile._update_crccCsp|dks|dkrw|j|jd�}d|_d|_x0|jsr|j|j�}|rC||7}PqCW|S||j}|t|j�kr�|j|j|�}||_|S|t|j�}|j|jd�}d|_d|_|dkrlxf|jsk|j|�}|t|�krW||_||_||d|�7}P|r||7}PqW|S)z7Read up to n bytes with at most one read() system call.NrrL)r�r�r�rrr7)rur�rrIrrrr�read1`s>		

					
zZipExtFile.read1cCs�|js|dkrdS|jtkrf|jj}|t|�kru||j|t|��7}n|j|�}|jtkr�|jdk|_n�|jtkrt	||j
�}|jj||�}|jjp�|jdko�|jj|_|jrI||jj
�7}n0|jj|�}|jjpC|jdk|_|d|j�}|jt|�8_|jdkr�d|_|j|�|S)NrrLT)r�r�rr�Zunconsumed_tailr7�_read2rr�rT�
MIN_READ_SIZEr�r�r�r�r
)rur�rIrrrr�s2 		
zZipExtFile._read1cCs�|jdkrdSt||j�}t||j�}|jj|�}|jt|�8_|sjt�|jdk	r�t	t
|j|��}|S)NrrL)r�rTr
�minr�r/r7�EOFErrorr��bytes�map)rur�rIrrrr�szZipExtFile._read2c
s/z|jr|jj�Wdt�j�XdS)N)r�r�r��super)ru)rzrrr��s	zZipExtFile.close�i@ryry)rrrrrr
�re�compiler�rvr�r�r�rr/r
rrrr�rr)rzrr��s  2
!
%$r�c@s�eZdZdZdZdZdeddd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
ddd�Zdd�Zdd�Zdd�Zedd��Zejdd��Zddd�Zddd d!�Zddd"d#�Zdddd$d%�Zed&d'��Zd(d)�Zd*d+�Zddd,d-�Zdd.d/�Zd0d1�Zd2d3�Z d4d5�Z!d6d7�Z"dS)8ra� Class with methods to open, read, write, close, list zip files.

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

    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.

    N�rTcCs�|dkrtd��t|�||_d|_d|_i|_g|_||_||_d|_	d	|_
t|t�r#d|_
||_dd
dddddd
d
dddddi}||}xyytj||�|_Wn.tk
r||kr||}w��YnXPq�Wn'd|_
||_t|dd�|_d|_tj�|_d|_yD|dkr�|j�n'|dkr/d|_y|jj�|_Wn<ttfk
r�t|j�|_d|_d|_Yq�Xy|jj|j�Wq�ttfk
r+d|_Yq�Xn|dkr�y!|j�|jj|j�Wq�tk
r�|jjdd�d|_|jj�|_Yq�Xntd��Wn*|j}d|_|j |��YnXdS)z]Open the ZIP file with mode read 'r', write 'w', exclusive create 'x',
        or append 'a'.r�w�x�az+ZipFile requires mode 'r', 'w', 'x', or 'a'FrNrLr0zw+bzx+bzr+b�wbZxbrr�Trz"Mode must be 'r', 'w', 'x', or 'a')rrrr)rr)!r�r��_allowZip64�
_didModify�debug�
NameToInfo�filelistr�r�r��_commentr��str�_filePassedr3r�r2r-r,�getattr�_fileRefCnt�	threading�RLockr��	_seekable�_RealGetContentsrN�	start_dir�AttributeErrorr�r5r�_fpclose)rur�r�r��
allowZip64ZmodeDictr~r-rrrrv�s|
											


				
		

			
zZipFile.__init__cCs|S)Nr)rurrr�	__enter__)szZipFile.__enter__cCs|j�dS)N)r�)ru�type�value�	tracebackrrr�__exit__,szZipFile.__exit__cCs�d|jj|jjfg}|jdk	r�|jrN|jd|j�n#|jdk	rq|jd|j�|jd|j�n
|jd�|jd�dj|�S)Nz<%s.%sz file=%rz filename=%rz mode=%rz	 [closed]rwrx)	rzrrr-r"rSr3r�r)rur4rrrr�/s	

zZipFile.__repr__cCs�|j}yt|�}Wntk
r9td��YnX|sLtd��|jdkret|�|t}|t}|t|_	|t
||}|ttkr�|t
t8}|jdkr�||}td|||�|||_|j|jd�|j|�}tj|�}d}xi||kr�|jt�}	t|	�tkrbtd��tjt|	�}	|	ttkr�td��|jdkr�t|	�|j|	t�}
|	d}|d	@r�|
jd
�}
n|
jd�}
t|
�}|j|	t�|_|j|	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|j4�|j#||_#|j5j6|�||j7|j8<|t|	t|	t|	t }|jdkr)td|�q)WdS)z/Read in the table of contents for the ZIP file.zFile 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�totalN)9r-r+r,rr�printrDrE�_ECD_COMMENTr �
_ECD_LOCATIONr?r>r<r6r)r5r/r��BytesIO�sizeCentralDirr7r8r9�structCentralDir�
_CD_SIGNATURE�stringCentralDir�_CD_FILENAME_LENGTH�decoder
�_CD_EXTRA_FIELD_LENGTHr\�_CD_COMMENT_LENGTHrX�_CD_LOCAL_HEADER_OFFSETrdrJr]r^r_r`r[rerfrg�MAX_EXTRACT_VERSIONr�rarbrcrhrZr�rrSrr3)rur-rHZsize_cdZ	offset_cd�concatZinferredrIr3�centdirr3�flagsr�t�drrrr(=sp	










L"	&
"zZipFile._RealGetContentscCsdd�|jD�S)z+Return a list of file names in the archive.cSsg|]}|j�qSr)r3)�.0rIrrr�
<listcomp>�s	z$ZipFile.namelist.<locals>.<listcomp>)r)rurrr�namelist�szZipFile.namelistcCs|jS)zJReturn a list of class ZipInfo instances for files in the
        archive.)r)rurrr�infolist�szZipFile.infolistcCsftdd
d|�xK|jD]@}d|jdd�}td	|j||jfd|�qWdS)z+Print a table of contents for the zip file.z%-46s %19s %12s�	File Name�Modified    �Sizer�z%d-%02d-%02d %02d:%02d:%02dNr"z
%-46s %s %12d)rKrLrM)r4rrZr3rg)rur��zinfoZdaterrr�printdir�s
zZipFile.printdircCssd}xf|jD][}y9|j|jd��}x|j|�rFq4WWdQRXWqtk
rj|jSYqXqWdS)z%Read all the files and check the CRC.rrrNi)rr2r3r/r)ruZ
chunk_sizerN�frrr�testzip�s
zZipFile.testzipcCs2|jj|�}|dkr.td|��|S)z,Return the instance of ZipInfo given 'name'.Nz(There is no item named %r in the archive)rr|�KeyError)rur��inforrr�getinfo�s

zZipFile.getinfocCsK|r,t|t�r,tdt|���|r>||_n	d|_dS)z)Set default password for encrypted files.zpwd: expected bytes, got %sN)r�r�	TypeErrorr.r�)rur�rrr�setpassword�s
zZipFile.setpasswordcCs|jS)z.The comment text associated with the ZIP file.)r )rurrrrX�szZipFile.commentcCs�t|t�s%tdt|���t|�tkrjddl}|jdtdd�|dt�}||_d|_	dS)Nzcomment: expected bytes, got %srz3Archive comment is too long; truncating to %d bytes�
stacklevelrT)
r�rrUr.r7�ZIP_MAX_COMMENT�warnings�warnr r)rurXrYrrrrX�s		c	Cs-|j|d|��}|j�SWdQRXdS)z)Return file bytes (as a string) for name.rN)r2r/)rur�r�r-rrrr/�szZipFile.readcCs�|dkrtd��d|krCddl}|jdtd�|rot|t�rotd	t|���|js�td
��t|t	�r�|}n|j
|�}|jd7_t|j|j
|j|j�}y�|jt�}t|�tkrtd��tjt|�}|ttkr9td
��|j|t�}|trg|j|t�|jd@r�td��|jd@r�td��|jd@r�|jd�}	n|jd�}	|	|jkr�td|j|f��|jd@}
d}|
r�|s|j}|s-td|��t |�}|jd�}t!t"||dd���}
|jd@r�|j#d?d@}n|j$d?d@}|
d|kr�td|��t%||||d�SWn|j&��YnXdS)z#Return file-like object for 'name'.rr��rUz&open() requires mode "r", "U", or "rU"rNz'U' mode is deprecatedrzpwd: expected bytes, got %sz3Attempt to read ZIP archive that was already closedrzTruncated file headerz Bad magic number for file header� z$compressed patched data (flag bit 5)�@zstrong encryption (flag bit 6)izutf-8r2z/File name in directory %r and header %r differ.z6File %s is encrypted, password required for extractionrrr�r�r&zBad password for fileT)rr�r[)'r�rYrZ�DeprecationWarningr�rrUr.r-r
rTr$r�rdr+r�r/�sizeFileHeaderr7rr8r9r��
_FH_SIGNATUREr��_FH_FILENAME_LENGTH�_FH_EXTRA_FIELD_LENGTHr`r�r=rYr�r�rRrrhrer�r�)rur�r�r�rYrNZzef_fileZfheader�fnameZ	fname_strZis_encryptedZzdr��hZ
check_byterrrr2�sr	
			!




	


zZipFile.opencCsIt|t�s|j|�}|dkr6tj�}|j|||�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)r�r
rTrn�getcwd�_extract_member)ru�member�pathr�rrr�extract+s
zZipFile.extractcCs@|dkr|j�}x!|D]}|j|||�qWdS)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)rIri)rurhZmembersr�r�rrr�
extractall9s
zZipFile.extractallcCs�|j}|s:d}tj|dt|��}||_|j|�}dd�|j|�D�}|jdd�|D��}|S)z;Replace bad characters and remove trailing dots from parts.z:<>|"?*�_css|]}|jd�VqdS)�.N)�rstrip)rGrrrr�	<genexpr>Osz1ZipFile._sanitize_windows_name.<locals>.<genexpr>css|]}|r|VqdS)Nr)rGrrrrrnQs)�!_windows_illegal_name_trans_tabler!�	maketransr7�	translate�splitr)�cls�arcname�pathsepr�Zillegalrrr�_sanitize_windows_nameEs		zZipFile._sanitize_windows_namecs�|jjdtjj�}tjjrE|jtjjtjj�}tjj|�d}dtjjtjjf�tjjj	�fdd�|j
tjj�D��}tjjdkr�|j|tjj�}tjj	||�}tjj|�}tjj
|�}|r6tjj|�r6tj|�|jd
dkrltjj|�shtj|�|S|j|d|��0}t|d��}tj||�Wd	QRXWd	QRX|S)zbExtract the ZipInfo object 'member' to a physical
           file on the path targetpath.
        rjrrxc3s!|]}|�kr|VqdS)Nr)rGr)�invalid_path_partsrrrnbsz*ZipFile._extract_member.<locals>.<genexpr>�\r�rNry)r3rprnrhro�altsep�
splitdrive�curdir�pardirrrrrv�normpath�dirname�exists�makedirsr��mkdirr2�shutilZcopyfileobj)rurgZ
targetpathr�rtZ	upperdirs�source�targetr)rwrrfTs*7

zZipFile._extract_membercCs�|j|jkr8ddl}|jd|jdd�|jdkrStd	��|jshtd
��t|j�|j	s�d}t
|j�tkr�d}n-|j
tkr�d}n|jtkr�d
}|r�t|d��dS)z6Check for errors before writing a file to the archive.rNzDuplicate name: %rrWrrrrz&write() requires mode 'w', 'x', or 'a'z4Attempt to write ZIP archive that was already closedzFiles countZFilesizezZipfile sizez would require ZIP64 extensions)rrr)r3rrYrZr�r�r-r�r[rr7r�ZIP_FILECOUNT_LIMITrgr�rdr
)rurNrY�requires_zip64rrr�_writecheck{s(		
			zZipFile._writecheckcCs�|jstd��tj|�}tj|j�}tj|j�}|dd�}|dkrj|}tj	j
tj	j|�d�}x0|dtjtj
fkr�|dd�}q�W|r�|d7}t||�}|dd@d>|_|rt|_n$|dkr |j|_n	||_|j|_d|_|j�U|jrd|jj|j�|jj�|_|jtkr�|jd	O_|j|�d
|_|r)d|_d|_d|_ |jdO_|j!j"|�||j#|j$<|jj%|j&d��|jj�|_dSt'|j�}	|jsP|jdO_t(|d
���}
d|_ }d|_}|j)o�|jdt*k}
|jj%|j&|
��d}xn|
j+d�}|s�P|t,|�}t-||�}|	r|	j.|�}|t,|�}|jj%|�q�WWdQRX|	rm|	j/�}|t,|�}|jj%|�||_n	||_||_ ||_|jd@r�|
r�dnd}|jj%t0j1||j |j|j��|jj�|_n�|
r'|j)r'|t*krtd��|t*kr'td��|jj�|_|jj|j�|jj%|j&|
��|jj|j�|j!j"|�||j#|j$<WdQRXdS)zLPut the bytes from filename into the archive under the name
        arcname.z7Attempt to write to ZIP archive that was already closedrr"Nrrji��rrTFrr0g�������?iz<LQQz<LLLz*File size has increased during compressingz-Compressed size larger than uncompressed sizei )2r-r�rnr}�S_ISDIR�st_mode�time�	localtime�st_mtimerhr}rzroryr
rcrr[r��st_sizergr`r�r'r5r)rNrdrr�rrfrerrSrr3r�r�r�r2rr�r/r7r�r�r�r8r�)rur3rtr[�str��mtimerZrNZcmprr-rerfr�rgrr�rrrr��s�		"
		
	
					

				

z
ZipFile.writec
Cs�t|t�r|jd�}t|t�s�td|dtjtj��dd��}|j|_|jddkr�d|_	|j	d	O_	q�d|_	n|}|j
s�td��t|�|_
|j��|jr�|j
j|j�|j
j�|_|dk	r||_|j
j�|_|dk	r?||_|jtkr]|jdO_|j|�d
|_t|�|_t|j�}|r�|j|�|j�}t|�|_n|j
|_|j
tkp�|jtk}|r|jrt d��|j
j!|j"|��|j
j!|�|jd@r{|rJdnd}|j
j!t#j$||j|j|j
��|j
j�|j
j�|_|j%j&|�||j'|j<WdQRXdS)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.zutf-8r3rZNr"rrji�Ari�z7Attempt to write to ZIP archive that was already closedrTz'Filesize would require ZIP64 extensionsrz<LQQz<LLLryi�Ai�)(r�r!r�r
r�r�r�r[r3rcr-r�r7rgr�r'r5r)rNrdrr`r�rr�rer�r�r�rfr�rr
r�r�r8r�rrSr)ruZzinfo_or_arcnamerIr[rN�cor�r�rrr�writestr�s`"			
			
	


zZipFile.writestrcCs|j�dS)z2Call the "close()" method in case the user forgot.N)r�)rurrr�__del__9szZipFile.__del__cCs�|jdkrdSzS|jdkre|jre|j�+|jrT|jj|j�|j�WdQRXWd|j}d|_|j|�XdS)zOClose the file, and for mode 'w', 'x' and 'a' write the ending
        records.Nrrr)rrr)	r-r�rr�r'r5r)�_write_end_recordr+)rur-rrrr�=s
			z
ZipFile.closecCs�x
|jD]�}|j}|ddd>|dd>B|dB}|dd>|d	d>B|ddB}g}|jtks�|jtkr�|j|j�|j|j�d
}d
}n|j}|j}|jtkr�|j|j�d
}n	|j}|j}	d}
|rJtj	ddt
|�dd
t
|�|�|	}	t}
|jt
krktt|
�}
n|jtkr�tt|
�}
t|
|j�}t|
|j�}y�|j�\}
}tj	tt||j||j||j|||j||t
|
�t
|	�t
|j�d|j|j|�}Wn�tk
r�ttt||j||j|j|j|||j||t
|j �t
|	�t
|j�d|j|j|fdt!j"��YnX|j#j$|�|j#j$|
�|j#j$|	�|j#j$|j�q
W|j#j%�}t
|j�}||j&}|j&}d}|t'kr\d}n'|tkrqd}n|tkr�d}|r7|j(s�t)|d��tj	t*t+ddddd||||�}|j#j$|�tj	t,t-d|d�}|j#j$|�t.|d�}t.|d
�}t.|d
�}tj	t/t0dd||||t
|j1��	}|j#j$|�|j#j$|j1�|j#j2�dS)Nri�r$rr!rrr&r l��z<HH�Qrr�zFiles countzCentral directory offsetzCentral directory sizez would require ZIP64 extensions�,ri��)3rrZrgr�rfrSrdr\r8r�r7r�r[rrTr�rr�r^rJr�r9r;r]r_rerXrbrcr^r4r`r3rr�stderrr-r�rNr)r�rr
r=r>r:r;rrQrPr r�)rurNr�r�r�r\rgrfrdZ
extra_datar�r^rJr3r`rCZpos2ZcentDirCountZcentDirSizeZ
centDirOffsetr�Zzip64endrecZzip64locrecrHrrrr�Ns�	&&							

!
				
zZipFile._write_end_recordcCsF|jdkst�|jd8_|jrB|jrB|j�dS)Nrr)r$r�r"r�)rur-rrrr+�szZipFile._fpclose)#rrrrr-rorrvr-r1r�r(rIrJrOrQrTrV�propertyrX�setterr/r2rirj�classmethodrvrfr�r�r�r�r�r�r+rrrrr�s:TN	
		
X'h?ec@sLeZdZdZdedd
dd�Zddd	d
�Zdd�ZdS)rzDClass to create ZIP archives with Python library files and packages.rTrc	Cs/tj||d|d|d|�||_dS)Nr�r�r,)rrv�	_optimize)rur�r�r�r,�optimizerrrrv�szPyZipFile.__init__rxNcCs�|rR||�rR|jrNtjj|�r4dnd}td||f�dStjj|�\}}tjj|�r1tjj|d�}tjj|�rP|r�d||f}n|}|jr�td|d|�|j|d	d�|�\}}	|jrtd|	�|j	||	�tj
|�}
|
jd�x�|
D]}tjj||�}tjj|�\}
}tjj|�r�tjjtjj|d��rI|j
||d|�qI|d
krI|r||�r|jrItd|�qI|j|d	d�|�\}}	|jr9td|	�|j	||	�qIWq�|jrftd|�x2tj
|�D]�}tjj||�}tjj|�\}
}|d
krv|r�||�r�|jrvtd|�qv|j|d	d�|�\}}	|jrtd|	�|j	||	�qvWnj|dd�d
krStd��|j|d	d�|�\}}	|jr�td|	�|j	||	�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.
        rhr�z%s "%s" skipped by filterfuncNz__init__.pyz%s/%szAdding package in�asrrZAdding�
filterfuncz.pyzfile "%s" skipped by filterfunczAdding files from directoryz.Files added with writepy() must end with ".py"zAdding file���r�r�r�r�)rrnrhr�r4rrr�isfile�
_get_codenamer��listdir�remove�splitext�writepyr�)ru�pathname�basenamer�Zlabel�dirr�ZinitnamercrtZdirlistr3rh�rootZextrrrr��sv		"	


!
		
	
		
	"	
zPyZipFile.writepyc
s�d
�fdd�}|d}|d}tjj|dd�}tjj|dd�}tjj|dd�}�jdkr�tjj|�r�tj|�jtj|�jkr�|}	}
q�tjj|�rtj|�jtj|�jkr|}
|}	q�tjj|�rMtj|�jtj|�jkrM|}
|}	q�tjj|�r�tj|�jtj|�jkr�|}
|}	q�||�r�t	j
jd	kr�|}
n!t	j
jdkr�|}
n|}
|}	q�|}
}	n��jd	kr|}
|}	nT|}	�jdkr,|}
n6�jdkrD|}
nd
j�j�}t
|��tjj|
�o�tj|
�jtj|�jks�||d�j�s�|}
}	tjj|	�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).
        rcsddl}�jr"td|�y|j|ddd|�Wn9|jk
rz}zt|j�dSWYdd}~XnXdS)NrZ	Compiling�doraiseTr�F)�
py_compilerr4r�PyCompileError�msg)r�r�r��err)rurr�_compiles	

z)PyZipFile._get_codename.<locals>._compilez.pyz.pyc�optimizationrxrrz"invalid value for 'optimize': {!r}r�z%s/%sryry)�	importlib�util�cache_from_sourcer�rnrhr�r}r�rrrDr��formatrqrr)
rur�r�r�Zfile_pyZfile_pycZpycache_opt0Zpycache_opt1Zpycache_opt2rtrcr�Zarchivenamer)rurr�s`

$
$	$	$				
			$
zPyZipFile._get_codenamery)rrrrrrvr�r�rrrrr�s
Qcs�ddl}|jd�}|dkr:tjdd�}|sQ|ddkrht|�tjd�|ddkr�t|�dkr�t|�tjd�t|dd	��}|j�WdQRXn�|ddkrSt|�dkrt|�tjd�t|dd	��}|j	�}WdQRX|rFtd
j
|��td�nT|ddkr�t|�dkr�t|�tjd�t|dd	��}|j|d�WdQRXn�|ddkr�t|�dkr�t|�tjd��fd
d��t|dd���}x|dd�D]m}tj
j|�}|sktj
jtj
j|��}|dtjtjfkr�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�-trrz.The following enclosed file is corrupted: {!r}zDone testingrcs�tjj|�r(|j||t�nptjj|�r�|rP|j||�xEtj|�D]4}�|tjj||�tjj||��q`WdS)N)rnrhr�r�rr�r�r)�zfrh�zippathZnm)�addToZiprrr��szmain.<locals>.addToZiprrx)r�r�r�r�)�textwrap�dedentrr�argvr4�exitr7rrOrQr�rjrnrhr�r~r{r|)�argsr�ZUSAGEr�Zbadfilerhr�r)r�r�maingsT	










r��__main__)}rr�rnr�importlib.utilr�rrr�r}r�r8Zbinasciir%�ImportErrorZdummy_threadingr�r�r�r��__all__�	Exceptionrr
rrr�r�rXrrrrrtr�r�r�rArQrPr�rOr?r@rArBrCrDrErVr5r6r9r;r8r: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_SYSTEMZ_FH_GENERAL_PURPOSE_FLAG_BITSZ_FH_COMPRESSION_METHODZ_FH_LAST_MOD_TIMEZ_FH_LAST_MOD_DATEZ_FH_CRCZ_FH_COMPRESSED_SIZEZ_FH_UNCOMPRESSED_SIZErarbr:r;r6r=r>r<Z_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.r	rKr+�objectr
r�r�r�r{r�r�r�r�r�r�r�rrr�rrrrr�<module>s.




	

+=�=�����B

?>