lJc@s_dZddkZddkZddkZddkZddkZddkZyddkZWnej o e ZnXddddddd d d g Z de fd YZ d e fd YZ e Zdd>dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#dZ$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.dZ/dZ0dZ1dZ2dZ3dZ4d Z5d!Z6dZ7d"Z8d#Z9d$Z:d,Z;d-Z<d.Z=de>fd/YZ?d fd0YZ@d e@fd1YZAe d2ZBeCd3jo eBndS(4s Read and write ZIP files. iNt BadZipfileterrort ZIP_STOREDt ZIP_DEFLATEDt is_zipfiletZipInfotZipFilet PyZipFilet LargeZipFilecBseZRS((t__name__t __module__(((s/sys/lib/python/zipfile.pyRscBseZdZRS(su Raised when writing a zipfile, the zipfile requires ZIP64 extensions and those extensions are disabled. (R R t__doc__(((s/sys/lib/python/zipfile.pyRsiiiis<4s4H2lHsPKs<4s4B4HlLL5HLlsPKs <4s2B4HlLL2HsPKs<4slqlsPKs <4sqhhllqqqqsPKiiiiiii i i i i iiiiicCsRy8t|d}t|}|i|otSnWntj onXtS(s?Quickly see if file is a ZIP file by checking the magic number.trb(topent _EndRecDatatclosetTruetIOErrortFalse(tfilenametfpintendrec((s/sys/lib/python/zipfile.pyRRs   c CsJtit}|i||d|i|}tit|\}}}}|tjo|Sn|djp |djotdntit} |i||| d|i| }tit|\ }} } } } }}}}}|t jo|Sn| |d<||d<||d<||d<||d<||d<|S( sM Read the ZIP64 end-of-archive records and use that to update endrec iiis3zipfiles that span multiple disks are not supportediiii( tstructtcalcsizetstructEndArchive64LocatortseektreadtunpacktstringEndArchive64LocatorRtstructEndArchive64tstringEndArchive64(RtoffsetRt locatorSizetdatatsigtdisknotrelofftdiskstendArchiveSizetsztcreate_versiont read_versiontdisk_numtdisk_dirtdircountt dircount2tdirsizet diroffset((s/sys/lib/python/zipfile.pyt _EndRecData64^s* 0       cCs|idd|id}|i}|dd!tjo|ddjoztit|}t|}|id|i|d|d d jp|d d jot |d|Sn|Snt |d}|i||d|i}|i t}|djotit|||d!}t|}||d}|d t |joe|i||i||||d d jp|d d jot || ||Sn|SqndS(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.iiiiiittiiliiNi( RttellRtstringEndArchiveRRtstructEndArchivetlisttappendR0tmintrfindtlen(RtfilesizeR!Rt END_BLOCKtstarttcomment((s/sys/lib/python/zipfile.pyRs4 %  "    " cBs5eZdZdZdddZdZdZRS(s>Class with attributes describing each file in the ZIP archive.t orig_filenameRt date_timet compress_typeR>textrat create_systemR(textract_versiontreservedt flag_bitstvolumet internal_attrt external_attrt header_offsettCRCt compress_sizet file_sizetNoNameiiicCs ||_|itd}|djo|d|!}ntidjo)ti|jo|itid}n||_||_t|_ d|_ d|_ t i djo d|_n d|_d|_d|_d|_d|_d|_d|_d|_dS(Nit/R2twin32ii(R?tfindtchrtostseptreplaceRR@RRAR>RBtsystplatformRCR(RDRERFRGRHRI(tselfRR@t null_byte((s/sys/lib/python/zipfile.pyt__init__s*                c Cs||i}|ddd>|dd>B|dB}|dd>|d d>B|ddB}|id @od}}}n|i}|i}|i}|i}|tjp |tjold }|ti|dti |d ||}d }d }t d |i |_ t d |i |_ ntit t|i |i|i|i|||||t|it| } | |i|S(s'Return the per-file header as a string.iii iiiii iisOpen the ZIP file with mode read "r", write "w" or append "a".s.Compression requires the (missing) zlib modules(That compression method is not supporteditbR2R Rntwbtwsr+btaitnameisMode must be "r", "w" or "a"N(t _allowZip64Rt _didModifyRRtzlibRftdebugt NameToInfotfilelistt compressionRUtmodet isinstancet basestringt _filePassedRR tfptgetattrtNonet _GetContentst_RealGetContentsRt start_dirRR(RXtfileR{Rzt allowZip64tkeytmodeDict((s/sys/lib/python/zipfile.pyRZ<sH           !         cCsOy|iWn:tj o.|ip|iid|_nnXdS(sORead the directory, making sure we close the file if the format is bad.N(RRR~RRR(RX((s/sys/lib/python/zipfile.pyRjs   c Cs|i}t|}|p tdn|idjo |GHn|d}|d}|d|_|dtjo|d|dd}n|d|}||}|id jod G|G|G|GHn|||_|i|id |i|}t i |}d }x||jo|id } |d }| d d !t jo tdnt i t| } |id jo | GHn|i| t} t| }|i| t|_|i| t|_|| t| t| t}| t|_| dd!\ |_|_|_|_|_|_} } |_|_|_| dd!\|_|_ |_!| d?d| d?d@| d@| d?| d?d@| d@d f|_"|i#|i||_|i$i%|||i&|i'<|id jo dG|GHqqWdS(s/Read in the table of contents for the ZIP file.sFile is not a zip fileiiiii i8iisgiven, inferred, offsetii.is&Bad magic number for central directoryi iiiii i?ttotalN((RRRRwR>R[RRRt cStringIOtStringIOtstringCentralDirRRtstructCentralDirt_CD_FILENAME_LENGTHRt_CD_EXTRA_FIELD_LENGTHRBt_CD_COMMENT_LENGTHt_CD_LOCAL_HEADER_OFFSETRJR(RCRDRERFRARKRLRMRGRHRIR@RlRyR7RxR( RXRRtsize_cdt offset_cdtxtconcatR!RtcentdirRtttd((s/sys/lib/python/zipfile.pyRusX              I& cCs.g}x!|iD]}|i|iqW|S(s+Return a list of file names in the archive.(RyR7R(RXtlR!((s/sys/lib/python/zipfile.pytnamelists  cCs|iS(sJReturn a list of class ZipInfo instances for files in the archive.(Ry(RX((s/sys/lib/python/zipfile.pytinfolistscCsFddGHx6|iD]+}d|i}d|i||ifGHqWdS( s+Print a table of contents for the zip file.s%-46s %19s %12ss File Names Modified tSizes%d-%02d-%02d %02d:%02d:%02ds %-46s %s %12dN(s File Names Modified R(RyR@RRM(RXtzinfotdate((s/sys/lib/python/zipfile.pytprintdirs    cCsIxB|iD]7}y|i|iWq tj o|iSq Xq WdS(s%Read all the files and check the CRC.N(RyRRR(RXR((s/sys/lib/python/zipfile.pyttestzips  cCs |i|S(s,Return the instance of ZipInfo given 'name'.(Rx(RXRs((s/sys/lib/python/zipfile.pytgetinfosc Cs |idjo tdn|ip tdn|i|}|ii}|ii|id|iid}|dd!tjo t dnt i t |}|ii|t }|to|ii|tn||ijot d |i|fn|ii|i}|ii|d|itjon|itjodtp td ntid }|i|}|id |i}|o||}qnt d |i|fti|} | |ijot d|n|S(s)Return file bytes (as a string) for name.RnRrsread() requires mode "r" or "a"s3Attempt to read ZIP archive that was already closediiis Bad magic number for file headers3File name in directory "%s" and header "%s" differ.s1De-compression requires the (missing) zlib moduleitZs-Unsupported compression method %d for file %ssBad CRC-32 for file %s(RnRr(R{RfRRR3RRJRR_RRRR^t_FH_FILENAME_LENGTHt_FH_EXTRA_FIELD_LENGTHR?RLRARRRvt decompressobjt decompresstflushtbinasciitcrc32RK( RXRsRtfilepostfheadertfnametbytestdctextcrc((s/sys/lib/python/zipfile.pyRsN      cCs |i|ijo|iodG|iGHq1n|id jo tdn|ip tdn|itjot o tdn|it tfjo tdn|i t jo|i pt dqn|it jo|i pt d q nd S( s6Check for errors before writing a file to the archive.sDuplicate name:RqRrs 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(RqRr(RRxRwR{RfRRARRvRRMR[RtRRJ(RXR((s/sys/lib/python/zipfile.pyt _writechecks(        cCs ti|}ti|i}|dd!}|d jo |}ntiitii|d}x,|dti ti fjo|d}qjWt ||}|dd@d>|_ |d jo|i |_n ||_|i|_d|_|ii|_|i|t|_t|d}d|_} d|_} d|_} |ii|i|itjotiti ti!d} nd } xz|i"d } | pPn| t#| } t$i%| | } | o#| i&| } | t#| } n|ii| q|i'| o9| i(} | t#| } |ii| | |_n | |_| |_| |_|ii}|ii)|id d|iit*i+d |i|i|i|ii)|d|i,i-|||i.|i/|dd>B|d B}|d d >|d d>B|dd B}g}|itjp|i tjo0|i |i|i |i d }d } n|i}|i } |i tjo|i |i d} n |i } |i } |o\t iddt|ddt||| } td|i} td|i} n|i} |i} t itt| |i| |i|i|i|||i| |t|it| t|id|i|i| }|ii||ii|i|ii| |ii|iqQW|ii}|tjot itt ddddd||||| }|ii|t it!t"d|d}|ii||ii}t it#t$dd||||dd }|ii|n<t it#t$dd|||||d }|ii||ii%n|i&p|ii'nd|_dS(sJClose the file, and for mode "w" and "a" write the ending records.NRqRriiii iiii ilisRHRIRRRRRR5R4RR~R(RXtcounttpos1RR`RaRbRBRMRLRJt extra_dataRDR(Rtpos2t zip64endrect zip64locrectpos3R((s/sys/lib/python/zipfile.pyRs   &&          !  %   N(R R R RRRRRZRRRRRRRRRRRRR(((s/sys/lib/python/zipfile.pyR+s  . ;     3 A ! cBs#eZdZddZdZRS(sDClass to create ZIP archives with Python library files and packages.R2c Cstii|\}}tii|oitii|d}tii|o|od||f}n|}|iodG|GdG|GHn|i|dd!|\}}|io dG|GHn|i||ti |}|i dx|D]} tii|| } tii | \} } tii| o:tiitii| do|i | |qq| djoJ|i| dd!|\}}|io dG|GHn|i||qqWq|io d G|GHnxti |D]} tii|| } tii | \} } | djoJ|i| dd!|\}}|io dG|GHn|i||qqWne|ddjo t d n|i|dd!|\}}|io d G|GHn|i||d S( s,Add 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. s __init__.pys%s/%ssAdding package intasiitAddings.pysAdding files from directorys.Files added with writepy() must end with ".py"s Adding fileN(RSRtsplittisdirtjointisfileRwt _get_codenameRtlistdirtremovetsplitexttwritepyRf( RXtpathnametbasenametdirRstinitnameRRtdirlistRRtroottext((s/sys/lib/python/zipfile.pyRs^     "           c CsD|d}|d}|d}tii|o/ti|iti|ijo |}ntii| p%ti|iti|ijojddk}|io dG|GHny|i||dt Wn |i j o}|i GHnX|}n|}tii |d} |od|| f} n|| fS( sReturn (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). s.pys.pycs.pyoiNt Compilingis%s/%s( RSRRRRt py_compileRwtcompileRRtPyCompileErrortmsgR( RXRRtfile_pytfile_pyctfile_pyoRRterrt archivename((s/sys/lib/python/zipfile.pyRs*   % %     (R R R RR(((s/sys/lib/python/zipfile.pyRs Ac sddk}|id}|djotid}n| p|ddjo|GHtidn|ddjoTt|d jo|GHtidnt|dd }|i|i n%|ddjoOt|d jo|GHtidnt|dd }|i d GHn|ddjot|d jo|GHtidnt|dd }|d }x|i D]}|i d ot ii||d }nt ii||}t ii|}t ii|pt i|nt|d}|i|i||i qW|i n|ddjot|d jo|GHtidnfdt|dddt}x.|d D]"} || t ii| qW|i ndS(NisE 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 iis-ls-cs-es-tiRns Done testingis./Rpcstii|o|i||tn`tii|oLxIti|D]4}|tii||tii||qMWndS(N(RSRRRRRRR(tzfRtzippathtnm(taddToZip(s/sys/lib/python/zipfile.pyRtsRqR(s-ls-cs-es-t(ttextwraptdedentRRVtargvtexitR:RRRRRt startswithRSRRtdirnametexiststmakedirsR RRRR( targsRtUSAGERtoutRttgtttgtdirRtsrc((Rs/sys/lib/python/zipfile.pytmain:sd           t__main__(DR RRSRRVRRRvt ImportErrorRt__all__t ExceptionRRRR[RRR5R4RRR^R_RRRRt _CD_SIGNATUREt_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_SIZERRRt_CD_DISK_NUMBER_STARTt_CD_INTERNAL_FILE_ATTRIBUTESt_CD_EXTERNAL_FILE_ATTRIBUTESRt _FH_SIGNATUREt_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_SIZERRRR0RtobjectRRRRR (((s/sys/lib/python/zipfile.pyss0  " 'c I