• File: zipfile.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib64/python3.7/__pycache__/zipfile.cpython-37.pyc
  • Date Modified: 10/26/2026 8:08 PM
  • File size: 49.83 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

NjA@sdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZyddlZej
Z
Wnek
rdZe
j
Z
YnXyddlZWnek
rdZYnXyddlZWnek
rdZYnXddddddd	d
ddd
dgZGdddeZGdddeZeZZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$e	%e#Z&dZ'dZ(dZ)dZ*dZ+d Z,d!Z-d"Z.dZ/d#Z0d$Z1d%Z2e	%e1Z3dZ4dZ5dZ6dZ7dZ8d Z9d!Z:d"Z;dZ<d#Z=d&Z>d'Z?dZ@d(ZAdZBd)ZCd*ZDd+ZEd,ZFd-ZGd.ZHe	%eGZIdZJdZKdZLdZMdZNd ZOd!ZPd"ZQdZRd#ZSd&ZTd'ZUd/ZVd0ZWe	%eVZXd1ZYd2ZZe	%eYZ[dZ\dZ]dZ^dZ_dZ`d Zad!Zbd"ZcdZdd#Zed3Zfe	gd4Zhd5d6Zid7d8Zjd9d
Zkd:d;Zld<d=ZmGd>ddenZodapd?d@ZqdAdBZrGdCdDdDZsGdEdFdFZtdGdHdIdIdIdIdJdKdLdMdJdNdOdPdQdRdSdTZudUdVZvdhdWdXZwdYdZZxGd[d\d\ZyGd]d^d^ZzGd_d`d`ej{Z|Gdadbdbej{Z}GdcddZ~Gddd
d
e~ZdidedfZedgkredS)jzP
Read and write ZIP files.

XXX references to utf-8 need further investigation.
N
BadZipFile
BadZipfileerror
ZIP_STOREDZIP_DEFLATED	ZIP_BZIP2ZIP_LZMA
is_zipfileZipInfoZipFile	PyZipFileLargeZipFilec@seZdZdS)rN)__name__
__module____qualname__rr,/opt/alt/python37/lib64/python3.7/zipfile.pyr&sc@seZdZdZdS)r
zu
    Raised when writing a zipfile, the zipfile requires ZIP64 extensions
    and those extensions are disabled.
    N)rrr__doc__rrrrr
*sii-.?s<4s4H2LHsPK	z<4s4B4HL2L5H2LsPK

z<4s2B4HL2L2HsPKz<4sLQLsPKz
<4sQ2H2L4QsPKiPKz<HHc
Cstj}d}g}d}}xf|dt|kr|||||d\}}|d|}	||krv||krn|||||	}d}|	}qW|s|Sd|S)NFrrT)_EXTRA_FIELD_STRUCTunpacklenappendjoin)
extraZxidsr,ZmodifiedbufferstartiZxidZxlenjrrr_strip_extras r5cCs*yt|rdSWntk
r$YnXdS)NTF)_EndRecDataOSError)fprrr_check_zipfilesr9c	CsZd}y8t|drt|d}nt|d}t|}WdQRXWnttfk
rTYnX|S)zQuickly 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.
    Fread)r8rbN)hasattrr9openr7r)filenameresultr8rrrr	s
c
Cs|t8}|dkr|S|||t}t|tkr<tdtt|\}}}}|tkr\|S|dksl|dkrtt	d|t
8}||krt	d||||}|t
}t|t
krtd|ts||kr||d}|t
}t|t
krtd|tst	dtt
|\
}}	}
}}}
}}}}|||ksN|	dt
|krVt	d||t<||t<|
|t<||t<||t<||t<||t<|||t<|S)	zM
    Read the ZIP64 end-of-archive records and use that to update endrec
    rzUnknown I/O errorrz3zipfiles that span multiple disks are not supportedz.Corrupt zip64 end of central directory locatorz/Zip64 end of central directory record not foundrz-Corrupt zip64 end of central directory record)sizeEndCentDir64Locatorseekr:r-r7structr,structEndArchive64LocatorstringEndArchive64LocatorrsizeEndCentDir64
startswithstringEndArchive64structEndArchive64_ECD_SIGNATURE_ECD_DISK_NUMBER_ECD_DISK_START_ECD_ENTRIES_THIS_DISK_ECD_ENTRIES_TOTAL	_ECD_SIZE_ECD_OFFSET
_ECD_LOCATION)fpinoffsetendrecdataZsigZdisknoZreloffZdisksZextraszZszcreate_versionZread_versionZdisk_numZdisk_dirZdircountZ	dircount2ZdirsizeZ	diroffsetrrr
_EndRecData64sR





 rVc	Csd|dd|}y|tdWntk
r:dSX|}t|tkr|ddtkr|dddkrtt	|}t
|}|d||tt||t|St
|dtd}||d|}|t}|dkr`|||t}t|tkrdSt
tt	|}|t}||t|t|}|||||t||||SdS)	zReturn 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.rrNrsr*i)rAtellsizeEndCentDirr7r:r-stringEndArchiverBr,structEndArchivelistr.rVmaxrfind_ECD_COMMENT_SIZE)	rQZfilesizerTrSZmaxCommentStartr2ZrecDataZcommentSizecommentrrrr6
s<



r6c@sVeZdZdZdZdddZddZdd
dZdd
ZddZ	e
dddZddZd	S)r
z>Class with attributes describing each file in the ZIP archive.)
orig_filenamer>	date_time
compress_type_compresslevelr`r0
create_systemrUextract_versionreserved	flag_bitsvolume
internal_attr
external_attr
header_offsetCRC
compress_size	file_size	_raw_time_end_offsetNoNameirrrrrcCs||_|td}|dkr(|d|}tjdkrJtj|krJ|tjd}||_||_|ddkrjtdt	|_
d|_d|_d|_
tjdkrd|_nd|_t|_t|_d|_d|_d|_d|_d|_d|_dS)Nr/iz+ZIP does not support timestamps before 1980r*Zwin32r)rafindchrossepreplacer>rb
ValueErrorrrcrdr`r0sysplatformreDEFAULT_VERSIONrUrfrgrhrirjrkrq)selfr>rbZ	null_byterrr__init__ds2
zZipInfo.__init__cCsd|jj|jfg}|jtkr8|dt|j|j|jd?}|jd@}|rd|dt	
||rv|d||}|r|jr|d|j|r|j
r|jtks|j|j
kr|d|j
|d	d
|S)Nz<%s filename=%rz compress_type=%sr'iz filemode=%rz external_attr=%#xz
 file_size=%rz compress_size=%r>)	__class__rr>rcrr.compressor_namesgetrkstatfilemodeis_dirrornr/)r~r?hiloisdirrrr__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}|rd}
|t|
dt	|
d	||}|tks|tkr|st
d
d}d}t}	|jt
krtt|	}	n|jtkrtt|	}	t|	|j|_t|	|j|_|\}}ttt|j|j||j|||||t|t|
}
|
||S)z-Return the per-file header as a bytes object.rir"rrrrr$rrNz<HHQQz'Filesize would require ZIP64 extensionsl)rbrhrmrnror0ZIP64_LIMITrBpackcalcsizer

ZIP64_VERSIONrcrr]
BZIP2_VERSIONrLZMA_VERSIONrfrU_encodeFilenameFlagsstructFileHeaderstringFileHeaderrgr-)r~zip64dtdosdatedostimermrnror0min_versionfmtr>rhheaderrrr
FileHeadersF$$



zZipInfo.FileHeadercCs>y|jd|jfStk
r8|jd|jdBfSXdS)Nasciizutf-8i)r>encoderhUnicodeEncodeError)r~rrrrszZipInfo._encodeFilenameFlagscCs|j}tj}xxt|dkr|d|dd\}}|dt|krTtd||f|dkrt|dkrz|d|dd}nV|dkr|d	|dd
}n:|dkr|d|dd
}n|dkrd}ntd||fd}|jdkrt||krtd|||_|d7}|jdkr:t||kr(td|||_|d7}|jdkrtt||kr\td|j}|||_|d7}||dd}qWdS)Nrz<HHz"Corrupt extra field %04x (size=%d)rz<QQQr'z<QQrrz<Qrrr)llz/Corrupt zip64 extra field. File size not found.lz3Corrupt zip64 extra field. Compress size not found.z3Corrupt zip64 extra field. Header offset not found.)r0rBr,r-rrornrl)r~r0r,tpZlnZcountsidxoldrrr_decodeExtrasJ



zZipInfo._decodeExtracCst|tjrt|}t|}t|j}t|j	}|dd}|dkrP|}tj
tj
|d}x$|dtj
tjfkr|dd}qjW|r|d7}|||}|jd@d>|_|rd|_|jdO_n|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 Nrrtir')
isinstancerwPathLikefspathrS_ISDIRst_modetime	localtimest_mtimepathnormpath
splitdriverxaltseprkrost_size)clsr>arcnamestrmtimerbzinforrr	from_files(



zZipInfo.from_filecCs|jddkS)z2Return True if this archive member is a directory.rt)r>)r~rrrr.szZipInfo.is_dir)rrrs)N)N)
rrrr	__slots__rrrrrclassmethodrrrrrrr
Is
,
.2!cCs4x.tdD]"}|d@r$|d?dA}q
|dL}q
W|S)Nrrl q[)range)crcr4rrr_gen_crc8s
rcspdddtdkr&ttttdatfddfddx|D]}|qNWfd	d
}|S)NixV4igE#ixV4cs|d?||Ad@AS)z(Compute the CRC32 primitive on one byte.rr)Zchr)crctablerrcrc32Rsz_ZipDecrypter.<locals>.crc32cs<|d@d@ddd@d?dS)Nrlirrr)c)rkey0key1key2rrupdate_keysVs
z"_ZipDecrypter.<locals>.update_keyscsRt}|j}x<|D]4}dB}|||dAd?d@N}|||qWt|S)zDecrypt a bytes object.rrrr)	bytearrayr.bytes)rTr?r.rk)rrrr	decrypter`s
z _ZipDecrypter.<locals>.decrypter)	_crctabler\maprr)pwdprr)rrrrrrr
_ZipDecrypterHs
rc@s,eZdZddZddZddZddZd	S)
LZMACompressorcCs
d|_dS)N)_comp)r~rrrrpszLZMACompressor.__init__cCsFtdtji}tjtjttj|gd|_tdddt	||S)Nid)filtersz<BBHr"r)
lzmaZ_encode_filter_propertiesFILTER_LZMA1r
FORMAT_RAW_decode_filter_propertiesrrBrr-)r~Zpropsrrr_initsszLZMACompressor._initcCs*|jdkr||j|S|j|S)N)rrcompress)r~rTrrrrzs
zLZMACompressor.compresscCs&|jdkr||jS|jS)N)rrflush)r~rrrrs
zLZMACompressor.flushN)rrrrrrrrrrrrnsrc@seZdZddZddZdS)LZMADecompressorcCsd|_d|_d|_dS)Nr*F)_decomp_unconsumedeof)r~rrrrszLZMADecompressor.__init__c	Cs|jdkr|j|7_t|jdkr*dStd|jdd\}t|jd|krXdStjtjttj	|jdd|gd|_|jd|d}|`|j
|}|jj|_|S)Nrr*z<Hr)r)rrr-rBr,rrrrr
decompressr)r~rTZpsizer?rrrrs

zLZMADecompressor.decompressN)rrrrrrrrrrsrZstoreZshrinkreduceZimplodetokenizeZdeflateZ	deflate64Zbzip2rZterseZlz77ZwavpackZppmd)rrrrrrr r!rr"r#rrr)abcCsX|tkr
nJ|tkr tsTtdn4|tkr6tsTtdn|tkrLtsTtdntddS)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)	rrzlibRuntimeErrorrbz2rrNotImplementedError)compressionrrr_check_compressionsrcCsj|tkr2|dk	r t|tjdSttjtjdS|tkrT|dk	rLt|StS|tkrbt	SdSdS)Ni)
rrZcompressobjZDEFLATEDZZ_DEFAULT_COMPRESSIONrrZ
BZ2Compressorrr)rc
compresslevelrrr_get_compressors
rcCsn|tkrdS|tkrtdS|tkr.tS|tkr<tSt	
|}|r\td||fntd|fdS)Nizcompression type %d (%s)zcompression type %d)rrrZ
decompressobjrrZBZ2Decompressorrrrrr)rcZdescrrrr_get_decompressors

rc@s0eZdZddZdddZd
ddZd	d
ZdS)_SharedFilecCs2||_||_||_||_||_|j|_|j|_dS)N)_file_pos_close_lock_writingseekablerX)r~fileposcloselockZwritingrrrrsz_SharedFile.__init__rc	CsB|j2|rtd|j|||j|_|jSQRXdS)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.)rrrzrrArXr)r~rRwhencerrrrAsz_SharedFile.seekrc	CsL|j<|rtd|j|j|j|}|j|_|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.)rrrzrrArr:rX)r~nrTrrrr:sz_SharedFile.readcCs$|jdk	r |j}d|_||dS)N)rr)r~fileobjrrrrs
z_SharedFile.closeN)r)r)rrrrrAr:rrrrrrs	


rc@s4eZdZddZddZddZddZd	d
ZdS)	_TellablecCs||_d|_dS)Nr)r8rR)r~r8rrrrsz_Tellable.__init__cCs|j|}|j|7_|S)N)r8writerR)r~rTrrrrrsz_Tellable.writecCs|jS)N)rR)r~rrrrXsz_Tellable.tellcCs|jdS)N)r8r)r~rrrrsz_Tellable.flushcCs|jdS)N)r8r)r~rrrrsz_Tellable.closeN)rrrrrrXrrrrrrrs
rcseZdZdZdZdZdZd(ddZd	d
ZddZ	d)ddZ
d*ddZddZd+ddZ
ddZddZddZddZfdd Zd!d"Zd,d$d%Zd&d'ZZS)-
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|drz|j|_td|_nd|_d|_y4|r||_|j|_|j|_|j|_d|_Wntk
rYnXd|_|r$|j d@r|j!d?d@}n|jd?d@}|"}||kr$t#d	|j$dS)
NFr*rrmTrrrzBad password for file %r)%_fileobj_pwd_close_fileobjrc_compress_typern_compress_leftro_leftr
_decompressor_eof_readbuffer_offsetnewlinesmoder>namer<rm
_expected_crcr_running_crc	_seekablerrX_orig_compress_start_orig_compress_size_orig_file_size_orig_start_crcAttributeError
_decrypterrhrp_init_decrypterrra)r~rrzipinforZ
close_fileobjZ
check_bytehrrrr1sF




zZipExtFile.__init__cCs4t|j|_|jd}|jd8_||dS)Nrr$)rrrrr:r)r~rrrrrdszZipExtFile._init_decryptercCsvd|jj|jjfg}|jsX|d|j|jf|jtkrb|dt	
|j|jn
|d|dd|S)Nz<%s.%sz name=%r mode=%rz compress_type=%sz	 [closed]rr)rrrclosedr.rrrrrrr/)r~r?rrrros


zZipExtFile.__repr__rcCsL|dkr>|jd|jd}|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)rrur	ioBufferedIOBasereadline)r~limitr3linerrrr}szZipExtFile.readlinercCsr|t|j|jkr\||}t||jkrJ||j|jd|_d|_n|jt|8_|j|j|jdS)z6Returns buffered bytes without advancing the position.Nri)r-rr	r:)r~rchunkrrrpeeks
zZipExtFile.peekcCsdS)NTr)r~rrrreadableszZipExtFile.readablecCs|dks|dkrL|j|jd}d|_d|_x|jsF|||j7}q.W|S||j}|t|jkr~|j|j|}||_|S|t|j}|j|jd}d|_d|_x^|dkr|js||}|t|kr||_||_||d|7}P||7}|t|8}qW|S)zRead and return up to n bytes.
        If the argument is omitted, None, or negative, data is read and returned until EOF is reached.
        Nrr*)rr	r_read1MAX_Nr-)r~rbufendrTrrrr:s4

zZipExtFile.readcCs@|jdkrdSt||j|_|jr<|j|jkr<td|jdS)NzBad CRC-32 for file %r)r
rrrrr)r~newdatarrr_update_crcs

zZipExtFile._update_crccCs|dks|dkrV|j|jd}d|_d|_x$|jsP||j}|r.||7}Pq.W|S||j}|t|jkr|j|j|}||_|S|t|j}|j|jd}d|_d|_|dkrxN|js
||}|t|kr||_||_||d|7}P|r||7}PqW|S)z7Read up to n bytes with at most one read() system call.Nrr*)rr	rr#r$r-)r~rr%rTr&rrrread1s>



zZipExtFile.read1cCs"|js|dkrdS|jtkrH|jj}|t|krR|||t|7}n
||}|jtkrj|jdk|_nx|jtkrt	||j
}|j||}|jjp|jdko|jj|_|jr||j
7}n |j|}|jjp|jdk|_|d|j}|jt|8_|jdkrd|_|||S)Nrr*T)rrrrZunconsumed_tailr-_read2rrr]
MIN_READ_SIZErrrrr()r~rrTrrrr#s2





zZipExtFile._read1cCsd|jdkrdSt||j}t||j}|j|}|jt|8_|sLt|jdk	r`||}|S)Nrr*)	rr]r+minrr:r-EOFErrorr)r~rrTrrrr*s


