AlkantarClanX12

Your IP : 3.147.68.201


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/zipfile.cpython-34.pyo

�
j f��$@sdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZyddlZej
Z
Wn!ek
r�dZej
Z
YnXyddlZWnek
r�dZYnXyddlZWnek
rdZYnXddddddd	d
ddd
dgZGdd�de�ZGdd�de�ZeZZdd>dZdd>dZdd>dZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$e
j%e#�Z&dZ'dZ(dZ)dZ*dZ+d Z,d!Z-d"Z.dZ/d#Z0d$Z1d%Z2e
j%e1�Z3dZ4dZ5dZ6dZ7dZ8d Z9d!Z:d"Z;dZ<d#Z=d&Z>d'Z?dZ@d(ZAdZBd)ZCdZDd*ZEd+ZFd,ZGd-ZHe
j%eG�ZIdZJdZKdZLdZMdZNd ZOd!ZPd"ZQdZRd#ZSd&ZTd'ZUd.ZVd/ZWe
j%eV�ZXd0ZYd1ZZe
j%eY�Z[dZ\dZ]dZ^dZ_dZ`d Zad!Zbd"ZcdZdd#Zed2d3�Zfd4d
�Zgd5d6�Zhd7d8�ZiGd9d�dej�ZkGd:d;�d;�ZlGd<d=�d=�ZmGd>d?�d?�Znid@d6dAd6dBd6dBd6dBd6dBd 6dCd!6dDd"6dEd6dFd#6dCd&6dGd6dHd6dId+6dJdK6dLdM6dNdO6ZodPdQ�ZpdRdS�ZqdTdU�ZrGdVdW�dWejs�ZtGdXd�d�ZuGdYd
�d
eu�ZvddZd[�Zwexd\krew�ndS)]zP
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/python34/lib64/python3.4/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.cCshd}yIt|d�r*td|�}n$t|d��}t|�}WdQXWntk
rcYnX|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
cCsry|j|td�Wntk
r0|SYnX|jt�}t|�tkrV|Stjt|�\}}}}|tkr�|S|dks�|dkr�t	d��n|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@sUeZdZdZd"Zdd#dd�Zddd�Zdd�Zd d!�ZdS)$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|�}ntjdkrstj|krs|jtjd�}n||_||_|ddkr�td��nt	|_
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__NcCs|j}|ddd>|dd>B|dB}|dd>|d	d>B|ddB}|jd
@rsd}}}n|j}|j}|j}|j}d}	|dkr�|tkp�|tk}n|r�d}
|tj|
dtj	|
�d	||�}n|tks|tkrA|s,t
d
��nd}d}t}	n|jt
krbtt|	�}	n!|jtkr�tt|	�}	nt|	|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�
FileHeaderfsF	&&
				#	zZipInfo.FileHeadercCsSy|jjd�|jfSWn/tk
rN|jjd�|jdBfSYnXdS)N�asciizutf-8i)r3�encoder`�UnicodeEncodeError)rurrrr}�s
zZipInfo._encodeFilenameFlagscCs�|j}tj}x�t|�dkr�|d|dd��\}}|dkr|dkrz|d|dd��}nx|dkr�|d|dd	��}nP|d
kr�|d|dd��}n(|d
kr�f}ntd|f��d
}|jdkr!|||_|d7}n|jdkrJ|||_|d7}n|jdkr|j}|||_|d7}qn||dd�}qWdS)Nr z<HHr�z<QQQ�rz<QQrrz<QrrzCorrupt extra field %s��������)r�r�)r\r8r9r7�RuntimeErrorrgrfrd)rur\r9Ztp�lnZcounts�idx�oldrrr�_decodeExtra�s4			



	
zZipInfo._decodeExtra)z
orig_filenamezfilenamez	date_timez
compress_typezcommentzextraz
create_systemzcreate_versionzextract_versionzreservedz	flag_bitszvolumez
internal_attrz
external_attrz
header_offsetzCRCz
compress_sizez	file_sizez	_raw_time)rirrrrr)	rrrr�	__slots__rvr�r}r�rrrrr
#s0*.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^tjdkr!tj�t_nd|_d|_d|_x|D]}|j|�qCWdS)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._UpdateKeyscCs8|jdB}|||dAd?d@A}|j|�|S)zDecrypt a single character.rrrr�)r�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)rurrrrv�szLZMACompressor.__init__cCsftjitjd6�}tjtjdtjtj|�g�|_tjdddt	|��|S)N�id�filtersz<BBHr$r )
�lzmaZ_encode_filter_properties�FILTER_LZMA1r��
FORMAT_RAW�_decode_filter_propertiesr�r8rxr7)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)rurrrrvs		zLZMADecompressor.__init__c	Cs�|jdkr�|j|7_t|j�dkr7dStjd|jdd��\}t|j�d|krvdStjtjdtjtj	|jdd|��g�|_|jd|d�}|`n|jj
|�}|jj|_|S)Nr rLz<Hrr�)r�r�r7r8r9r�r�r�r�r��
decompressr�)rurIZpsizer4rrrr�s"#	zLZMADecompressor.decompressN)rrrrvr�rrrrr�sr�ZstoreZshrink�reduceZimplode�tokenizeZdeflateZ	deflate64Zbzip2r�ZterseZlz77�Zwavpack�aZppmd�bcCs�|tkrnx|tkr3ts�td��q�nT|tkrWts�td��q�n0|tkr{ts�td��q�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_compressionCsr�cCsV|tkr%tjtjtjd�S|tkr;tj�S|tkrNt	�SdSdS)Nr(i�)
rr�ZcompressobjZZ_DEFAULT_COMPRESSIONZDEFLATEDrr�Z
BZ2Compressorrr�)r[rrr�_get_compressorVs

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��compressor_names�get�NotImplementedError)r[Zdescrrrr�_get_decompressorbs

r�cs�eZdZdZdZdZejd�Zdddd	�Z	dd
d�Z
ddd
�Zdd�Zddd�Z
dd�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_n||_|j|_t|d�r�|j|_td�d@|_n	d|_dS)NFrLr�Urrel��)�_fileobj�
_decrypter�_close_fileobjr[�_compress_typerf�_compress_leftrg�_leftr��
_decompressor�_eof�_readbuffer�_offset�
_universal�newlines�moder3�namer1re�
_expected_crc�crc32�_running_crc)ruZfileobjr��zipinfoZ	decrypter�
close_fileobjrrrrv�s(								zZipExtFile.__init__cCs�|jrd|dkrd|jjd|j�d}|dkrd|j|j|�}||_|Sn|js�tjj||�Sd}x|dks�t|�|kr�|jd�}|dkr�|S|j	j
|�}|jd�}|dk	rM|jdkrg|_n||jkr0|jj
|�n|jt|�7_|dS|jd�}|dkr�|d|t|��}n|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|_q�|jt|�8_n|j|j|jd�S)z6Returns buffered bytes without advancing the position.Nri)r7r�r�r/)ru�nr�rrrr��szZipExtFile.peekcCsdS)NTr)rurrr�readable�szZipExtFile.readablecCsp|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|dkrk|jrk|j|�}|t|�krN||_||_||d|�7}Pn||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/�s4		
					
zZipExtFile.readcCsa|jdkrdSt||j�d@|_|jr]|j|jkr]td|j��ndS)Nl��zBad CRC-32 for file %r)r�r�r�r�rr�)ru�newdatarrr�_update_crcs
zZipExtFile._update_crccCs||dks|dkrz|j|jd�}d|_d|_x3|jsu|j|j�}|rC||7}PqCqCW|S||j}|t|j�kr�|j|j|�}||_|S|t|j�}|j|jd�}d|_d|_|dkrxxo|jst|j|�}|t|�kr]||_||_||d|�7}Pn|r	||7}Pq	q	Wn|S)z7Read up to n bytes with at most one read() system call.NrrL)r�r�r�r�r�r7)rur�r�rIr�rrr�read1s>		

					
zZipExtFile.read1cCs�|js|dkrdS|jtkri|jj}|t|�krx||j|t|��7}qxn|j|�}|jtkr�|jdk|_n�|jtkrt	||j
�}|jj||�}|jjp�|jdko�|jj|_|jrO||jj
�7}qOn0|jj|�}|jjpI|jdk|_|d|j�}|jt|�8_|jdkr�d|_n|j|�|S)NrrLT)r�r�rr�Zunconsumed_tailr7�_read2rr�rT�
MIN_READ_SIZEr�r�r�r�r�)rur�rIrrrr�4s2#	
zZipExtFile._read1cCs�|jdkrdSt||j�}t||j�}|jj|�}|jt|�8_|smt�n|jdk	r�t	t
|j|��}n|S)NrrL)r�rTr��minr�r/r7�EOFErrorr��bytes�map)rur�rIrrrr�Xs	zZipExtFile._read2c
s2z|jr|jj�nWdt�j�XdS)N)r�r��close�super)ru)�	__class__rrr�hs	zZipExtFile.close�i@���r�)rrrrr�r��re�compiler�rvr�r�r�r/r�r�r�r�r�rr)r�rr�ss 2
!
%$r�c@sxeZdZdZdZdZdeddd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zddd�Z
dd�Zdd�Zdd�Zedd��Zejdd��Zddd�Zdddd�Zddd d!�Zdddd"d#�Zed$d%��Zd&d'�Zd(d)�Zddd*d+�Zdd,d-�Zd.d/�Zd0d1�ZdS)2ra� 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" 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�rTcCs6|dkrtd��nt|�||_d|_d|_i|_g|_||_|jdd�d|_	}d	|_
d
|_t|t
�r0d|_||_idd6dd6d
d6}ytj|||�|_WqWtk
r,|dkr%d}}tj|||�|_n�YqWXn'd|_||_t|dd	�|_y�|dkrs|j�n�|dkr�d|_np|dkr�y$|j�|jj|jd�Wq�tk
r�|jjdd�d|_Yq�Xntd��Wn3|j}d	|_|js*|j�n�YnXd	S)z>Open the ZIP file with mode read "r", write "w" or append "a".r��w�az(ZipFile() requires mode "r", "w", or "a"Fr�b�NrLr0�wbzr+brr�TrzMode must be "r", "w" or "a")r�r�r)r�r��_allowZip64�
_didModify�debug�
NameToInfo�filelistr�rpr�r��_comment�
isinstance�str�_filePassedr3r�r2r-r,�getattr�_RealGetContentsr5�	start_dirrr�)ru�filer�r��
allowZip64�keyZmodeDictr-rrrrv�sZ
										

		


			
zZipFile.__init__cCs|S)Nr)rurrr�	__enter__�szZipFile.__enter__cCs|j�dS)N)r�)ru�type�value�	tracebackrrr�__exit__�szZipFile.__exit__cCs�|j}yt|�}Wntk
r9td��YnX|sOtd��n|jdkrkt|�n|t}|t}|t|_	|t
||}|ttkr�|t
t8}n|jdkr�||}td|||�n|||_|j|jd�|j|�}tj|�}d}xx||kr�|jt�}	t|	�tkrqtd��ntjt|	�}	|	ttkr�td��n|jdkr�t|	�n|j|	t�}
|	d}|d	@r�|
jd
�}
n|
jd�}
t|
�}|j|	t�|_|j|	t �|_!|	t"|_#|	dd�\|_$|_%|_&|_'|_(|_)}
}|_*|_+|_,|j&t-kr�t.d
|j&d��n|	dd�\|_/|_0|_1|
|_2|d?d|d?d@|d@|
d?|
d?d@|
d@df|_3|j4�|j#||_#|j5j6|�||j7|j8<|t|	t|	t|	t }|jdkr5td|�q5q5WdS)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<r6rr5r/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�concatZinferredrIr�centdirr3�flags�x�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�namelistszZipFile.namelistcCs|jS)zJReturn a list of class ZipInfo instances for files in the
        archive.)r)rurrr�infolistszZipFile.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    �Sizerz%d-%02d-%02d %02d:%02d:%02dNr"z
%-46s %s %12d)r2r3r4)rrrZr3rg)rur�zinfoZdaterrr�printdir!s
zZipFile.printdircCsrd}xe|jD]Z}y8|j|jd��}x|j|�rFq4WWdQXWqtk
ri|jSYqXqWdS)z%Read all the files and check the CRC.rrr�Ni)rr2r3r/r)ruZ
chunk_sizer5�frrr�testzip*s
zZipFile.testzipcCs5|jj|�}|dkr1td|��n|S)z,Return the instance of ZipInfo given 'name'.Nz(There is no item named %r in the archive)rr��KeyError)rur��inforrr�getinfo7s
zZipFile.getinfocCsN|r/t|t�r/tdt|���n|rA||_n	d|_dS)z)Set default password for encrypted files.zpwd: expected bytes, got %sN)r
r��	TypeErrorrr�)rur�rrr�setpassword@s
zZipFile.setpasswordcCs|jS)z.The comment text associated with the ZIP file.)r	)rurrrrXIszZipFile.commentcCs�t|t�s(tdt|���nt|�tkrpddl}|jdtdd�|dt�}n||_d|_	dS)Nzcomment: expected bytes, got %srz3Archive comment is too long; truncating to %d bytes�
stacklevelrT)
r
r�r<rr7�ZIP_MAX_COMMENT�warnings�warnr	r)rurXr@rrrrXNs		cCs,|j|d|��}|j�SWdQXdS)z)Return file bytes (as a string) for name.r�N)r2r/)rur�r�r-rrrr/[szZipFile.readc
Cs5|dkrtd��nd|krIddl}|jdtd�n|rxt|t�rxtd	t|���n|js�td
��n|j	r�|j}nt
j|jd�}ySt|t
�r�|}n|j|�}|j|jd�|jt�}t|�tkr'td��ntjt|�}|ttkrXtd
��n|j|t�}|tr�|j|t�n|jd@r�td��n|jd@r�td��n|jd@r�|jd�}	n|jd�}	|	|jkrtd|j|f��n|jd@}
d}|
r�|sE|j }n|s^td|��nt!|�}|jd�}t"t#||dd���}
|jd@r�|j$d?d@}n|j%d?d@}|
d|kr�td|��q�nt&||||d|j	�SWn!|j	s)|j'�n�YnXdS) z#Return file-like object for 'name'.r�r��rUz&open() requires mode "r", "U", or "rU"rNz'U' mode is deprecatedrzpwd: expected bytes, got %sz3Attempt to read ZIP archive that was already closedr0zTruncated file headerz Bad magic number for file header� z$compressed patched data (flag bit 5)�@zstrong encryption (flag bit 6)izutf-8rz/File name in directory %r and header %r differ.rz6File %s is encrypted, password required for extractionrrr�r�r&zBad password for filer�)r�r�rB)(r�r@rA�DeprecationWarningr
r�r<rr-rr�r2r3r
r;r5rdr/�sizeFileHeaderr7rr8r9r~�
_FH_SIGNATUREr�_FH_FILENAME_LENGTH�_FH_EXTRA_FIELD_LENGTHr`r�r#rYr�r�rRr�rhrer�r�)rur�r�r�r@Zzef_filer5Zfheader�fnameZ	fname_strZis_encryptedZzdr��hZ
check_byterrrr2`sz	
			






	
zZipFile.opencCsOt|t�s!|j|�}n|dkr<tj�}n|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
r;rn�getcwd�_extract_member)ru�member�pathr�rrr�extract�s
zZipFile.extractcCsC|dkr|j�}nx!|D]}|j|||�q"WdS)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)r0rP)rurOZmembersr�r�rrr�
extractall�s
zZipFile.extractallcCs�|j}|s=d}tj|dt|��}||_n|j|�}dd�|j|�D�}|jdd�|D��}|S)z;Replace bad characters and remove trailing dots from parts.z:<>|"?*�_css|]}|jd�VqdS)�.N)�rstrip)r.r+rrr�	<genexpr>�sz1ZipFile._sanitize_windows_name.<locals>.<genexpr>css|]}|r|VqdS)Nr)r.r+rrrrU�s)�!_windows_illegal_name_trans_tabler�	maketransr7�	translate�split�join)�cls�arcname�pathsepr�Zillegalrrr�_sanitize_windows_name�s	zZipFile._sanitize_windows_namecs�|jjdtjj�}tjjrH|jtjjtjj�}ntjj|�d}dtjjtjjf�tjjj	�fdd�|j
tjj�D��}tjjdkr�|j|tjj�}ntjj	||�}tjj|�}tjj
|�}|r?tjj|�r?tj|�n|jd
dkrxtjj|�sttj|�n|S|j|d|��/}t|d��}tj||�Wd	QXWd	QX|S)zbExtract the ZipInfo object 'member' to a physical
           file on the path targetpath.
        rjrrc3s!|]}|�kr|VqdS)Nr)r.r+)�invalid_path_partsrrrU�sz*ZipFile._extract_member.<locals>.<genexpr>�\r�rNr�)r3rprnrOro�altsep�
splitdrive�curdir�pardirrZrYr^�normpath�dirname�exists�makedirs�isdir�mkdirr2�shutilZcopyfileobj)rurNZ
targetpathr�r\Z	upperdirs�source�targetr)r_rrM�s*!7zZipFile._extract_membercCs�|j|jkr;ddl}|jd|jdd�n|jdkrYtd��n|jsqtd	��nt|j�|j	s�d}t
|j�tkr�d
}n0|j
tkr�d}n|jtkr�d}n|r�t|d
��q�ndS)z6Check for errors before writing a file to the archive.rNzDuplicate name: %rr>rr�rz write() requires mode "w" or "a"z4Attempt to write ZIP archive that was already closedzFiles countZFilesizezZipfile sizez would require ZIP64 extensions)r�r)r3rr@rAr�r�r-r�r[rr7r�ZIP_FILECOUNT_LIMITrgrwrdr
)rur5r@�requires_zip64rrr�_writechecks(	
				zZipFile._writecheckc
Cs|jstd��ntj|�}tj|j�}tj|j�}|dd�}|dkrp|}ntj	j
tj	j|�d�}x0|dtjtj
fkr�|dd�}q�W|r�|d7}nt||�}|dd@d>|_|rt|_n$|dkr)|j|_n	||_|j|_d|_|jj�|_|jtkrz|jd	O_n|j|�d
|_|r�d|_d|_d|_|jdO_|jj|�||j|j <|jj!|j"d��dSt#|j�}	t$|d���}
d|_}d|_}|j%oQ|jd
t&k}
|jj!|j"|
��d}xx|
j'd�}|s�Pn|t(|�}t)||�d@}|	r�|	j*|�}|t(|�}n|jj!|�qvWWdQX|	r2|	j+�}|t(|�}|jj!|�||_n	||_||_||_|
r�|j%r�|t&krxtd��n|t&kr�td��q�n|jj�}|jj,|jd�|jj!|j"|
��|jj,|d�|jj|�||j|j <dS)zLPut the bytes from filename into the archive under the name
        arcname.z7Attempt to write to ZIP archive that was already closedrr"Nrrji��rrTFr0g�������?irl��z*File size has increased during compressingz-Compressed size larger than uncompressed sizei )-r-r�rn�stat�S_ISDIR�st_mode�time�	localtime�st_mtimerOrerbrorar
rcrr[r��st_sizergr`rNrdrrprrfrerrSrr3�writer�r�r2rrwr/r7r�r�r�r5)rur3r\r[�stri�mtimerZr5Zcmprr-rerfr�rgr�Zpositionrrrrx's�		"
		
				

				z
ZipFile.writecCsut|t�r!|jd�}nt|t�s�td|dtjtj��dd��}|j|_|jddkr�d|_	|j	d	O_	q�d|_	n|}|j
s�td��nt|�|_
|j
j�|_|dk	r�||_n|jtkr|jdO_n|j|�d
|_t|�d@|_t|j�}|r�|j|�|j�}t|�|_n|j
|_|j
tkp�|jtk}|r�|jr�td��n|j
j|j|��|j
j|�|jd@rD|rdnd}|j
jtj ||j|j|j
��n|j
j�|j!j"|�||j#|j<dS)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 closedrTl��z'Filesize would require ZIP64 extensionsrz<LQQz<LLLr�i�Ai�)$r
rr�r
rtrur�r[r3rcr-r�r7rgrNrdrr`rprr�rer�r�r�rfrwrr
rxr�r8rxrrSr)ruZzinfo_or_arcnamerIr[r5�cor�r�rrr�writestr�sR"		
	

zZipFile.writestrcCs|j�dS)z2Call the "close()" method in case the user forgot.N)r�)rurrr�__del__�szZipFile.__del__c"Cs|jdkrdSz�|jdkr�|jr�|jj�}x|jD]}|j}|ddd>|dd>B|d	B}|d
d>|dd>B|dd	B}g}|jtks�|jtkr�|j	|j�|j	|j�d
}d
}n|j}|j}|j
tkr/|j	|j
�d
}	n	|j
}	|j}
d}|r�tj
ddt|�ddt|�|�|
}
t}n|jtkr�tt|�}n!|jtkr�tt|�}nt||j�}t||j�}
y�|j�\}}tj
tt|
|j||j||j|||j||t|�t|
�t|j�d|j|j |	�}Wn�t!k
rt"tt|
|j||j|j#|j|||j||t|j$�t|
�t|j�d|j|j |	fdt%j&��YnX|jj'|�|jj'|�|jj'|
�|jj'|j�qGW|jj�}t|j�}||}|}d}|t(kr�d}n*|tkr�d}n|tkr�d}n|r}|j)s�t*|d��ntj
t+t,ddddd||||�}|jj'|�tj
t-t.d|d�}|jj'|�t/|d�}t/|d
�}t/|d
�}ntj
t0t1dd||||t|j2��	}|jj'|�|jj'|j2�|jj3�nWd|j}d|_|j4s|j5�nXdS)zJClose the file, and for mode "w" and "a" write the ending
        records.Nr�rri�r$rr!rrr&r l��z<HH�QrrzFiles countzCentral directory offsetzCentral directory sizez would require ZIP64 extensions�,ri��)r�r)6r-r�rrNrrZrgrwrfrSrdr\r8rxr7rzr[rrTr{rr|r^rJr}rr!r]r_rerXrbrcrErr`r3rr�stderrrxrnrr
r=r>r:r;r�rQrPr	r�rr�)ruZpos1r5r�r�r�r\rgrfrdZ
extra_datar�r^rJr3r`r)Zpos2ZcentDirCountZcentDirSizeZ
centDirOffsetroZzip64endrecZzip64locrecrHr-rrrr��s�	&&								

!
				
			z
ZipFile.close) rrrrr-rVrrvrrrr0r1r6r8r;r=�propertyrX�setterr/r2rPrQ�classmethodr^rMrprxr|r}r�rrrrrps4AN	
		
`'[8c@sLeZdZdZdedd
dd�Zddd	d
�Zdd�ZdS)rzDClass to create ZIP archives with Python library files and packages.r�Trc	Cs/tj||d|d|d|�||_dS)Nr�r�r)rrv�	_optimize)rurr�r�r�optimizerrrrv4szPyZipFile.__init__rNcCs�|rU||�rU|jrQtjj|�r4dnd}td||f�ndStjj|�\}}tjj|�rXtjj|d�}tjj|�rh|r�d||f}n|}|jr�td|d|�n|j|d	d�|�\}}	|jrtd|	�n|j	||	�tj
|�}
|
jd�x|
D]}tjj||�}tjj|�\}
}tjj|�r�tjjtjj|d��ra|j
||d|�qaqR|d
krR|r||�r|jrRtd|�qRqRn|j|d	d�|�\}}	|jrNtd|	�n|j	||	�qRqRWq�|jr�td|�nxDtj
|�D]�}tjj||�}tjj|�\}
}|d
kr�|r||�r|jr�td|�q�q�n|j|d	d�|�\}}	|jr>td|	�n|j	||	�q�q�Wnp|dd�d
kr}td��n|j|d	d�|�\}}	|jr�td|	�n|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.pyo or 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.
        rOrz%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�)rrnrOrirrYrZ�isfile�
