Kaydet (Commit) 5606801b authored tarafından Guido van Rossum's avatar Guido van Rossum

Make read() and readlines() conform more to the file object interface:

the default arg for read() is -1, not None, and readlines() has an
optional argument (which for now is ignored).
üst 4acc25bd
...@@ -139,12 +139,12 @@ class GzipFile: ...@@ -139,12 +139,12 @@ class GzipFile:
def writelines(self,lines): def writelines(self,lines):
self.write(string.join(lines)) self.write(string.join(lines))
def read(self, size=None): def read(self, size=-1):
if self.extrasize <= 0 and self.fileobj is None: if self.extrasize <= 0 and self.fileobj is None:
return '' return ''
readsize = 1024 readsize = 1024
if not size: # get the whole thing if size < 0: # get the whole thing
try: try:
while 1: while 1:
self._read(readsize) self._read(readsize)
...@@ -281,7 +281,7 @@ class GzipFile: ...@@ -281,7 +281,7 @@ class GzipFile:
bufs.append(c) bufs.append(c)
readsize = readsize * 2 readsize = readsize * 2
def readlines(self): def readlines(self, ignored=None):
buf = self.read() buf = self.read()
lines = string.split(buf, '\n') lines = string.split(buf, '\n')
for i in range(len(lines)-1): for i in range(len(lines)-1):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment