Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee918cb

Browse files
committed
Fix bug reported by Harri Pasanen: gzip + cPickle doesn't work. The
problem was a couple of bugs in the readline implementation. 1. Include the '\n' in the string returned by readline 2. Bug calculating new buffer size in _unread Also remove unncessary import of StringIO
1 parent ed7adcf commit ee918cb

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

Lib/gzip.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import time
22
import string
33
import zlib
4-
import StringIO
54
import __builtin__
65

76
# implements a python function that reads and writes a gzipped file
@@ -157,7 +156,7 @@ def write(self,data):
157156
def writelines(self,lines):
158157
self.write(string.join(lines))
159158

160-
def read(self,size=None):
159+
def read(self, size=None):
161160
if self.extrasize <= 0 and self.fileobj is None:
162161
return ''
163162

@@ -185,7 +184,7 @@ def read(self,size=None):
185184

186185
def _unread(self, buf):
187186
self.extrabuf = buf + self.extrabuf
188-
self.extrasize = len(buf) + self.extrasize
187+
self.extrasize = len(self.extrabuf)
189188

190189
def _read(self, size=1024):
191190
try:
@@ -250,7 +249,7 @@ def readline(self):
250249
c = self.read(readsize)
251250
i = string.find(c, '\n')
252251
if i >= 0 or c == '':
253-
bufs.append(c[:i])
252+
bufs.append(c[:i+1])
254253
self._unread(c[i+1:])
255254
return string.join(bufs, '')
256255
bufs.append(c)

0 commit comments

Comments
 (0)