[pypy-svn] r38724 - in pypy/dist/pypy/module/_file: . test

arigo at codespeak.net arigo at codespeak.net
Tue Feb 13 17:29:37 CET 2007


Author: arigo
Date: Tue Feb 13 17:29:35 2007
New Revision: 38724

Modified:
   pypy/dist/pypy/module/_file/app_file.py
   pypy/dist/pypy/module/_file/test/test_file.py
Log:
Allow file.write(unicode-string), converted to str in the default encoding
as usual for 'str' in unwrap_spec gateways.  I believe that it's exactly
what CPython does too.


Modified: pypy/dist/pypy/module/_file/app_file.py
==============================================================================
--- pypy/dist/pypy/module/_file/app_file.py	(original)
+++ pypy/dist/pypy/module/_file/app_file.py	Tue Feb 13 17:29:35 2007
@@ -152,8 +152,6 @@
 the file on disk reflects the data written."""
         if self._closed:
             raise ValueError('I/O operation on closed file')
-        if not isinstance(data, str):
-            raise TypeError('write() argument must be a string (for now)')
         return self.stream.write(data)
 
     def writelines(self, sequence_of_strings):
@@ -164,9 +162,6 @@
         if self._closed:
             raise ValueError('I/O operation on closed file')
         for line in sequence_of_strings:
-            if not isinstance(line, str):
-                raise TypeError('writelines() argument must be a list '
-                                'of strings')
             self.stream.write(line)
 
     def tell(self):

Modified: pypy/dist/pypy/module/_file/test/test_file.py
==============================================================================
--- pypy/dist/pypy/module/_file/test/test_file.py	(original)
+++ pypy/dist/pypy/module/_file/test/test_file.py	Tue Feb 13 17:29:35 2007
@@ -105,3 +105,14 @@
         res = f.read()
         assert res == "\n"
         assert f.newlines == "\r\n"
+
+    def test_unicode(self):
+        import _file, os
+        f = _file.file(self.temppath, "w")
+        f.write(u"hello\n")
+        f.close()
+        f = _file.file(self.temppath, "r")
+        res = f.read()
+        assert res == "hello\n"
+        assert type(res) is str
+        f.close()



More information about the Pypy-commit mailing list