summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-08-03 15:41:39 (GMT)
committerGuido van Rossum <guido@python.org>1998-08-03 15:41:39 (GMT)
commit84c6fc9653ec5482fc94a8923812591a0cf14e53 (patch)
tree21cc4f31f7c605e854e515c26b1e4f8e0a58a927 /Lib
parent6fd83b7b38d0b2a8c9ff5e5b553a1ea6f7306ef4 (diff)
downloadcpython-84c6fc9653ec5482fc94a8923812591a0cf14e53.zip
cpython-84c6fc9653ec5482fc94a8923812591a0cf14e53.tar.gz
cpython-84c6fc9653ec5482fc94a8923812591a0cf14e53.tar.bz2
Patch by Ron Klatchko: fix invariant in _unread(). Also fixed
readlines() to behave like it should (return lines with "\n" appended).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/gzip.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index fda1121..e25464c 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -174,7 +174,8 @@ class GzipFile:
self._read(readsize)
readsize = readsize * 2
except EOFError:
- pass
+ if size > self.extrasize:
+ size = self.extrasize
chunk = self.extrabuf[:size]
self.extrabuf = self.extrabuf[size:]
@@ -184,7 +185,7 @@ class GzipFile:
def _unread(self, buf):
self.extrabuf = buf + self.extrabuf
- self.extrasize = len(self.extrabuf)
+ self.extrasize = len(buf) + self.extrasize
def _read(self, size=1024):
try:
@@ -257,7 +258,12 @@ class GzipFile:
def readlines(self):
buf = self.read()
- return string.split(buf, '\n')
+ lines = string.split(buf, '\n')
+ for i in range(len(lines)-1):
+ lines[i] = lines[i] + '\n'
+ if lines and not lines[-1]:
+ del lines[-1]
+ return lines
def writelines(self, L):
for line in L: