Commits

Philip Jenvey  committed 5bdfc3d

fix some IOError -> UnsupportedOperation

  • Participants
  • Parent commits 91f2102
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/module/_io/interp_textio.py

         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)
         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")
         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

File pypy/module/_io/test/test_textio.py

         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):