diff -ru rev62920/Doc/library/zipfile.rst new/Doc/library/zipfile.rst --- rev62920/Doc/library/zipfile.rst Tue May 20 00:15:35 2008 +++ new/Doc/library/zipfile.rst Tue May 20 00:40:22 2008 @@ -155,11 +155,11 @@ .. method:: ZipFile.open(name[, mode[, pwd]]) Extract a member from the archive as a file-like object (ZipExtFile). *name* is - the name of the file in the archive. The *mode* parameter, if included, must be - one of the following: ``'r'`` (the default), ``'U'``, or ``'rU'``. Choosing - ``'U'`` or ``'rU'`` will enable universal newline support in the read-only - object. *pwd* is the password used for encrypted files. Calling :meth:`open` - on a closed ZipFile will raise a :exc:`RuntimeError`. + the name of the file in the archive, or a :class:`ZipInfo` object. The *mode* + parameter, if included, must be one of the following: ``'r'`` (the default), + ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable universal newline + support in the read-only object. *pwd* is the password used for encrypted files. + Calling :meth:`open` on a closed ZipFile will raise a :exc:`RuntimeError`. .. note:: @@ -178,6 +178,12 @@ create a new file object that will be held by the ZipExtFile, allowing it to operate independently of the ZipFile. + .. note:: + + The :meth:`open`, :meth:`read` and :meth:`extract` methods can take a filename + or a :class:`ZipInfo` object. You will appreciate this when trying to read a + ZIP file that contains members with duplicate names. + .. versionadded:: 2.6 @@ -216,9 +222,10 @@ .. method:: ZipFile.read(name[, pwd]) - Return the bytes of the file in the archive. The archive must be open for read - or append. *pwd* is the password used for encrypted files and, if specified, it - will override the default password set with :meth:`setpassword`. Calling + Return the bytes of the file *name* in the archive. *name* is the name of the + file in the archive, or a :class:`ZipInfo` object. The archive must be open for + read or append. *pwd* is the password used for encrypted files and, if specified, + it will override the default password set with :meth:`setpassword`. Calling :meth:`read` on a closed ZipFile will raise a :exc:`RuntimeError`. .. versionchanged:: 2.6 diff -ru rev62920/Lib/zipfile.py new/Lib/zipfile.py --- rev62920/Lib/zipfile.py Tue May 20 00:17:39 2008 +++ new/Lib/zipfile.py Tue May 20 00:43:33 2008 @@ -776,10 +776,13 @@ else: zef_file = open(self.filename, 'rb') - # Get info object for name - zinfo = self.getinfo(name) - - filepos = zef_file.tell() + # Make sure we have an info object + if isinstance(name, ZipInfo): + # 'name' is already an info object + zinfo = name + else: + # Get info object for name + zinfo = self.getinfo(name) zef_file.seek(zinfo.header_offset, 0) @@ -884,7 +887,7 @@ if upperdirs and not os.path.exists(upperdirs): os.makedirs(upperdirs) - source = self.open(member.filename, pwd=pwd) + source = self.open(member, pwd=pwd) target = file(targetpath, "wb") shutil.copyfileobj(source, target) source.close()