[pypy-commit] pypy py3k: io module: replace some ValueError by UnsupportedOperation.
amauryfa
noreply at buildbot.pypy.org
Wed Oct 24 23:35:23 CEST 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r58410:7a0955158bb6
Date: 2012-10-24 23:08 +0200
http://bitbucket.org/pypy/pypy/changeset/7a0955158bb6/
Log: io module: replace some ValueError by UnsupportedOperation.
diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -77,11 +77,6 @@
return False
class W_BufferedIOBase(W_IOBase):
- def _unsupportedoperation(self, space, message):
- w_exc = space.getattr(space.getbuiltinmodule('_io'),
- space.wrap('UnsupportedOperation'))
- raise OperationError(w_exc, space.wrap(message))
-
def _check_init(self, space):
raise NotImplementedError
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -212,15 +212,11 @@
def _check_readable(self, space):
if not self.readable:
- raise OperationError(
- space.w_ValueError,
- space.wrap("file not open for reading"))
+ self._unsupportedoperation(space, "File not open for reading")
def _check_writable(self, space):
if not self.writable:
- raise OperationError(
- space.w_ValueError,
- space.wrap("file not open for writing"))
+ self._unsupportedoperation(space, "File not open for writing")
def _close(self, space):
if self.fd < 0:
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,26 +16,25 @@
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')):
- raise OperationError(
- space.w_IOError,
- space.wrap("file or stream is not readable"))
+ raise unsupported(space, "File or stream is not readable")
# May be called with any object
def check_writable_w(space, w_obj):
if not space.is_true(space.call_method(w_obj, 'writable')):
- raise OperationError(
- space.w_IOError,
- space.wrap("file or stream is not writable"))
+ raise unsupported(space, "File or stream is not writable")
# May be called with any object
def check_seekable_w(space, w_obj):
if not space.is_true(space.call_method(w_obj, 'seekable')):
- raise OperationError(
- space.w_IOError,
- space.wrap("file or stream is not seekable"))
+ raise unsupported(space, "File or stream is not seekable")
class W_IOBase(Wrappable):
def __init__(self, space):
@@ -85,6 +84,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"
@@ -113,9 +115,18 @@
space.w_ValueError,
space.wrap("I/O operation on closed file"))
+ def seek_w(self, space):
+ 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):
+ 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)
@@ -252,7 +263,10 @@
__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),
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")
@@ -544,7 +539,7 @@
remain buffered in the decoder, yet to be converted."""
if not self.w_decoder:
- raise OperationError(space.w_IOError, space.wrap("not readable"))
+ self._unsupportedoperation(space, "not readable")
if self.telling:
# To prepare for tell(), we need to snapshot a point in the file
@@ -590,7 +585,7 @@
def read_w(self, space, w_size=None):
self._check_closed(space)
if not self.w_decoder:
- raise OperationError(space.w_IOError, space.wrap("not readable"))
+ self._unsupportedoperation(space, "not readable")
size = convert_size(space, w_size)
self._writeflush(space)
More information about the pypy-commit
mailing list