diff options
author | Guido van Rossum <guido@python.org> | 2001-09-18 14:34:06 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-09-18 14:34:06 (GMT) |
commit | 912e56c3acadf2d68a43e126f5c42e6ca7074025 (patch) | |
tree | e78ba7ec36954873f6751ceccab61cb77ad5dede /Lib/multifile.py | |
parent | 555d12f986bbf422a98e9083fae266f5ec3550a7 (diff) | |
download | cpython-912e56c3acadf2d68a43e126f5c42e6ca7074025.zip cpython-912e56c3acadf2d68a43e126f5c42e6ca7074025.tar.gz cpython-912e56c3acadf2d68a43e126f5c42e6ca7074025.tar.bz2 |
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?
Diffstat (limited to 'Lib/multifile.py')
-rw-r--r-- | Lib/multifile.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/multifile.py b/Lib/multifile.py index 74c35f0..47e2346 100644 --- a/Lib/multifile.py +++ b/Lib/multifile.py @@ -41,6 +41,7 @@ class MultiFile: self.stack = [] # Grows down self.level = 0 self.last = 0 + self.readahead = "" if seekable: self.seekable = 1 self.start = self.fp.tell() @@ -49,7 +50,7 @@ class MultiFile: def tell(self): if self.level > 0: return self.lastpos - return self.fp.tell() - self.start + return self.fp.tell() - len(self.readahead) - self.start def seek(self, pos, whence=0): here = self.tell() @@ -67,8 +68,19 @@ class MultiFile: self.fp.seek(pos + self.start) self.level = 0 self.last = 0 + self.readahead = "" 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: return '' line = self.fp.readline() |