[pypy-commit] pypy py3k: fix some IOError -> UnsupportedOperation

pjenvey noreply at buildbot.pypy.org
Tue Feb 19 20:17:49 CET 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r61463:5bdfc3da631a
Date: 2013-02-19 11:12 -0800
http://bitbucket.org/pypy/pypy/changeset/5bdfc3da631a/

Log:	fix some IOError -> UnsupportedOperation

diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -716,7 +716,7 @@
         self._check_closed(space)
 
         if not self.w_encoder:
-            raise OperationError(space.w_IOError, space.wrap("not writable"))
+            self._unsupportedoperation(space, "not writable")
 
         text = space.unicode_w(w_text)
         textlen = len(text)
@@ -817,8 +817,8 @@
         if whence == 1:
             # seek relative to current position
             if not space.is_true(space.eq(w_pos, space.wrap(0))):
-                raise OperationError(space.w_IOError, space.wrap(
-                    "can't do nonzero cur-relative seeks"))
+                self._unsupportedoperation(
+                    space, "can't do nonzero cur-relative seeks")
             # Seeking to the current position should attempt to sync the
             # underlying buffer with the current position.
             w_pos = space.call_method(self, "tell")
@@ -826,8 +826,8 @@
         elif whence == 2:
             # seek relative to end of file
             if not space.is_true(space.eq(w_pos, space.wrap(0))):
-                raise OperationError(space.w_IOError, space.wrap(
-                    "can't do nonzero end-relative seeks"))
+                self._unsupportedoperation(
+                    space, "can't do nonzero end-relative seeks")
             space.call_method(self, "flush")
             self._set_decoded_chars(None)
             self.snapshot = None
diff --git a/pypy/module/_io/test/test_textio.py b/pypy/module/_io/test/test_textio.py
--- a/pypy/module/_io/test/test_textio.py
+++ b/pypy/module/_io/test/test_textio.py
@@ -42,6 +42,21 @@
         txt = _io.TextIOWrapper(UnReadable())
         raises(IOError, txt.read)
 
+    def test_unwritable(self):
+        import _io
+        class UnWritable(_io.BytesIO):
+            def writable(self):
+                return False
+        txt = _io.TextIOWrapper(UnWritable())
+        raises(_io.UnsupportedOperation, txt.write, "blah")
+        raises(_io.UnsupportedOperation, txt.writelines, ["blah\n"])
+
+    def test_invalid_seek(self):
+        import _io
+        t = _io.TextIOWrapper(_io.BytesIO(b"\xc3\xa9\n\n"))
+        raises(_io.UnsupportedOperation, t.seek, 1, 1)
+        raises(_io.UnsupportedOperation, t.seek, 1, 2)
+
     def test_unseekable(self):
         import _io
         class Unseekable(_io.BytesIO):


More information about the pypy-commit mailing list