[Python-checkins] python/dist/src/Lib zipfile.py,1.26,1.27

jvr@users.sourceforge.net jvr@users.sourceforge.net
2002年12月12日 04:23:34 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv20932/Lib
Modified Files:
	zipfile.py 
Log Message:
Patch #651621, approved by MvL.
This patch allows ZipFile.writestr() to be called with
an archive file name instead of a ZipInfo instance:
z = ZipFile("myarchive.zip", "w")
z.writestr("foo/baz/file.ext", data)
z.close()
I found the old writestr() method very inconvenient
for simple (but common) things.
If called with a file name instead of a ZipInfo
instance, the date_time is set to the current date/time,
which makes sense to me for anonymous data. 
Index: zipfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/zipfile.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** zipfile.py	13 Oct 2002 13:54:50 -0000	1.26
--- zipfile.py	12 Dec 2002 12:23:32 -0000	1.27
***************
*** 448,454 ****
 self.NameToInfo[zinfo.filename] = zinfo
 
! def writestr(self, zinfo, bytes):
 """Write a file into the archive. The contents is the string
! 'bytes'."""
 self._writecheck(zinfo)
 zinfo.file_size = len(bytes) # Uncompressed size
--- 448,461 ----
 self.NameToInfo[zinfo.filename] = zinfo
 
! def writestr(self, zinfo_or_arcname, bytes):
 """Write a file into the archive. The contents is the string
! 'bytes'. 'zinfo_or_arcname' is either a ZipInfo instance or
! the name of the file in the archive."""
! if not isinstance(zinfo_or_arcname, ZipInfo):
! zinfo = ZipInfo(filename=zinfo_or_arcname,
! date_time=time.localtime(time.time()))
! zinfo.compress_type = self.compression
! else:
! zinfo = zinfo_or_arcname
 self._writecheck(zinfo)
 zinfo.file_size = len(bytes) # Uncompressed size

AltStyle によって変換されたページ (->オリジナル) /