eaiovnaovbqoebvqoeavibavo B  f<@sdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z yddl Z e j Z Wnek rdZ e j Z YnXy ddlZWnek rdZYnXy ddlZWnek rdZYnXddddddd d d d 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;dZd'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;Zldd d enZodapd?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        r6c@sVeZdZdZdZdddZddZdd d Zd d ZddZ e dddZ ddZ d S)r z>Class with attributes describing each file in the ZIP archive.) orig_filenamer> date_time compress_type_compresslevelr^r0 create_systemrSextract_versionreserved flag_bitsvolume internal_attr external_attr header_offsetCRC compress_size file_size _raw_timeNoNameirrrrrcCs||_|td}|dkr(|d|}tjdkrJtj|krJ|tjd}||_||_|ddkrjtdt |_ d|_ d|_ d|_ tjdkrd|_nd|_t|_t|_d|_d|_d|_d|_d|_dS)Nr/iz+ZIP does not support timestamps before 1980r*Zwin32r)r_findchrossepreplacer>r` ValueErrorrrarbr^r0sysplatformrcDEFAULT_VERSIONrSrdrerfrgrhri)selfr>r`Z null_byterrr__init__Ss0   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>rarr.compressor_namesgetristatfilemodeis_dirrmrlr/)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} |d kr|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$rrNzrfheaderrrr FileHeadersF$$        zZipInfo.FileHeadercCs>y|jd|jfStk r8|jd|jdBfSXdS)Nasciizutf-8i)r>encoderfUnicodeEncodeError)r{rrrrszZipInfo._encodeFilenameFlagscCs|j}tj}xxt|dkr|d|dd\}}|dt|krTtd||f|dkrt|dkrz|d|dd}nV|dkr|d |dd }n:|d kr|d |dd }n|dkrd}ntd||fd}|jdkrt||krtd|||_|d7}|jdkr:t||kr(td|||_|d7}|jdkrtt||kr\td|j}|||_|d7}||dd}qWdS)Nrz|_|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 Nrrqir') isinstancertPathLikefspathrS_ISDIRst_modetime localtimest_mtimepathnormpath splitdriverualtseprirmst_size)clsr>arcnamestrmtimer`zinforrr from_files(       zZipInfo.from_filecCs|jddkS)z2Return True if this archive member is a directory.rq)r>)r{rrrrszZipInfo.is_dir)rorp)N)N) rrrr __slots__r|rrrr classmethodrrrrrrr 9s + .2 !cCs4x.tdD]"}|d@r$|d?dA}q |dL}q W|S)Nrrl q[)range)crcr4rrr_gen_crc&s  rcspdddtdkr&ttttdatfddfddx|D] }|qNWfd d }|S) NixV4igE#ixV4cs|d?||Ad@AS)z(Compute the CRC32 primitive on one byte.rr)Zchr)crctablerrcrc32@sz_ZipDecrypter..crc32cs<|d@d@ddd@d?dS)Nrlirrr)c)rkey0key1key2rr update_keysDs z"_ZipDecrypter..update_keyscsRt}|j}x<|D]4}dB}|||dAd?d@N}|||qWt|S)zDecrypt a bytes object.rrrr) bytearrayr.bytes)rRr?r.rk)rrrr decrypterNs  z _ZipDecrypter..decrypter) _crctablerZmaprr)pwdprr)rrrrrrr _ZipDecrypter6s    rc@s,eZdZddZddZddZddZd S) LZMACompressorcCs d|_dS)N)_comp)r{rrrr|^szLZMACompressor.__init__cCsFtdtji}tjtjttj|gd|_tdddt ||S)Nid)filtersznamer<rk _expected_crcr _running_crc _seekablerrV_orig_compress_start_orig_compress_size_orig_file_size_orig_start_crcAttributeError _decrypterrfrn_init_decrypterrr_)r{rrzipinforZ close_fileobjZ check_bytehrrrr|sF       zZipExtFile.__init__cCs4t|j|_|jd}|jd8_||dS)Nrr$)rrrrr:r)r{rrrrrRs  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]r}r~) rrrclosedr.r rrrrrr/)r{r?rrrr]s   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)rrrrioBufferedIOBasereadline)r{limitr3linerrrrkszZipExtFile.readlinercCsr|t|j|jkr\||}t||jkrJ||j|jd|_d|_n|jt|8_|j|j|jdS)z6Returns buffered bytes without advancing the position.Nri)r-rrr:)r{rchunkrrrpeek{s 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*)rrr_read1MAX_Nr-)r{rbufendrRrrrr:s4   zZipExtFile.readcCs@|jdkrdSt||j|_|jr<|j|jkr      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{rrRrrrr s2           zZipExtFile._read1cCsd|jdkrdSt||j}t||j}|j|}|jt|8_|sLt|jdk r`||}|S)Nrr*) rr[r(minrr:r-EOFErrorr)r{rrRrrrr's      zZipExtFile._read2cs&z|jr|jWdtXdS)N)rrrsuper)r{)rrrrszZipExtFile.closecCs|jS)N)r )r{rrrrszZipExtFile.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)r rUnsupportedOperationrVrrwrr-rrr@r rr rrrrrrrrrr) MAX_SEEK_READr:)r{rPrZcurr_posZnew_posZ read_offsetZ buff_offsetZread_lenrrrr@sH           zZipExtFile.seekcCs0|jstd|j|jt|j|j}|S)Nz!underlying stream is not seekable)r rr,rrr-rr)r{ZfileposrrrrVIs zZipExtFile.tell)NF)r)r)r)r)rrrrr!r(r-r|rrrrrr:r%r&r r'rrr@rV __classcell__rr)rrrs( 2    ! %$  0rcs@eZdZddZeddZddZddZfd d ZZ S) _ZipWriteFilecCs8||_||_||_t|j|j|_d|_d|_d|_ dS)Nr) _zinfo_zip64_zipfilerrarb _compressor _file_size_compress_size_crc)r{zfrrrrrr|Qs z_ZipWriteFile.__init__cCs|jjS)N)r2r8)r{rrrr[sz_ZipWriteFile._fileobjcCsdS)NTr)r{rrrwritable_sz_ZipWriteFile.writablecCsf|jrtdt|}|j|7_t||j|_|jrV|j|}|jt|7_|j ||S)NzI/O operation on closed file.) rrwr-r4rr6r3rr5rr)r{rRnbytesrrrrbs  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|j tkrtd|jtkrtd|j|j_|j|j j|j|j |j|j|jj|jj|j |j |jj|j j<Wdd|j_ XdS)Nrzr)r{r"r)rrrrns>          z_ZipWriteFile.close) rrrr|propertyrr8rrr.rr)rrr/Ps   r/c@seZdZdZdZdZdeddfddZddZd d Z d d Z d dZ ddZ ddZ dd d!d"d#Zd?d$d%Zd@d&d'ZdAd(d)Zed*d+Zd,d-Zd.d/ZdBd0d1ZdCd2d3Zd4d5Z d6d7Z!d8d9Z"d:d;Z#dS)Dr ai 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 dd d 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'.)r?wxaz+ZipFile requires mode 'r', 'w', 'x', or 'a'FrNr*r;zw+bzx+bzr+bwbZxb)r?r@rArBzr+bzw+bzx+brr Tr?)r@rArBrz"Mode must be 'r', 'w', 'x', or 'a')&rwr _allowZip64 _didModifydebugr=r<rrrr_commentrrtrrstr _filePassedr>rr=r8r7getattr _fileRefCnt threadingRLockrr r_RealGetContentsrVr;rrr@r_fpclose) r{rrr allowZip64rZmodeDictrr8rrrr|s             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]r}r~) rrrr8rIr.r>rr/)r{r?rrrrs    zZipFile.__repr__c Cs|j}y t|}Wntk r.tdYnX|s)r{r8rQZsize_cdZ offset_cdconcatZinferredrRrXcentdirr>flagsrAtdrrrrN%sp                4       zZipFile._RealGetContentscCsdd|jDS)z+Return a list of file names in the archive.cSsg|] }|jqSr)r>).0rRrrr usz$ZipFile.namelist..)r<)r{rrrnamelistsszZipFile.namelistcCs|jS)zJReturn a list of class ZipInfo instances for files in the archive.)r<)r{rrrinfolistwszZipFile.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)rYr<r`r>rm)r{rrZdaterrrprintdir|s  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.ir?N)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 TypeErrorrRrr)r{rrrr setpasswords zZipFile.setpasswordcCs|jS)z.The comment text associated with the ZIP file.)rG)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) rrrvrRrr-ZIP_MAX_COMMENTwarningswarnrGrE)r{r^rzrrrr^s    c Cs"||d| }|SQRXdS)zReturn file bytes for name.r?N)r=r:)r{r rr8rrrr:sz ZipFile.readF) force_zip64c s|dkrtd|r0t|ts0tdt|j|rD|dkrDtdjsRtdt|trb|}n,|dkrt|}j|_ j |_ n |}|dkrj ||dSjrtdjd 7_tj|jjjfd d }y|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|jd @} | r|sЈj#}|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. >r?r@zopen() requires mode "r" or "w"zpwd: expected bytes, got %sr@z'pwd is only supported for reading filesz2Attempt to use ZIP archive that was already closed)r|zyCan'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*zZipFile.open..zTruncated file headerz Bad magic number for file header z$compressed patched data (flag bit 5)@zstrong encryption (flag bit 6)izutf-8rVz/File name in directory %r and header %r differ.z6File %r is encrypted, password required for extractionNT)'rwrrrvrRrr8r rrarrbru_open_to_writerrKrrjrOrr:sizeFileHeaderr-rrBr,r _FH_SIGNATUREr_FH_FILENAME_LENGTH_FH_EXTRA_FIELD_LENGTHrfrrbr_rrrr) r{r rrr|rZzef_fileZfheaderfnameZ fname_strZ is_encryptedr)r{rr=sp                z ZipFile.opencCs|r|jstd|jr tdt|ds0d|_d|_d|_d|_|jt krZ|jdO_|j sn|jdO_|j szd|_ |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.rmrrrig?T)rDrwrr<rmrlrkrfrarr rirr8r@r;rVrj _writecheckrErrr/)r{rr|rrrrrs4     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)rtgetcwdr_extract_member)r{memberrrrrrextractHs  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)rnrtrrr)r{rmembersrrrrr extractallUs   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)rlrArrr psz1ZipFile._sanitize_windows_name..css|]}|r|VqdS)Nr)rlrArrrrrs)!_windows_illegal_name_trans_tablerH maketransr- translatesplitr/)rrpathseptableZillegalrrr_sanitize_windows_namefs zZipFile._sanitize_windows_namec sLt|ts||}|jdtjj}tjjrB|tjjtjj}tj |d}dtjj tjj ftjj 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. rqrr~c3s|]}|kr|VqdS)Nr)rlrA)invalid_path_partsrrrsz*ZipFile._extract_member..\)rrCN)rr rur>rvrtrrurrcurdirpardirr/rrrdirnameexistsmakedirsrrmkdirr=shutil copyfileobj)r{rZ targetpathrrZ upperdirssourcetargetr)rrrus.  &        zZipFile._extract_membercCs|j|jkr(ddl}|jd|jdd|jdkr:td|jsHtdt|j|j sd}t |j t krpd }n|j tkrd }n|jtkrd }|rt|d dS) z6Check for errors before writing a file to the archive.rNzDuplicate name: %rr)rx)r@rArBz&write() requires mode 'w', 'x', or 'a'z4Attempt to write ZIP archive that was already closedz Files countZFilesizez Zipfile sizez would require ZIP64 extensions)r>r=rzr{rrwr8rrarDr-r<ZIP_FILECOUNT_LIMITrmrrjr )r{rrzrequires_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|_WdQRXnCan't write to ZIP archive while an open writing handle existsrNrTFr;r@i )r8rwrr rrrlrkrarrbrrr r@r;rVrjrrfrrEr<r.r=r>rrr=rr)r{r>rrarrsrcdestrrrrs>       z ZipFile.writec Cst|tr|d}t|tsxt|ttddd}|j|_|j|_ |j ddkrpd|_ |j dO_ 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>r`rrqiAr'iz7Attempt to write to ZIP archive that was already closedz?Can't write to ZIP archive while an open writing handle exists.r@)r)rrHrr rrrrarrbr>rir8rwrr-rmrr=r)r{Zzinfo_or_arcnamerRrarrrrrrwritestrs4    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.)r@rArB) r8rrwrrErr r@r;_write_end_recordrO)r{r8rrrrs z ZipFile.closecCsrxP|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,ddddd|||| }|j$%|t t-t.d|d}|j$%|t/|d}t/|d }t/|d }t t0t1dd||||t |j2 }|j$%||j$%|j2|j$3dS)Nrir"rrrrr$rl)rzrxstderrr8rrVr;rrDr rFrGrCrDr)rYrXrGr)r{rrrrr0rmrlrjZ extra_datarrdrSr>rfrhZpos2Z centDirCountZ centDirSizeZ centDirOffsetrZ zip64endrecZ zip64locrecrQrrrr)s$$                                     zZipFile._write_end_recordcCs4|jdkst|jd8_|js0|js0|dS)Nrr)rKAssertionErrorrIr)r{r8rrrrOs zZipFile._fpclose)N)N)r?N)F)NN)NNN)NNN)NN)$rrrrr8rrr|rQrUrrNrnrorprrrurwr>r^setterr:r=rrrrrrrrrrrrrOrrrrr s@ XN     b +  * 0 (fc@s4eZdZdZdeddfddZd d d Zd d ZdS)r zDClass to create ZIP archives with Python library files and packages.r?TrcCstj|||||d||_dS)N)rrrP)r r| _optimize)r{rrrrPoptimizerrrr|s zPyZipFile.__init__r~NcCst|}|rD||sD|jr@tj|r,dnd}td||fdStj|\}}tj|rptj|d}tj|r|rd||f}n|}|jrtd|d|| |d d |\}} |jrtd | | || t t |} | dx| D]} tj|| } tj| \} }tj| rTtjtj| dr|j| ||d q|d kr|r|| s|jrtd| q| | d d |\}} |jrtd | | || qWn|jrtd|xt t |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"z Adding file)rtrrFrrrYrr/isfile _get_codenamersortedlistdirremovesplitextwritepyr)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 j d kr4|} nt j j dkrH|} 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_compilerFrYcompilePyCompileErrormsg)rrrerr)r{rr_compiles  z)PyZipFile._get_codename.._compilez.pyz.pycr~) optimizationrrrz"invalid value for 'optimize': {!r})rz%s/%s)r) importlibutilcache_from_sourcerrtrrrrrxrirformatrwr) r{rrrZfile_pyZfile_pycZ pycache_opt0Z pycache_opt1Z pycache_opt2rrrZ archivenamer)r{rrs`             zPyZipFile._get_codename)r~N)rrrrrr|rrrrrrr s  Rc sddl}d}|j|d}|jdd}|jdddd d |jd d 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 zShow listing of a zipfile)metavarhelpz-ez --extractr)z z zExtract zipfile into target dir)nargsrrz-cz--create+)zzzCreate zipfile from sourcesz-tz--testzTest if a zipfile is validr?z.The following enclosed file is corrupted: {!r}z Done testingcsttj|r|||tnTtj|rp|r8|||x6tt|D]$}|tj||tj||qHWdS)N) rtrrrrrrrr/)r7rzippathZnm)addToZiprrrls   zmain..addToZipr@r~)argparseArgumentParserZadd_mutually_exclusive_group add_argument parse_argsZtestr rrrYrrZrprrZcreatepoprtrrrrr) argsrrparsergrouprr7ZbadfilerZzip_namefilesrrr)rrmainDsT                    r__main__)N)N)rrrtimportlib.utilrrxrrrrBZbinasciirLrr ImportErrorrr__all__ Exceptionrr rrrrryrrrrrzrrrrfrYrXrrWrHrIrJrKrLrMrNr]rZr[r^r`r]r_Z_CD_CREATE_VERSIONZ_CD_CREATE_SYSTEMZ_CD_EXTRACT_VERSIONZ_CD_EXTRACT_SYSTEMZ _CD_FLAG_BITSZ_CD_COMPRESS_TYPEZ_CD_TIMEZ_CD_DATEZ_CD_CRCZ_CD_COMPRESSED_SIZEZ_CD_UNCOMPRESSED_SIZErarcrdZ_CD_DISK_NUMBER_STARTZ_CD_INTERNAL_FILE_ATTRIBUTESZ_CD_EXTERNAL_FILE_ATTRIBUTESrerrrrZ_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_SIZErrrCrDrArFrGrEZ_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 rTr6objectr rrrrrrrrrrrrrr/r r rrrrrrs>             +=m& &AN}/ <