[pypy-svn] pypy default: Be consistent with CPython and reset file.softspace when print() and write() are mixed.

amauryfa commits-noreply at bitbucket.org
Sun Dec 26 21:30:32 CET 2010


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r40230:dc972414d69a
Date: 2010-12-26 21:30 +0100
http://bitbucket.org/pypy/pypy/changeset/dc972414d69a/

Log:	Be consistent with CPython and reset file.softspace when print() and
	write() are mixed.

diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -210,12 +210,14 @@
         stream.truncate(size)
 
     def direct_write(self, data):
+        self.softspace = 0
         self.getstream().write(data)
 
     def direct_writelines(self, w_lines):    # note: a wrapped list!
         stream = self.getstream()
         space = self.space
         w_iterator = space.iter(w_lines)
+        self.softspace = 0
         while True:
             try:
                 w_line = space.next(w_iterator)

diff --git a/pypy/module/_file/test/test_file.py b/pypy/module/_file/test/test_file.py
--- a/pypy/module/_file/test/test_file.py
+++ b/pypy/module/_file/test/test_file.py
@@ -171,7 +171,18 @@
         raises(ValueError, self.file, self.temppath, "aU")
         raises(ValueError, self.file, self.temppath, "wU+")
         raises(ValueError, self.file, self.temppath, "")
-        
+
+    def test_write_resets_softspace(self):
+        f = self.file(self.temppath, "w")
+        print >> f, '.',
+        f.write(',')
+        print >> f, '.',
+        f.close()
+        f = self.file(self.temppath, "r")
+        res = f.read()
+        assert res == ".,."
+        f.close()
+
 class AppTestConcurrency(object):
     # these tests only really make sense on top of a translated pypy-c,
     # because on top of py.py the inner calls to os.write() don't


More information about the Pypy-commit mailing list