Author: Tomer Chachamu <[email protected]>
Branch: 
Changeset: r64564:2780a755bf49
Date: 2013-05-10 01:00 +0100
http://bitbucket.org/pypy/pypy/changeset/2780a755bf49/

Log:    add missing stub methods to io.IOBase

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
@@ -49,6 +49,11 @@
         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
 
@@ -144,6 +149,15 @@
     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):
@@ -253,6 +267,11 @@
     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/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -196,11 +196,6 @@
     def __init__(self, space):
         W_IOBase.__init__(self, space)
 
-    def _unsupportedoperation(self, space, message):
-        w_exc = space.getattr(space.getbuiltinmodule('_io'),
-                              space.wrap('UnsupportedOperation'))
-        raise OperationError(w_exc, space.wrap(message))
-
     def read_w(self, space, w_size=None):
         self._unsupportedoperation(space, "read")
 
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
-        MyFile("file")
+        f = MyFile("file")
 
     def test_openclose(self):
         import io
@@ -43,6 +43,16 @@
         import _io
         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)
+
     def test_blockingerror(self):
         import _io
         try:
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,6 +26,17 @@
         assert t.readable()
         assert t.seekable()
 
+    def test_textiobase(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)
+
     def test_unreadable(self):
         import _io
         class UnReadable(_io.BytesIO):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to