[pypy-commit] pypy default: shorten operationerrfmt -> oefmt to ease its use all over the place
pjenvey
noreply at buildbot.pypy.org
Mon Feb 3 22:32:37 CET 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch:
Changeset: r69061:030972171657
Date: 2014-02-03 13:11 -0800
http://bitbucket.org/pypy/pypy/changeset/030972171657/
Log: shorten operationerrfmt -> oefmt to ease its use all over the place
diff too long, truncating to 2000 out of 4552 lines
diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -1,11 +1,11 @@
"""
Arguments objects.
"""
-
-from pypy.interpreter.error import OperationError, operationerrfmt
from rpython.rlib.debug import make_sure_not_resized
from rpython.rlib import jit
+from pypy.interpreter.error import OperationError, oefmt
+
class Arguments(object):
"""
@@ -86,9 +86,9 @@
args_w = space.fixedview(w_stararg)
except OperationError, e:
if e.match(space, space.w_TypeError):
- raise operationerrfmt(
- space.w_TypeError,
- "argument after * must be a sequence, not %T", w_stararg)
+ raise oefmt(space.w_TypeError,
+ "argument after * must be a sequence, not %T",
+ w_stararg)
raise
self.arguments_w = self.arguments_w + args_w
@@ -113,10 +113,9 @@
w_keys = space.call_method(w_starstararg, "keys")
except OperationError, e:
if e.match(space, space.w_AttributeError):
- raise operationerrfmt(
- space.w_TypeError,
- "argument after ** must be a mapping, not %T",
- w_starstararg)
+ raise oefmt(space.w_TypeError,
+ "argument after ** must be a mapping, not %T",
+ w_starstararg)
raise
keys_w = space.unpackiterable(w_keys)
keywords_w = [None] * len(keys_w)
@@ -281,8 +280,7 @@
self._match_signature(w_firstarg,
scope_w, signature, defaults_w, 0)
except ArgErr, e:
- raise operationerrfmt(self.space.w_TypeError,
- "%s() %s", fnname, e.getmsg())
+ raise oefmt(self.space.w_TypeError, "%s() %s", fnname, e.getmsg())
return signature.scope_length()
def _parse(self, w_firstarg, signature, defaults_w, blindargs=0):
@@ -304,8 +302,7 @@
try:
return self._parse(w_firstarg, signature, defaults_w, blindargs)
except ArgErr, e:
- raise operationerrfmt(self.space.w_TypeError,
- "%s() %s", fnname, e.getmsg())
+ raise oefmt(self.space.w_TypeError, "%s() %s", fnname, e.getmsg())
@staticmethod
def frompacked(space, w_args=None, w_kwds=None):
@@ -344,10 +341,9 @@
for key in keywords:
for otherkey in existingkeywords:
if otherkey == key:
- raise operationerrfmt(space.w_TypeError,
- "got multiple values "
- "for keyword argument "
- "'%s'", key)
+ raise oefmt(space.w_TypeError,
+ "got multiple values for keyword argument '%s'",
+ key)
def _do_combine_starstarargs_wrapped(space, keys_w, w_starstararg, keywords,
keywords_w, existingkeywords):
@@ -367,10 +363,9 @@
raise
else:
if existingkeywords and key in existingkeywords:
- raise operationerrfmt(space.w_TypeError,
- "got multiple values "
- "for keyword argument "
- "'%s'", key)
+ raise oefmt(space.w_TypeError,
+ "got multiple values for keyword argument '%s'",
+ key)
keywords[i] = key
keywords_w[i] = space.getitem(w_starstararg, w_key)
i += 1
diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -1,17 +1,17 @@
# Generated by tools/asdl_py.py
-from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter import typedef
-from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.error import OperationError, operationerrfmt
from rpython.rlib.unroll import unrolling_iterable
from rpython.tool.pairtype import extendabletype
from rpython.tool.sourcetools import func_with_new_name
+from pypy.interpreter import typedef
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.gateway import interp2app
+
def raise_attriberr(space, w_obj, name):
- raise operationerrfmt(space.w_AttributeError,
- "'%T' object has no attribute '%s'",
- w_obj, name)
+ raise oefmt(space.w_AttributeError,
+ "'%T' object has no attribute '%s'", w_obj, name)
def check_string(space, w_obj):
@@ -76,11 +76,13 @@
continue # field is optional
w_obj = self.getdictvalue(space, missing)
if w_obj is None:
- err = "required field \"%s\" missing from %s"
- raise operationerrfmt(space.w_TypeError, err, missing, host)
+ raise oefmt(space.w_TypeError,
+ "required field \"%s\" missing from %s",
+ missing, host)
else:
- err = "incorrect type for field \"%s\" in %s"
- raise operationerrfmt(space.w_TypeError, err, missing, host)
+ raise oefmt(space.w_TypeError,
+ "incorrect type for field \"%s\" in %s",
+ missing, host)
raise AssertionError("should not reach here")
diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -536,19 +536,19 @@
HEAD = """# Generated by tools/asdl_py.py
-from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter import typedef
-from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.error import OperationError, operationerrfmt
from rpython.rlib.unroll import unrolling_iterable
from rpython.tool.pairtype import extendabletype
from rpython.tool.sourcetools import func_with_new_name
+from pypy.interpreter import typedef
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.gateway import interp2app
+
def raise_attriberr(space, w_obj, name):
- raise operationerrfmt(space.w_AttributeError,
- \"'%T' object has no attribute '%s'\",
- w_obj, name)
+ raise oefmt(space.w_AttributeError,
+ \"'%T' object has no attribute '%s'\", w_obj, name)
def check_string(space, w_obj):
@@ -613,11 +613,13 @@
continue # field is optional
w_obj = self.getdictvalue(space, missing)
if w_obj is None:
- err = "required field \\"%s\\" missing from %s"
- raise operationerrfmt(space.w_TypeError, err, missing, host)
+ raise oefmt(space.w_TypeError,
+ "required field \\"%s\\" missing from %s",
+ missing, host)
else:
- err = "incorrect type for field \\"%s\\" in %s"
- raise operationerrfmt(space.w_TypeError, err, missing, host)
+ raise oefmt(space.w_TypeError,
+ "incorrect type for field \\"%s\\" in %s",
+ missing, host)
raise AssertionError("should not reach here")
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -11,8 +11,7 @@
from pypy.interpreter.executioncontext import (ExecutionContext, ActionFlag,
UserDelAction)
-from pypy.interpreter.error import (OperationError, operationerrfmt,
- new_exception_class)
+from pypy.interpreter.error import OperationError, new_exception_class, oefmt
from pypy.interpreter.argument import Arguments
from pypy.interpreter.miscutils import ThreadLocals
@@ -61,9 +60,9 @@
return False
def setdict(self, space, w_dict):
- raise operationerrfmt(space.w_TypeError,
- "attribute '__dict__' of %T objects "
- "is not writable", self)
+ raise oefmt(space.w_TypeError,
+ "attribute '__dict__' of %T objects is not writable",
+ self)
# to be used directly only by space.type implementations
def getclass(self, space):
@@ -123,8 +122,8 @@
classname = '?'
else:
classname = wrappable_class_name(RequiredClass)
- msg = "'%s' object expected, got '%T' instead"
- raise operationerrfmt(space.w_TypeError, msg, classname, self)
+ raise oefmt(space.w_TypeError,
+ "'%s' object expected, got '%T' instead", classname, self)
# used by _weakref implemenation
@@ -132,8 +131,8 @@
return None
def setweakref(self, space, weakreflifeline):
- raise operationerrfmt(space.w_TypeError,
- "cannot create weak reference to '%T' object", self)
+ raise oefmt(space.w_TypeError,
+ "cannot create weak reference to '%T' object", self)
def delweakref(self):
pass
@@ -215,25 +214,25 @@
self._typed_unwrap_error(space, "integer")
def _typed_unwrap_error(self, space, expected):
- raise operationerrfmt(space.w_TypeError, "expected %s, got %T object",
- expected, self)
+ raise oefmt(space.w_TypeError,
+ "expected %s, got %T object", expected, self)
def int(self, space):
w_impl = space.lookup(self, '__int__')
if w_impl is None:
- raise operationerrfmt(space.w_TypeError,
- "unsupported operand type for int(): '%T'", self)
+ raise oefmt(space.w_TypeError,
+ "unsupported operand type for int(): '%T'", self)
w_result = space.get_and_call_function(w_impl, self)
if (space.isinstance_w(w_result, space.w_int) or
space.isinstance_w(w_result, space.w_long)):
return w_result
- msg = "__int__ returned non-int (type '%T')"
- raise operationerrfmt(space.w_TypeError, msg, w_result)
+ raise oefmt(space.w_TypeError,
+ "__int__ returned non-int (type '%T')", w_result)
def ord(self, space):
- msg = "ord() expected string of length 1, but %T found"
- raise operationerrfmt(space.w_TypeError, msg, self)
+ raise oefmt(space.w_TypeError,
+ "ord() expected string of length 1, but %T found", self)
def __spacebind__(self, space):
return self
@@ -430,10 +429,9 @@
try:
w_mod = self.builtin_modules[name]
except KeyError:
- raise operationerrfmt(
- self.w_SystemError,
- "getbuiltinmodule() called "
- "with non-builtin module %s", name)
+ raise oefmt(self.w_SystemError,
+ "getbuiltinmodule() called with non-builtin module %s",
+ name)
else:
# Add the module to sys.modules
self.setitem(w_modules, w_name, w_mod)
@@ -753,9 +751,10 @@
if can_be_None and self.is_none(w_obj):
return None
if not isinstance(w_obj, RequiredClass): # or obj is None
- msg = "'%s' object expected, got '%N' instead"
- raise operationerrfmt(self.w_TypeError, msg,
- wrappable_class_name(RequiredClass), w_obj.getclass(self))
+ raise oefmt(self.w_TypeError,
+ "'%s' object expected, got '%N' instead",
+ wrappable_class_name(RequiredClass),
+ w_obj.getclass(self))
return w_obj
interp_w._annspecialcase_ = 'specialize:arg(1)'
@@ -832,13 +831,9 @@
items[idx] = w_item
idx += 1
if idx < expected_length:
- if idx == 1:
- plural = ""
- else:
- plural = "s"
- raise operationerrfmt(self.w_ValueError,
- "need more than %d value%s to unpack",
- idx, plural)
+ raise oefmt(self.w_ValueError,
+ "need more than %d value%s to unpack",
+ idx, "" if idx == 1 else "s")
return items
def unpackiterable_unroll(self, w_iterable, expected_length):
@@ -1257,8 +1252,8 @@
except OperationError, err:
if objdescr is None or not err.match(self, self.w_TypeError):
raise
- msg = "%s must be an integer, not %T"
- raise operationerrfmt(self.w_TypeError, msg, objdescr, w_obj)
+ raise oefmt(self.w_TypeError, "%s must be an integer, not %T",
+ objdescr, w_obj)
try:
index = self.int_w(w_index)
except OperationError, err:
@@ -1271,9 +1266,9 @@
else:
return sys.maxint
else:
- raise operationerrfmt(
- w_exception, "cannot fit '%T' into an index-sized integer",
- w_obj)
+ raise oefmt(w_exception,
+ "cannot fit '%T' into an index-sized integer",
+ w_obj)
else:
return index
@@ -1517,9 +1512,9 @@
)
fd = self.int_w(w_fd)
if fd < 0:
- raise operationerrfmt(self.w_ValueError,
- "file descriptor cannot be a negative integer (%d)", fd
- )
+ raise oefmt(self.w_ValueError,
+ "file descriptor cannot be a negative integer (%d)",
+ fd)
return fd
def warn(self, w_msg, w_warningcls, stacklevel=2):
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -226,9 +226,9 @@
def _exception_getclass(self, space, w_inst):
w_type = space.exception_getclass(w_inst)
if not space.exception_is_valid_class_w(w_type):
- msg = ("exceptions must be old-style classes or derived "
- "from BaseException, not %N")
- raise operationerrfmt(space.w_TypeError, msg, w_type)
+ raise oefmt(space.w_TypeError,
+ "exceptions must be old-style classes or derived from "
+ "BaseException, not %N", w_type)
return w_type
def write_unraisable(self, space, where, w_object=None,
@@ -383,15 +383,16 @@
self._w_value = w_value = space.wrap(self._value)
return w_value
-def get_operationerr_class(valuefmt):
+ at specialize.memo()
+def get_operr_class(valuefmt):
try:
result = _fmtcache[valuefmt]
except KeyError:
result = _fmtcache[valuefmt] = get_operrcls2(valuefmt)
return result
-get_operationerr_class._annspecialcase_ = 'specialize:memo'
-def operationerrfmt(w_type, valuefmt, *args):
+ at specialize.arg(1)
+def oefmt(w_type, valuefmt, *args):
"""Equivalent to OperationError(w_type, space.wrap(valuefmt % args)).
More efficient in the (common) case where the value is not actually
needed.
@@ -405,9 +406,8 @@
"""
if not len(args):
return OpErrFmtNoArgs(w_type, valuefmt)
- OpErrFmt, strings = get_operationerr_class(valuefmt)
+ OpErrFmt, strings = get_operr_class(valuefmt)
return OpErrFmt(w_type, strings, *args)
-operationerrfmt._annspecialcase_ = 'specialize:arg(1)'
# ____________________________________________________________
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -7,8 +7,8 @@
"""
from rpython.rlib.unroll import unrolling_iterable
-from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.eval import Code
from pypy.interpreter.argument import Arguments
from rpython.rlib import jit
@@ -413,9 +413,9 @@
if self.closure:
closure_len = len(self.closure)
if isinstance(code, PyCode) and closure_len != len(code.co_freevars):
- raise operationerrfmt(space.w_ValueError,
- "%N() requires a code object with %d free vars, not %d",
- self, closure_len, len(code.co_freevars))
+ raise oefmt(space.w_ValueError,
+ "%N() requires a code object with %d free vars, not "
+ "%d", self, closure_len, len(code.co_freevars))
self.fget_func_doc(space) # see test_issue1293
self.code = code
@@ -495,10 +495,9 @@
instdescr = instname + " instance"
else:
instdescr = "instance"
- msg = ("unbound method %N() must be called with %s "
- "as first argument (got %s instead)")
- raise operationerrfmt(space.w_TypeError, msg,
- self, clsdescr, instdescr)
+ raise oefmt(space.w_TypeError,
+ "unbound method %N() must be called with %s as first "
+ "argument (got %s instead)", self, clsdescr, instdescr)
return space.call_args(self.w_function, args)
def descr_method_get(self, w_obj, w_cls=None):
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -12,7 +12,7 @@
from pypy.interpreter.argument import Arguments
from pypy.interpreter.astcompiler import consts
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.executioncontext import ExecutionContext
from pypy.interpreter.nestedscope import Cell
from pypy.tool import stdlib_opcode
@@ -622,8 +622,8 @@
line = self.pycode.co_firstlineno
if new_lineno < line:
- raise operationerrfmt(space.w_ValueError,
- "line %d comes before the current code.", new_lineno)
+ raise oefmt(space.w_ValueError,
+ "line %d comes before the current code.", new_lineno)
elif new_lineno == line:
new_lasti = 0
else:
@@ -639,8 +639,8 @@
break
if new_lasti == -1:
- raise operationerrfmt(space.w_ValueError,
- "line %d comes after the current code.", new_lineno)
+ raise oefmt(space.w_ValueError,
+ "line %d comes after the current code.", new_lineno)
# Don't jump to a line with an except in it.
code = self.pycode.co_code
@@ -687,9 +687,9 @@
assert len(blockstack) == 0
if new_lasti_setup_addr != f_lasti_setup_addr:
- raise operationerrfmt(space.w_ValueError,
- "can't jump into or out of a 'finally' block %d -> %d",
- f_lasti_setup_addr, new_lasti_setup_addr)
+ raise oefmt(space.w_ValueError,
+ "can't jump into or out of a 'finally' block %d -> %d",
+ f_lasti_setup_addr, new_lasti_setup_addr)
if new_lasti < self.last_instr:
min_addr = new_lasti
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -14,7 +14,7 @@
gateway, function, eval, pyframe, pytraceback, pycode
)
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.nestedscope import Cell
from pypy.interpreter.pycode import PyCode, BytecodeCorruption
from pypy.tool.stdlib_opcode import bytecode_spec
@@ -492,8 +492,9 @@
def _load_fast_failed(self, varindex):
varname = self.getlocalvarname(varindex)
- message = "local variable '%s' referenced before assignment"
- raise operationerrfmt(self.space.w_UnboundLocalError, message, varname)
+ raise oefmt(self.space.w_UnboundLocalError,
+ "local variable '%s' referenced before assignment",
+ varname)
_load_fast_failed._dont_inline_ = True
def LOAD_CONST(self, constindex, next_instr):
@@ -848,9 +849,8 @@
# catch KeyErrors and turn them into NameErrors
if not e.match(self.space, self.space.w_KeyError):
raise
- message = "name '%s' is not defined"
- raise operationerrfmt(self.space.w_NameError, message,
- self.space.str_w(w_varname))
+ raise oefmt(self.space.w_NameError, "name '%s' is not defined",
+ self.space.str_w(w_varname))
def UNPACK_SEQUENCE(self, itemcount, next_instr):
w_iterable = self.popvalue()
@@ -899,8 +899,8 @@
_load_global._always_inline_ = True
def _load_global_failed(self, varname):
- message = "global name '%s' is not defined"
- raise operationerrfmt(self.space.w_NameError, message, varname)
+ raise oefmt(self.space.w_NameError,
+ "global name '%s' is not defined", varname)
_load_global_failed._dont_inline_ = True
def LOAD_GLOBAL(self, nameindex, next_instr):
@@ -910,9 +910,9 @@
def DELETE_FAST(self, varindex, next_instr):
if self.locals_stack_w[varindex] is None:
varname = self.getlocalvarname(varindex)
- message = "local variable '%s' referenced before assignment"
- raise operationerrfmt(self.space.w_UnboundLocalError, message,
- varname)
+ raise oefmt(self.space.w_UnboundLocalError,
+ "local variable '%s' referenced before assignment",
+ varname)
self.locals_stack_w[varindex] = None
def BUILD_TUPLE(self, itemcount, next_instr):
@@ -1040,9 +1040,8 @@
except OperationError, e:
if not e.match(self.space, self.space.w_AttributeError):
raise
- raise operationerrfmt(self.space.w_ImportError,
- "cannot import name '%s'",
- self.space.str_w(w_name))
+ raise oefmt(self.space.w_ImportError,
+ "cannot import name '%s'", self.space.str_w(w_name))
self.pushvalue(w_obj)
def YIELD_VALUE(self, oparg, next_instr):
@@ -1127,9 +1126,9 @@
w_enter = self.space.lookup(w_manager, "__enter__")
w_descr = self.space.lookup(w_manager, "__exit__")
if w_enter is None or w_descr is None:
- raise operationerrfmt(self.space.w_AttributeError,
- "'%T' object is not a context manager"
- " (no __enter__/__exit__ method)", w_manager)
+ raise oefmt(self.space.w_AttributeError,
+ "'%T' object is not a context manager (no __enter__/"
+ "__exit__ method)", w_manager)
w_exit = self.space.get(w_descr, w_manager)
self.settopvalue(w_exit)
w_result = self.space.get_and_call_function(w_enter, w_manager)
diff --git a/pypy/interpreter/test/test_error.py b/pypy/interpreter/test/test_error.py
--- a/pypy/interpreter/test/test_error.py
+++ b/pypy/interpreter/test/test_error.py
@@ -1,7 +1,7 @@
import py, os, errno
-from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.error import decompose_valuefmt, get_operrcls2
-from pypy.interpreter.error import wrap_oserror, new_exception_class
+from pypy.interpreter.error import (
+ OperationError, decompose_valuefmt, get_operrcls2, new_exception_class,
+ oefmt, wrap_oserror)
def test_decompose_valuefmt():
@@ -22,59 +22,59 @@
assert cls2 is cls # caching
assert strings2 == ("a ", " b ", " c")
-def test_operationerrfmt(space):
- operr = operationerrfmt("w_type", "abc %s def %d", "foo", 42)
+def test_oefmt(space):
+ operr = oefmt("w_type", "abc %s def %d", "foo", 42)
assert isinstance(operr, OperationError)
assert operr.w_type == "w_type"
assert operr._w_value is None
assert operr._compute_value(space) == "abc foo def 42"
- operr2 = operationerrfmt("w_type2", "a %s b %d c", "bar", 43)
+ operr2 = oefmt("w_type2", "a %s b %d c", "bar", 43)
assert operr2.__class__ is operr.__class__
- operr3 = operationerrfmt("w_type2", "a %s b %s c", "bar", "4b")
+ operr3 = oefmt("w_type2", "a %s b %s c", "bar", "4b")
assert operr3.__class__ is not operr.__class__
-def test_operationerrfmt_noargs(space):
- operr = operationerrfmt(space.w_AttributeError, "no attribute 'foo'")
+def test_oefmt_noargs(space):
+ operr = oefmt(space.w_AttributeError, "no attribute 'foo'")
operr.normalize_exception(space)
val = operr.get_w_value(space)
assert space.isinstance_w(val, space.w_AttributeError)
w_repr = space.repr(val)
assert space.str_w(w_repr) == "AttributeError(\"no attribute 'foo'\",)"
-def test_operationerrfmt_T(space):
- operr = operationerrfmt(space.w_AttributeError,
- "'%T' object has no attribute '%s'",
- space.wrap('foo'), 'foo')
+def test_oefmt_T(space):
+ operr = oefmt(space.w_AttributeError,
+ "'%T' object has no attribute '%s'",
+ space.wrap('foo'), 'foo')
assert operr._compute_value(space) == "'str' object has no attribute 'foo'"
- operr = operationerrfmt("w_type",
- "'%T' object has no attribute '%s'",
- space.wrap('foo'), 'foo')
+ operr = oefmt("w_type",
+ "'%T' object has no attribute '%s'",
+ space.wrap('foo'), 'foo')
assert operr._compute_value(space) == "'str' object has no attribute 'foo'"
-def test_operationerrfmt_N(space):
- operr = operationerrfmt(space.w_AttributeError,
- "'%N' object has no attribute '%s'",
- space.type(space.wrap('foo')), 'foo')
+def test_oefmt_N(space):
+ operr = oefmt(space.w_AttributeError,
+ "'%N' object has no attribute '%s'",
+ space.type(space.wrap('foo')), 'foo')
assert operr._compute_value(space) == "'str' object has no attribute 'foo'"
- operr = operationerrfmt("w_type",
- "'%N' object has no attribute '%s'",
- space.type(space.wrap('foo')), 'foo')
+ operr = oefmt("w_type",
+ "'%N' object has no attribute '%s'",
+ space.type(space.wrap('foo')), 'foo')
assert operr._compute_value(space) == "'str' object has no attribute 'foo'"
- operr = operationerrfmt(space.w_AttributeError,
- "'%N' object has no attribute '%s'",
- space.wrap('foo'), 'foo')
+ operr = oefmt(space.w_AttributeError,
+ "'%N' object has no attribute '%s'",
+ space.wrap('foo'), 'foo')
assert operr._compute_value(space) == "'?' object has no attribute 'foo'"
- operr = operationerrfmt("w_type",
- "'%N' object has no attribute '%s'",
- space.wrap('foo'), 'foo')
+ operr = oefmt("w_type",
+ "'%N' object has no attribute '%s'",
+ space.wrap('foo'), 'foo')
assert operr._compute_value(space) == "'?' object has no attribute 'foo'"
-def test_operationerrfmt_R(space):
- operr = operationerrfmt(space.w_ValueError, "illegal newline value: %R",
- space.wrap('foo'))
+def test_oefmt_R(space):
+ operr = oefmt(space.w_ValueError,
+ "illegal newline value: %R", space.wrap('foo'))
assert operr._compute_value(space) == "illegal newline value: 'foo'"
- operr = operationerrfmt(space.w_ValueError, "illegal newline value: %R",
- space.wrap("'PyLadies'"))
+ operr = oefmt(space.w_ValueError, "illegal newline value: %R",
+ space.wrap("'PyLadies'"))
expected = "illegal newline value: \"'PyLadies'\""
assert operr._compute_value(space) == expected
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -2,7 +2,7 @@
from pypy.interpreter.argument import Arguments
from pypy.interpreter.baseobjspace import W_Root, DescrMismatch
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import (interp2app, BuiltinCode, unwrap_spec,
WrappedDefault)
@@ -549,9 +549,9 @@
def typecheck(self, space, w_obj):
if not space.isinstance_w(w_obj, self.w_cls):
- m = "descriptor '%N' for '%N' objects doesn't apply to '%T' object"
- raise operationerrfmt(space.w_TypeError, m,
- self, self.w_cls, w_obj)
+ raise oefmt(space.w_TypeError,
+ "descriptor '%N' for '%N' objects doesn't apply to "
+ "'%T' object", self, self.w_cls, w_obj)
def descr_member_get(self, space, w_obj, w_cls=None):
"""member.__get__(obj[, type]) -> value
@@ -620,8 +620,9 @@
def descr_get_dict(space, w_obj):
w_dict = w_obj.getdict(space)
if w_dict is None:
- msg = "descriptor '__dict__' doesn't apply to '%T' objects"
- raise operationerrfmt(space.w_TypeError, msg, w_obj)
+ raise oefmt(space.w_TypeError,
+ "descriptor '__dict__' doesn't apply to '%T' objects",
+ w_obj)
return w_dict
def descr_set_dict(space, w_obj, w_dict):
diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -1,5 +1,5 @@
import new
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.interpreter.baseobjspace import W_Root
@@ -10,8 +10,8 @@
def raise_type_err(space, argument, expected, w_obj):
- raise operationerrfmt(space.w_TypeError, "argument %s must be %s, not %T",
- argument, expected, w_obj)
+ raise oefmt(space.w_TypeError,
+ "argument %s must be %s, not %T", argument, expected, w_obj)
def unwrap_attr(space, w_attr):
try:
@@ -126,10 +126,8 @@
return space.newtuple(self.bases_w)
w_value = self.lookup(space, name)
if w_value is None:
- raise operationerrfmt(
- space.w_AttributeError,
- "class %s has no attribute '%s'",
- self.name, name)
+ raise oefmt(space.w_AttributeError,
+ "class %s has no attribute '%s'", self.name, name)
w_descr_get = space.lookup(w_value, '__get__')
if w_descr_get is None:
@@ -158,18 +156,15 @@
def descr_delattr(self, space, w_attr):
name = unwrap_attr(space, w_attr)
if name in ("__dict__", "__name__", "__bases__"):
- raise operationerrfmt(
- space.w_TypeError,
- "cannot delete attribute '%s'", name)
+ raise oefmt(space.w_TypeError,
+ "cannot delete attribute '%s'", name)
try:
space.delitem(self.w_dict, w_attr)
except OperationError, e:
if not e.match(space, space.w_KeyError):
raise
- raise operationerrfmt(
- space.w_AttributeError,
- "class %s has no attribute '%s'",
- self.name, name)
+ raise oefmt(space.w_AttributeError,
+ "class %s has no attribute '%s'", self.name, name)
def descr_repr(self, space):
mod = self.get_module_string(space)
@@ -362,10 +357,9 @@
raise
# not found at all
if exc:
- raise operationerrfmt(
- space.w_AttributeError,
- "%s instance has no attribute '%s'",
- self.w_class.name, name)
+ raise oefmt(space.w_AttributeError,
+ "%s instance has no attribute '%s'",
+ self.w_class.name, name)
else:
return None
@@ -416,10 +410,9 @@
space.call_function(w_meth, w_name)
else:
if not self.deldictvalue(space, name):
- raise operationerrfmt(
- space.w_AttributeError,
- "%s instance has no attribute '%s'",
- self.w_class.name, name)
+ raise oefmt(space.w_AttributeError,
+ "%s instance has no attribute '%s'",
+ self.w_class.name, name)
def descr_repr(self, space):
w_meth = self.getattr(space, '__repr__', False)
diff --git a/pypy/module/__pypy__/interp_dict.py b/pypy/module/__pypy__/interp_dict.py
--- a/pypy/module/__pypy__/interp_dict.py
+++ b/pypy/module/__pypy__/interp_dict.py
@@ -1,6 +1,6 @@
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import operationerrfmt, OperationError
from pypy.objspace.std.dictmultiobject import W_DictMultiObject
@unwrap_spec(type=str)
@@ -30,8 +30,7 @@
elif type == 'strdict':
return space.newdict(strdict=True)
else:
- raise operationerrfmt(space.w_TypeError, "unknown type of dict %s",
- type)
+ raise oefmt(space.w_TypeError, "unknown type of dict %s", type)
def dictstrategy(space, w_obj):
""" dictstrategy(dict)
diff --git a/pypy/module/_cffi_backend/cbuffer.py b/pypy/module/_cffi_backend/cbuffer.py
--- a/pypy/module/_cffi_backend/cbuffer.py
+++ b/pypy/module/_cffi_backend/cbuffer.py
@@ -1,6 +1,6 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.buffer import RWBuffer
-from pypy.interpreter.error import operationerrfmt
+from pypy.interpreter.error import oefmt
from pypy.interpreter.gateway import unwrap_spec, interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
@@ -87,11 +87,9 @@
if size < 0:
size = w_cdata._sizeof()
else:
- raise operationerrfmt(space.w_TypeError,
- "expected a pointer or array cdata, got '%s'",
- ctype.name)
+ raise oefmt(space.w_TypeError,
+ "expected a pointer or array cdata, got '%s'", ctype.name)
if size < 0:
- raise operationerrfmt(space.w_TypeError,
- "don't know the size pointed to by '%s'",
- ctype.name)
+ raise oefmt(space.w_TypeError,
+ "don't know the size pointed to by '%s'", ctype.name)
return space.wrap(MiniBuffer(LLBuffer(w_cdata._cdata, size), w_cdata))
diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -7,7 +7,7 @@
from rpython.rlib.objectmodel import compute_unique_id, keepalive_until_here
from rpython.rtyper.lltypesystem import lltype, rffi
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.module._cffi_backend import cerrno, misc
from pypy.module._cffi_backend.cdataobj import W_CData
from pypy.module._cffi_backend.ctypefunc import SIZE_OF_FFI_ARG, BIG_ENDIAN, W_CTypeFunc
@@ -26,9 +26,8 @@
W_CData.__init__(self, space, raw_closure, ctype)
#
if not space.is_true(space.callable(w_callable)):
- raise operationerrfmt(space.w_TypeError,
- "expected a callable object, not %T",
- w_callable)
+ raise oefmt(space.w_TypeError,
+ "expected a callable object, not %T", w_callable)
self.w_callable = w_callable
#
fresult = self.getfunctype().ctitem
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -1,7 +1,7 @@
import operator
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
@@ -78,9 +78,8 @@
space = self.space
if isinstance(self.ctype, ctypearray.W_CTypeArray):
return space.wrap(self.get_array_length())
- raise operationerrfmt(space.w_TypeError,
- "cdata of type '%s' has no len()",
- self.ctype.name)
+ raise oefmt(space.w_TypeError,
+ "cdata of type '%s' has no len()", self.ctype.name)
def _make_comparison(name):
op = getattr(operator, name)
@@ -219,9 +218,9 @@
from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw
value = space.str_w(w_value)
if len(value) != length:
- raise operationerrfmt(space.w_ValueError,
- "need a string of length %d, got %d",
- length, len(value))
+ raise oefmt(space.w_ValueError,
+ "need a string of length %d, got %d",
+ length, len(value))
copy_string_to_raw(llstr(value), cdata, 0, length)
return
#
@@ -232,9 +231,8 @@
except OperationError, e:
if not e.match(space, space.w_StopIteration):
raise
- raise operationerrfmt(space.w_ValueError,
- "need %d values to unpack, got %d",
- length, i)
+ raise oefmt(space.w_ValueError,
+ "need %d values to unpack, got %d", length, i)
ctitem.convert_from_object(cdata, w_item)
cdata = rffi.ptradd(cdata, ctitemsize)
try:
@@ -243,8 +241,8 @@
if not e.match(space, space.w_StopIteration):
raise
else:
- raise operationerrfmt(space.w_ValueError,
- "got more than %d values to unpack", length)
+ raise oefmt(space.w_ValueError,
+ "got more than %d values to unpack", length)
def _add_or_sub(self, w_other, sign):
space = self.space
@@ -265,9 +263,9 @@
if (ct is not self.ctype or
not isinstance(ct, ctypeptr.W_CTypePointer) or
(ct.ctitem.size <= 0 and not ct.is_void_ptr)):
- raise operationerrfmt(space.w_TypeError,
- "cannot subtract cdata '%s' and cdata '%s'",
- self.ctype.name, ct.name)
+ raise oefmt(space.w_TypeError,
+ "cannot subtract cdata '%s' and cdata '%s'",
+ self.ctype.name, ct.name)
#
itemsize = ct.ctitem.size
if itemsize <= 0: itemsize = 1
diff --git a/pypy/module/_cffi_backend/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -3,7 +3,7 @@
"""
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef
@@ -59,9 +59,9 @@
raise OperationError(space.w_IndexError,
space.wrap("negative index not supported"))
if i >= w_cdata.get_array_length():
- raise operationerrfmt(space.w_IndexError,
- "index too large for cdata '%s' (expected %d < %d)",
- self.name, i, w_cdata.get_array_length())
+ raise oefmt(space.w_IndexError,
+ "index too large for cdata '%s' (expected %d < %d)",
+ self.name, i, w_cdata.get_array_length())
return self
def _check_slice_index(self, w_cdata, start, stop):
@@ -70,9 +70,9 @@
raise OperationError(space.w_IndexError,
space.wrap("negative index not supported"))
if stop > w_cdata.get_array_length():
- raise operationerrfmt(space.w_IndexError,
- "index too large (expected %d <= %d)",
- stop, w_cdata.get_array_length())
+ raise oefmt(space.w_IndexError,
+ "index too large (expected %d <= %d)",
+ stop, w_cdata.get_array_length())
return self.ctptr
def convert_from_object(self, cdata, w_ob):
diff --git a/pypy/module/_cffi_backend/ctypefunc.py b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -3,7 +3,6 @@
"""
import sys
-from pypy.interpreter.error import OperationError, operationerrfmt
from rpython.rlib import jit, clibffi, jit_libffi
from rpython.rlib.jit_libffi import (CIF_DESCRIPTION, CIF_DESCRIPTION_P,
@@ -11,6 +10,7 @@
from rpython.rlib.objectmodel import we_are_translated, instantiate
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from pypy.interpreter.error import OperationError, oefmt
from pypy.module._cffi_backend import ctypearray, cdataobj, cerrno
from pypy.module._cffi_backend.ctypeobj import W_CType
from pypy.module._cffi_backend.ctypeptr import W_CTypePtrBase, W_CTypePointer
@@ -52,10 +52,9 @@
if isinstance(w_obj, cdataobj.W_CData):
ct = w_obj.ctype.get_vararg_type()
else:
- raise operationerrfmt(space.w_TypeError,
- "argument %d passed in the variadic part "
- "needs to be a cdata object (got %T)",
- i + 1, w_obj)
+ raise oefmt(space.w_TypeError,
+ "argument %d passed in the variadic part needs to "
+ "be a cdata object (got %T)", i + 1, w_obj)
fvarargs[i] = ct
ctypefunc = instantiate(W_CTypeFunc)
ctypefunc.space = space
@@ -100,9 +99,9 @@
nargs_declared = len(self.fargs)
if len(args_w) != nargs_declared:
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "'%s' expects %d arguments, got %d",
- self.name, nargs_declared, len(args_w))
+ raise oefmt(space.w_TypeError,
+ "'%s' expects %d arguments, got %d",
+ self.name, nargs_declared, len(args_w))
return self._call(funcaddr, args_w)
else:
# call of a variadic function
@@ -113,9 +112,9 @@
nargs_declared = len(self.fargs)
if len(args_w) < nargs_declared:
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "'%s' expects at least %d arguments, got %d",
- self.name, nargs_declared, len(args_w))
+ raise oefmt(space.w_TypeError,
+ "'%s' expects at least %d arguments, got %d",
+ self.name, nargs_declared, len(args_w))
completed = self.new_ctypefunc_completing_argtypes(args_w)
return completed._call(funcaddr, args_w)
@@ -187,16 +186,15 @@
def _missing_ffi_type(self, cifbuilder, is_result_type):
space = self.space
if self.size < 0:
- raise operationerrfmt(space.w_TypeError,
- "ctype '%s' has incomplete type",
- self.name)
+ raise oefmt(space.w_TypeError,
+ "ctype '%s' has incomplete type", self.name)
if is_result_type:
place = "return value"
else:
place = "argument"
- raise operationerrfmt(space.w_NotImplementedError,
- "ctype '%s' (size %d) not supported as %s",
- self.name, self.size, place)
+ raise oefmt(space.w_NotImplementedError,
+ "ctype '%s' (size %d) not supported as %s",
+ self.name, self.size, place)
def _struct_ffi_type(self, cifbuilder, is_result_type):
if self.size >= 0:
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -1,5 +1,5 @@
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr, GetSetProperty
@@ -54,34 +54,31 @@
def newp(self, w_init):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "expected a pointer or array ctype, got '%s'",
- self.name)
+ raise oefmt(space.w_TypeError,
+ "expected a pointer or array ctype, got '%s'", self.name)
def cast(self, w_ob):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "cannot cast to '%s'", self.name)
+ raise oefmt(space.w_TypeError, "cannot cast to '%s'", self.name)
def cast_to_int(self, cdata):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "int() not supported on cdata '%s'", self.name)
+ raise oefmt(space.w_TypeError, "int() not supported on cdata '%s'",
+ self.name)
def float(self, cdata):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "float() not supported on cdata '%s'", self.name)
+ raise oefmt(space.w_TypeError, "float() not supported on cdata '%s'",
+ self.name)
def convert_to_object(self, cdata):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "cannot return a cdata '%s'", self.name)
+ raise oefmt(space.w_TypeError, "cannot return a cdata '%s'", self.name)
def convert_from_object(self, cdata, w_ob):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "cannot initialize cdata '%s'", self.name)
+ raise oefmt(space.w_TypeError, "cannot initialize cdata '%s'",
+ self.name)
def convert_argument_from_object(self, cdata, w_ob):
self.convert_from_object(cdata, w_ob)
@@ -90,20 +87,18 @@
def _convert_error(self, expected, w_got):
space = self.space
if isinstance(w_got, cdataobj.W_CData):
- return operationerrfmt(space.w_TypeError,
- "initializer for ctype '%s' must be a %s, "
- "not cdata '%s'", self.name, expected,
- w_got.ctype.name)
+ return oefmt(space.w_TypeError,
+ "initializer for ctype '%s' must be a %s, not cdata "
+ "'%s'", self.name, expected, w_got.ctype.name)
else:
- return operationerrfmt(space.w_TypeError,
- "initializer for ctype '%s' must be a %s, "
- "not %T", self.name, expected, w_got)
+ return oefmt(space.w_TypeError,
+ "initializer for ctype '%s' must be a %s, not %T",
+ self.name, expected, w_got)
def _cannot_index(self):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "cdata of type '%s' cannot be indexed",
- self.name)
+ raise oefmt(space.w_TypeError, "cdata of type '%s' cannot be indexed",
+ self.name)
def _check_subscript_index(self, w_cdata, i):
raise self._cannot_index()
@@ -113,15 +108,13 @@
def string(self, cdataobj, maxlen):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "string(): unexpected cdata '%s' argument",
- self.name)
+ raise oefmt(space.w_TypeError,
+ "string(): unexpected cdata '%s' argument", self.name)
def add(self, cdata, i):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "cannot add a cdata '%s' and a number",
- self.name)
+ raise oefmt(space.w_TypeError, "cannot add a cdata '%s' and a number",
+ self.name)
def insert_name(self, extra, extra_position):
name = '%s%s%s' % (self.name[:self.name_position],
@@ -144,9 +137,8 @@
def _alignof(self):
space = self.space
- raise operationerrfmt(space.w_ValueError,
- "ctype '%s' is of unknown alignment",
- self.name)
+ raise oefmt(space.w_ValueError, "ctype '%s' is of unknown alignment",
+ self.name)
def typeoffsetof(self, fieldname):
space = self.space
@@ -163,14 +155,12 @@
def call(self, funcaddr, args_w):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "cdata '%s' is not callable", self.name)
+ raise oefmt(space.w_TypeError, "cdata '%s' is not callable", self.name)
def iter(self, cdata):
space = self.space
- raise operationerrfmt(space.w_TypeError,
- "cdata '%s' does not support iteration",
- self.name)
+ raise oefmt(space.w_TypeError,
+ "cdata '%s' does not support iteration", self.name)
def unpackiterable_int(self, cdata):
return None
@@ -180,9 +170,8 @@
def getcfield(self, attr):
space = self.space
- raise operationerrfmt(space.w_AttributeError,
- "cdata '%s' has no attribute '%s'",
- self.name, attr)
+ raise oefmt(space.w_AttributeError,
+ "cdata '%s' has no attribute '%s'", self.name, attr)
def copy_and_convert_to_object(self, cdata):
return self.convert_to_object(cdata)
@@ -202,9 +191,8 @@
return space.wrap(self.kind) # class attribute
if attrchar == 'c': # cname
return space.wrap(self.name)
- raise operationerrfmt(space.w_AttributeError,
- "ctype '%s' has no such attribute",
- self.name)
+ raise oefmt(space.w_AttributeError,
+ "ctype '%s' has no such attribute", self.name)
def fget_kind(self, space): return self._fget('k')
def fget_cname(self, space): return self._fget('c')
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -3,13 +3,13 @@
"""
import sys
-from pypy.interpreter.error import operationerrfmt
from rpython.rlib.rarithmetic import r_uint, r_ulonglong, intmask
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib import jit
from rpython.rtyper.lltypesystem import lltype, rffi
+from pypy.interpreter.error import oefmt
from pypy.module._cffi_backend import cdataobj, misc
from pypy.module._cffi_backend.ctypeobj import W_CType
@@ -34,18 +34,18 @@
space = self.space
s = space.str_w(w_ob)
if len(s) != 1:
- raise operationerrfmt(space.w_TypeError,
- "cannot cast string of length %d to ctype '%s'",
- len(s), self.name)
+ raise oefmt(space.w_TypeError,
+ "cannot cast string of length %d to ctype '%s'",
+ len(s), self.name)
return ord(s[0])
def cast_unicode(self, w_ob):
space = self.space
s = space.unicode_w(w_ob)
if len(s) != 1:
- raise operationerrfmt(space.w_TypeError,
- "cannot cast unicode string of length %d to ctype '%s'",
- len(s), self.name)
+ raise oefmt(space.w_TypeError,
+ "cannot cast unicode string of length %d to ctype '%s'",
+ len(s), self.name)
return ord(s[0])
def cast(self, w_ob):
@@ -76,8 +76,8 @@
def _overflow(self, w_ob):
space = self.space
s = space.str_w(space.str(w_ob))
- raise operationerrfmt(space.w_OverflowError,
- "integer %s does not fit '%s'", s, self.name)
+ raise oefmt(space.w_OverflowError,
+ "integer %s does not fit '%s'", s, self.name)
def string(self, cdataobj, maxlen):
if self.size == 1:
@@ -330,9 +330,9 @@
space = self.space
if isinstance(w_ob, cdataobj.W_CData):
if not isinstance(w_ob.ctype, W_CTypePrimitive):
- raise operationerrfmt(space.w_TypeError,
- "cannot cast ctype '%s' to ctype '%s'",
- w_ob.ctype.name, self.name)
+ raise oefmt(space.w_TypeError,
+ "cannot cast ctype '%s' to ctype '%s'",
+ w_ob.ctype.name, self.name)
w_ob = w_ob.convert_to_object()
#
if space.isinstance_w(w_ob, space.w_str):
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -9,7 +9,7 @@
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw, copy_unicode_to_raw
-from pypy.interpreter.error import OperationError, operationerrfmt, wrap_oserror
+from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
from pypy.module._cffi_backend import cdataobj, misc, ctypeprim, ctypevoid
from pypy.module._cffi_backend.ctypeobj import W_CType
@@ -62,9 +62,9 @@
space = self.space
lst_w = space.listview(w_ob)
if self.length >= 0 and len(lst_w) > self.length:
- raise operationerrfmt(space.w_IndexError,
- "too many initializers for '%s' (got %d)",
- self.name, len(lst_w))
+ raise oefmt(space.w_IndexError,
+ "too many initializers for '%s' (got %d)",
+ self.name, len(lst_w))
ctitem = self.ctitem
for i in range(len(lst_w)):
ctitem.convert_from_object(cdata, lst_w[i])
@@ -83,10 +83,9 @@
s = space.str_w(w_ob)
n = len(s)
if self.length >= 0 and n > self.length:
- raise operationerrfmt(space.w_IndexError,
- "initializer string is too long for '%s'"
- " (got %d characters)",
- self.name, n)
+ raise oefmt(space.w_IndexError,
+ "initializer string is too long for '%s' (got %d "
+ "characters)", self.name, n)
copy_string_to_raw(llstr(s), cdata, 0, n)
if n != self.length:
cdata[n] = '\x00'
@@ -96,10 +95,9 @@
s = space.unicode_w(w_ob)
n = len(s)
if self.length >= 0 and n > self.length:
- raise operationerrfmt(space.w_IndexError,
- "initializer unicode string is too long for '%s'"
- " (got %d characters)",
- self.name, n)
+ raise oefmt(space.w_IndexError,
+ "initializer unicode string is too long for '%s' "
+ "(got %d characters)", self.name, n)
unichardata = rffi.cast(rffi.CWCHARP, cdata)
copy_unicode_to_raw(llunicode(s), unichardata, 0, n)
if n != self.length:
@@ -112,9 +110,8 @@
if isinstance(self.ctitem, ctypeprim.W_CTypePrimitive):
cdata = cdataobj._cdata
if not cdata:
- raise operationerrfmt(space.w_RuntimeError,
- "cannot use string() on %s",
- space.str_w(cdataobj.repr()))
+ raise oefmt(space.w_RuntimeError, "cannot use string() on %s",
+ space.str_w(cdataobj.repr()))
#
from pypy.module._cffi_backend import ctypearray
length = maxlen
@@ -196,9 +193,9 @@
ctitem = self.ctitem
datasize = ctitem.size
if datasize < 0:
- raise operationerrfmt(space.w_TypeError,
- "cannot instantiate ctype '%s' of unknown size",
- self.name)
+ raise oefmt(space.w_TypeError,
+ "cannot instantiate ctype '%s' of unknown size",
+ self.name)
if isinstance(ctitem, W_CTypeStructOrUnion):
# 'newp' on a struct-or-union pointer: in this case, we return
# a W_CDataPtrToStruct object which has a strong reference
@@ -227,9 +224,8 @@
isinstance(w_cdata, cdataobj.W_CDataPtrToStructOrUnion)):
if i != 0:
space = self.space
- raise operationerrfmt(space.w_IndexError,
- "cdata '%s' can only be indexed by 0",
- self.name)
+ raise oefmt(space.w_IndexError,
+ "cdata '%s' can only be indexed by 0", self.name)
return self
def _check_slice_index(self, w_cdata, start, stop):
@@ -243,9 +239,9 @@
if self.is_void_ptr:
itemsize = 1
else:
- raise operationerrfmt(space.w_TypeError,
- "ctype '%s' points to items of unknown size",
- self.name)
+ raise oefmt(space.w_TypeError,
+ "ctype '%s' points to items of unknown size",
+ self.name)
p = rffi.ptradd(cdata, i * itemsize)
return cdataobj.W_CData(space, p, self)
diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py
--- a/pypy/module/_cffi_backend/ctypestruct.py
+++ b/pypy/module/_cffi_backend/ctypestruct.py
@@ -2,8 +2,8 @@
Struct and unions.
"""
-from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import TypeDef, interp_attrproperty
from rpython.rlib import jit
@@ -32,8 +32,8 @@
def check_complete(self, w_errorcls=None):
if self.fields_dict is None:
space = self.space
- raise operationerrfmt(w_errorcls or space.w_TypeError,
- "'%s' is opaque or not completed yet", self.name)
+ raise oefmt(w_errorcls or space.w_TypeError,
+ "'%s' is opaque or not completed yet", self.name)
def _alignof(self):
self.check_complete(w_errorcls=self.space.w_ValueError)
@@ -106,9 +106,9 @@
space.isinstance_w(w_ob, space.w_tuple)):
lst_w = space.listview(w_ob)
if len(lst_w) > len(self.fields_list):
- raise operationerrfmt(space.w_ValueError,
- "too many initializers for '%s' (got %d)",
- self.name, len(lst_w))
+ raise oefmt(space.w_ValueError,
+ "too many initializers for '%s' (got %d)",
+ self.name, len(lst_w))
for i in range(len(lst_w)):
optvarsize = self.fields_list[i].write_v(cdata, lst_w[i],
optvarsize)
@@ -161,10 +161,9 @@
space = self.space
n = space.int_w(space.len(w_ob))
if n > 1:
- raise operationerrfmt(space.w_ValueError,
- "initializer for '%s': %d items given, but "
- "only one supported (use a dict if needed)",
- self.name, n)
+ raise oefmt(space.w_ValueError,
+ "initializer for '%s': %d items given, but only one "
+ "supported (use a dict if needed)", self.name, n)
class W_CField(W_Root):
@@ -295,10 +294,9 @@
fmin = r_longlong(0)
fmax = r_longlong((r_ulonglong(1) << self.bitsize) - 1)
if value < fmin or value > fmax:
- raise operationerrfmt(space.w_OverflowError,
- "value %d outside the range allowed by the "
- "bit field width: %d <= x <= %d",
- value, fmin, fmax)
+ raise oefmt(space.w_OverflowError,
+ "value %d outside the range allowed by the bit field "
+ "width: %d <= x <= %d", value, fmin, fmax)
rawmask = ((r_ulonglong(1) << self.bitsize) - 1) << self.bitshift
rawvalue = r_ulonglong(value) << self.bitshift
rawfielddata = misc.read_raw_unsigned_data(cdata, ctype.size)
diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py
--- a/pypy/module/_cffi_backend/func.py
+++ b/pypy/module/_cffi_backend/func.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
from pypy.module._cffi_backend import ctypeobj, cdataobj
@@ -36,9 +36,8 @@
elif isinstance(w_obj, ctypeobj.W_CType):
size = w_obj.size
if size < 0:
- raise operationerrfmt(space.w_ValueError,
- "ctype '%s' is of unknown size",
- w_obj.name)
+ raise oefmt(space.w_ValueError,
+ "ctype '%s' is of unknown size", w_obj.name)
else:
raise OperationError(space.w_TypeError,
space.wrap("expected a 'cdata' or 'ctype' object"))
diff --git a/pypy/module/_cffi_backend/handle.py b/pypy/module/_cffi_backend/handle.py
--- a/pypy/module/_cffi_backend/handle.py
+++ b/pypy/module/_cffi_backend/handle.py
@@ -1,5 +1,5 @@
import weakref
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import unwrap_spec
from pypy.module._cffi_backend import ctypeobj, ctypeptr, cdataobj
from rpython.rtyper.lltypesystem import lltype, rffi
@@ -19,8 +19,8 @@
def newp_handle(space, w_ctype, w_x):
if (not isinstance(w_ctype, ctypeptr.W_CTypePointer) or
not w_ctype.is_void_ptr):
- raise operationerrfmt(space.w_TypeError,
- "needs 'void *', got '%s'", w_ctype.name)
+ raise oefmt(space.w_TypeError,
+ "needs 'void *', got '%s'", w_ctype.name)
index = get(space).reserve_next_handle_index()
_cdata = rffi.cast(rffi.CCHARP, index + 1)
new_cdataobj = cdataobj.W_CDataHandle(space, _cdata, w_ctype, w_x)
@@ -32,9 +32,9 @@
ctype = w_cdata.ctype
if (not isinstance(ctype, ctypeptr.W_CTypePtrOrArray) or
not ctype.can_cast_anything):
- raise operationerrfmt(space.w_TypeError,
- "expected a 'cdata' object with a 'void *' out "
- "of new_handle(), got '%s'", ctype.name)
+ raise oefmt(space.w_TypeError,
+ "expected a 'cdata' object with a 'void *' out of "
+ "new_handle(), got '%s'", ctype.name)
index = rffi.cast(lltype.Signed, w_cdata._cdata)
original_cdataobj = get(space).fetch_handle(index - 1)
#
diff --git a/pypy/module/_cffi_backend/libraryobj.py b/pypy/module/_cffi_backend/libraryobj.py
--- a/pypy/module/_cffi_backend/libraryobj.py
+++ b/pypy/module/_cffi_backend/libraryobj.py
@@ -1,7 +1,7 @@
from __future__ import with_statement
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import operationerrfmt
+from pypy.interpreter.error import oefmt
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef
from pypy.module._rawffi.interp_rawffi import wrap_dlopenerror
@@ -50,16 +50,15 @@
isinstance(w_ctype.ctitem, ctypevoid.W_CTypeVoid)):
ok = True
if not ok:
- raise operationerrfmt(space.w_TypeError,
- "function cdata expected, got '%s'",
- w_ctype.name)
+ raise oefmt(space.w_TypeError,
+ "function cdata expected, got '%s'", w_ctype.name)
#
try:
cdata = dlsym(self.handle, name)
except KeyError:
- raise operationerrfmt(space.w_KeyError,
- "function '%s' not found in library '%s'",
- name, self.name)
+ raise oefmt(space.w_KeyError,
+ "function '%s' not found in library '%s'",
+ name, self.name)
return W_CData(space, rffi.cast(rffi.CCHARP, cdata), w_ctype)
@unwrap_spec(w_ctype=W_CType, name=str)
@@ -68,9 +67,9 @@
try:
cdata = dlsym(self.handle, name)
except KeyError:
- raise operationerrfmt(space.w_KeyError,
- "variable '%s' not found in library '%s'",
- name, self.name)
+ raise oefmt(space.w_KeyError,
+ "variable '%s' not found in library '%s'",
+ name, self.name)
return w_ctype.convert_to_object(rffi.cast(rffi.CCHARP, cdata))
@unwrap_spec(w_ctype=W_CType, name=str)
@@ -79,9 +78,9 @@
try:
cdata = dlsym(self.handle, name)
except KeyError:
- raise operationerrfmt(space.w_KeyError,
- "variable '%s' not found in library '%s'",
- name, self.name)
+ raise oefmt(space.w_KeyError,
+ "variable '%s' not found in library '%s'",
+ name, self.name)
w_ctype.convert_from_object(rffi.cast(rffi.CCHARP, cdata), w_value)
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -1,5 +1,5 @@
import sys
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import unwrap_spec
from rpython.rlib.objectmodel import specialize
@@ -91,9 +91,8 @@
space.wrap("first arg must be a pointer ctype"))
ctitem = w_ctptr.ctitem
if ctitem.size < 0:
- raise operationerrfmt(space.w_ValueError,
- "array item of unknown size: '%s'",
- ctitem.name)
+ raise oefmt(space.w_ValueError, "array item of unknown size: '%s'",
+ ctitem.name)
if space.is_w(w_length, space.w_None):
length = -1
arraysize = -1
@@ -175,17 +174,16 @@
if len(field_w) > 3: foffset = space.int_w(field_w[3])
#
if fname in fields_dict:
- raise operationerrfmt(space.w_KeyError,
- "duplicate field name '%s'", fname)
+ raise oefmt(space.w_KeyError, "duplicate field name '%s'", fname)
#
if ftype.size < 0:
if (isinstance(ftype, ctypearray.W_CTypeArray) and fbitsize < 0
and (i == len(fields_w) - 1 or foffset != -1)):
with_var_array = True
else:
- raise operationerrfmt(space.w_TypeError,
- "field '%s.%s' has ctype '%s' of unknown size",
- w_ctype.name, fname, ftype.name)
+ raise oefmt(space.w_TypeError,
+ "field '%s.%s' has ctype '%s' of unknown size",
+ w_ctype.name, fname, ftype.name)
#
if is_union:
boffset = 0 # reset each field at offset 0
@@ -250,24 +248,21 @@
# this is the case of a bitfield
if foffset >= 0:
- raise operationerrfmt(space.w_TypeError,
- "field '%s.%s' is a bitfield, "
- "but a fixed offset is specified",
- w_ctype.name, fname)
+ raise oefmt(space.w_TypeError,
+ "field '%s.%s' is a bitfield, but a fixed offset "
+ "is specified", w_ctype.name, fname)
if not (isinstance(ftype, ctypeprim.W_CTypePrimitiveSigned) or
isinstance(ftype, ctypeprim.W_CTypePrimitiveUnsigned) or
isinstance(ftype,ctypeprim.W_CTypePrimitiveCharOrUniChar)):
- raise operationerrfmt(space.w_TypeError,
- "field '%s.%s' declared as '%s' "
- "cannot be a bit field",
- w_ctype.name, fname, ftype.name)
+ raise oefmt(space.w_TypeError,
+ "field '%s.%s' declared as '%s' cannot be a bit "
+ "field", w_ctype.name, fname, ftype.name)
if fbitsize > 8 * ftype.size:
- raise operationerrfmt(space.w_TypeError,
- "bit field '%s.%s' is declared '%s:%d',"
- " which exceeds the width of the type",
- w_ctype.name, fname,
- ftype.name, fbitsize)
+ raise oefmt(space.w_TypeError,
+ "bit field '%s.%s' is declared '%s:%d', which "
+ "exceeds the width of the type",
+ w_ctype.name, fname, ftype.name, fbitsize)
# compute the starting position of the theoretical field
# that covers a complete 'ftype', inside of which we will
@@ -277,9 +272,9 @@
if fbitsize == 0:
if fname != '':
- raise operationerrfmt(space.w_TypeError,
- "field '%s.%s' is declared with :0",
- w_ctype.name, fname)
+ raise oefmt(space.w_TypeError,
+ "field '%s.%s' is declared with :0",
+ w_ctype.name, fname)
if (sflags & SF_MSVC_BITFIELDS) == 0:
# GCC's notion of "ftype :0;"
# pad boffset to a value aligned for "ftype"
@@ -308,10 +303,11 @@
# allowed position
if ((sflags & SF_PACKED) != 0 and
(bits_already_occupied & 7) != 0):
- raise operationerrfmt(space.w_NotImplementedError,
- "with 'packed', gcc would compile field "
- "'%s.%s' to reuse some bits in the previous "
- "field", w_ctype.name, fname)
+ raise oefmt(space.w_NotImplementedError,
+ "with 'packed', gcc would compile "
+ "field '%s.%s' to reuse some bits in "
+ "the previous field",
+ w_ctype.name, fname)
field_offset_bytes += falign
assert boffset < field_offset_bytes * 8
boffset = field_offset_bytes * 8
@@ -362,9 +358,9 @@
totalsize = (got + alignment - 1) & ~(alignment - 1)
totalsize = totalsize or 1
elif totalsize < got:
- raise operationerrfmt(space.w_TypeError,
- "%s cannot be of size %d: there are fields at least "
- "up to %d", w_ctype.name, totalsize, got)
+ raise oefmt(space.w_TypeError,
+ "%s cannot be of size %d: there are fields at least up to "
+ "%d", w_ctype.name, totalsize, got)
if totalalignment < 0:
totalalignment = alignment
@@ -436,11 +432,11 @@
or isinstance(w_fresult, ctypearray.W_CTypeArray)):
if (isinstance(w_fresult, ctypestruct.W_CTypeStructOrUnion) and
w_fresult.size < 0):
- raise operationerrfmt(space.w_TypeError,
- "result type '%s' is opaque", w_fresult.name)
+ raise oefmt(space.w_TypeError,
+ "result type '%s' is opaque", w_fresult.name)
else:
- raise operationerrfmt(space.w_TypeError,
- "invalid result type: '%s'", w_fresult.name)
+ raise oefmt(space.w_TypeError,
+ "invalid result type: '%s'", w_fresult.name)
#
fct = ctypefunc.W_CTypeFunc(space, fargs, w_fresult, ellipsis)
return fct
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -2,7 +2,7 @@
from rpython.rlib.objectmodel import we_are_translated
from rpython.rlib.rstring import UnicodeBuilder
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
@@ -56,15 +56,15 @@
else:
msg = ("encoding error handler must return "
"(unicode, int) tuple, not %R")
- raise operationerrfmt(space.w_TypeError, msg, w_res)
+ raise oefmt(space.w_TypeError, msg, w_res)
w_replace, w_newpos = space.fixedview(w_res, 2)
newpos = space.int_w(w_newpos)
if newpos < 0:
newpos = len(input) + newpos
if newpos < 0 or newpos > len(input):
- raise operationerrfmt(
- space.w_IndexError,
- "position %d from error handler out of bounds", newpos)
+ raise oefmt(space.w_IndexError,
+ "position %d from error handler out of bounds",
+ newpos)
replace = space.unicode_w(w_replace)
return replace, newpos
return call_errorhandler
@@ -164,9 +164,7 @@
state.codec_search_cache[normalized_encoding] = w_result
state.modified()
return w_result
- raise operationerrfmt(
- space.w_LookupError,
- "unknown encoding: %s", encoding)
+ raise oefmt(space.w_LookupError, "unknown encoding: %s", encoding)
# ____________________________________________________________
# Register standard error handlers
@@ -216,8 +214,8 @@
text = u'\ufffd' * size
return space.newtuple([space.wrap(text), w_end])
else:
- raise operationerrfmt(space.w_TypeError,
- "don't know how to handle %T in error callback", w_exc)
+ raise oefmt(space.w_TypeError,
+ "don't know how to handle %T in error callback", w_exc)
def xmlcharrefreplace_errors(space, w_exc):
check_exception(space, w_exc)
@@ -236,8 +234,8 @@
pos += 1
return space.newtuple([space.wrap(builder.build()), w_end])
else:
- raise operationerrfmt(space.w_TypeError,
- "don't know how to handle %T in error callback", w_exc)
+ raise oefmt(space.w_TypeError,
+ "don't know how to handle %T in error callback", w_exc)
def backslashreplace_errors(space, w_exc):
check_exception(space, w_exc)
@@ -268,8 +266,8 @@
pos += 1
return space.newtuple([space.wrap(builder.build()), w_end])
else:
- raise operationerrfmt(space.w_TypeError,
- "don't know how to handle %T in error callback", w_exc)
+ raise oefmt(space.w_TypeError,
+ "don't know how to handle %T in error callback", w_exc)
def register_builtin_error_handlers(space):
"NOT_RPYTHON"
@@ -292,9 +290,8 @@
try:
w_err_handler = state.codec_error_registry[errors]
except KeyError:
- raise operationerrfmt(
- space.w_LookupError,
- "unknown error handler name %s", errors)
+ raise oefmt(space.w_LookupError,
+ "unknown error handler name %s", errors)
return w_err_handler
diff --git a/pypy/module/_csv/interp_csv.py b/pypy/module/_csv/interp_csv.py
--- a/pypy/module/_csv/interp_csv.py
+++ b/pypy/module/_csv/interp_csv.py
@@ -1,5 +1,5 @@
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import TypeDef, interp_attrproperty
from pypy.interpreter.typedef import GetSetProperty
from pypy.interpreter.gateway import interp2app
@@ -49,8 +49,7 @@
return src[0]
if len(src) == 0:
return '\0'
- raise operationerrfmt(space.w_TypeError,
- '"%s" must be a 1-character string', name)
+ raise oefmt(space.w_TypeError, '"%s" must be a 1-character string', name)
def _build_dialect(space, w_dialect, w_delimiter, w_doublequote,
w_escapechar, w_lineterminator, w_quotechar, w_quoting,
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -7,7 +7,7 @@
from rpython.rlib.rstring import StringBuilder
from pypy.module._file.interp_stream import W_AbstractStream, StreamErrors
from pypy.module.posix.interp_posix import dispatch_filename
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import (TypeDef, GetSetProperty,
interp_attrproperty, make_weakref_descr, interp_attrproperty_w)
from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -79,8 +79,7 @@
if (not mode or mode[0] not in ['r', 'w', 'a', 'U'] or
('U' in mode and ('w' in mode or 'a' in mode))):
space = self.space
- raise operationerrfmt(space.w_ValueError,
- "invalid mode: '%s'", mode)
+ raise oefmt(space.w_ValueError, "invalid mode: '%s'", mode)
def check_closed(self):
if self.stream is None:
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
@@ -1,8 +1,9 @@
from __future__ import with_statement
+
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import (
TypeDef, GetSetProperty, generic_new_descr, interp_attrproperty_w)
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.buffer import RWBuffer
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.rarithmetic import r_longlong, intmask
@@ -257,8 +258,8 @@
def seek_w(self, space, pos, whence=0):
self._check_init(space)
if whence not in (0, 1, 2):
- raise operationerrfmt(space.w_ValueError,
- "whence must be between 0 and 2, not %d", whence)
+ raise oefmt(space.w_ValueError,
+ "whence must be between 0 and 2, not %d", whence)
self._check_closed(space, "seek of closed file")
if whence != 2 and self.readable:
# Check if seeking leaves us inside the current buffer, so as to
diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -1,7 +1,7 @@
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import (
TypeDef, generic_new_descr, GetSetProperty)
from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.error import OperationError, operationerrfmt
from rpython.rlib.rStringIO import RStringIO
from rpython.rlib.rarithmetic import r_longlong
from pypy.module._io.interp_bufferedio import W_BufferedIOBase
@@ -105,8 +105,8 @@
raise OperationError(space.w_OverflowError, space.wrap(
"new position too large"))
else:
- raise operationerrfmt(space.w_ValueError,
- "whence must be between 0 and 2, not %d", whence)
+ raise oefmt(space.w_ValueError,
+ "whence must be between 0 and 2, not %d", whence)
self.seek(pos, whence)
return space.wrap(self.tell())
@@ -137,9 +137,9 @@
self._check_closed(space)
if space.len_w(w_state) != 3:
- raise operationerrfmt(space.w_TypeError,
- "%T.__setstate__ argument should be 3-tuple, got %T",
- self, w_state)
+ raise oefmt(space.w_TypeError,
+ "%T.__setstate__ argument should be 3-tuple, got %T",
+ self, w_state)
w_content, w_pos, w_dict = space.unpackiterable(w_state, 3)
self.truncate(0)
self.write_w(space, w_content)
diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -1,6 +1,6 @@
import os
-from pypy.interpreter.error import operationerrfmt, OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import (
TypeDef, interp_attrproperty, generic_new_descr)
@@ -42,7 +42,7 @@
if not (space.isinstance_w(w_file, space.w_basestring) or
space.isinstance_w(w_file, space.w_int) or
space.isinstance_w(w_file, space.w_long)):
- raise operationerrfmt(space.w_TypeError, "invalid file: %R", w_file)
+ raise oefmt(space.w_TypeError, "invalid file: %R", w_file)
reading = writing = appending = updating = text = binary = universal = False
@@ -50,9 +50,7 @@
for flag in mode:
uniq_mode[flag] = None
if len(uniq_mode) != len(mode):
- raise operationerrfmt(space.w_ValueError,
- "invalid mode: %s", mode
- )
+ raise oefmt(space.w_ValueError, "invalid mode: %s", mode)
for flag in mode:
if flag == "r":
reading = True
@@ -70,9 +68,7 @@
universal = True
reading = True
else:
- raise operationerrfmt(space.w_ValueError,
- "invalid mode: %s", mode
- )
+ raise oefmt(space.w_ValueError, "invalid mode: %s", mode)
rawmode = ""
if reading:
@@ -146,7 +142,7 @@
elif reading:
buffer_cls = W_BufferedReader
else:
- raise operationerrfmt(space.w_ValueError, "unknown mode: '%s'", mode)
+ raise oefmt(space.w_ValueError, "unknown mode: '%s'", mode)
w_buffer = space.call_function(
space.gettypefor(buffer_cls), w_raw, space.wrap(buffering)
)
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
@@ -1,9 +1,9 @@
from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import (
TypeDef, GetSetProperty, generic_new_descr, descr_get_dict, descr_set_dict,
make_weakref_descr)
from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.error import OperationError, operationerrfmt
from rpython.rlib.rstring import StringBuilder
from rpython.rlib import rweakref, rweaklist
@@ -180,10 +180,9 @@
if has_peek:
w_readahead = space.call_method(self, "peek", space.wrap(1))
if not space.isinstance_w(w_readahead, space.w_str):
- raise operationerrfmt(
- space.w_IOError,
- "peek() should have returned a bytes object, not '%T'",
- w_readahead)
+ raise oefmt(space.w_IOError,
+ "peek() should have returned a bytes object, "
+ "not '%T'", w_readahead)
length = space.len_w(w_readahead)
if length > 0:
n = 0
@@ -206,10 +205,9 @@
w_read = space.call_method(self, "read", space.wrap(nreadahead))
if not space.isinstance_w(w_read, space.w_str):
- raise operationerrfmt(
- space.w_IOError,
- "peek() should have returned a bytes object, not '%T'",
- w_read)
+ raise oefmt(space.w_IOError,
+ "peek() should have returned a bytes object, not "
+ "'%T'", w_read)
read = space.str_w(w_read)
if not read:
break
diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -1,7 +1,7 @@
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import (
TypeDef, generic_new_descr, GetSetProperty)
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.module._io.interp_textio import W_TextIOBase, W_IncrementalNewlineDecoder
from pypy.module._io.interp_iobase import convert_size
More information about the pypy-commit
mailing list