]> granicus.if.org Git - python/commitdiff
Patch # 188 by Philip Jenvey.
authorGuido van Rossum <guido@python.org>
Sat, 22 Sep 2007 20:18:03 +0000 (20:18 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 22 Sep 2007 20:18:03 +0000 (20:18 +0000)
Make tell() mark CRLF as a newline.
With unit test.

Lib/test/test_univnewlines.py
Objects/fileobject.c

index e91bde72c64d2d960f3722bb0d7c274f1239a94a..d6bd64655d927148a83a577ad2a885901610dc71 100644 (file)
@@ -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
index 16786f87edaecea7f57da7789f886e9ec9c2a1f2..271f4cdc55a613eaf77aff3d168960dc106ae5d7 100644 (file)
@@ -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);