From ad8fb0d47ce7709f3c6b9589c52cfd6f6467ac63 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 22 Sep 2007 20:18:03 +0000 Subject: [PATCH] Patch # 188 by Philip Jenvey. Make tell() mark CRLF as a newline. With unit test. --- Lib/test/test_univnewlines.py | 7 +++++++ Objects/fileobject.c | 1 + 2 files changed, 8 insertions(+) diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_univnewlines.py index e91bde72c64..d6bd64655d9 100644 --- a/Lib/test/test_univnewlines.py +++ b/Lib/test/test_univnewlines.py @@ -105,6 +105,13 @@ class TestCRLFNewlines(TestGenericUnivNewlines): NEWLINE = '\r\n' DATA = DATA_CRLF + def test_tell(self): + fp = open(test_support.TESTFN, self.READMODE) + self.assertEqual(repr(fp.newlines), repr(None)) + data = fp.readline() + pos = fp.tell() + self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) + class TestMixedNewlines(TestGenericUnivNewlines): NEWLINE = ('\r', '\n') DATA = DATA_MIXED diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 16786f87eda..271f4cdc55a 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -718,6 +718,7 @@ file_tell(PyFileObject *f) int c; c = GETC(f->f_fp); if (c == '\n') { + f->f_newlinetypes |= NEWLINE_CRLF; pos++; f->f_skipnextlf = 0; } else if (c != EOF) ungetc(c, f->f_fp);