Author: Maciej Fijalkowski <[email protected]>
Branch: fileops2
Changeset: r67181:35758f162380
Date: 2013-10-07 17:10 +0200
http://bitbucket.org/pypy/pypy/changeset/35758f162380/
Log: flush
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -156,3 +156,16 @@
raise OSError(errno, os.strerror(errno))
return res
raise ValueError("I/O operation on closed file")
+
+ def flush(self):
+ if self.ll_file:
+ res = c_fflush(self.ll_file)
+ if res != 0:
+ errno = rposix.get_errno()
+ raise OSError(errno, os.strerror(errno))
+ return
+ raise ValueError("I/O operation on closed file")
+
+ def __del__(self):
+ self.close()
+
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
@@ -106,3 +106,16 @@
res = self.interpret(f, [])
assert res == 3
+ def test_flush(self):
+ fname = str(self.tmpdir.join('file_trunc'))
+
+ def f():
+ f = open(fname, "w")
+ f.write("xyz")
+ f.flush()
+ f2 = open(fname)
+ assert f2.read() == "xyz"
+ f2.close()
+ f.close()
+
+ self.interpret(f, [])
diff --git a/rpython/translator/goal/translate.py
b/rpython/translator/goal/translate.py
--- a/rpython/translator/goal/translate.py
+++ b/rpython/translator/goal/translate.py
@@ -11,10 +11,10 @@
import py
# clean up early rpython/_cache
-try:
- py.path.local(cache_dir).remove()
-except Exception:
- pass
+#try:
+# py.path.local(cache_dir).remove()
+#except Exception:
+# pass
from rpython.config.config import (to_optparse, OptionDescription, BoolOption,
ArbitraryOption, StrOption, IntOption, Config, ChoiceOption,
OptHelpFormatter)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit