j f $@sdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z yddl Z e j Z Wn!ek rdZ e j Z YnXyddlZWnek rdZYnXyddlZWnek rdZYnXddddddd d d d d dg ZGdddeZGdddeZeZZdd>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%e1Z3dZ4dZ5dZ6dZ7dZ8d Z9d!Z:d"Z;dZ<d#Z=d&Z>d'Z?dZ@d(ZAdZBd)ZCdZDd*ZEd+ZFd,ZGd-ZHe j%eGZIdZJdZKdZLdZMdZNd ZOd!ZPd"ZQdZRd#ZSd&ZTd'ZUd.ZVd/ZWe j%eVZXd0ZYd1ZZe j%eYZ[dZ\dZ]dZ^dZ_dZ`d Zad!Zbd"ZcdZdd#Zed2d3Zfd4d Zgd5d6Zhd7d8ZiGd9d d ejZkGd:d;d;ZlGd<d=d=ZmGd>d?d?Znid@d6dAd6dBd6dBd6dBd6dBd 6dCd!6dDd"6dEd6dFd#6dCd&6dGd6dHd6dId+6dJdK6dLdM6dNdO6ZodPdQZpdRdSZqdTdUZrGdVdWdWejsZtGdXd d ZuGdYd d euZvddZd[Zwexd\krewndS)]zP 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@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 <4sQ2H2L4QsPKc Cs-yt|rdSWntk r(YnXdS)NTF) _EndRecDataOSError)fprrr_check_zipfiles   r.cCshd}yIt|dr*td|}n$t|d}t|}WdQXWntk rcYnX|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. Freadr-rbN)hasattrr.openr,)filenameresultr-rrrr s cCsry|j|tdWntk r0|SYnX|jt}t|tkrV|Stjt|\}}}}|tkr|S|dks|dkrt dn|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)seeksizeEndCentDir64Locatorr,r/lenstructunpackstructEndArchive64LocatorstringEndArchive64LocatorrsizeEndCentDir64structEndArchive64stringEndArchive64_ECD_SIGNATURE_ECD_DISK_NUMBER_ECD_DISK_START_ECD_ENTRIES_THIS_DISK_ECD_ENTRIES_TOTAL _ECD_SIZE _ECD_OFFSET)fpinoffsetendrecdataZsigZdisknoZreloffZdisksZszcreate_versionZ read_versionZdisk_numZdisk_dirZdircountZ dircount2ZdirsizeZ diroffsetrrr _EndRecData64s6   0        rKc Cs|jdd|j}y|jt dWntk rIdSYnX|j}t|tkr|ddtkr|d ddkrtjt |}t |}|j d|j |tt |t |St |d td}|j|d|j}|jt}|dkr|||t}t|tkrYdSt tjt |}|t}||t|t|}|j ||j ||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.rrNr srri)r5tellsizeEndCentDirr,r/r7stringEndArchiver8r9structEndArchivelistappendrKmaxrfind_ECD_COMMENT_SIZE) rFZfilesizerIrHZmaxCommentStartstartZrecDataZ commentSizecommentrrrr+s>          r+c@sUeZdZdZd"Zdd#ddZdddZddZd d!ZdS)$r z>Class with attributes describing each file in the ZIP archive. orig_filenamer3 date_time compress_typerXextra create_systemrJextract_versionreserved flag_bitsvolume internal_attr external_attr header_offsetCRC compress_size file_size _raw_timeZNoNamerrcCs&||_|jtd}|dkr=|d|}ntjdkrstj|krs|jtjd}n||_||_|ddkrtdnt |_ d|_ d|_ t jdkrd|_n d|_t|_t|_d|_d|_d|_d|_d|_dS)Nr/iz+ZIP does not support timestamps before 1980rLwin32r)rYfindchrossepreplacer3rZ ValueErrorrr[rXr\sysplatformr]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} |d kr|tkp|tk}n|rd } |tj| dtj | d ||}n|tks|tkrA|s,t d nd}d}t } n|j t krbtt| } n!|j tkrtt| } nt| |j|_t| |j|_|j\} } tjtt|j|j| |j |||||t| t| } | | |S)z'Return the per-file header as a string.rir$rr!rrr&r rNz[^\r\n]+)|(?P\n|\r\n?)NFcCs||_||_||_|j|_|j|_|j|_t |j|_ d|_ d|_ d|_ d|k|_d|_|jdk r|jd8_n||_|j|_t|dr|j|_tdd@|_n d|_dS)NFrLrUrrel)_fileobj _decrypter_close_fileobjr[_compress_typerf_compress_leftrg_leftr _decompressor_eof _readbuffer_offset _universalnewlinesmoder3namer1re _expected_crccrc32 _running_crc)ruZfileobjrzipinfoZ decrypter close_fileobjrrrrvs(             zZipExtFile.__init__cCs|j rd|dkrd|jjd|jd}|dkrd|j|j|}||_|Sn|jstjj||Sd}x|dkst||kr|jd}|dkr|S|j j |}|j d}|dk rM|j dkrg|_ n||j kr0|j j |n|jt|7_|dS|j d}|dkr|d|t|}n|jt|7_||7}qW|S) zrRead and return a line from the stream. If limit is specified, at most limit bytes will be read. rs rrLrnewlineNchunk)rrrlrioBufferedIOBasereadliner7peekPATTERNsearchgrouprrS)rulimitrlineZ readaheadmatchrrrrrrs8   !     zZipExtFile.readlinecCs|t|j|jkr|j|}t||jkri||j|jd|_d|_q|jt|8_n|j|j|jdS)z6Returns buffered bytes without advancing the position.Nri)r7rrr/)runrrrrrs zZipExtFile.peekcCsdS)NTr)rurrrreadableszZipExtFile.readablecCsp|dks|dkrj|j|jd}d|_d|_x#|jse||j|j7}qCW|S||j}|t|jkr|j|j|}||_|S|t|j}|j|jd}d|_d|_x|dkrk|j rk|j|}|t|krN||_||_||d|7}Pn||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.. NrrL)rrr_read1MAX_Nr7)rurbufendrIrrrr/s4          zZipExtFile.readcCsa|jdkrdSt||jd@|_|jr]|j|jkr]td|jndS)NlzBad CRC-32 for file %r)rrrrrr)runewdatarrr _update_crcs zZipExtFile._update_crccCs||dks|dkrz|j|jd}d|_d|_x3|jsu|j|j}|rC||7}PqCqCW|S||j}|t|jkr|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)rrrrrr7)rurrrIrrrrread1s>              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_|jdkrd|_n|j||S)NrrLT)rrrrZunconsumed_tailr7_read2rrrT MIN_READ_SIZErrrrr)rurrIrrrr4s2 #    zZipExtFile._read1cCs|jdkrdSt||j}t||j}|jj|}|jt|8_|smtn|jdk rt t |j|}n|S)NrrL) rrTrminrr/r7EOFErrorrbytesmap)rurrIrrrrXs zZipExtFile._read2c s2z|jr|jjnWdtjXdS)N)rrclosesuper)ru) __class__rrrhs zZipExtFile.closei@r)rrrrrrrecompilerrvrrrr/rrrrrrr)rrrss  2 ! % $ rc@sxeZdZdZdZdZdedddZddZd d Z d d Z d dZ ddZ dddZ ddZddZddZeddZejddZdddZddddZddd d!Zdddd"d#Zed$d%Zd&d'Zd(d)Zddd*d+Zdd,d-Zd.d/Zd0d1ZdS)2r 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" 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. NrTcCs6|dkrtdnt|||_d|_d|_i|_g|_||_|jddd|_ }d |_ d |_ t |t r0d|_||_id d6d d6d d6}ytj||||_WqWtk r,|dkr%d}}tj||||_nYqWXn'd|_||_t|dd |_y|dkrs|jn|dkrd|_np|dkry$|j|jj|jdWqtk r|jjddd|_YqXn tdWn3|j}d |_|js*|jnYnXd S)z>Open the ZIP file with mode read "r", write "w" or append "a".rwaz(ZipFile() requires mode "r", "w", or "a"FrbNrLr0wbzr+brrTrzMode must be "r", "w" or "a")rrr)rr _allowZip64 _didModifydebug NameToInfofilelistrrprr_comment isinstancestr _filePassedr3rr2r-r,getattr_RealGetContentsr5 start_dirrr)rufilerr allowZip64keyZmodeDictr-rrrrvsZ                             zZipFile.__init__cCs|S)Nr)rurrr __enter__szZipFile.__enter__cCs|jdS)N)r)rutypevalue tracebackrrr__exit__szZipFile.__exit__cCs|j}yt|}Wntk r9tdYnX|sOtdn|jdkrkt|n|t}|t}|t|_ |t ||}|t t kr|t t8}n|jdkr||}td|||n|||_|j|jd|j|}tj|}d}xx||kr|jt} t| tkrqtdntjt| } | ttkrtdn|jdkrt| n|j| t} | d} | d @r| jd } n| jd } t| } |j| t| _|j| t | _!| t"| _#| dd \ | _$| _%| _&| _'| _(| _)} }| _*| _+| _,| j&t-krt.d | j&dn| 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-8cp437rzzip file version %.1fr%r(r*r$irr&rtotalN)9r-r+r,rrprintrDrE _ECD_COMMENTr  _ECD_LOCATIONr?r>r<r6rr5r/rBytesIOsizeCentralDirr7r8r9structCentralDir _CD_SIGNATUREstringCentralDir_CD_FILENAME_LENGTHdecoder _CD_EXTRA_FIELD_LENGTHr\_CD_COMMENT_LENGTHrX_CD_LOCAL_HEADER_OFFSETrdrJr]r^r_r`r[rerfrgMAX_EXTRACT_VERSIONrrarbrcrhrZrrrSrr3)rur-rHZsize_cdZ offset_cdconcatZinferredrIrcentdirr3flagsxtdrrrrsp             L" & "zZipFile._RealGetContentscCsdd|jDS)z+Return a list of file names in the archive.cSsg|]}|jqSr)r3).0rIrrr s z$ZipFile.namelist..)r)rurrrnamelistszZipFile.namelistcCs|jS)zJReturn a list of class ZipInfo instances for files in the archive.)r)rurrrinfolistszZipFile.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)rurzinfoZdaterrrprintdir!s  zZipFile.printdircCsrd}xe|jD]Z}y8|j|jd}x|j|rFq4WWdQXWqtk ri|jSYqXqWdS)z%Read all the files and check the CRC.rrrNi)rr2r3r/r)ruZ chunk_sizer5frrrtestzip*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)rrKeyError)rurinforrrgetinfo7s  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)rurrrr setpassword@s  zZipFile.setpasswordcCs|jS)z.The comment text associated with the ZIP file.)r )rurrrrXIszZipFile.commentcCst|ts(tdt|nt|tkrpddl}|jdtdd|dt}n||_d|_ dS)Nzcomment: expected bytes, got %srz3Archive comment is too long; truncating to %d bytes stacklevelrT) r rr<rr7ZIP_MAX_COMMENTwarningswarnr r)rurXr@rrrrXNs   cCs,|j|d|}|jSWdQXdS)z)Return file bytes (as a string) for name.rN)r2r/)rurrr-rrrr/[sz ZipFile.readc Cs5|dkrtdnd|krIddl}|jdtdn|rxt|t rxtd t|n|jstd 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|tn|jd@rtdn|jd@rtdn|jd@r|jd} n|jd} | |jkrtd|j|fn|jd@} d} | r|sE|j }n|s^td|nt!|} |jd} t"t#| | dd} |jd@r|j$d?d@}n|j%d?d@}| d|krtd|qnt&|||| d|j SWn!|j s)|j'nYnXdS) z#Return file-like object for 'name'.rrrUz&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 extractionrrrrr&zBad password for filer)rrrB)(rr@rADeprecationWarningr rr<rr-r rr2r3r r;r5rdr/sizeFileHeaderr7rr8r9r~ _FH_SIGNATUREr_FH_FILENAME_LENGTH_FH_EXTRA_FIELD_LENGTHr`rr#rYrrrRrrhrerr)rurrrr@Zzef_filer5ZfheaderfnameZ fname_strZ is_encryptedZzdrhZ check_byterrrr2`sz                     z ZipFile.opencCsOt|ts!|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;rngetcwd_extract_member)rumemberpathrrrrextracts  zZipFile.extractcCsC|dkr|j}nx!|D]}|j|||q"WdS)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)r0rP)rurOZmembersrrrrr extractalls  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|]}|jdVqdS).N)rstrip)r.r+rrr sz1ZipFile._sanitize_windows_name..css|]}|r|VqdS)Nr)r.r+rrrrUs)!_windows_illegal_name_trans_tabler  maketransr7 translatesplitjoin)clsarcnamepathseprZillegalrrr_sanitize_windows_names  zZipFile._sanitize_windows_namecs|jjdtjj}tjjrH|jtjjtjj}ntjj|d}dtjjtjjftjjj fdd|j tjjD}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_partsrrrUsz*ZipFile._extract_member..\rrNr)r3rprnrOroaltsep splitdrivecurdirpardirrZrYr^normpathdirnameexistsmakedirsisdirmkdirr2shutilZ copyfileobj)rurNZ targetpathrr\Z upperdirssourcetargetr)r_rrMs* !7zZipFile._extract_membercCs|j|jkr;ddl}|jd|jddn|jdkrYtdn|jsqtd nt|j|j sd}t |j t krd }n0|j tkrd }n|jtkrd }n|rt|d qndS)z6Check for errors before writing a file to the archive.rNzDuplicate name: %rr>rrrz write() requires mode "w" or "a"z4Attempt to write ZIP archive that was already closedz Files countZFilesizez Zipfile sizez would require ZIP64 extensions)rr)r3rr@rArrr-rr[rr7rZIP_FILECOUNT_LIMITrgrwrdr )rur5r@requires_zip64rrr _writechecks(        zZipFile._writecheckc Cs |jstdntj|}tj|j}tj|j}|dd}|dkrp|}ntj j tj j |d}x0|dtj tj fkr|dd}qW|r|d7}nt||}|dd@d>|_|rt|_n$|dkr)|j|_n ||_|j|_d|_|jj|_|jtkrz|jd O_n|j|d |_|rd|_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}|sPn|t(|}t)|| d@} | r| j*|}| t(|} n|jj!|qvWWdQX| r2| j+}| t(|} |jj!|| |_n ||_| |_||_| r|j%r|t&krxtdn| t&krtdqn|jj}|jj,|jd|jj!|j"| |jj,|d|jj|||j|j |dd>B|d B}|d d >|d d>B|dd B}g}|jtks|jtkr|j |j|j |jd }d }n|j}|j}|j tkr/|j |j d } n |j } |j } d} |rt j ddt|ddt||| } t} n|jtkrtt| } n!|jtkrtt| } nt| |j} t| |j} y|j\}}t j tt| |j| |j||j|||j||t|t| t|jd|j|j | }Wnt!k rt"tt| |j| |j|j#|j|||j||t|j$t| t|jd|j|j | fdt%j&YnX|jj'||jj'||jj'| |jj'|jqGW|jj}t|j}||}|}d}|t(krd}n*|tkrd}n|tkrd}n|r}|j)st*|dnt 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|jj3nWd|j}d|_|j4s |j5nXdS)zJClose the file, and for mode "w" and "a" write the ending records.Nrrrir$rr!rrr&r lzr:r;rrQrPr rr r)ruZpos1r5rrrr\rgrfrdZ extra_datarr^rJr3r`r)Zpos2Z centDirCountZ centDirSizeZ centDirOffsetroZ zip64endrecZ zip64locrecrHr-rrrrs &&             !               z ZipFile.close) rrrrr-rVrrvrrrr0r1r6r8r;r=propertyrXsetterr/r2rPrQ classmethodr^rMrprxr|r}rrrrrr ps4 A   N    `  ' [8 c@sLeZdZdZdedd ddZddd d Zd d ZdS)r zDClass to create ZIP archives with Python library files and packages.rTrc Cs/tj||d|d|d|||_dS)Nrrr)r rv _optimize)rurrrroptimizerrrrv4szPyZipFile.__init__rNcCs|rU|| rU|jrQtjj|r4dnd}td||fndStjj|\}}tjj|rXtjj|d}tjj|rh|rd||f}n|}|jrtd|d|n|j|d d|\}} |jrtd | n|j || tj |} | j dx| D]} tjj|| } tjj | \} }tjj| rtjjtjj| dra|j | |d |qaqR|d krR|r||  r|jrRtd| qRqRn|j| d d|\}} |jrNtd | n|j || qRqRWq|jrtd|nxDtj |D]} tjj|| } tjj | \} }|d kr|r||  r|jrtd| qqn|j| d d|\}} |jr>td | n|j || qqWnp|ddd kr}tdn|j|d d|\}} |jrtd| n|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.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 inasrrZAdding filterfuncz.pyzfile "%s" skipped by filterfunczAdding files from directoryz.Files added with writepy() must end with ".py"z Adding filerrrr)rrnrOrirrYrZisfile _get_codenamerxlistdirremovesplitextwritepyr)rupathnamebasenamerZlabeldirrZinitnamerJr\Zdirlistr3rOrootZextrrrr:sv  "   !         " zPyZipFile.writepyc szd fdd}|d}|d}|d}tjj|d}tjj|d}jd krtjj|rtj|jtj|jkr|} } qAtjj|rtj|jtj|jkr|} } qAtjj|r7tj|jtj|jkr7|} |} qAtjj|r|tj|jtj|jkr||} |} qA||rt r|n|} t r|n|} qA|} } njd kr|} |} n |} |} tjj| otj| jtj|jksA||d jsA|} } 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). rcsddl}jr%td|ny|j|ddd|Wn9|jk r}}zt|jdSWYdd}~XnXdS)NrZ CompilingdoraiseTrF) py_compilerrrPyCompileErrormsg)rrrerr)rurr_compiles   z)PyZipFile._get_codename.._compilez.pyz.pycz.pyoTFrrz%s/%srr) importlibutilcache_from_sourcerrnrOrrqrv __debug__rY) rurrrZfile_pyZfile_pycZfile_pyoZ pycache_pycZ pycache_pyor\rJZ archivenamer)rurrsL   $ $ $ $    $zPyZipFile._get_codenamer)rrrrrrvrrrrrrr 1s Qc sddl}|jd}|dkr=tjdd}n| sT|ddkrnt|tjdn|ddkrt|dkrt|tjdnt|dd }|jWdQXn|ddkr`t|dkrt|tjdnt|dd }|j }WdQX|rStd j |ntd na|ddkrt|d krt|tjdnt|dd }|j |dWdQXn|ddkrt|d krt|tjdnfd dt|dd}x|ddD]s}t j j|}|st j jt j j|}n|dt jt jfkrd}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-trrz.The following enclosed file is corrupted: {!r}z Done testingrcstjj|r(|j||tnvtjj|r|rS|j||nxHtj|D]4}|tjj||tjj||qcWndS)N)rnrOrrxrrirrZ)zfrOzippathZnm)addToZiprrrszmain..addToZiprr)rrrr)textwrapdedentrrargvrexitr7r r6r8formatrQrnrOrrfrcrd)argsrZUSAGErZbadfilerOrr)rrmainsT          ! r__main__)yrrrnrimportlib.utilrrrrtrqrkr8Zbinasciirr ImportErrorrr__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 rrrrrrrrrr r rrrrrrs"                        + ==   B