Issue 18323: 'GzipFile' object has no attribute 'extrastart' (original) (raw)

Created on 2013-06-28 11:26 by Laurent.Gautier, last changed 2022-04-11 14:57 by admin.

Messages (5)
msg191989 - (view) Author: Laurent Gautier (Laurent.Gautier) Date: 2013-06-28 11:26
When creating a `gzip.GzipFile` using the named parameter `fileobj` rather than filename, iterating over it is broken: ``` AttributeError: 'GzipFile' object has no attribute 'extrastart' ``` The short example below is demonstrating the problem: ## --- import gzip, tempfile _data = (b'@WXOVW:25:85', b'ATACGCGGCT'+b'GATCGTAGCG', b'+', b'@@))CCCCBB'+b'???ECCEECC') data = gzip.zlib.compress(b'\n'.join(_data)) foo = tempfile.NamedTemporaryFile() foo.write(data) foo.flush() foo.seek(0) gzf = gzip.GzipFile(fileobj=foo) # this will trigger the AttributeError for x in gzf: print(x)
msg191998 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-06-28 15:30
Based on a quick glance at the code, the problem isn't that you are passing fileobj, it is that fileobj has been opened for writing, not reading, and you are attempting to read from it. extrastart (and other attibutes) are only set if mode starts with 'r'. There is certainly a bug here, but it might just be that a clearer error should be generated if you try to read a fileobj open for writing.
msg191999 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-06-28 15:31
On the other hand, it seems reasonable to be able to read if you've done a seek(0), so a more complicated fix may also be appropriate.
msg196147 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-08-25 15:28
We can add in readline() the check that GzipFile is opened in read mode. However it will slowdown readline(). See alse . Note that the original example is not correct. zlib.compress() doesn't produce legal Gzip file.
msg243391 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-17 09:14
As a workaround specify mode='r' for GzipFile.
History
Date User Action Args
2022-04-11 14:57:47 admin set github: 62523
2018-07-11 07:40:02 serhiy.storchaka set type: crash -> behavior
2015-05-17 09:14:42 serhiy.storchaka set messages: +
2013-08-25 15:28:06 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2013-08-25 13:04:13 gkcn set nosy: + gkcn
2013-06-28 15:31:03 r.david.murray set messages: +
2013-06-28 15:30:02 r.david.murray set nosy: + r.david.murraymessages: +
2013-06-28 13:04:55 pitrou set nosy: + nadeem.vawda
2013-06-28 11:26:57 Laurent.Gautier create