Author: walter.doerwald
Date: Wed Jun  6 18:31:14 2007
New Revision: 55789

Modified:
   python/branches/py3k-struni/Lib/test/test_fileio.py
   python/branches/py3k-struni/Modules/_fileio.c
Log:
If append mode is specified seek to the end of the file.
Add a test to test_fileio.py for this.


Modified: python/branches/py3k-struni/Lib/test/test_fileio.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_fileio.py (original)
+++ python/branches/py3k-struni/Lib/test/test_fileio.py Wed Jun  6 18:31:14 2007
@@ -205,6 +205,24 @@
         finally:
             os.unlink(TESTFN)
 
+    def testAppend(self):
+        try:
+            f = open(TESTFN, 'wb')
+            f.write(b'spam')
+            f.close()
+            f = open(TESTFN, 'ab')
+            f.write(b'eggs')
+            f.close()
+            f = open(TESTFN, 'rb')
+            d = f.read()
+            f.close()
+            self.assertEqual(d, b'spameggs')
+        finally:
+            try:
+                os.unlink(TESTFN)
+            except:
+                pass
+
 def test_main():
     # Historically, these tests have been sloppy about removing TESTFN.
     # So get rid of it no matter what.

Modified: python/branches/py3k-struni/Modules/_fileio.c
==============================================================================
--- python/branches/py3k-struni/Modules/_fileio.c       (original)
+++ python/branches/py3k-struni/Modules/_fileio.c       Wed Jun  6 18:31:14 2007
@@ -242,6 +242,18 @@
                        PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
                        goto error;
                }
+               if (append) {
+                       int result;
+                       Py_BEGIN_ALLOW_THREADS
+                       errno = 0;
+                       result = lseek(self->fd, 0, SEEK_END);
+                       Py_END_ALLOW_THREADS
+                       if (result < 0) {
+                               close(self->fd);
+                               PyErr_SetFromErrnoWithFilename(PyExc_IOError, 
name);
+                               goto error;
+                       }
+               }
        }
 
        goto done;
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to