zZipExtFile._read2cs&z|jr|jWdtXdS)N)rrrsuper)r~)rrrr!szZipExtFile.closecCs|jS)N)r)r~rrrr(szZipExtFile.seekablercCsB|jstd|}|dkr&|}n.|dkr8||}n|dkrL|j|}ntd||jkrd|j}|dkrpd}||}||j}|dkr|t|jkr||_d}nf|dkr
|j	
|j|j|_
|j|_|j|_d|_d|_t|j|_d|_|}|jdk	r
|x.|dkr8t|j|}||||8}qW|S)Nz!underlying stream is not seekablerrrzCwhence must be os.SEEK_SET (0), os.SEEK_CUR (1), or os.SEEK_END (2)r*F)rrUnsupportedOperationrXrrzr	r-rrrArrrrrrrrrrrrr,
MAX_SEEK_READr:)r~rRrZcurr_posZnew_posZread_offsetZbuff_offsetZread_lenrrrrA+sH





zZipExtFile.seekcCs0|jstd|j|jt|j|j}|S)Nz!underlying stream is not seekable)rrr/rrr-rr	)r~ZfileposrrrrX[s
zZipExtFile.tell)NF)r)r)r)r)rrrrr$r+r0rrrrr!r"r:r(r)r#r*rrrArX
__classcell__rr)rrr#s(
2



