[Patches] [ python-Patches-443899 ] Minor fix to gzip.py module.

noreply@sourceforge.net noreply@sourceforge.net
Fri, 19 Oct 2001 04:03:53 -0700


Patches item #443899, was opened at 2001-07-23 12:35
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=443899&group_id=5470

Category: Library (Lib)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Titus Brown (titus)
Assigned to: Jeremy Hylton (jhylton)
Summary: Minor fix to gzip.py module.

Initial Comment:
---
from cStringIO import StringIO
from gzip import GzipFile

stringFile = StringIO()

gzFile = GzipFile("test1", 'wb', 9, stringFile)

gzFile.write('howdy there!')
r = gzFile.read()
---

the above code fragment gave a nonintuitive error
response (attribute missing).  Now, an exception is
raised stating that the file is not opened for reading
or writing.



----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2001-10-19 04:03

Message:
Logged In: YES 
user_id=21627

I think gzip files should behave like fileobjects with
respect to exceptions. Perhaps inconsistently, performing
read or write on files that are opened only for the other
operation raises an IOError (EBADF), since Posix says so,
whereas performing close on a closed file raises a
ValueError (it can't perform a system call since the file
descriptor might have been recycled meanwhile).

So I'm still in favour of applying this patch, with the
valueerror changed to IOError, and perhaps passing EBADF as
the error code in all cases of IOError.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-10-18 19:09

Message:
Logged In: YES 
user_id=6380

Time to look at this again?

----------------------------------------------------------------------

Comment By: Titus Brown (titus)
Date: 2001-08-16 13:33

Message:
Logged In: YES 
user_id=23486

Re: context diff, thanks & sorry for the trouble; my newer
patches are being submitted this way.

Re: IOError, I wasn't sure which exception to use at the time.
I therefore took my cue from other code in the gzip module,
which raises a ValueError when self.fileobj is closed.

The only IO errors raised in the module are those that
pertain to incorrect file formats.  I'd be happy to change
any and all of the ValueErrors that are raised into
IOErrors, but I think the current consistency of errors
should be maintained ;).


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2001-08-16 11:42

Message:
Logged In: YES 
user_id=21627

Please always submit context (-c) or unified (-u) diffs; 
I've reformatted your patch by retrieving 1.24, applying 
the patch, updating to the current version, and 
regenerating the patch.

Apart from that, the patch looks fine to me, and I 
recommend to approve it.

One consideration is the exception being raised: Maybe 
IOError is more appropriate.


----------------------------------------------------------------------

Comment By: Titus Brown (titus)
Date: 2001-08-14 12:15

Message:
Logged In: YES 
user_id=23486

(sorry -- misunderstanding of how the changelog view works)

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=443899&group_id=5470