_get_codenamerx�listdir�remove�splitext�writepyr�)ru�pathname�basenamer�Zlabel�dirr�ZinitnamerJr\Zdirlistr3rO�rootZextrrrr�:sv		"	

!
					"	zPyZipFile.writepycszd�fdd�}|d}|d}|d}tjj|d�}tjj|d�}�jd
kr�tjj|�r�tj|�jtj|�jkr�|}	}
qAtjj|�r�tj|�jtj|�jkr�|}	}
qAtjj|�r7tj|�jtj|�jkr7|}
|}	qAtjj|�r|tj|�jtj|�jkr||}
|}	qA||�r�t	r�|n|}
t	r�|n|}	qA|}
}	n��jd	kr�|}
|}	n|}
|}	tjj|
�otj|
�jtj|�jksA||d
�j�sA|}
}	qAntjj
|	�d}|rpd||f}n|
|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).
        rcs�ddl}�jr%td|�ny|j|ddd|�Wn9|jk
r}}zt|j�dSWYdd}~XnXdS)NrZ	Compiling�doraiseTr�F)�
py_compilerrr��PyCompileError�msg)rr�r��err)rurr�_compile�s	
z)PyZipFile._get_codename.<locals>._compilez.pyz.pycz.pyoTFrr�z%s/%sr�r�)�	importlib�util�cache_from_sourcer�rnrOr�rqrv�	__debug__rY)rur�r�r�Zfile_pyZfile_pycZfile_pyoZpycache_pycZpycache_pyor\rJZarchivenamer)rurr��sL