!
%$
0rcs@eZdZddZeddZddZddZfd	d
ZZ	S)
_ZipWriteFilecCs8||_||_||_t|j|j|_d|_d|_d|_	dS)Nr)
_zinfo_zip64_zipfilerrcrd_compressor
_file_size_compress_size_crc)r~zfrrrrrrcs
z_ZipWriteFile.__init__cCs|jjS)N)r5r8)r~rrrrmsz_ZipWriteFile._fileobjcCsdS)NTr)r~rrrwritableqsz_ZipWriteFile.writablecCsf|jrtdt|}|j|7_t||j|_|jrV|j|}|jt|7_|j	
||S)NzI/O operation on closed file.)rrzr-r7rr9r6rr8rr)r~rTnbytesrrrrtsz_ZipWriteFile.writec	sb|jr
dSzFt|jrR|j}|jt|7_|j||j|j	_
n
|j|j	_
|j|j	_
|j|j	_|j	jd@r|jrdnd}|jt|t|j	j
|j	j
|j	j|j|j_nn|js|jtkrtd|jtkrtd|j|j_|j|j	j|j|j	|j|j|jj|jj|j	|j	|jj|j	j<Wdd|j_ XdS)Nrz<LLQQz<LLLLz+File size unexpectedly exceeded ZIP64 limitz1Compressed size unexpectedly exceeded ZIP64 limitF)!rr.rr6rr8r-rrr3rnr7r9rmrorhr4rBr
_DD_SIGNATURErXr5	start_dirrrrArlrfilelistr.
NameToInfor>r)r~r%r)rrrrs>






z_ZipWriteFile.close)
rrrrpropertyrr;rrr1rr)rrr2bs

r2c@seZdZdZdZdZdeddfddZddZd	d
Z	ddZ
d
dZddZddZ
d<ddZddZddZddZeddZejddZd=ddZd>d d!d"d#Zd?d$d%Zd@d&d'ZdAd(d)Zed*d+Zd,d-Zd.d/ZdBd0d1ZdCd2d3Zd4d5Z d6d7Z!d8d9Z"d:d;Z#dS)Drai 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.

    NrTc		CsL|dkrtdt|||_d|_d|_i|_g|_||_||_||_	d|_
d|_t|t
jrjt
|}t|trd|_||_ddd	d
dddd
}||}x^yt|||_Wn(tk
r||kr||}wYnXPqWnd|_||_t|dd|_d|_t|_d|_d|_y|dkr0|n|dkrd|_y|j|_ Wn2t!tfk
rt"|j|_d|_ d|_Yn6Xy|j#|j Wn t!tfk
rd|_YnXnf|dkry||j#|j Wn6t$k
r|j#ddd|_|j|_ YnXntdWn$|j}d|_|%|YnXdS)z]Open the ZIP file with mode read 'r', write 'w', exclusive create 'x',
        or append 'a'.)rBwxaz+ZipFile requires mode 'r', 'w', 'x', or 'a'FrNr*r;zw+bzx+bzr+bwbZxb)rBrCrDrEzr+bzw+bzx+brrTrB)rCrDrErz"Mode must be 'r', 'w', 'x', or 'a')&rzr_allowZip64
_didModifydebugr@r?rrrr_commentrrwrrstr_filePassedr>rr=r8r7getattr_fileRefCnt	threadingRLockrrr_RealGetContentsrXr>rrrAr_fpclose)	r~rrr
allowZip64rZmodeDictrr8rrrrs







zZipFile.__init__cCs|S)Nr)r~rrr	__enter__#szZipFile.__enter__cCs|dS)N)r)r~typevalue	tracebackrrr__exit__&szZipFile.__exit__cCsd|jj|jjfg}|jdk	rd|jr8|d|jn|jdk	rR|d|j|d|jn
|d|dd|S)Nz<%s.%sz file=%rz filename=%rz mode=%rz	 [closed]rr)	rrrr8rLr.r>rr/)r~r?rrrr)s



