Author: Brian Kearns <bdkea...@gmail.com>
Branch: use-file-star-for-file
Changeset: r73391:21e58ff89bd9
Date: 2014-09-08 19:35 -0400
http://bitbucket.org/pypy/pypy/changeset/21e58ff89bd9/

Log:    merge default

diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -77,6 +77,7 @@
 _pclose2 = (c_pclose, c_pclose_in_del)
 
 c_getc = llexternal('getc', [FILEP], rffi.INT, macro=True)
+c_ungetc = llexternal('ungetc', [rffi.INT, FILEP], rffi.INT)
 c_fgets = llexternal('fgets', [rffi.CCHARP, rffi.INT, FILEP], rffi.CCHARP)
 c_fread = llexternal('fread', [rffi.CCHARP, rffi.SIZE_T, rffi.SIZE_T, FILEP],
                      rffi.SIZE_T)
@@ -466,6 +467,14 @@
         if res == -1:
             errno = rposix.get_errno()
             raise IOError(errno, os.strerror(errno))
+        if self._skipnextlf:
+            c = c_getc(self._ll_file)
+            if c == ord('\n'):
+                self._newlinetypes |= NEWLINE_CRLF
+                res += 1
+                self._skipnextlf = False
+            elif c != EOF:
+                c_ungetc(c, self._ll_file)
         return res
 
     def fileno(self):
diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -191,21 +191,26 @@
 
     def test_read_universal(self):
         fname = self.tmpdir.join('read_univ')
-        fname.write("dupa\ndupb\r\ndupc")
+        fname.write("dupa\ndupb\r\ndupc\rdupd")
         fname = str(fname)
 
         def f():
             f = open(fname, 'U')
-            assert f.read() == "dupa\ndupb\ndupc"
+            assert f.read() == "dupa\ndupb\ndupc\ndupd"
             assert f.read() == ""
             f.seek(0)
-            assert f.read(9) == "dupa\ndupb"
-            assert f.read(42) == "\ndupc"
+            assert f.read(10) == "dupa\ndupb\n"
+            assert f.read(42) == "dupc\ndupd"
             assert f.read(1) == ""
             f.seek(0)
             assert f.readline() == "dupa\n"
+            assert f.tell() == 5
             assert f.readline() == "dupb\n"
-            assert f.readline() == "dupc"
+            assert f.tell() == 11
+            assert f.readline() == "dupc\n"
+            assert f.tell() == 16
+            assert f.readline() == "dupd"
+            assert f.tell() == 20
             assert f.readline() == ""
             f.close()
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to