mirror of https://github.com/python/cpython
Patch # 188 by Philip Jenvey.
Make tell() mark CRLF as a newline. With unit test.
This commit is contained in:
parent
aaad0d602b
commit
ad8fb0d47c
|
@ -105,6 +105,13 @@ class TestCRLFNewlines(TestGenericUnivNewlines):
|
||||||
NEWLINE = '\r\n'
|
NEWLINE = '\r\n'
|
||||||
DATA = DATA_CRLF
|
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):
|
class TestMixedNewlines(TestGenericUnivNewlines):
|
||||||
NEWLINE = ('\r', '\n')
|
NEWLINE = ('\r', '\n')
|
||||||
DATA = DATA_MIXED
|
DATA = DATA_MIXED
|
||||||
|
|
|
@ -718,6 +718,7 @@ file_tell(PyFileObject *f)
|
||||||
int c;
|
int c;
|
||||||
c = GETC(f->f_fp);
|
c = GETC(f->f_fp);
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
|
f->f_newlinetypes |= NEWLINE_CRLF;
|
||||||
pos++;
|
pos++;
|
||||||
f->f_skipnextlf = 0;
|
f->f_skipnextlf = 0;
|
||||||
} else if (c != EOF) ungetc(c, f->f_fp);
|
} else if (c != EOF) ungetc(c, f->f_fp);
|
||||||
|
|
Loading…
Reference in New Issue