[pypy-commit] pypy default: rearrange to match py3k which already implemented these

pjenvey noreply at buildbot.pypy.org
Sun May 26 01:20:52 CEST 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: 
Changeset: r64565:d7ce4a47ae50
Date: 2013-05-25 16:02 -0700
http://bitbucket.org/pypy/pypy/changeset/d7ce4a47ae50/

Log:	rearrange to match py3k which already implemented these

diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -16,6 +16,11 @@
     else:
         return space.int_w(w_size)
 
+def unsupported(space, message):
+    w_exc = space.getattr(space.getbuiltinmodule('_io'),
+                          space.wrap('UnsupportedOperation'))
+    return OperationError(w_exc, space.wrap(message))
+
 # May be called with any object
 def check_readable_w(space, w_obj):
     if not space.is_true(space.call_method(w_obj, 'readable')):
@@ -49,11 +54,6 @@
         self.streamholder = None # needed by AutoFlusher
         get_autoflusher(space).add(self)
 
-    def _unsupportedoperation(self, space, message):
-        w_exc = space.getattr(space.getbuiltinmodule('_io'),
-                              space.wrap('UnsupportedOperation'))
-        raise OperationError(w_exc, space.wrap(message))
-
     def getdict(self, space):
         return self.w_dict
 
@@ -91,6 +91,9 @@
         # attribute as returned by whatever subclass.
         return self.__IOBase_closed
 
+    def _unsupportedoperation(self, space, message):
+        raise unsupported(space, message)
+
     def _check_closed(self, space, message=None):
         if message is None:
             message = "I/O operation on closed file"
@@ -116,9 +119,18 @@
                 space.w_ValueError,
                 space.wrap("I/O operation on closed file"))
 
+    def seek_w(self, space, w_offset, w_whence=None):
+        self._unsupportedoperation(space, "seek")
+
     def tell_w(self, space):
         return space.call_method(self, "seek", space.wrap(0), space.wrap(1))
 
+    def truncate_w(self, space, w_size=None):
+        self._unsupportedoperation(space, "truncate")
+
+    def fileno_w(self, space):
+        self._unsupportedoperation(space, "fileno")
+
     def enter_w(self, space):
         self._check_closed(space)
         return space.wrap(self)
@@ -149,15 +161,6 @@
     def seekable_w(self, space):
         return space.w_False
 
-    def seek_w(self, space, w_offset, w_whence=None):
-        self._unsupportedoperation(space, "seek")
-
-    def truncate_w(self, space, w_size=None):
-        self._unsupportedoperation(space, "truncate")
-
-    def fileno_w(self, space):
-        self._unsupportedoperation(space, "fileno")
-
     # ______________________________________________________________
 
     def readline_w(self, space, w_limit=None):
@@ -262,16 +265,15 @@
     next = interp2app(W_IOBase.next_w),
     close = interp2app(W_IOBase.close_w),
     flush = interp2app(W_IOBase.flush_w),
+    seek = interp2app(W_IOBase.seek_w),
     tell = interp2app(W_IOBase.tell_w),
+    truncate = interp2app(W_IOBase.truncate_w),
+    fileno = interp2app(W_IOBase.fileno_w),
     isatty = interp2app(W_IOBase.isatty_w),
     readable = interp2app(W_IOBase.readable_w),
     writable = interp2app(W_IOBase.writable_w),
     seekable = interp2app(W_IOBase.seekable_w),
 
-    seek = interp2app(W_IOBase.seek_w),
-    truncate = interp2app(W_IOBase.truncate_w),
-    fileno = interp2app(W_IOBase.fileno_w),
-
     _checkReadable = interp2app(check_readable_w),
     _checkWritable = interp2app(check_writable_w),
     _checkSeekable = interp2app(check_seekable_w),
diff --git a/pypy/module/_io/test/test_io.py b/pypy/module/_io/test/test_io.py
--- a/pypy/module/_io/test/test_io.py
+++ b/pypy/module/_io/test/test_io.py
@@ -16,7 +16,7 @@
         class MyFile(io.BufferedIOBase):
             def __init__(self, filename):
                 pass
-        f = MyFile("file")
+        MyFile("file")
 
     def test_openclose(self):
         import io
@@ -44,14 +44,11 @@
         e = _io.UnsupportedOperation("seek")
 
     def test_default_implementations(self):
-        import io
-        class MyFile(io.BufferedIOBase):
-            def __init__(self, filename):
-                pass
-        f = MyFile("file")
-        raises(io.UnsupportedOperation, f.seek, 0)
-        raises(io.UnsupportedOperation, f.fileno)
-        raises(io.UnsupportedOperation, f.truncate)
+        import _io
+        file = _io._IOBase()
+        raises(_io.UnsupportedOperation, file.seek, 0, 1)
+        raises(_io.UnsupportedOperation, file.fileno)
+        raises(_io.UnsupportedOperation, file.truncate)
 
     def test_blockingerror(self):
         import _io
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
@@ -26,16 +26,13 @@
         assert t.readable()
         assert t.seekable()
 
-    def test_textiobase(self):
+    def test_default_implementations(self):
         import _io
-        class TextIOBad(_io._TextIOBase):
-            def __init__(self):
-                pass
-        txt = TextIOBad()
-        raises(_io.UnsupportedOperation, txt.read)
-        raises(_io.UnsupportedOperation, txt.seek, 0)
-        raises(_io.UnsupportedOperation, txt.readline)
-        raises(_io.UnsupportedOperation, txt.detach)
+        file = _io._TextIOBase()
+        raises(_io.UnsupportedOperation, file.read)
+        raises(_io.UnsupportedOperation, file.seek, 0)
+        raises(_io.UnsupportedOperation, file.readline)
+        raises(_io.UnsupportedOperation, file.detach)
 
     def test_unreadable(self):
         import _io


More information about the pypy-commit mailing list