[issue7471] GZipFile.readline too slow
Antoine Pitrou
report at bugs.python.org
Thu Dec 17 23:07:15 CET 2009
Antoine Pitrou <pitrou at free.fr> added the comment:
Thanks for the new patch. The problem with inheriting from
BufferedRandom, though, is that if you call e.g. write() on a read-only
gzipfile, it will appear to succeed because the bytes are buffered
internally.
I think the solution would be to use delegation rather than inheritance.
Something like:
def __init__(self, ...)
if 'w' in mode:
self.buf = BufferedWriter(...)
for meth in ('read', 'write', etc.):
setattr(self, meth, getattr(self.buf, meth))
It would also be nice to add some tests for the issues I mentioned
earlier (check that IOError is raised when reading a write-only file,
and vice-versa).
By the way, we can't apply this approach to 2.x since
BufferedWriter/BufferedRandom won't accept unicode arguments for write()
and friends, and that would break compatibility. For 3.x it is fine though.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7471>
_______________________________________
More information about the Python-bugs-list
mailing list