zZipFile.__repr__cCs|j}yt|}Wntk
r.tdYnX|s<td|jdkrNt||t}|t}|t|_	|t
||}|jdkr||}td||||||_||jd|
|}t|}d}x||kr|
t}	t|	tkrtdtt|	}	|	ttkrtd|jdkr*t|	|
|	t}
|	d}|d	@rV|
d
}
n
|
d}
t|
}|
|	t|_|
|	t|_|	t|_|	dd\|_ |_!|_"|_#|_$|_%}
}|_&|_'|_(|j"t)krt*d
|j"d|	dd\|_+|_,|_-|
|_.|d?d|d?d@|d@|
d?|
d?d@|
d@df|_/|0|j||_|j12|||j3|j4<|t|	t|	t|	t}|jdkrtd|qW|j}x*t5|j1ddddD]}||_6|j}qWdS)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 directoryrizutf-8cp437rzzip file version %.1fr#r&r)r"ir$rtotalcSs|jS)N)rl)rrrr<lambda>r*z*ZipFile._RealGetContents.<locals>.<lambda>T)keyreverseN)7r8r6r7rrIprintrNrO_ECD_COMMENTrJrPr>rAr:rBytesIOsizeCentralDirr-rBr,structCentralDir
_CD_SIGNATUREstringCentralDir_CD_FILENAME_LENGTHdecoder
_CD_EXTRA_FIELD_LENGTHr0_CD_COMMENT_LENGTHr`_CD_LOCAL_HEADER_OFFSETrlrUrerfrgrhrcrmrnroMAX_EXTRACT_VERSIONrrirjrkrprbrr?r.r@r>sortedrq)r~r8rSZsize_cdZ	offset_cdconcatZinferredrTr[centdirr>flagsrDtdZ
end_offsetrrrrrQ7sx









4  
zZipFile._RealGetContentscCsdd|jDS)z+Return a list of file names in the archive.cSsg|]
}|jqSr)r>).0rTrrr
<listcomp>sz$ZipFile.namelist.<locals>.<listcomp>)r?)r~rrrnamelistszZipFile.namelistcCs|jS)zJReturn a list of class ZipInfo instances for files in the
        archive.)r?)r~rrrinfolistszZipFile.infolistcCsPtdd|dx:|jD]0}d|jdd}td|j||jf|dqWdS)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_r?rbr>ro)r~rrZdaterrrprintdirszZipFile.printdirc
Cs^d}xT|jD]J}y.||jd}x||r0q$WWdQRXWqtk
rT|jSXqWdS)z%Read all the files and check the CRC.irBN)r?r=r>r:r)r~Z
chunk_sizerfrrrtestzipszZipFile.testzipcCs$|j|}|dkr td||S)z,Return the instance of ZipInfo given 'name'.Nz(There is no item named %r in the archive)r@rKeyError)r~rinforrrgetinfos

zZipFile.getinfocCs6|r t|ts tdt|j|r,||_nd|_dS)z)Set default password for encrypted files.zpwd: expected bytes, got %sN)rr	TypeErrorrUrr)r~rrrrsetpasswords
zZipFile.setpasswordcCs|jS)z.The comment text associated with the ZIP file.)rJ)r~rrrr`szZipFile.commentcCs^t|tstdt|jt|tkrNddl}|jdtdd|dt}||_	d|_
dS)Nzcomment: expected bytes, got %srz3Archive comment is too long; truncating to %d bytesr)
stacklevelT)rrr|rUrr-ZIP_MAX_COMMENTwarningswarnrJrH)r~r`rrrrr`s
c	Cs"||d|
}|SQRXdS)zReturn file bytes for name.rBN)r=r:)r~rrr8rrrr:szZipFile.readF)force_zip64csF|dkrtd|r0t|ts0tdt|j|rD|dkrDtdjsRtdt|trb|}n,|dkrt|}j|_	j
|_n
|}|dkrj
||dSjrtdjd	7_tj|jjjfd
d}yH|t}t|tkrtdtt|}|ttkr&td
||t}|trL||t|jd@r`t d|jd@rtt d|jd@r|!d}	n
|!d}	|	|j"krtd|j"|f|j#dk	r|$|j%|j#krtd|j"d|jd	@}
|
r|sj&}|st'd|nd}t(||||dS|)YnXdS)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.
        >rBrCzopen() requires mode "r" or "w"zpwd: expected bytes, got %srCz'pwd is only supported for reading filesz2Attempt to use ZIP archive that was already closed)rzyCan't read from the ZIP file while there is an open writing handle on it. Close the writing handle before trying to read.rcsjS)N)rr)r~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)izutf-8rYz/File name in directory %r and header %r differ.NzOverlapped entries: z (possible zip bomb)z6File %r is encrypted, password required for extractionT)*rzrrr|rUrr8r
rrcrrdr{_open_to_writerrNrrlrRrr:sizeFileHeaderr-rrBr,r
_FH_SIGNATUREr_FH_FILENAME_LENGTH_FH_EXTRA_FIELD_LENGTHrhrrgrarqrXrnrrrr)r~rrrrrZzef_fileZfheaderfnameZ	fname_strZis_encryptedr)r~rr=sv








zZipFile.opencCs|r|jstd|jr tdt|ds0d|_d|_d|_d|_|jt	krZ|jdO_|j
sn|jdO_|jszd|_|jo|p|jdtk}|j
r|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.rorrrig?T)rGrzrr<rornrmrhrcrrrkrr8rAr>rXrl_writecheckrHrrr2)r~rrrrrrr6s4



zZipFile._open_to_writecCs*|dkrt}n
t|}||||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)rwgetcwdr_extract_member)r~memberrrrrrextractas

zZipFile.extractcCsL|dkr|}|dkr"t}n
t|}x|D]}||||q2WdS)zExtract 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)rtrwrrr)r~rmembersrrrrr
extractallns


zZipFile.extractallcCs^|j}|s(d}t|dt|}||_||}dd||D}|dd|D}|S)z;Replace bad characters and remove trailing dots from parts.z:<>|"?*_css|]}|dVqdS).N)rstrip)rrrDrrr	<genexpr>sz1ZipFile._sanitize_windows_name.<locals>.<genexpr>css|]}|r|VqdS)Nr)rrrDrrrrs)!_windows_illegal_name_trans_tablerK	maketransr-	translatesplitr/)rrpathseptableZillegalrrr_sanitize_windows_names
zZipFile._sanitize_windows_namec
sLt|ts||}|jdtjj}tjjrB|tjjtjj}tj	|d}dtjj
tjjftjjfdd|
tjjD}tjjdkr||tjj}tj||}tj|}tj|}|rtj|st||rtj|st||S|j||d(}t|d}t||Wd	QRXWd	QRX|S)
zbExtract the ZipInfo object 'member' to a physical
           file on the path targetpath.
        rtrrc3s|]}|kr|VqdS)Nr)rrrD)invalid_path_partsrrrsz*ZipFile._extract_member.<locals>.<genexpr>\)rrFN)rr
r{r>ryrwrrxrrcurdirpardirr/rrrdirnameexistsmakedirsrrmkdirr=shutilcopyfileobj)r~rZ
targetpathrrZ	upperdirssourcetargetr)rrrs.

&


 zZipFile._extract_membercCs|j|jkr(ddl}|jd|jdd|jdkr:td|jsHtdt|j|j	sd}t
|jtkrpd	}n|j
tkrd
}n|jtkrd}|rt|ddS)
z6Check for errors before writing a file to the archive.rNzDuplicate name: %rr)r~)rCrDrEz&write() requires mode 'w', 'x', or 'a'z4Attempt to write ZIP archive that was already closedzFiles countZFilesizezZipfile sizez would require ZIP64 extensions)r>r@rrrrzr8rrcrGr-r?ZIP_FILECOUNT_LIMITrorrlr
)r~rrrequires_zip64rrrrs(



zZipFile._writecheckc
CsJ|jstd|jrtdt||}|r>d|_d|_n0|dk	rN||_n|j	|_|dk	rf||_
n|j|_
|r
|j|j
r|j|j|j|_|jtkr|jdO_||d|_|j|||j|j<|j|d|j|_WdQRXn<t|d,}||d	}t||d
WdQRXWdQRXdS)zLPut the bytes from filename into the archive under the name
        arcname.z7Attempt to write to ZIP archive that was already closedz>Can't write to ZIP archive while an open writing handle existsrNrTFr;rCi )r8rzrr
rrrnrmrcrrdrrrrAr>rXrlrrhrrHr?r.r@r>rrr=rr)r~r>rrcrrsrcdestrrrrs>


z
ZipFile.writec
Cst|tr|d}t|tsxt|ttddd}|j|_|j|_	|j
ddkrpd|_|jdO_q|d	|_n|}|jst
d
|jrt
d|dk	r||_|dk	r||_	t||_|j*|j|dd
}||WdQRXWdQRXdS)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-8Nr )r>rbrrtiAr'iz7Attempt to write to ZIP archive that was already closedz?Can't write to ZIP archive while an open writing handle exists.rC)r)rrKrr
rrrrcrrdr>rkr8rzrr-rorr=r)r~Zzinfo_or_arcnamerTrcrrrrrrwritestrs4



zZipFile.writestrcCs|dS)z2Call the "close()" method in case the user forgot.N)r)r~rrr__del__(szZipFile.__del__c	Cs||jdkrdS|jrtdzB|jdkr\|jr\|j"|jrJ|j|j|	WdQRXWd|j}d|_|
|XdS)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.)rCrDrE)r8rrzrrHrrrAr>_write_end_recordrR)r~r8rrrr,s
z
ZipFile.closecCsvxP|jD]D}|j}|ddd>|dd>B|dB}|dd>|d	d>B|ddB}g}|jtksv|jtkr||j||jd
}d
}n|j}|j}|jtkr||jd
}n|j}|j}	d}
|rt|	d}	t	j
dd
t|ddt|f||	}	t}
|j
tkr(tt|
}
n|j
tkr>tt|
}
t|
|j}t|
|j}yZ|\}
}t	
tt||j||j||j
|||j||t|
t|	t|jd|j|j|}Wnltk
rttt||j||j|j |j
|||j||t|j!t|	t|jd|j|j|ft"j#dYnX|j$%||j$%|
|j$%|	|j$%|jq
W|j$&}t|j}||j'}|j'}d}|t(krd}n|tkrd}n|tkrd}|r.|j)st*|dt	
t+t,t-ddddd||||}|j$%|t	
t.t/d|d}|j$%|t0|d}t0|d
}t0|d
}t	
t1t2dd||||t|j3	}|j$%||j$%|j3|j$4dS)Nrir"rrrrr$rl)rz<HHQr)rzFiles countzCentral directory offsetzCentral directory sizez would require ZIP64 extensionsrri)5r?rbrorrnr.rlr0r5rBrr-rrcrr]rrrrfrUrrcrerergrmr`rjrkDeprecationWarningr_rhr>r{stderrr8rrXr>rrGr
rHrGrErCrDr,r[rZrJr)r~rrrrr0rornrlZ
extra_datarrfrUr>rhrnZpos2ZcentDirCountZcentDirSizeZ
centDirOffsetrZzip64endrecZzip64locrecrSrrrrBs$$



















zZipFile._write_end_recordcCs4|jdkst|jd8_|js0|js0|dS)Nrr)rNAssertionErrorrLr)r~r8rrrrRszZipFile._fpclose)N)N)rBN)F)NN)NNN)NNN)NN)$rrrrr8rrrrTrXrrQrtrurvrxr{r}rAr`setterr:r=rrrrrrrrrrrrrRrrrrrs@XQ
	
		
f
+

*
0
(fc@s4eZdZdZdeddfddZd
d	d
ZddZdS)rzDClass to create ZIP archives with Python library files and packages.rBTrcCstj|||||d||_dS)N)rrrS)rr	_optimize)r~rrrrSoptimizerrrrszPyZipFile.__init__rNcCst|}|rD||sD|jr@tj|r,dnd}td||fdStj|\}}tj|rptj|d}tj|r|rd||f}n|}|jrtd|d||	|d	d
|\}}	|jrtd|	|
||	tt|}
|

dx|
D]}tj||}tj|\}
}tj|rTtjtj|dr|j|||dq|d
kr|r||s|jrtd|q|	|d	d
|\}}	|jrtd|	|
||	qWn|jrtd|xtt|D]}tj||}tj|\}
}|d
kr|r2||s2|jrtd|q|	|d	d
|\}}	|jr\td|	|
||	qWnP|d
dd
krtd|	|d	d
|\}}	|jrtd|	|
||	dS)aAdd 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.
        rrz%s %r skipped by filterfuncNz__init__.pyz%s/%szAdding package inasrZAdding)
filterfuncz.pyzfile %r skipped by filterfunczAdding files from directoryz.Files added with writepy() must end with ".py"zAdding file)rwrrIrrr_rr/isfile
_get_codenamerrllistdirremovesplitextwritepyr)r~pathnamebasenamerZlabeldirrZinitnamerrZdirlistr>rrootZextrrrrsx











zPyZipFile.writepyc
sdfdd	}|d}|d}tjj|dd}tjj|dd}tjj|d	d}jdkr\tj|rt|jt|jkr|}	}
ntj|rt|jt|jkr|}
|}	ntj|rt|jt|jkr|}
|}	nvtj|rt|jt|jkr|}
|}	nD||rRt	j
jd
kr4|}
nt	j
jdkrH|}
n|}
|}	n|}
}	njd
krr|}
|}	n<|}	jdkr|}
n&jd	kr|}
ndj}t
|tj|
rt|
jt|jks||jds|}
}	tj|	d}|rd
||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).
        rc
s`ddl}jrtd|y|j|d|dWn.|jk
rZ}zt|jdSd}~XYnXdS)NrZ	CompilingT)doraiserF)
py_compilerIr_compilePyCompileErrormsg)rrrerr)r~rr_compiles

