[Patches] [Patch #103789] Add support to zipfile for passing file-like objects

noreply@sourceforge.net noreply@sourceforge.net
Mon, 19 Feb 2001 11:46:11 -0800


Patch #103789 has been updated. 

Project: python
Category: Modules
Status: Rejected
Submitted by: itamar
Assigned to : fdrake
Summary: Add support to zipfile for passing file-like objects

Follow-Ups:

Date: 2001-Feb-19 11:46
By: fdrake

Comment:
Please provide test cases for this.  The tests should be added to
Lib/test/test_zipfile.py.  File-ness should probably be determined by
checking if the object is a string or not (remember to test for a Unicode
string as well!).

Instead of catching an exception from checking for file.name, you can
instead fetch the name using getattr(file, 'name', None) and not worry
about exceptions; only the AttributeError you were actually trying to catch
will be caught, and everything else will "do the right thing" instead of
getting masked, as the current code does.

I'll re-evaluate the patch when it gets updated at SF.  (I think the idea
is right -- there's no need to require a built-in file object.)
-------------------------------------------------------

Date: 2001-Feb-14 05:26
By: itamar

Comment:
Right now I detect file-like objects by doing hasattr(file, "read"). Doing
hasattr(file, "write") might be better though, since for mode="w" ZipFiles,
all you need are write() and tell() methods on the file-like object.
-------------------------------------------------------

-------------------------------------------------------
For more info, visit:

http://sourceforge.net/patch/?func=detailpatch&patch_id=103789&group_id=5470