Patch # 188 by Philip Jenvey.

Make tell() mark CRLF as a newline.
With unit test.
This commit is contained in:
Guido van Rossum 2007-09-22 20:18:03 +00:00
parent aaad0d602b
commit ad8fb0d47c
2 changed files with 8 additions and 0 deletions

View 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

View 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);