SF bug #417176 (Martijn Pieters): MultiFile.read() includes CRLF
boundary. Fixed by keeping a readahead buffer containing the next line. XXX We have no test suite for this. Maybe the new email package will help?
This commit is contained in:
parent
555d12f986
commit
912e56c3ac
|
@ -41,6 +41,7 @@ class MultiFile:
|
||||||
self.stack = [] # Grows down
|
self.stack = [] # Grows down
|
||||||
self.level = 0
|
self.level = 0
|
||||||
self.last = 0
|
self.last = 0
|
||||||
|
self.readahead = ""
|
||||||
if seekable:
|
if seekable:
|
||||||
self.seekable = 1
|
self.seekable = 1
|
||||||
self.start = self.fp.tell()
|
self.start = self.fp.tell()
|
||||||
|
@ -49,7 +50,7 @@ class MultiFile:
|
||||||
def tell(self):
|
def tell(self):
|
||||||
if self.level > 0:
|
if self.level > 0:
|
||||||
return self.lastpos
|
return self.lastpos
|
||||||
return self.fp.tell() - self.start
|
return self.fp.tell() - len(self.readahead) - self.start
|
||||||
|
|
||||||
def seek(self, pos, whence=0):
|
def seek(self, pos, whence=0):
|
||||||
here = self.tell()
|
here = self.tell()
|
||||||
|
@ -67,8 +68,19 @@ class MultiFile:
|
||||||
self.fp.seek(pos + self.start)
|
self.fp.seek(pos + self.start)
|
||||||
self.level = 0
|
self.level = 0
|
||||||
self.last = 0
|
self.last = 0
|
||||||
|
self.readahead = ""
|
||||||
|
|
||||||
def readline(self):
|
def readline(self):
|
||||||
|
if not self.readahead:
|
||||||
|
self.readahead = self._readline()
|
||||||
|
line = self.readahead
|
||||||
|
if line:
|
||||||
|
self.readahead = self._readline()
|
||||||
|
if not self.readahead and line[-1:] == "\n":
|
||||||
|
line = line[:-1]
|
||||||
|
return line
|
||||||
|
|
||||||
|
def _readline(self):
|
||||||
if self.level > 0:
|
if self.level > 0:
|
||||||
return ''
|
return ''
|
||||||
line = self.fp.readline()
|
line = self.fp.readline()
|
||||||
|
|
Loading…
Reference in New Issue