z)PyZipFile._get_codename.<locals>._compilez.pyz.pycr)optimizationrrrz"invalid value for 'optimize': {!r})rz%s/%s)r)	importlibutilcache_from_sourcerrwrrrrr{rorformatrzr)
r~rrrZfile_pyZfile_pycZpycache_opt0Zpycache_opt1Zpycache_opt2rrrZarchivenamer)r~rr
s`


zPyZipFile._get_codename)rN)rrrrrrrrrrrrrs

Rc
	sddl}d}|j|d}|jdd}|jdddd	d
|jddd
ddd|jdddddd|jddddd
||}|jdk	r|j}t|d}|}WdQRX|rtd	|tdn|j
dk	r|j
}t|d}|WdQRXn|jdk	r.|j\}}t|d}|
|WdQRXn|jdk	r|jd}	|j}
fddt|	d`}xX|
D]P}tj|}|stjtj|}|dtjtjfkrd}|||qjWWdQRXdS) Nrz3A simple command-line interface for zipfile module.)descriptionT)Zrequiredz-lz--listz	<zipfile>zShow listing of a zipfile)metavarhelpz-ez	--extractr)z	<zipfile>z<output_dir>zExtract zipfile into target dir)nargsrrz-cz--create+)z<name>z<file>zCreate zipfile from sourcesz-tz--testzTest if a zipfile is validrBz.The following enclosed file is corrupted: {!r}zDone testingcsttj|r|||tnTtj|rp|r8|||x6tt|D]$}|tj||tj||qHWdS)N)	rwrrrrrrlrr/)r:rzippathZnm)addToZiprrrszmain.<locals>.addToZiprCr)argparseArgumentParserZadd_mutually_exclusive_groupadd_argument
parse_argsZtestrrxr_rr\rvrrZcreatepoprwrrrrr)
argsrrparsergrouprr:ZbadfilerZzip_namefilesrrr)rrmain]sT








r__main__)N)N)rrrwimportlib.utilrr{rrrrBZbinasciirOrrImportErrorrr__all__	Exceptionrr
rrrrrrrrrr}rrrrkr[rZrrYrIrJrKrLrMrNrOr_r`rPrcrerbrdZ_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_SIZErfrhriZ_CD_DISK_NUMBER_STARTZ_CD_INTERNAL_FILE_ATTRIBUTESZ_CD_EXTERNAL_FILE_ATTRIBUTESrjrrrrZ_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_SIZErrrCrDr@rHrGrEZ_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+r5r9r	rVr6objectr
rrrrrrrrrrrrrr2rrrrrrrr<module>s@









<<o&
&AN/
<