Efc @s9dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z yddl Z e j Z Wn ek reZ ej Z nXddddddd d d g Zdefd YZd efd YZeZdd>dZdd>Zdd>dZdZdZdZdZejeZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)eje(Z*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6d Z7d!Z8d"Z9d#Z:dZ;d$Z<d%Z=d&Z>d'Z?eje>Z@dZAdZBdZCdZDdZEdZFdZGdZHdZIdZJdZKdZLd(ZMd)ZNejeMZOd*ZPd+ZQejePZRdZSdZTdZUdZVdZWdZXdZYdZZdZ[dZ\d,Z]d-Z^d.Z_d/Z`deafd0YZbd1fd2YZcid3d6d4d6d5d6d5d6d5d6d5d6d6d6d7d6d8d6d9d6d6d6d:d 6d;d"6d<d%6d=d>6d?d@6dAdB6ZddCe jefdDYZfd eafdEYZgd egfdFYZhedGZiejdHkr5eindS(Is Read and write ZIP files. iNt BadZipfileterrort ZIP_STOREDt ZIP_DEFLATEDt is_zipfiletZipInfotZipFilet PyZipFilet LargeZipFilecBseZRS((t__name__t __module__(((s/usr/lib64/python2.7/zipfile.pyRscBseZdZRS(su Raised when writing a zipfile, the zipfile requires ZIP64 extensions and those extensions are disabled. (R R t__doc__(((s/usr/lib64/python2.7/zipfile.pyRsiiiiis<4s4H2LHsPKiiiiiii s<4s4B4HL2L5H2LsPKi i i i iiiis <4s2B4HL2L2HsPKs<4sLQLsPKs <4sQ2H2L4QsPKcCs,yt|rtSWntk r'nXtS(N(t _EndRecDatatTruetIOErrortFalse(tfp((s/usr/lib64/python2.7/zipfile.pyt_check_zipfiles   cCsgt}yIt|dr*td|}n$t|d}t|}WdQXWntk rbnX|S(sQuickly 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. treadRtrbN(RthasattrRtopenR(tfilenametresultR((s/usr/lib64/python2.7/zipfile.pyRs c Csny|j|tdWntk r,|SX|jt}t|tkrR|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(sM Read the ZIP64 end-of-archive records and use that to update endrec iiis3zipfiles that span multiple disks are not supported(tseektsizeEndCentDir64LocatorRRtlentstructtunpacktstructEndArchive64LocatortstringEndArchive64LocatorRtsizeEndCentDir64tstructEndArchive64tstringEndArchive64t_ECD_SIGNATUREt_ECD_DISK_NUMBERt_ECD_DISK_STARTt_ECD_ENTRIES_THIS_DISKt_ECD_ENTRIES_TOTALt _ECD_SIZEt _ECD_OFFSET(tfpintoffsettendrectdatatsigtdisknotrelofftdiskstsztcreate_versiont read_versiontdisk_numtdisk_dirtdircountt dircount2tdirsizet diroffset((s/usr/lib64/python2.7/zipfile.pyt _EndRecData64s6  0        c Cs|jdd|j}y|jt dWntk rEd SX|j}t|tkr|dd!tkr|ddkrtj t |}t |}|j d|j |tt |t |St|d td}|j|d|j}|jt}|dkr|||t!}t|tkrId St tj t |}|t}||t|t|!}|j ||j ||t |||||Sd S( sReturn 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.iiiittiiNi(RttelltsizeEndCentDirRtNoneRRtstringEndArchiveRRtstructEndArchivetlisttappendR:tmaxtrfindt_ECD_COMMENT_SIZE( R)tfilesizeR,R+tmaxCommentStarttstarttrecDatat commentSizetcomment((s/usr/lib64/python2.7/zipfile.pyR s>         cBsJeZdZdZdddZddZdZdZdZ RS( s>Class with attributes describing each file in the ZIP archive.t orig_filenameRt date_timet compress_typeRLtextrat create_systemR2textract_versiontreservedt flag_bitstvolumet internal_attrt external_attrt header_offsettCRCt compress_sizet file_sizet _raw_timetNoNameiiicCs#||_|jtd}|dkr:|d|!}ntjdkrptj|krp|jtjd}n||_||_|ddkrtdnt |_ d|_ d|_ t jdkrd|_n d|_d|_d|_d|_d|_d|_d|_d|_dS( Nit/is+ZIP does not support timestamps before 1980R<twin32ii(RMtfindtchrtostseptreplaceRRNt ValueErrorRRORLRPtsystplatformRQR2RRRSRTRURVRW(tselfRRNt null_byte((s/usr/lib64/python2.7/zipfile.pyt__init__s.               c Cs|j}|ddd>|dd>B|dB}|dd>|d d>B|ddB}|jd @rsd}}}n|j}|j}|j}|j}|dkr|tkp|tk}n|rd } |tj | dtj | d ||}n|tks|tkr_|s&t d nd }d }t d|j |_ t d|j |_n|j\} } tj tt|j |j| |j|||||t| t| } | | |S(s'Return the per-file header as a string.iii iiiii iisZdZejdZde dZ ddZ ddZ d Z dd Zd Zd Zd ZRS(sZFile-like object for reading an archive member. Is returned by ZipFile.open(). iiis*^(?P[^\r\n]+)|(?P\n|\r\n?)cCsf||_||_||_|j|_|j|_|j|_|jtkrct j d|_ n\|jt krt j|j}|rtd|j|fqtd|jfnd|_d|_d|_d|k|_d|_|jdk r|jd8_n||_|j|_t|drY|j|_tdd @|_n d|_dS( Niscompression type %d (%s)scompression type %dR<itUi RYI(t_fileobjt _decryptert_close_fileobjROt_compress_typeRZt_compress_sizet_compress_leftRtzlibt decompressobjt _decompressorRtcompressor_namestgettNotImplementedErrort _unconsumedt _readbuffert_offsett _universalR?tnewlinestmodeRtnameRRYt _expected_crctcrc32t _running_crc(RhtfileobjRtzipinfot decryptert close_fileobjtdescr((s/usr/lib64/python2.7/zipfile.pyRjs4             icCs|j ra|dkra|jjd|jd}|dkra|j|j|!}||_|Sn|js}tjj||Sd}x|dkst||kr|jd}|dkr|S|j j |}|j d}|dk rJ|j dkr g|_ n||j kr-|j j|n|jt|7_|dS|j d}|dkr|||t| }n|jt|7_||7}qW|S( srRead and return a line from the stream. If limit is specified, at most limit bytes will be read. is iR<itnewlinetchunkN(RRR`RtiotBufferedIOBasetreadlineRtpeektPATTERNtsearchtgroupR?RRC(RhtlimitRtlinet readaheadtmatchRR((s/usr/lib64/python2.7/zipfile.pyR+s8   !     cCs[|t|j|jkrC|j|}|jt|8_n|j|j|jd!S(s6Returns buffered bytes without advancing the position.i(RRRR(RhtnR((s/usr/lib64/python2.7/zipfile.pyR]scCstS(N(R (Rh((s/usr/lib64/python2.7/zipfile.pytreadablefscCsd}|dkrd}nxztr|dkrB|j|}n2|t|krp|j|t|}n|St|dkr|S||7}qWdS(sRead and return up to n bytes. If the argument is omitted, None, or negative, data is read and returned until EOF is reached.. R<iiN(R?R tread1R(RhRtbufR,((s/usr/lib64/python2.7/zipfile.pyRis    cCs^|jdkrdSt||jd@|_|rZ|j|jkrZtd|jndS(NIsBad CRC-32 for file %r(RR?RRRR(Rhtnewdatateof((s/usr/lib64/python2.7/zipfile.pyt _update_crc{s c Csg|dks|dkr$|j}nt|j|j}|jdkrW||t|jkrW||t|j}t||j}t ||j}|j j |}|jt|8_|r|j dk rdj t|j |}n|jtkrE|j|d|jdk|j|j||_d|_qW|j|7_nt|jdkr4||kr4|jtkr4|jj|jt|||j}|jj|_t|jdko|jdk}|r||jj7}n|j|d||j|j||_d|_n|j|j|j|!}|jt|7_|S(s7Read up to n bytes with at most one read() system call.iR<RN(R?tMAX_NRRRRRRDt MIN_READ_SIZEtminRRRtjointmapRRRRRt decompresstunconsumed_tailtflush(RhRtlen_readbuffertnbytesR,R((s/usr/lib64/python2.7/zipfile.pyRs> ( ! $ cCs8z|jr|jjnWdtt|jXdS(N(RRtclosetsuperR(Rh((s/usr/lib64/python2.7/zipfile.pyRs iN(R R R RRtretcompileRR?RRjRRRRRRR(((s/usr/lib64/python2.7/zipfile.pyRs  ' 2   4cBseZdZdZdeedZdZdZ dZ dZ dZ dZ d Zd Zd Zed Zejd ZddZdddZdddZddddZdZdZdddZddZdZdZRS(sd Class with methods to open, read, write, close, list zip files. z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=False) 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) or ZIP_DEFLATED (requires zlib). allowZip64: if True ZipFile will create files with ZIP64 extensions when needed, otherwise it will raise an exception when this would be necessary. trcCs\|dkrtdn|tkr*n*|tkrKtsTtdqTn td||_t|_d|_i|_g|_ ||_ |j dd d|_ }d|_d |_t|trXd|_||_id d6d d6d d6}yt||||_Wqtk rT|dkrNd}}t||||_qUqXn'd |_||_t|dd|_y|dkr|jn|dkrt|_no|dkry$|j|jj|jdWq"tk r|jjddt|_q"Xn tdWn2|j}d|_|jsQ|jnnXdS(s>Open the ZIP file with mode read "r", write "w" or append "a".Rtwtas(ZipFile() requires mode "r", "w", or "a"s.Compression requires the (missing) zlib modules(That compression method is not supporteditbR<Rtwbsr+biRisMode must be "r", "w" or "a"N(RRR(RRRRt _allowZip64Rt _didModifytdebugt NameToInfotfilelistt compressionRdRR?Rt_commentRyt basestringt _filePassedRRRRtgetattrt_RealGetContentsR Rt start_dirRR(RhtfileRRt allowZip64tkeytmodeDictR((s/usr/lib64/python2.7/zipfile.pyRjsf                                cCs|S(N((Rh((s/usr/lib64/python2.7/zipfile.pyt __enter__scCs|jdS(N(R(Rhttypetvaluet traceback((s/usr/lib64/python2.7/zipfile.pyt__exit__sc CsH|j}yt|}Wntk r8tdnX|sKtdn|jdkrb|GHn|t}|t}|t|_|t ||}|t t kr|t t 8}n|jdkr||}dG|G|G|GHn|||_|j|jd|j|}tj|}d}x||krC|jt} t| tkrftdntjt| } | ttkrtdn|jdkr| GHn|j| t} t| } |j| t| _|j| t| _| t | _!| dd!\ | _"| _#| _$| _%| _&| _'} } | _(| _)| _*| d d !\| _+| _,| _-| | _.| d ?d | d ?d @| d@| d?| d ?d@| d@df| _/| j0| j!|| _!| j1| _2|j3j4| | |j5| j2<|t| t| t| t}|jdkr*dG|GHq*q*WdS(s/Read in the table of contents for the ZIP file.sFile is not a zip fileiisgiven, inferred, offsetisTruncated central directorys&Bad magic number for central directoryi iii iiii i?ttotalN(6RR RRRR'R(t _ECD_COMMENTRt _ECD_LOCATIONR"R!RRRRRt cStringIOtStringIOtsizeCentralDirRRRtstructCentralDirt _CD_SIGNATUREtstringCentralDirt_CD_FILENAME_LENGTHRt_CD_EXTRA_FIELD_LENGTHRPt_CD_COMMENT_LENGTHRLt_CD_LOCAL_HEADER_OFFSETRXR2RQRRRSRTRORYRZR[RURVRWR\RNRR~RRRCR(RhRR+tsize_cdt offset_cdtconcattinferredR,RtcentdirRtxtttd((s/usr/lib64/python2.7/zipfile.pyRsd          I & "cCs.g}x!|jD]}|j|jqW|S(s+Return a list of file names in the archive.(RRCR(RhtlR,((s/usr/lib64/python2.7/zipfile.pytnamelistdscCs|jS(sJReturn a list of class ZipInfo instances for files in the archive.(R(Rh((s/usr/lib64/python2.7/zipfile.pytinfolistkscCsJdd GHx:|jD]/}d|jd }d|j||jfGHqWdS( s+Print a table of contents for the zip file.s%-46s %19s %12ss File Names Modified tSizes%d-%02d-%02d %02d:%02d:%02dis %-46s %s %12dN(s File Names Modified R(RRNRR[(Rhtzinfotdate((s/usr/lib64/python2.7/zipfile.pytprintdirps cCsnd}xa|jD]V}y8|j|jd}x|j|rFq4WWdQXWqtk re|jSXqWdS(s%Read all the files and check the CRC.iiRNi(RRRRR(Rht chunk_sizeRtf((s/usr/lib64/python2.7/zipfile.pyttestzipws cCs5|jj|}|dkr1td|n|S(s,Return the instance of ZipInfo given 'name'.s(There is no item named %r in the archiveN(RRR?tKeyError(RhRtinfo((s/usr/lib64/python2.7/zipfile.pytgetinfos  cCs ||_dS(s)Set default password for encrypted files.N(R(RhR((s/usr/lib64/python2.7/zipfile.pyt setpasswordscCs|jS(s.The comment text associated with the ZIP file.(R(Rh((s/usr/lib64/python2.7/zipfile.pyRLscCsJt|tkr4|jr'dtGHn|t }n||_t|_dS(Ns3Archive comment is too long; truncating to %d bytes(RtZIP_MAX_COMMENTRRR R(RhRL((s/usr/lib64/python2.7/zipfile.pyRLs    cCs|j|d|jS(s)Return file bytes (as a string) for name.R(RR(RhRR((s/usr/lib64/python2.7/zipfile.pyRscCsd|dkrtdn|js-tdn|jrH|j}t}nt|jd}t}yt|tr{|}n|j |}|j |j d|j t }t|t krtdntjt|}|ttkrtd n|j |t}|tr/|j |tn||jkrWtd |j|fn|jd @} d} | r&|s|j}n|std |nt|} |j d } t| | dd !} |jd@r|jd?d@} n|jd?d@} t| d| kr&td|q&nt |||| d|SWn|rY|j!nnXdS(s#Return file-like object for 'name'.RRtrUs&open() requires mode "r", "U", or "rU"s3Attempt to read ZIP archive that was already closedRisTruncated file headers Bad magic number for file headers3File name in directory "%s" and header "%s" differ.is6File %s is encrypted, password required for extractioni iiii sBad password for fileRN(RRsrU("RRRRRRR RyRR#RRXRtsizeFileHeaderRRRRRot _FH_SIGNATURERpt_FH_FILENAME_LENGTHt_FH_EXTRA_FIELD_LENGTHRMRTR?RRRR\RYRRR(RhRRRtzef_filet should_closeRtfheadertfnamet is_encryptedtzdtbytestht check_byte((s/usr/lib64/python2.7/zipfile.pyRsd                cCsOt|ts!|j|}n|dkr<tj}n|j|||S(s#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(RyRR#R?Rbtgetcwdt_extract_member(RhtmembertpathR((s/usr/lib64/python2.7/zipfile.pytextracts  cCsC|dkr|j}nx!|D]}|j|||q"WdS(sExtract 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(R?RR8(RhR7tmembersRR((s/usr/lib64/python2.7/zipfile.pyt extractalls  c Cs|jjdtjj}tjjrH|jtjjtjj}ntjj|d}tjjjd|jtjjD}tjjdkr2d}t |t rd|D}nt j |dt |}|j|}d|jtjjD}tjjjd |D}ntjj||}tjj|}tjj|}|rtjj| rtj|n|jd dkrtjj|stj|n|S|j|d |/}t|d } tj|| Wd QXWd QX|S(sbExtract the ZipInfo object 'member' to a physical file on the path targetpath. R^icss6|],}|dtjjtjjfkr|VqdS(R<N(RbR7tcurdirtpardir(t.0R((s/usr/lib64/python2.7/zipfile.pys ss\s:<>|"?*cSs%i|]}tdt|qS(t_(R(R=R((s/usr/lib64/python2.7/zipfile.pys !s R>css|]}|jdVqdS(t.N(trstrip(R=R((s/usr/lib64/python2.7/zipfile.pys &scss|]}|r|VqdS(N((R=R((s/usr/lib64/python2.7/zipfile.pys 'siRRN(RRdRbR7Rctaltsept splitdriveRtsplitRyRztstringt maketransRt translatetnormpathtdirnametexiststmakedirstisdirtmkdirRRtshutilt copyfileobj( RhR6t targetpathRtarcnametillegalRt upperdirstsourcettarget((s/usr/lib64/python2.7/zipfile.pyR5s4 !."cCs|j|jkr-|jr-dG|jGHq-n|jd krHtdn|js]tdn|jtkrt rtdn|jt tfkrtdn|j t kr|j st dqn|jt kr|j st d qnd S( s6Check for errors before writing a file to the archive.sDuplicate name:RRs write() requires mode "w" or "a"s4Attempt to write ZIP archive that was already closeds.Compression requires the (missing) zlib modules(That compression method is not supporteds'Filesize would require ZIP64 extensionss+Zipfile size would require ZIP64 extensionsN(RR(RRRRRRRORRRR[RkRRRX(RhR((s/usr/lib64/python2.7/zipfile.pyt _writecheck<s(        c Cs|jstdntj|}tj|j}tj|j}|dd!}|dkrm|}ntj j tj j |d}x*|dtj tjfkr|d}qW|r|d7}nt||}|dd@d>|_|dkr|j|_n ||_|j|_d|_|jj|_|j|t|_|rd|_d|_d|_|jj|||j|j <|jj!|j"t#dSt$|d  } d|_} d|_} |j%o|jd t&k} |jj!|j"| |jt'kr@t(j)t(j*t(j+d } nd} d}xw| j,d}|shPn|t-|}t.|| d@} | r| j/|}| t-|} n|jj!|qOWdQX| r | j0}| t-|} |jj!|| |_n ||_| |_||_| rn|j%rn|t&krPtdn| t&krntdqnn|jj}|jj1|jd|jj!|j"| |jj1|d|jj|||j|j |dd>B|d B}|d d >|d d>B|dd B}g}|jtks|j tkr|j |j|j |j d }d } n|j}|j } |j tkr?|j |j d} n |j } |j } |rt jddt|ddt||| } td|j} td|j} n|j} |j} y|j\}}t jtt| |j| |j||j|||j| |t|t| t|jd|j|j| }Wntk rtjtt| |j| |j|j |j|||j| |t|j!t| t|jd|j|j| fIJnX|jj"||jj"||jj"| |jj"|jqMW|jj}|}||}|}|t#ksf|tksf|tkrt jt$t%ddddd|||| }|jj"|t jt&t'd|d}|jj"|t(|d}t(|d }t(|d }nt jt)t*dd||||t|j+ }|jj"||jj"|j+|jj,nWd|j}d|_|j-s|j.nXdS(sJClose the file, and for mode "w" and "a" write the ending records.NRRiiii iiii iIlsR"R#R$R%R&R'R(RFRRRR RR t_CD_CREATE_VERSIONt_CD_CREATE_SYSTEMt_CD_EXTRACT_VERSIONt_CD_EXTRACT_SYSTEMt _CD_FLAG_BITSt_CD_COMPRESS_TYPEt_CD_TIMEt_CD_DATEt_CD_CRCt_CD_COMPRESSED_SIZEt_CD_UNCOMPRESSED_SIZER R R t_CD_DISK_NUMBER_STARTt_CD_INTERNAL_FILE_ATTRIBUTESt_CD_EXTERNAL_FILE_ATTRIBUTESRRoRpR'R(t_FH_EXTRACT_VERSIONt_FH_EXTRACT_SYSTEMt_FH_GENERAL_PURPOSE_FLAG_BITSt_FH_COMPRESSION_METHODt_FH_LAST_MOD_TIMEt_FH_LAST_MOD_DATEt_FH_CRCt_FH_COMPRESSED_SIZEt_FH_UNCOMPRESSED_SIZER)R*RRRR R!Rt_CD64_SIGNATUREt_CD64_DIRECTORY_RECSIZEt_CD64_CREATE_VERSIONt_CD64_EXTRACT_VERSIONt_CD64_DISK_NUMBERt_CD64_DISK_NUMBER_STARTt_CD64_NUMBER_ENTRIES_THIS_DISKt_CD64_NUMBER_ENTRIES_TOTALt_CD64_DIRECTORY_SIZEt_CD64_OFFSET_START_CENTDIRRRR:R tobjectRRRRRRRRR (((s/usr/lib64/python2.7/zipfile.pyts<$            + =< c F