$
$
$	$	
	$zPyZipFile._get_codenamer�)rrrrrrvr�r�rrrrr1s
Qcs�ddl}|jd�}|dkr=tjdd�}n|sT|ddkrnt|�tjd�n|ddkr�t|�dkr�t|�tjd�nt|dd	��}|j�WdQXn�|ddkr`t|�dkrt|�tjd�nt|dd	��}|j	�}WdQX|rStd
j
|��ntd�na|ddkr�t|�dkr�t|�tjd�nt|dd	��}|j|d�WdQXn�|ddkr�t|�dkrt|�tjd�n�fd
d��t|dd���}x�|dd�D]s}tj
j|�}|s�tj
jtj
j|��}n|dtjtjfkr�d}n�|||�qAWWdQXndS)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�-trr�z.The following enclosed file is corrupted: {!r}zDone testingrcs�tjj|�r(|j||t�nvtjj|�r�|rS|j||�nxHtj|�D]4}�|tjj||�tjj||��qcWndS)N)rnrOr�rxrrir�rZ)�zfrO�zippathZnm)�addToZiprrr��szmain.<locals>.addToZipr�r)r�r�r�r�)�textwrap�dedentrr�argvr�exitr7rr6r8�formatrQrnrOr�rfrcrd)�argsr�ZUSAGEr�ZbadfilerOr�r)r�r�main�sT	





!	r��__main__)yrr�rnr��importlib.utilr�rrrtrqrkr8Zbinasciir�r��ImportErrorr�r��__all__�	Exceptionrr
rrrwrnr?rrrrrtrzr{r|r'rQrPryrOr?r@rArBrCrDrErVrrrr!rr 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~rrFrGZ_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_SIZErHrIr: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�rrr�rrrrr�<module>s"



	

+=�=
�����B