3 f482@sdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z y ddl Z Wne k r|ddlZ YnXyddlZejZWne k rdZe jZYnXy ddlZWne k rdZYnXy ddlZWne k rdZYnXddddddd d d d d dg ZGdddeZGdddeZeZZdfZdhZdjZdZdZdZdZdZ 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'e3Z5dZ6dZ7dZ8dZ9dZ:d Z;d!Zd#Z?d&Z@d'ZAdZBd(ZCdZDd)ZEdZFd*ZGd+ZHd,ZId-ZJe j'eIZKdZLdZMdZNdZOdZPd ZQd!ZRd"ZSdZTd#ZUd&ZVd'ZWd.ZXd/ZYe j'eXZZd0Z[d1Z\e j'e[Z]dZ^dZ_dZ`dZadZbd Zcd!Zdd"ZedZfd#Zgd2Zhe jid3Zjd4d5Zkd6d7Zld8d Zmd9d:Znd;d<ZoGd=d d epZqGd>d?d?ZrGd@dAdAZsGdBdCdCZtdDdEdFdFdFdFdGdHdIdJdGdKdLdMdNdOdPdQZudRdSZvdTdUZwdVdWZxGdXdYdYZyGdZd[d[ZzGd\d]d]ej{Z|Gd^d_d_ej{Z}Gd`d d Z~Gdad d e~ZdkdbdcZeddkredS)lzP 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/usr/lib64/python3.6/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 /s -.?s<4s4H2LHsPK z<4s4B4HL2L5H2LsPK z <4s2B4HL2L2HsPKz<4sLQLsPKz <4sQ2H2L4QsPKiPKz        r7c@sVeZdZdZd)Zd+ddZddZd,dd Zd!d"Zd#d$Z e d-d%d&Z d'd(Z dS).r z>Class with attributes describing each file in the ZIP archive. orig_filenamer? date_time compress_typer_r1 create_systemrTextract_versionreserved flag_bitsvolume internal_attr external_attr header_offsetCRC compress_size file_size _raw_time _end_offsetNoNamerrcCs||_|jtd}|dkr(|d|}tjdkrJtj|krJ|jtjd}||_||_|ddkrjtdt |_ d|_ d|_ t jdkrd|_nd|_t|_t|_d|_d|_d|_d|_d|_d|_dS)Nr/iz+ZIP does not support timestamps before 1980r+Zwin32r)r`findchrossepreplacer?ra ValueErrorrrbr_r1sysplatformrcDEFAULT_VERSIONrTrdrerfrgrhriro)selfr?raZ null_byterrr__init__Xs0   zZipInfo.__init__cCsd|jj|jfg}|jtkr8|jdtj|j|j|jd?}|jd@}|rd|jdt j ||rv|jd||j }| s|j r|jd|j | s|j r|jtks|j |j kr|jd|j |jd d j|S) Nz<%s filename=%rz compress_type=%sriz filemode=%rz external_attr=%#xz file_size=%rz compress_size=%r>) __class__rr?rbrr/compressor_namesgetristatfilemodeis_dirrmrlr0)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 } |tj| dtj | d ||}|tks|tkr|st d d}d}t } |j t krtt| } n|j tkrtt| } t| |j|_t| |j|_|j\} } tjtt|j|j| |j |||||t| t| } | | |S)z-Return the per-file header as a bytes object.rir$rr!rrr&r rNzy|jjd|jfStk r8|jjd|jdBfSXdS)Nasciizutf-8i)r?encoderfUnicodeEncodeError)r|rrrrszZipInfo._encodeFilenameFlagscCs(|j}tj}xt|dkr"|d|dd\}}|dkr|dkrZ|d|dd}nV|dkrv|d|dd }n:|d kr|d |dd }n|d krf}ntd||fd }|jdkr|||_|d7}|jdkr|||_|d7}|jdkr|j}|||_|d7}||dd}qWdS)Nr z|_|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"Nrrrir) isinstanceruPathLikefspathrS_ISDIRst_modetime localtimest_mtimepathnormpath splitdrivervaltseprirmst_size)clsr?arcnamestrmtimerazinforrr from_files(       zZipInfo.from_filecCs|jddkS)z2Return True if this archive member is a directory.rrr)r?)r|rrrrszZipInfo.is_dir)r`r?rarbr_r1rcrTrdrerfrgrhrirjrkrlrmrnrorqrrrrr)rpr)N)N) rrrr __slots__r}rrrr classmethodrrrrrrr >s: + .$ !c@s<eZdZdZddZdZddZddZd d Zd d 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) cCshd}dgd}xTtdD]H}|}x6tdD]*}|d@rH|d?d@|A}q*|d?d@}q*W|||<qW|S)zGenerate 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[rrri)range)Zpolytabler4crcr5rrr_GenerateCRCTable%s  z_ZipDecrypter._GenerateCRCTableNcCs|d?d@|j||Ad@AS)z(Compute the CRC32 primitive on one byte.ri)crctable)r|Zchrrrr_crc329sz_ZipDecrypter._crc32cCsBtjdkrtjt_d|_d|_d|_x|D]}|j|q,WdS)NixV4igE#ixV4)rrrkey0key1key2 _UpdateKeys)r|pwdprrrr}=s   z_ZipDecrypter.__init__cCsX|j||j|_|j|jd@d@|_|jddd@|_|j|jd?d@|j|_dS)Nrlirr)rrrr)r|crrrrFsz_ZipDecrypter._UpdateKeyscCs>t|tst|jdB}|||dAd?d@A}|j||S)zDecrypt a single character.rrrr)rintAssertionErrorrr)r|rkrrr__call__Ls   z_ZipDecrypter.__call__) rrrrrrrr}rrrrrrrs  rc@s,eZdZddZddZddZddZd S) LZMACompressorcCs d|_dS)N)_comp)r|rrrr}WszLZMACompressor.__init__cCsFtjdtji}tjtjtjtj|gd|_tjdddt ||S)Nid)filtersz|jjd|jd}|dkr>|j|j|}||_|Stjj||S)zrRead and return a line from the stream. If limit is specified, at most limit bytes will be read. r r)r rsr ioBufferedIOBasereadline)r|limitr4linerrrrMszZipExtFile.readlinecCsr|t|j|jkr\|j|}t||jkrJ||j|jd|_d|_n|jt|8_|j|j|jdS)z6Returns buffered bytes without advancing the position.Nri)r.r r r;)r|rchunkrrrpeek]s zZipExtFile.peekcCsdS)NTr)r|rrrreadablejszZipExtFile.readablecCs |dks|dkrL|j|jd}d|_d|_x|jsF||j|j7}q.W|S||j}|t|jkr~|j|j|}||_|S|t|j}|j|jd}d|_d|_x^|dko|j r|j|}|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+)r r r_read1MAX_Nr.)r|rbufendrSrrrr;ms4   zZipExtFile.readcCs@|jdkrdSt||j|_|jr<|j|jkr      zZipExtFile.read1cCs"|js|dkrdS|jtkrH|jj}|t|krR||j|t|7}n |j|}|jtkrj|jdk|_nx|jtkrt ||j }|jj ||}|jj p|jdko|jj |_|jr||jj 7}n |jj |}|jj p|jdk|_|d|j}|jt|8_|jdkrd|_|j||S)Nrr+T)rrrrZunconsumed_tailr._read2rrr\ MIN_READ_SIZErrrrr')r|rrSrrrr"s2           zZipExtFile._read1cCsj|jdkrdSt||j}t||j}|jj|}|jt|8_|sLt|jdk rft t |j|}|S)Nrr+) rr\r*minrr;r.EOFErrorrbytesmap)r|rrSrrrr)s     zZipExtFile._read2c s&z|jr|jjWdtjXdS)N)rrrsuper)r|)rrrrszZipExtFile.closecCs|jS)N)r)r|rrrrszZipExtFile.seekablercCs,|jstjd|j}|dkr&|}n.|dkr8||}n|dkrL|j|}ntd||jkrd|j}|dkrpd}||}||j}|dkr|t|jkr||_d}nR|dkr|j j |j |j |_ |j|_|j|_d|_d|_tj|j|_d|_|}x,|dkr"t|j|}|j|||8}qW|jS)Nz!underlying stream is not seekablerrrzCwhence must be os.SEEK_SET (0), os.SEEK_CUR (1), or os.SEEK_END (2)r+F)rrUnsupportedOperationrWrrxr r.r rrArrrrrrZzipfilerrrrr+ MAX_SEEK_READr;)r|rQrZcurr_posZnew_posZ read_offsetZ buff_offsetZread_lenrrrrAsD         zZipExtFile.seekcCs0|jstjd|j|jt|j|j}|S)Nz!underlying stream is not seekable)rrr0rrr.r r )r|ZfileposrrrrW*s zZipExtFile.telli@i)NFr)r)rr)r)r)rrrrr#r*r1r}rrr r!r;r'r(r"r)rrrArW __classcell__rr)rrrs& *   ! %$  /rcs@eZdZddZeddZddZddZfd d ZZ S) _ZipWriteFilecCs4||_||_||_t|j|_d|_d|_d|_dS)Nr) _zinfo_zip64_zipfilerrb _compressor _file_size_compress_size_crc)r|zfrrrrrr}2s z_ZipWriteFile.__init__cCs|jjS)N)r7r9)r|rrrr;sz_ZipWriteFile._fileobjcCsdS)NTr)r|rrrwritable?sz_ZipWriteFile.writablecCsf|jrtdt|}|j|7_t||j|_|jrV|jj|}|jt|7_|j j ||S)NzI/O operation on closed file.) rrxr.r9rr;r8rr:rr)r|rSnbytesrrrrBs  z_ZipWriteFile.writecsX|jr dStj|jrN|jj}|jt|7_|jj||j|j _ n |j |j _ |j |j _ |j |j _|j jd@r|jrdnd}|jjtj|t|j j |j j |j j|jj|j_nn|js|j tkrtd|jtkrtd|jj|j_|jj|j j|jj|j j|j|jj|jjd|j_|jjj|j |j |jj|j j <dS)Nrzd 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 a 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. NrTcCsF|dkrtdt|||_d|_d|_i|_g|_||_||_d|_ d |_ t |t j rdt j|}t |trd|_||_d d d d d ddd}||}x^ytj|||_Wn(tk r||kr||}wYnXPqWnd|_||_t|dd|_d|_tj|_d|_d|_y|dkr*|jn|dkrd|_y|jj|_Wn2t tfk r|t!|j|_d|_d|_Yn6Xy|jj"|jWn t tfk rd|_YnXnf|dkry|j|jj"|jWn6t#k r|jj"ddd|_|jj|_YnXntdWn$|j}d|_|j$|YnXdS)z]Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'.rDwxaz+ZipFile requires mode 'r', 'w', 'x', or 'a'FrNr+r<zw+bzx+bzr+bwbZxb)rDrErFrGzr+bzw+bzx+brr Trz"Mode must be 'r', 'w', 'x', or 'a')rDrErFrG)rErF)%rxr _allowZip64 _didModifydebugrBrArr r_commentrrurrstr _filePassedr?rr>r9r8getattr _fileRefCnt threadingRLockrrr_RealGetContentsrWr@rrrAr_fpclose)r|rr r allowZip64ZmodeDictrr9rrrr}s             zZipFile.__init__cCs|S)Nr)r|rrr __enter__szZipFile.__enter__cCs |jdS)N)r)r|typevalue tracebackrrr__exit__szZipFile.__exit__cCsd|jj|jjfg}|jdk rd|jr8|jd|jn|jdk rR|jd|j|jd|jn |jd|jddj|S)Nz<%s.%sz file=%rz filename=%rz mode=%rz [closed]r~r) rrrr9rNr/r?r r0)r|r@rrrrs    zZipFile.__repr__cCs|j}y t|}Wntk r.tdYnX|sIsz*ZipFile._RealGetContents..T)keyreverseN);r9r7r8rrKprintrNrO _ECD_COMMENTrL _ECD_LOCATIONrIrHrFrBr@rAr;rBytesIOsizeCentralDirr.rCr-structCentralDir _CD_SIGNATUREstringCentralDir_CD_FILENAME_LENGTHdecoder _CD_EXTRA_FIELD_LENGTHr1_CD_COMMENT_LENGTHr__CD_LOCAL_HEADER_OFFSETrjrTrcrdrerfrbrkrlrmMAX_EXTRACT_VERSIONrrgrhrirnrarrAr/rBr?sortedro)r|r9rRZsize_cdZ offset_cdconcatZinferredrSr\centdirr?flagsrFtdZ end_offsetrrrrrSs|                4        zZipFile._RealGetContentscCsdd|jDS)z+Return a list of file names in the archive.cSsg|] }|jqSr)r?).0rSrrr Psz$ZipFile.namelist..)rA)r|rrrnamelistNszZipFile.namelistcCs|jS)zJReturn a list of class ZipInfo instances for files in the archive.)rA)r|rrrinfolistRszZipFile.infolistcCsPtdd |dx:|jD]0}d|jdd}td |j||jf|dqWdS) z+Print a table of contents for the zip file.z%-46s %19s %12s File Name Modified Size)rz%d-%02d-%02d %02d:%02d:%02dNr"z %-46s %s %12d)rxryrz)r`rArar?rm)r|rrZdaterrrprintdirWs  zZipFile.printdircCs^d}xT|jD]J}y.|j|jd}x|j|r0q$WWdQRXWq tk rT|jSXq WdS)z%Read all the files and check the CRC.rrrDNi)rAr>r?r;r)r|Z chunk_sizerfrrrtestzip`s  zZipFile.testzipcCs$|jj|}|dkr td||S)z,Return the instance of ZipInfo given 'name'.Nz(There is no item named %r in the archive)rBrKeyError)r|r inforrrgetinfoms   zZipFile.getinfocCs8|r"t|t r"tdt|j|r.||_nd|_dS)z)Set default password for encrypted files.zpwd: expected bytes, got %sN)rr- TypeErrorrWrr)r|rrrr setpasswordvs zZipFile.setpasswordcCs|jS)z.The comment text associated with the ZIP file.)rL)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) rr-rrWrr.ZIP_MAX_COMMENTwarningswarnrLrJ)r|r_rrrrr_s    c Cs"|j|d| }|jSQRXdS)zReturn file bytes for name.rDN)r>r;)r|r rr9rrrr;sz ZipFile.readF) force_zip64c s|d"krtd|r2t|t r2tdt|j|rF|dkrFtdjsTtdt|trd|}n$|dkr~t|}j|_ n j |}|dkrj ||dSj rtdj d 7_ tj|jjjfd d }y|jt}t|tkrtd tjt|}|ttkr td |j|t}|trF|j|t|jd@rZtd|jd@rntd|jd@r|jd} n |jd} | |j krtd|j |f|j!dk r|j"|j#|j!krtd|j d|jd @} d} | r|sj$}|st%d|t&|} |jd} t't(| | dd} |jd@rX|j)d?d@}n|j*d?d@}| d|krt%d |t+|||| d!S|j,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. rDrEzopen() requires mode "r" or "w"zpwd: expected bytes, got %sz'pwd is only supported for reading filesz2Attempt to use ZIP archive that was already closed)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]szZipFile.open..zTruncated file headerz Bad magic number for file header z$compressed patched data (flag bit 5)@zstrong encryption (flag bit 6)izutf-8r[z/File name in directory %r and header %r differ.NzOverlapped entries: z (possible zip bomb)z6File %r is encrypted, password required for extractionrrrrrr&zBad password for file %rT>rDrE)-rxrr-rrWrr9r rrbr_open_to_writerrPrrjrTrr;sizeFileHeaderr.rrCr-r _FH_SIGNATUREr_FH_FILENAME_LENGTH_FH_EXTRA_FIELD_LENGTHrfrrir`rorWrlrrrr[r.rnrkrr)r|r r rrrZzef_fileZfheaderfnameZ fname_strZ is_encryptedZzdrhZ check_byter)r|rr>s                   z ZipFile.opencCs|r|j rtd|jr"tdt|ds2d|_d|_d|_d|_|jt kr\|jdO_|j sp|jdO_|j s|d |_ |jo|p|jd t k}|j r|j j|j|j j|_|j|d |_|j j|j|d |_t|||S) NzHforce_zip64 is True, but allowZip64 was False when opening the ZIP file.zzCan't write to the ZIP file while there is another write handle open on it. Close the first handle before opening another.rmrrrirg?Ti)rIrxrr=rmrlrkrfrbrrrirr9rAr@rWrj _writecheckrJrrr4)r|rrrrrrr s4     zZipFile._open_to_writecCs*|dkrtj}n tj|}|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)rugetcwdr_extract_member)r|memberrrrrrextract6s  zZipFile.extractcCsL|dkr|j}|dkr"tj}n tj|}x|D]}|j|||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)rvrurrr)r|rmembersrrrrr extractallCs   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|]}|jdVqdS).N)rstrip)rtrFrrr ^sz1ZipFile._sanitize_windows_name..css|]}|r|VqdS)Nr)rtrFrrrr`s)!_windows_illegal_name_trans_tablerM maketransr. translatesplitr0)rrpathseprZillegalrrr_sanitize_windows_nameTs zZipFile._sanitize_windows_namecsNt|ts|j|}|jjdtjj}tjjrB|jtjjtjj}tjj |d}dtjj tjj ftjjj fdd|j tjjD}tjjdkr|j|tjj}tjj ||}tjj|}tjj|}|rtjj| rtj||jrtjj|s tj||S|j||d(}t|d}tj||Wd QRXWd QRX|S) zbExtract the ZipInfo object 'member' to a physical file on the path targetpath. rrrrc3s|]}|kr|VqdS)Nr)rtrF)invalid_path_partsrrrtsz*ZipFile._extract_member..\)rrHN)rr rr?rwrurrvrrcurdirpardirr0rrrdirnameexistsmakedirsrrmkdirr>shutil copyfileobj)r|rZ targetpathrrZ upperdirssourcetargetr)rrrcs.  &        zZipFile._extract_membercCs|j|jkr(ddl}|jd|jdd|jdkr:td |jsHtd t|j|j sd}t |j t krpd }n|j tkrd }n|jtkrd }|rt|ddS)z6Check for errors before writing a file to the archive.rNzDuplicate name: %rr)rrErFrGz&write() requires mode 'w', 'x', or 'a'z4Attempt to write ZIP archive that was already closedz Files countZFilesizez Zipfile sizez would require ZIP64 extensions)rErFrG)r?rBrrr rxr9rrbrIr.rAZIP_FILECOUNT_LIMITrmrrjr )r|rrrequires_zip64rrrrs(     zZipFile._writecheckcCs0|jstd|jrtdtj||}|jr>d|_d|_n|dk rN||_n|j |_|jr|j |j rz|jj |j |jj|_|jtkr|jdO_|j|d|_|jj|||j|j<|jj|jd|jj|_ WdQRXnCan't write to ZIP archive while an open writing handle existsrNrTFr<rEiri )r9rxrr rrrlrkrbrrrrAr@rWrjrrfrrJrAr/rBr?rrr>rr)r|r?rrbrsrcdestrrrrs8      z ZipFile.writecCst|tr|jd}t|tspt|tjtjddd}|j|_|jddkrhd|_ |j dO_ qtd|_ n|}|j st d |j rt d |dk r||_t ||_|j*|j|d d }|j|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?rarrriAriz7Attempt to write to ZIP archive that was already closedz?Can't write to ZIP archive while an open writing handle exists.rE)r riAi)rrMrr rrrrbr?rir9rxrr.rmrr>r)r|Zzinfo_or_arcnamerSrbrrrrrwritestrs.    zZipFile.writestrcCs |jdS)z2Call the "close()" method in case the user forgot.N)r)r|rrr__del__szZipFile.__del__cCs||jdkrdS|jrtdzB|jdkr\|jr\|j"|jrJ|jj|j|j WdQRXWd|j}d|_|j |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.rErFrG)rErFrG) r9rrxr rJrrrAr@_write_end_recordrT)r|r9rrrrs z ZipFile.closecCsrxP|jD]D}|j}|ddd>|dd>B|dB}|dd>|d d>B|ddB}g}|jtksv|jtkr|j|j|j|jd }d }n |j}|j}|jtkr|j|jd }n|j}|j} d} |rt| d} t j d d t |dd t |f|| } t } |j tkr(tt| } n|j tkr>tt| } t| |j} t| |j} yZ|j\} }t j 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%| |j$j%| |j$j%|jq W|j$j&}t |j}||j'}|j'}d}|t(krd}n|tkrd}n|tkrd}|r*|j)st*|dt j t+t,ddddd|||| }|j$j%|t j t-t.d|d}|j$j%|t/|d}t/|d }t/|d }t j t0t1dd||||t |j2 }|j$j%||j$j%|j2|j$j3dS)Nrir$rr!rrr&r lzrrrrrrrrrrrrrTrrrrr {s<WT     u +  * * $fc@s4eZdZdZdedd fddZdd d Zd d ZdS)r zDClass to create ZIP archives with Python library files and packages.rDTrcCstj|||||d||_dS)N)r rrU)r r} _optimize)r|rr rrUoptimizerrrr}|s zPyZipFile.__init__rNcCstj|}|rF|| rF|jrBtjj|r.dnd}td||fdStjj|\}}tjj|rntjj|d}tjj|r|rd||f}n|}|jrtd|d||j |d d|\}} |jrtd | |j || tj |} | j dx| D]} tjj|| } tjj | \} }tjj| rRtjjtjj| dr|j| ||d q|d kr|r||  r|jrtd| q|j | d d|\}} |jrtd | |j || qWn|jrtd|xtj |D]} tjj|| } tjj | \} }|d kr|r0||  r0|jrtd| q|j | d d|\}} |jrZtd | |j || qWnP|ddd krtd|j |d d|\}} |jrtd| |j || 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 inasrrZAdding) filterfuncz.pyzfile %r skipped by filterfunczAdding files from directoryz.Files added with writepy() must end with ".py"z Adding filerrrr)rurrKrrr`rr0isfile _get_codenamerlistdirremovesplitextwritepyr)r|pathnamebasenamerZlabeldirr ZinitnamerrZdirlistr?rrootZextrrrrsx                zPyZipFile.writepyc sdfdd }|d}|d}tjj|dd}tjj|dd}tjj|dd}jdkr\tjj|rtj|jtj|jkr|} } ntjj|rtj|jtj|jkr|} |} ntjj|rtj|jtj|jkr|} |} nvtjj|rtj|jtj|jkr|} |} nD||rRt j j d kr4|} nt j j dkrH|} n|} |} n|} } njd krr|} |} n<|} jdkr|} n&jdkr|} nd j j} t | tjj| otj| jtj|jks||jd s|} } tjj| 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). rcs^ddl}jrtd|y|j|d|dWn,|jk rX}zt|jdSd}~XnXdS)NrZ CompilingT)doraiserF) py_compilerKr`compilePyCompileErrormsg)rrrerr)r|rr_compiles  z)PyZipFile._get_codename.._compilez.pyz.pycr) optimizationrrz"invalid value for 'optimize': {!r})rz%s/%sr)rr) importlibutilcache_from_sourcerrurrrrryrqrformatrxr) r|rrrZfile_pyZfile_pycZ pycache_opt0Z pycache_opt1Z pycache_opt2rrrZ archivenamer)r|rrs`             zPyZipFile._get_codenamer)rN)rrrrrr}rrrrrrr ys  Rc sddl}|jd}|dkr(tjdd}| s:|ddkrLt|tjd|ddkrt|dkrvt|tjdt|dd }|jWdQRXn||ddkr t|dkrt|tjdt|dd }|j }WdQRX|rtd j |td n|ddkrbt|d kr8t|tjdt|dd }|j |dWdQRXn|ddkrt|d krt|tjdfd dt|ddh}x`|ddD]P}t j j|}|st j jt j j|}|dt jt jfkrd}|||qWWdQRXdS)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-trrDz.The following enclosed file is corrupted: {!r}z Done testingrcsptjj|r|j||tnPtjj|rl|r8|j||x2tj|D]$}|tjj||tjj||qDWdS)N)rurrrrrrr0)r<rzippathZnm)addToZiprrrUs   zmain..addToZiprEr)rrrr)textwrapdedentryargvr`exitr.r r{r}rrrurrrrr)argsrZUSAGEr<Zbadfilerrr)rrmain'sT           r__main__liiiii)N)rrrureimportlib.utilrryrrrrCZbinasciirQ ImportErrorZdummy_threadingrrrr__all__ Exceptionrr rrrrrrrrrr{rrrrmrZrYrrXrIrJrKrLrMrNrOr^rarbrergrdrfZ_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_SIZErhrjrkZ_CD_DISK_NUMBER_STARTZ_CD_INTERNAL_FILE_ATTRIBUTESZ_CD_EXTERNAL_FILE_ATTRIBUTESrlrrrrZ_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_SIZErrrDrErBrGrHrFZ_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,r6r:r rUr7objectr rrrrrrrrrrrr4r r rrrrrrsD              +=[= &-J/ B