Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r84158:72ab4cdc6bd2 Date: 2016-05-02 17:47 -0700 http://bitbucket.org/pypy/pypy/changeset/72ab4cdc6bd2/
Log: merge default (oefmt pypy/module/_*) diff too long, truncating to 2000 out of 2441 lines diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py --- a/pypy/module/__builtin__/compiling.py +++ b/pypy/module/__builtin__/compiling.py @@ -3,7 +3,7 @@ """ from pypy.interpreter.pycode import PyCode -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.astcompiler import consts, ast from pypy.interpreter.gateway import unwrap_spec from pypy.interpreter.argument import Arguments @@ -30,8 +30,7 @@ if flags & ~(ec.compiler.compiler_flags | consts.PyCF_ONLY_AST | consts.PyCF_DONT_IMPLY_DEDENT | consts.PyCF_SOURCE_IS_UTF8 | consts.PyCF_ACCEPT_NULL_BYTES): - raise OperationError(space.w_ValueError, - space.wrap("compile() unrecognized flags")) + raise oefmt(space.w_ValueError, "compile() unrecognized flags") if not dont_inherit: caller = ec.gettopframe_nohidden() @@ -39,9 +38,8 @@ flags |= ec.compiler.getcodeflags(caller.getcode()) if mode not in ('exec', 'eval', 'single'): - raise OperationError( - space.w_ValueError, - space.wrap("compile() arg 3 must be 'exec', 'eval' or 'single'")) + raise oefmt(space.w_ValueError, + "compile() arg 3 must be 'exec', 'eval' or 'single'") if space.isinstance_w(w_source, space.gettypeobject(ast.W_AST.typedef)): ast_node = ast.mod.from_object(space, w_source) diff --git a/pypy/module/__builtin__/descriptor.py b/pypy/module/__builtin__/descriptor.py --- a/pypy/module/__builtin__/descriptor.py +++ b/pypy/module/__builtin__/descriptor.py @@ -1,5 +1,5 @@ from pypy.interpreter.baseobjspace import W_Root -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.function import StaticMethod, ClassMethod from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault from pypy.interpreter.typedef import ( @@ -100,9 +100,9 @@ raise w_type = w_objtype if not space.is_true(space.issubtype(w_type, w_starttype)): - raise OperationError(space.w_TypeError, - space.wrap("super(type, obj): " - "obj must be an instance or subtype of type")) + raise oefmt(space.w_TypeError, + "super(type, obj): obj must be an instance or " + "subtype of type") # XXX the details of how allocate_instance() should be used are not # really well defined w_result = space.allocate_instance(W_Super, w_subtype) @@ -159,21 +159,18 @@ if space.is_w(w_obj, space.w_None): return space.wrap(self) if space.is_w(self.w_fget, space.w_None): - raise OperationError(space.w_AttributeError, space.wrap( - "unreadable attribute")) + raise oefmt(space.w_AttributeError, "unreadable attribute") return space.call_function(self.w_fget, w_obj) def set(self, space, w_obj, w_value): if space.is_w(self.w_fset, space.w_None): - raise OperationError(space.w_AttributeError, space.wrap( - "can't set attribute")) + raise oefmt(space.w_AttributeError, "can't set attribute") space.call_function(self.w_fset, w_obj, w_value) return space.w_None def delete(self, space, w_obj): if space.is_w(self.w_fdel, space.w_None): - raise OperationError(space.w_AttributeError, space.wrap( - "can't delete attribute")) + raise oefmt(space.w_AttributeError, "can't delete attribute") space.call_function(self.w_fdel, w_obj) return space.w_None diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -61,8 +61,7 @@ else: w_step = space.index(w_slice.w_step) if space.is_true(space.eq(w_step, w_0)): - raise OperationError(space.w_ValueError, - space.wrap("slice step cannot be zero")) + raise oefmt(space.w_ValueError, "slice step cannot be zero") negative_step = space.is_true(space.lt(w_step, w_0)) if space.is_w(w_slice.w_start, space.w_None): if negative_step: @@ -124,16 +123,18 @@ elif len(args_w): w_sequence = args_w[0] else: - msg = "%s() expects at least one argument" % (implementation_of,) - raise OperationError(space.w_TypeError, space.wrap(msg)) + raise oefmt(space.w_TypeError, + "%s() expects at least one argument", + implementation_of) w_key = None kwds = args.keywords if kwds: if kwds[0] == "key" and len(kwds) == 1: w_key = args.keywords_w[0] else: - msg = "%s() got unexpected keyword argument" % (implementation_of,) - raise OperationError(space.w_TypeError, space.wrap(msg)) + raise oefmt(space.w_TypeError, + "%s() got unexpected keyword argument", + implementation_of) w_iter = space.iter(w_sequence) w_type = space.type(w_iter) @@ -160,8 +161,7 @@ w_max_item = w_item w_max_val = w_compare_with if w_max_item is None: - msg = "arg is an empty sequence" - raise OperationError(space.w_ValueError, space.wrap(msg)) + raise oefmt(space.w_ValueError, "arg is an empty sequence") return w_max_item if unroll: min_max_impl = jit.unroll_safe(min_max_impl) @@ -297,8 +297,8 @@ def __init__(self, space, w_sequence): self.remaining = space.len_w(w_sequence) - 1 if space.lookup(w_sequence, "__getitem__") is None: - msg = "reversed() argument must be a sequence" - raise OperationError(space.w_TypeError, space.wrap(msg)) + raise oefmt(space.w_TypeError, + "reversed() argument must be a sequence") self.w_sequence = w_sequence @staticmethod @@ -419,8 +419,7 @@ w_index = space.add(w_index, self.w_length) if (space.is_true(space.ge(w_index, self.w_length)) or space.is_true(space.lt(w_index, w_zero))): - raise OperationError(space.w_IndexError, space.wrap( - "range object index out of range")) + raise oefmt(space.w_IndexError, "range object index out of range") return self._compute_item0(space, w_index) def _compute_slice(self, space, w_slice): diff --git a/pypy/module/__builtin__/operation.py b/pypy/module/__builtin__/operation.py --- a/pypy/module/__builtin__/operation.py +++ b/pypy/module/__builtin__/operation.py @@ -28,8 +28,7 @@ try: c = UNICHR(code) except ValueError: - raise OperationError(space.w_ValueError, - space.wrap("chr() arg out of range")) + raise oefmt(space.w_ValueError, "chr() arg out of range") return space.wrap(c) def len(space, w_obj): diff --git a/pypy/module/__pypy__/interp_builders.py b/pypy/module/__pypy__/interp_builders.py --- a/pypy/module/__pypy__/interp_builders.py +++ b/pypy/module/__pypy__/interp_builders.py @@ -1,5 +1,5 @@ from pypy.interpreter.baseobjspace import W_Root -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import oefmt from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef from rpython.rlib.rstring import UnicodeBuilder, StringBuilder @@ -16,8 +16,8 @@ def _check_done(self, space): if self.builder is None: - raise OperationError(space.w_ValueError, space.wrap( - "Can't operate on a built builder")) + raise oefmt(space.w_ValueError, + "Can't operate on a built builder") @unwrap_spec(size=int) def descr__new__(space, w_subtype, size=-1): @@ -32,8 +32,7 @@ def descr_append_slice(self, space, s, start, end): self._check_done(space) if not 0 <= start <= end <= len(s): - raise OperationError(space.w_ValueError, space.wrap( - "bad start/stop")) + raise oefmt(space.w_ValueError, "bad start/stop") self.builder.append_slice(s, start, end) def descr_build(self, space): @@ -47,8 +46,7 @@ def descr_len(self, space): if self.builder is None: - raise OperationError(space.w_ValueError, space.wrap( - "no length of built builder")) + raise oefmt(space.w_ValueError, "no length of built builder") return space.wrap(self.builder.getlength()) W_Builder.__name__ = "W_%s" % name diff --git a/pypy/module/__pypy__/interp_identitydict.py b/pypy/module/__pypy__/interp_identitydict.py --- a/pypy/module/__pypy__/interp_identitydict.py +++ b/pypy/module/__pypy__/interp_identitydict.py @@ -1,4 +1,4 @@ -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.typedef import TypeDef from pypy.interpreter.gateway import interp2app from pypy.interpreter.baseobjspace import W_Root @@ -35,9 +35,9 @@ raise OperationError(space.w_KeyError, w_key) def descr_iter(self, space): - raise OperationError(space.w_TypeError, - space.wrap("'identity_dict' object does not support iteration; " - "iterate over x.keys()")) + raise oefmt(space.w_TypeError, + "'identity_dict' object does not support iteration; " + "iterate over x.keys()") def get(self, space, w_key, w_default=None): if w_default is None: diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py --- a/pypy/module/__pypy__/interp_magic.py +++ b/pypy/module/__pypy__/interp_magic.py @@ -87,8 +87,7 @@ elif isinstance(w_obj, W_BaseSetObject): name = w_obj.strategy.__class__.__name__ else: - raise OperationError(space.w_TypeError, - space.wrap("expecting dict or list or set object")) + raise oefmt(space.w_TypeError, "expecting dict or list or set object") return space.wrap(name) @@ -102,8 +101,7 @@ @unwrap_spec(sizehint=int) def resizelist_hint(space, w_iterable, sizehint): if not isinstance(w_iterable, W_ListObject): - raise OperationError(space.w_TypeError, - space.wrap("arg 1 must be a 'list'")) + raise oefmt(space.w_TypeError, "arg 1 must be a 'list'") w_iterable._resize_hint(sizehint) @unwrap_spec(sizehint=int) @@ -160,8 +158,7 @@ elif space.is_w(space.type(w_obj), space.w_str): jit.promote_string(space.str_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_unicode): - raise OperationError(space.w_TypeError, space.wrap( - "promoting unicode unsupported")) + raise oefmt(space.w_TypeError, "promoting unicode unsupported") else: jit.promote(w_obj) return w_obj 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 @@ -88,8 +88,7 @@ ctype = self.ctype if not isinstance(ctype, W_CTypeFunc): space = self.space - raise OperationError(space.w_TypeError, - space.wrap("expected a function ctype")) + raise oefmt(space.w_TypeError, "expected a function ctype") return ctype def hide_object(self): @@ -219,8 +218,8 @@ invoke_callback, unique_id) if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK: - raise OperationError(space.w_SystemError, - space.wrap("libffi failed to build this callback")) + raise oefmt(space.w_SystemError, + "libffi failed to build this callback") def py_invoke(self, ll_res, ll_args): jitdriver1.jit_merge_point(callback=self, @@ -234,9 +233,9 @@ space = fresult.space if isinstance(fresult, W_CTypeVoid): if not space.is_w(w_res, space.w_None): - raise OperationError(space.w_TypeError, - space.wrap("callback with the return type 'void'" - " must return None")) + raise oefmt(space.w_TypeError, + "callback with the return type 'void' must return " + "None") return # small_result = encode_result_for_libffi and fresult.size < SIZE_OF_FFI_ARG 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 @@ -113,8 +113,9 @@ if requires_ordering: if (isinstance(self.ctype, W_CTypePrimitive) or isinstance(w_other.ctype, W_CTypePrimitive)): - raise OperationError(space.w_TypeError, space.wrap( - "cannot do comparison on a primitive cdata")) + raise oefmt(space.w_TypeError, + "cannot do comparison on a primitive " + "cdata") ptr1 = rffi.cast(lltype.Unsigned, ptr1) ptr2 = rffi.cast(lltype.Unsigned, ptr2) result = op(ptr1, ptr2) @@ -175,22 +176,18 @@ space = self.space # if space.is_w(w_slice.w_start, space.w_None): - raise OperationError(space.w_IndexError, - space.wrap("slice start must be specified")) + raise oefmt(space.w_IndexError, "slice start must be specified") start = space.int_w(w_slice.w_start) # if space.is_w(w_slice.w_stop, space.w_None): - raise OperationError(space.w_IndexError, - space.wrap("slice stop must be specified")) + raise oefmt(space.w_IndexError, "slice stop must be specified") stop = space.int_w(w_slice.w_stop) # if not space.is_w(w_slice.w_step, space.w_None): - raise OperationError(space.w_IndexError, - space.wrap("slice with step not supported")) + raise oefmt(space.w_IndexError, "slice with step not supported") # if start > stop: - raise OperationError(space.w_IndexError, - space.wrap("slice start > stop")) + raise oefmt(space.w_IndexError, "slice start > stop") # ctype = self.ctype._check_slice_index(self, start, stop) assert isinstance(ctype, W_CTypePointer) 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 @@ -40,8 +40,8 @@ try: datasize = ovfcheck(length * self.ctitem.size) except OverflowError: - raise OperationError(space.w_OverflowError, - space.wrap("array size would overflow a ssize_t")) + raise oefmt(space.w_OverflowError, + "array size would overflow a ssize_t") else: length = self.length # @@ -55,8 +55,7 @@ def _check_subscript_index(self, w_cdata, i): space = self.space if i < 0: - raise OperationError(space.w_IndexError, - space.wrap("negative index not supported")) + raise oefmt(space.w_IndexError, "negative index not supported") if i >= w_cdata.get_array_length(): raise oefmt(space.w_IndexError, "index too large for cdata '%s' (expected %d < %d)", @@ -66,8 +65,7 @@ def _check_slice_index(self, w_cdata, start, stop): space = self.space if start < 0: - raise OperationError(space.w_IndexError, - space.wrap("negative index not supported")) + raise oefmt(space.w_IndexError, "negative index not supported") if stop > w_cdata.get_array_length(): raise oefmt(space.w_IndexError, "index too large (expected %d <= %d)", 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 @@ -471,5 +471,5 @@ # call libffi's ffi_prep_cif() function res = jit_libffi.jit_ffi_prep_cif(rawmem) if res != clibffi.FFI_OK: - raise OperationError(space.w_SystemError, - space.wrap("libffi failed to build this function type")) + raise oefmt(space.w_SystemError, + "libffi failed to build this function type") 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 @@ -185,26 +185,24 @@ except OperationError as e: if not e.match(space, space.w_TypeError): raise - raise OperationError(space.w_TypeError, - space.wrap("field name or array index expected")) + raise oefmt(space.w_TypeError, + "field name or array index expected") return self.typeoffsetof_index(index) else: return self.typeoffsetof_field(fieldname, following) def typeoffsetof_field(self, fieldname, following): - space = self.space - msg = "with a field name argument, expected a struct or union ctype" - raise OperationError(space.w_TypeError, space.wrap(msg)) + raise oefmt(self.space.w_TypeError, + "with a field name argument, expected a struct or union " + "ctype") def typeoffsetof_index(self, index): - space = self.space - msg = "with an integer argument, expected an array or pointer ctype" - raise OperationError(space.w_TypeError, space.wrap(msg)) + raise oefmt(self.space.w_TypeError, + "with an integer argument, expected an array or pointer " + "ctype") def rawaddressof(self, cdata, offset): - space = self.space - raise OperationError(space.w_TypeError, - space.wrap("expected a pointer ctype")) + raise oefmt(self.space.w_TypeError, "expected a pointer ctype") def call(self, funcaddr, args_w): space = self.space 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 @@ -292,8 +292,8 @@ try: datasize = ovfcheck(length * itemsize) except OverflowError: - raise OperationError(space.w_OverflowError, - space.wrap("array size would overflow a ssize_t")) + raise oefmt(space.w_OverflowError, + "array size would overflow a ssize_t") result = lltype.malloc(rffi.CCHARP.TO, datasize, flavor='raw', zero=True) try: @@ -325,13 +325,12 @@ space = self.space ctitem = self.ctitem if ctitem.size < 0: - raise OperationError(space.w_TypeError, - space.wrap("pointer to opaque")) + raise oefmt(space.w_TypeError, "pointer to opaque") try: offset = ovfcheck(index * ctitem.size) except OverflowError: - raise OperationError(space.w_OverflowError, - space.wrap("array offset would overflow a ssize_t")) + raise oefmt(space.w_OverflowError, + "array offset would overflow a ssize_t") return ctitem, offset def rawaddressof(self, cdata, offset): @@ -344,9 +343,8 @@ ptr = rffi.ptradd(ptr, offset) return cdataobj.W_CData(space, ptr, self) else: - raise OperationError(space.w_TypeError, - space.wrap("expected a cdata struct/union/array/pointer" - " object")) + raise oefmt(space.w_TypeError, + "expected a cdata struct/union/array/pointer object") def _fget(self, attrchar): if attrchar == 'i': # item @@ -382,8 +380,7 @@ if w_fileobj.cffi_fileobj is None: fd = space.int_w(space.call_method(w_fileobj, "fileno")) if fd < 0: - raise OperationError(space.w_ValueError, - space.wrap("file has no OS file descriptor")) + raise oefmt(space.w_ValueError, "file has no OS file descriptor") fd = os.dup(fd) mode = space.str_w(space.getattr(w_fileobj, space.wrap("mode"))) try: 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 @@ -94,8 +94,7 @@ except KeyError: raise OperationError(space.w_KeyError, space.wrap(fieldname)) if cfield.bitshift >= 0: - raise OperationError(space.w_TypeError, - space.wrap("not supported for bitfields")) + raise oefmt(space.w_TypeError, "not supported for bitfields") return (cfield.ctype, cfield.offset) def _copy_from_same(self, cdata, w_ob): @@ -243,8 +242,8 @@ varsize = ovfcheck(itemsize * varsizelength) size = ovfcheck(self.offset + varsize) except OverflowError: - raise OperationError(space.w_OverflowError, - space.wrap("array size would overflow a ssize_t")) + raise oefmt(space.w_OverflowError, + "array size would overflow a ssize_t") assert size >= 0 return max(size, optvarsize) # if 'value' was only an integer, get_new_array_length() returns 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 @@ -44,8 +44,7 @@ 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")) + raise oefmt(space.w_TypeError, "expected a 'cdata' or 'ctype' object") return space.wrap(size) @unwrap_spec(w_ctype=ctypeobj.W_CType) diff --git a/pypy/module/_cffi_backend/misc.py b/pypy/module/_cffi_backend/misc.py --- a/pypy/module/_cffi_backend/misc.py +++ b/pypy/module/_cffi_backend/misc.py @@ -1,6 +1,6 @@ from __future__ import with_statement -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from rpython.rlib import jit from rpython.rlib.objectmodel import specialize @@ -289,8 +289,7 @@ try: return _standard_object_as_bool(space, w_io) except _NotStandardObject: - raise OperationError(space.w_TypeError, - space.wrap("integer/float expected")) + raise oefmt(space.w_TypeError, "integer/float expected") # ____________________________________________________________ @@ -305,8 +304,7 @@ else: explicitlength = space.getindex_w(w_value, space.w_OverflowError) if explicitlength < 0: - raise OperationError(space.w_ValueError, - space.wrap("negative array length")) + raise oefmt(space.w_ValueError, "negative array length") return (space.w_None, explicitlength) # ____________________________________________________________ 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 @@ -181,16 +181,14 @@ else: length = space.getindex_w(w_length, space.w_OverflowError) if length < 0: - raise OperationError(space.w_ValueError, - space.wrap("negative array length")) + raise oefmt(space.w_ValueError, "negative array length") return _new_array_type(space, w_ctptr, length) @jit.elidable def _new_array_type(space, w_ctptr, length): _setup_wref(rweakref.has_weakref_support()) if not isinstance(w_ctptr, ctypeptr.W_CTypePointer): - raise OperationError(space.w_TypeError, - space.wrap("first arg must be a pointer ctype")) + raise oefmt(space.w_TypeError, "first arg must be a pointer ctype") arrays = w_ctptr._array_types if arrays is None: arrays = rweakref.RWeakValueDictionary(int, ctypearray.W_CTypeArray) @@ -212,8 +210,8 @@ try: arraysize = ovfcheck(length * ctitem.size) except OverflowError: - raise OperationError(space.w_OverflowError, - space.wrap("array size would overflow a ssize_t")) + raise oefmt(space.w_OverflowError, + "array size would overflow a ssize_t") extra = '[%d]' % length # ctype = ctypearray.W_CTypeArray(space, w_ctptr, length, arraysize, extra) @@ -290,9 +288,9 @@ sflags = complete_sflags(sflags) if (not isinstance(w_ctype, ctypestruct.W_CTypeStructOrUnion) or w_ctype.size >= 0): - raise OperationError(space.w_TypeError, - space.wrap("first arg must be a non-initialized" - " struct or union ctype")) + raise oefmt(space.w_TypeError, + "first arg must be a non-initialized struct or union " + "ctype") is_union = isinstance(w_ctype, ctypestruct.W_CTypeUnion) alignment = 1 @@ -310,8 +308,7 @@ w_field = fields_w[i] field_w = space.fixedview(w_field) if not (2 <= len(field_w) <= 4): - raise OperationError(space.w_TypeError, - space.wrap("bad field descr")) + raise oefmt(space.w_TypeError, "bad field descr") fname = space.str_w(field_w[0]) ftype = space.interp_w(ctypeobj.W_CType, field_w[1]) fbitsize = -1 @@ -564,14 +561,13 @@ enumerators_w = space.fixedview(w_enumerators) enumvalues_w = space.fixedview(w_enumvalues) if len(enumerators_w) != len(enumvalues_w): - raise OperationError(space.w_ValueError, - space.wrap("tuple args must have the same size")) + raise oefmt(space.w_ValueError, "tuple args must have the same size") enumerators = [space.str_w(w) for w in enumerators_w] # if (not isinstance(w_basectype, ctypeprim.W_CTypePrimitiveSigned) and not isinstance(w_basectype, ctypeprim.W_CTypePrimitiveUnsigned)): - raise OperationError(space.w_TypeError, - space.wrap("expected a primitive signed or unsigned base type")) + raise oefmt(space.w_TypeError, + "expected a primitive signed or unsigned base type") # lvalue = lltype.malloc(rffi.CCHARP.TO, w_basectype.size, flavor='raw') try: @@ -601,8 +597,8 @@ fargs = [] for w_farg in space.fixedview(w_fargs): if not isinstance(w_farg, ctypeobj.W_CType): - raise OperationError(space.w_TypeError, - space.wrap("first arg must be a tuple of ctype objects")) + raise oefmt(space.w_TypeError, + "first arg must be a tuple of ctype objects") if isinstance(w_farg, ctypearray.W_CTypeArray): w_farg = w_farg.ctptr fargs.append(w_farg) 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 @@ -138,9 +138,7 @@ if space.is_true(space.callable(w_search_function)): state.codec_search_path.append(w_search_function) else: - raise OperationError( - space.w_TypeError, - space.wrap("argument must be callable")) + raise oefmt(space.w_TypeError, "argument must be callable") @unwrap_spec(encoding=str) @@ -174,19 +172,17 @@ normalized_base)) state.codec_need_encodings = False if len(state.codec_search_path) == 0: - raise OperationError( - space.w_LookupError, - space.wrap("no codec search functions registered: " - "can't find encoding")) + raise oefmt(space.w_LookupError, + "no codec search functions registered: can't find " + "encoding") for w_search in state.codec_search_path: w_result = space.call_function(w_search, space.wrap(normalized_encoding)) if not space.is_w(w_result, space.w_None): if not (space.isinstance_w(w_result, space.w_tuple) and space.len_w(w_result) == 4): - raise OperationError( - space.w_TypeError, - space.wrap("codec search functions must return 4-tuples")) + raise oefmt(space.w_TypeError, + "codec search functions must return 4-tuples") else: state.codec_search_cache[normalized_encoding] = w_result state.modified() @@ -204,22 +200,19 @@ except OperationError as e: if not e.match(space, space.w_AttributeError): raise - raise OperationError(space.w_TypeError, space.wrap( - "wrong exception")) + raise oefmt(space.w_TypeError, "wrong exception") delta = space.int_w(w_end) - space.int_w(w_start) if delta < 0 or not (space.isinstance_w(w_obj, space.w_str) or space.isinstance_w(w_obj, space.w_unicode)): - raise OperationError(space.w_TypeError, space.wrap( - "wrong exception")) + raise oefmt(space.w_TypeError, "wrong exception") def strict_errors(space, w_exc): check_exception(space, w_exc) if space.isinstance_w(w_exc, space.w_BaseException): raise OperationError(space.type(w_exc), w_exc) else: - raise OperationError(space.w_TypeError, space.wrap( - "codec must pass exception instance")) + raise oefmt(space.w_TypeError, "codec must pass exception instance") def ignore_errors(space, w_exc): check_exception(space, w_exc) @@ -454,9 +447,8 @@ if space.is_true(w_decoder): w_res = space.call_function(w_decoder, w_obj, space.wrap(errors)) if (not space.isinstance_w(w_res, space.w_tuple) or space.len_w(w_res) != 2): - raise OperationError( - space.w_TypeError, - space.wrap("encoder must return a tuple (object, integer)")) + raise oefmt(space.w_TypeError, + "encoder must return a tuple (object, integer)") return space.getitem(w_res, space.wrap(0)) else: assert 0, "XXX, what to do here?" @@ -475,9 +467,7 @@ if space.is_true(space.callable(w_handler)): state.codec_error_registry[errors] = w_handler else: - raise OperationError( - space.w_TypeError, - space.wrap("handler must be callable")) + raise oefmt(space.w_TypeError, "handler must be callable") # ____________________________________________________________ # delegation to runicode diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py --- a/pypy/module/_collections/interp_deque.py +++ b/pypy/module/_collections/interp_deque.py @@ -4,7 +4,7 @@ from pypy.interpreter.typedef import TypeDef, make_weakref_descr from pypy.interpreter.typedef import GetSetProperty from pypy.interpreter.gateway import interp2app, unwrap_spec -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from rpython.rlib.debug import check_nonneg @@ -76,9 +76,8 @@ def checklock(self, lock): if lock is not self.lock: - raise OperationError( - self.space.w_RuntimeError, - self.space.wrap("deque mutated during iteration")) + raise oefmt(self.space.w_RuntimeError, + "deque mutated during iteration") def init(self, w_iterable=None, w_maxlen=None): space = self.space @@ -200,8 +199,7 @@ def pop(self): "Remove and return the rightmost element." if self.len == 0: - msg = "pop from an empty deque" - raise OperationError(self.space.w_IndexError, self.space.wrap(msg)) + raise oefmt(self.space.w_IndexError, "pop from an empty deque") self.len -= 1 ri = self.rightindex w_obj = self.rightblock.data[ri] @@ -224,8 +222,7 @@ def popleft(self): "Remove and return the leftmost element." if self.len == 0: - msg = "pop from an empty deque" - raise OperationError(self.space.w_IndexError, self.space.wrap(msg)) + raise oefmt(self.space.w_IndexError, "pop from an empty deque") self.len -= 1 li = self.leftindex w_obj = self.leftblock.data[li] @@ -263,8 +260,7 @@ if index >= BLOCKLEN: block = block.rightlink index = 0 - raise OperationError(space.w_ValueError, - space.wrap("deque.remove(x): x not in deque")) + raise oefmt(space.w_ValueError, "deque.remove(x): x not in deque") def reverse(self): "Reverse *IN PLACE*." @@ -371,8 +367,7 @@ b, i = self.locate(start) return b.data[i] else: - raise OperationError(space.w_TypeError, - space.wrap("deque[:] is not supported")) + raise oefmt(space.w_TypeError, "deque[:] is not supported") def setitem(self, w_index, w_newobj): space = self.space @@ -381,8 +376,7 @@ b, i = self.locate(start) b.data[i] = w_newobj else: - raise OperationError(space.w_TypeError, - space.wrap("deque[:] is not supported")) + raise oefmt(space.w_TypeError, "deque[:] is not supported") def delitem(self, w_index): space = self.space @@ -390,8 +384,7 @@ if step == 0: # index only self.del_item(start) else: - raise OperationError(space.w_TypeError, - space.wrap("deque[:] is not supported")) + raise oefmt(space.w_TypeError, "deque[:] is not supported") def copy(self): "Return a shallow copy of a deque." @@ -520,13 +513,12 @@ return self.space.wrap(self.counter) def next(self): + space = self.space if self.lock is not self.deque.lock: self.counter = 0 - raise OperationError( - self.space.w_RuntimeError, - self.space.wrap("deque mutated during iteration")) + raise oefmt(space.w_RuntimeError, "deque mutated during iteration") if self.counter == 0: - raise OperationError(self.space.w_StopIteration, self.space.w_None) + raise OperationError(space.w_StopIteration, space.w_None) self.counter -= 1 ri = self.index w_x = self.block.data[ri] @@ -563,13 +555,12 @@ return self.space.wrap(self.counter) def next(self): + space = self.space if self.lock is not self.deque.lock: self.counter = 0 - raise OperationError( - self.space.w_RuntimeError, - self.space.wrap("deque mutated during iteration")) + raise oefmt(space.w_RuntimeError, "deque mutated during iteration") if self.counter == 0: - raise OperationError(self.space.w_StopIteration, self.space.w_None) + raise OperationError(space.w_StopIteration, space.w_None) self.counter -= 1 ri = self.index w_x = self.block.data[ri] 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 @@ -106,18 +106,17 @@ # validate options if not (0 <= tmp_quoting < 4): - raise OperationError(space.w_TypeError, - space.wrap('bad "quoting" value')) + raise oefmt(space.w_TypeError, 'bad "quoting" value') if dialect.delimiter == u'\0': - raise OperationError(space.w_TypeError, - space.wrap('"delimiter" must be a 1-character string')) + raise oefmt(space.w_TypeError, + '"delimiter" must be a 1-character string') if space.is_w(w_quotechar, space.w_None) and w_quoting is None: tmp_quoting = QUOTE_NONE if tmp_quoting != QUOTE_NONE and dialect.quotechar == u'\0': - raise OperationError(space.w_TypeError, - space.wrap('quotechar must be set if quoting enabled')) + raise oefmt(space.w_TypeError, + "quotechar must be set if quoting enabled") dialect.quoting = tmp_quoting return dialect diff --git a/pypy/module/_demo/demo.py b/pypy/module/_demo/demo.py --- a/pypy/module/_demo/demo.py +++ b/pypy/module/_demo/demo.py @@ -1,4 +1,4 @@ -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import oefmt from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty @@ -22,8 +22,7 @@ def measuretime(space, repetitions, w_callable): if repetitions <= 0: w_DemoError = get(space, 'DemoError') - msg = "repetition count must be > 0" - raise OperationError(w_DemoError, space.wrap(msg)) + raise oefmt(w_DemoError, "repetition count must be > 0") starttime = time(0) for i in range(repetitions): space.call_function(w_callable) diff --git a/pypy/module/_hashlib/interp_hashlib.py b/pypy/module/_hashlib/interp_hashlib.py --- a/pypy/module/_hashlib/interp_hashlib.py +++ b/pypy/module/_hashlib/interp_hashlib.py @@ -7,7 +7,7 @@ from rpython.tool.sourcetools import func_renamer from pypy.interpreter.baseobjspace import W_Root -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import unwrap_spec, interp2app from pypy.interpreter.typedef import TypeDef, GetSetProperty from pypy.module.thread.os_lock import Lock @@ -85,8 +85,7 @@ def digest_type_by_name(self, space): digest_type = ropenssl.EVP_get_digestbyname(self.name) if not digest_type: - raise OperationError(space.w_ValueError, - space.wrap("unknown hash function")) + raise oefmt(space.w_ValueError, "unknown hash function") return digest_type def descr_repr(self, space): 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 @@ -40,8 +40,7 @@ ## self.lock.free() self.lock = space.allocate_lock() self.owner = 0 - self.operr = OperationError(space.w_RuntimeError, - space.wrap("reentrant call")) + self.operr = oefmt(space.w_RuntimeError, "reentrant call") def __enter__(self): if not self.lock.acquire(False): @@ -80,8 +79,7 @@ w_data = space.call_method(self, "read", space.wrap(length)) if not space.isinstance_w(w_data, space.w_str): - raise OperationError(space.w_TypeError, space.wrap( - "read() should return bytes")) + raise oefmt(space.w_TypeError, "read() should return bytes") data = space.bytes_w(w_data) if len(data) > length: raise oefmt(space.w_ValueError, @@ -151,8 +149,8 @@ def _init(self, space): if self.buffer_size <= 0: - raise OperationError(space.w_ValueError, space.wrap( - "buffer size must be strictly positive")) + raise oefmt(space.w_ValueError, + "buffer size must be strictly positive") self.buffer = ['\0'] * self.buffer_size @@ -165,11 +163,10 @@ def _check_init(self, space): if self.state == STATE_ZERO: - raise OperationError(space.w_ValueError, space.wrap( - "I/O operation on uninitialized object")) + raise oefmt(space.w_ValueError, + "I/O operation on uninitialized object") elif self.state == STATE_DETACHED: - raise OperationError(space.w_ValueError, space.wrap( - "raw stream has been detached")) + raise oefmt(space.w_ValueError, "raw stream has been detached") def _check_closed(self, space, message=None): self._check_init(space) @@ -179,8 +176,8 @@ w_pos = space.call_method(self.w_raw, "tell") pos = space.r_longlong_w(w_pos) if pos < 0: - raise OperationError(space.w_IOError, space.wrap( - "raw stream returned invalid position")) + raise oefmt(space.w_IOError, + "raw stream returned invalid position") self.abs_pos = pos return pos @@ -292,8 +289,8 @@ space.wrap(pos), space.wrap(whence)) pos = space.r_longlong_w(w_pos) if pos < 0: - raise OperationError(space.w_IOError, space.wrap( - "Raw stream returned invalid position")) + raise oefmt(space.w_IOError, + "Raw stream returned invalid position") self.abs_pos = pos return pos @@ -372,8 +369,7 @@ written = space.getindex_w(w_written, space.w_IOError) if not 0 <= written <= len(data): - raise OperationError(space.w_IOError, space.wrap( - "raw write() returned invalid length")) + raise oefmt(space.w_IOError, "raw write() returned invalid length") if self.abs_pos != -1: self.abs_pos += written return written @@ -426,8 +422,8 @@ with self.lock: res = self._read_generic(space, size) else: - raise OperationError(space.w_ValueError, space.wrap( - "read length must be positive or -1")) + raise oefmt(space.w_ValueError, + "read length must be positive or -1") return space.wrapbytes(res) @unwrap_spec(size=int) @@ -463,8 +459,7 @@ self._check_closed(space, "read of closed file") if size < 0: - raise OperationError(space.w_ValueError, space.wrap( - "read length must be positive")) + raise oefmt(space.w_ValueError, "read length must be positive") if size == 0: return space.wrapbytes("") @@ -546,9 +541,9 @@ raise BlockingIOError() size = space.int_w(w_size) if size < 0 or size > length: - raise OperationError(space.w_IOError, space.wrap( - "raw readinto() returned invalid length %d " - "(should have been between 0 and %d)" % (size, length))) + raise oefmt(space.w_IOError, + "raw readinto() returned invalid length %d (should " + "have been between 0 and %d)", size, length) if self.abs_pos != -1: self.abs_pos += size return size 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 @@ -114,8 +114,7 @@ size = space.r_longlong_w(w_size) if size < 0: - raise OperationError(space.w_ValueError, space.wrap( - "negative size value")) + raise oefmt(space.w_ValueError, "negative size value") self.truncate(size) if size == pos: @@ -141,16 +140,13 @@ if whence == 0: if pos < 0: - raise OperationError(space.w_ValueError, space.wrap( - "negative seek value")) + raise oefmt(space.w_ValueError, "negative seek value") elif whence == 1: if pos > sys.maxint - self.tell(): - raise OperationError(space.w_OverflowError, space.wrap( - "new position too large")) + raise oefmt(space.w_OverflowError, "new position too large") elif whence == 2: if pos > sys.maxint - self.getsize(): - raise OperationError(space.w_OverflowError, space.wrap( - "new position too large")) + raise oefmt(space.w_OverflowError, "new position too large") else: raise oefmt(space.w_ValueError, "whence must be between 0 and 2, not %d", whence) @@ -195,8 +191,8 @@ self.write_w(space, w_content) pos = space.int_w(w_pos) if pos < 0: - raise OperationError(space.w_ValueError, space.wrap( - "position value cannot be negative")) + raise oefmt(space.w_ValueError, + "position value cannot be negative") self.seek(pos) if not space.is_w(w_dict, space.w_None): space.call_method(self.getdict(space), "update", w_dict) 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 @@ -1,7 +1,7 @@ from pypy.interpreter.typedef import TypeDef, interp_attrproperty, GetSetProperty from pypy.interpreter.gateway import interp2app, unwrap_spec -from pypy.interpreter.error import OperationError, oefmt -from pypy.interpreter.error import wrap_oserror, wrap_oserror2 +from pypy.interpreter.error import ( + OperationError, oefmt, wrap_oserror, wrap_oserror2) from rpython.rlib.rarithmetic import r_longlong from rpython.rlib.rstring import StringBuilder from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_EXCL @@ -13,8 +13,7 @@ def fget(space, obj): w_value = getattr(obj, name) if w_value is None: - raise OperationError(space.w_AttributeError, - space.wrap(name)) + raise OperationError(space.w_AttributeError, space.wrap(name)) else: return w_value def fset(space, obj, w_value): @@ -22,8 +21,7 @@ def fdel(space, obj): w_value = getattr(obj, name) if w_value is None: - raise OperationError(space.w_AttributeError, - space.wrap(name)) + raise OperationError(space.w_AttributeError, space.wrap(name)) setattr(obj, name, None) return GetSetProperty(fget, fset, fdel, cls=cls, doc=doc) @@ -33,8 +31,8 @@ O_APPEND = getattr(os, "O_APPEND", 0) def _bad_mode(space): - raise OperationError(space.w_ValueError, space.wrap( - "Must have exactly one of read/write/create/append mode")) + raise oefmt(space.w_ValueError, + "Must have exactly one of read/write/create/append mode") def decode_mode(space, mode): flags = 0 @@ -79,8 +77,7 @@ readable = writable = True plus = True else: - raise OperationError(space.w_ValueError, space.wrap( - "invalid mode: %s" % (mode,))) + raise oefmt(space.w_ValueError, "invalid mode: %s", mode) if not rwa: _bad_mode(space) @@ -143,8 +140,8 @@ @unwrap_spec(mode=str, closefd=int) def descr_init(self, space, w_name, mode='r', closefd=True, w_opener=None): if space.isinstance_w(w_name, space.w_float): - raise OperationError(space.w_TypeError, space.wrap( - "integer argument expected, got float")) + raise oefmt(space.w_TypeError, + "integer argument expected, got float") fd = -1 try: @@ -153,8 +150,7 @@ pass else: if fd < 0: - raise OperationError(space.w_ValueError, space.wrap( - "negative file descriptor")) + raise oefmt(space.w_ValueError, "negative file descriptor") self.readable, self.writable, self.created, self.appending, flags = decode_mode(space, mode) @@ -172,8 +168,8 @@ elif space.is_none(w_opener): self.closefd = True if not closefd: - raise OperationError(space.w_ValueError, space.wrap( - "Cannot use closefd=False with file name")) + raise oefmt(space.w_ValueError, + "Cannot use closefd=False with file name") from pypy.module.posix.interp_posix import ( dispatch_filename, rposix) 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 @@ -73,25 +73,19 @@ rawmode += "+" if universal and (writing or appending): - raise OperationError(space.w_ValueError, - space.wrap("can't use U and writing mode at once") - ) + raise oefmt(space.w_ValueError, "can't use U and writing mode at once") if text and binary: - raise OperationError(space.w_ValueError, - space.wrap("can't have text and binary mode at once") - ) + raise oefmt(space.w_ValueError, + "can't have text and binary mode at once") if reading + writing + creating + appending > 1: - raise OperationError(space.w_ValueError, - space.wrap("must have exactly one of read/write/create/append mode") - ) + raise oefmt(space.w_ValueError, + "must have exactly one of read/write/create/append mode") if binary and encoding is not None: - raise OperationError(space.w_ValueError, - space.wrap("binary mode doesn't take an encoding argument") - ) + raise oefmt(space.w_ValueError, + "binary mode doesn't take an encoding argument") if binary and newline is not None: - raise OperationError(space.w_ValueError, - space.wrap("binary mode doesn't take a newline argument") - ) + raise oefmt(space.w_ValueError, + "binary mode doesn't take a newline argument") w_raw = space.call_function( space.gettypefor(W_FileIO), w_file, space.wrap(rawmode), space.wrap(closefd), w_opener) @@ -116,15 +110,11 @@ buffering = st.st_blksize if buffering < 0: - raise OperationError(space.w_ValueError, - space.wrap("invalid buffering size") - ) + raise oefmt(space.w_ValueError, "invalid buffering size") if buffering == 0: if not binary: - raise OperationError(space.w_ValueError, - space.wrap("can't have unbuffered text I/O") - ) + raise oefmt(space.w_ValueError, "can't have unbuffered text I/O") return w_raw if updating: 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 @@ -137,9 +137,7 @@ def flush_w(self, space): if self._CLOSED(): - raise OperationError( - space.w_ValueError, - space.wrap("I/O operation on closed file")) + raise oefmt(space.w_ValueError, "I/O operation on closed file") def seek_w(self, space, w_offset, w_whence=None): self._unsupportedoperation(space, "seek") @@ -361,8 +359,7 @@ break if not space.isinstance_w(w_data, space.w_bytes): - raise OperationError(space.w_TypeError, space.wrap( - "read() should return bytes")) + raise oefmt(space.w_TypeError, "read() should return bytes") data = space.bytes_w(w_data) if not data: 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 @@ -89,9 +89,8 @@ self.buf = list(initval) pos = space.getindex_w(w_pos, space.w_TypeError) if pos < 0: - raise OperationError(space.w_ValueError, - space.wrap("position value cannot be negative") - ) + raise oefmt(space.w_ValueError, + "position value cannot be negative") self.pos = pos if not space.is_w(w_dict, space.w_None): if not space.isinstance_w(w_dict, space.w_dict): @@ -203,9 +202,7 @@ elif mode == 0 and pos < 0: raise oefmt(space.w_ValueError, "negative seek position: %d", pos) elif mode != 0 and pos != 0: - raise OperationError(space.w_IOError, - space.wrap("Can't do nonzero cur-relative seeks") - ) + raise oefmt(space.w_IOError, "Can't do nonzero cur-relative seeks") # XXX: this makes almost no sense, but its how CPython does it. if mode == 1: 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 @@ -59,8 +59,8 @@ @unwrap_spec(final=int) def decode_w(self, space, w_input, final=False): if self.w_decoder is None: - raise OperationError(space.w_ValueError, space.wrap( - "IncrementalNewlineDecoder.__init__ not called")) + raise oefmt(space.w_ValueError, + "IncrementalNewlineDecoder.__init__ not called") # decode input (with the eventual \r from a previous pass) if not space.is_w(self.w_decoder, space.w_None): @@ -70,8 +70,8 @@ w_output = w_input if not space.isinstance_w(w_output, space.w_unicode): - raise OperationError(space.w_TypeError, space.wrap( - "decoder should return a string result")) + raise oefmt(space.w_TypeError, + "decoder should return a string result") output = space.unicode_w(w_output) output_len = len(output) @@ -302,8 +302,7 @@ if space.isinstance_w(w_encoding, space.w_unicode): return w_encoding - raise OperationError(space.w_IOError, space.wrap( - "could not determine default encoding")) + raise oefmt(space.w_IOError, "could not determine default encoding") class PositionCookie(object): def __init__(self, bigint): @@ -393,8 +392,8 @@ newline = space.unicode_w(w_newline) if newline and newline not in (u'\n', u'\r\n', u'\r'): r = space.str_w(space.repr(w_newline)) - raise OperationError(space.w_ValueError, space.wrap( - "illegal newline value: %s" % (r,))) + raise oefmt(space.w_ValueError, + "illegal newline value: %s", r) self.line_buffering = line_buffering self.write_through = write_through @@ -452,13 +451,13 @@ def _check_init(self, space): if self.state == STATE_ZERO: - raise OperationError(space.w_ValueError, space.wrap( - "I/O operation on uninitialized object")) + raise oefmt(space.w_ValueError, + "I/O operation on uninitialized object") def _check_attached(self, space): if self.state == STATE_DETACHED: - raise OperationError(space.w_ValueError, space.wrap( - "underlying buffer has been detached")) + raise oefmt(space.w_ValueError, + "underlying buffer has been detached") self._check_init(space) def _check_closed(self, space, message=None): @@ -774,8 +773,8 @@ self._unsupportedoperation(space, "not writable") if not space.isinstance_w(w_text, space.w_unicode): - msg = "unicode argument expected, got '%T'" - raise oefmt(space.w_TypeError, msg, w_text) + raise oefmt(space.w_TypeError, + "unicode argument expected, got '%T'", w_text) text = space.unicode_w(w_text) textlen = len(text) @@ -904,13 +903,14 @@ w_pos, space.wrap(whence)) elif whence != 0: - raise OperationError(space.w_ValueError, space.wrap( - "invalid whence (%d, should be 0, 1 or 2)" % (whence,))) + raise oefmt(space.w_ValueError, + "invalid whence (%d, should be 0, 1 or 2)", + whence) if space.is_true(space.lt(w_pos, space.wrap(0))): r = space.str_w(space.repr(w_pos)) - raise OperationError(space.w_ValueError, space.wrap( - "negative seek position %s" % (r,))) + raise oefmt(space.w_ValueError, + "negative seek position %s", r) space.call_method(self, "flush") @@ -947,8 +947,8 @@ # Skip chars_to_skip of the decoded characters if len(self.decoded_chars) < cookie.chars_to_skip: - raise OperationError(space.w_IOError, space.wrap( - "can't restore logical file position")) + raise oefmt(space.w_IOError, + "can't restore logical file position") self.decoded_chars_used = cookie.chars_to_skip else: self.snapshot = PositionSnapshot(cookie.dec_flags, "") @@ -967,8 +967,8 @@ "underlying stream is not seekable") if not self.telling: - raise OperationError(space.w_IOError, space.wrap( - "telling position disabled by next() call")) + raise oefmt(space.w_IOError, + "telling position disabled by next() call") self._writeflush(space) space.call_method(self, "flush") @@ -1041,8 +1041,8 @@ cookie.need_eof = 1 if chars_decoded < chars_to_skip: - raise OperationError(space.w_IOError, space.wrap( - "can't reconstruct logical file position")) + raise oefmt(space.w_IOError, + "can't reconstruct logical file position") finally: space.call_method(self.w_decoder, "setstate", w_saved_state) @@ -1058,9 +1058,8 @@ self._check_attached(space) size = space.int_w(w_size) if size <= 0: - raise OperationError(space.w_ValueError, - space.wrap("a strictly positive integer is required") - ) + raise oefmt(space.w_ValueError, + "a strictly positive integer is required") self.chunk_size = size W_TextIOWrapper.typedef = TypeDef( diff --git a/pypy/module/_locale/interp_locale.py b/pypy/module/_locale/interp_locale.py --- a/pypy/module/_locale/interp_locale.py +++ b/pypy/module/_locale/interp_locale.py @@ -1,7 +1,7 @@ from rpython.rlib import rposix from rpython.rlib.rarithmetic import intmask -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import unwrap_spec from rpython.rlib import rlocale @@ -149,8 +149,7 @@ try: return space.wrap(rlocale.nl_langinfo(key)) except ValueError: - raise OperationError(space.w_ValueError, - space.wrap("unsupported langinfo constant")) + raise oefmt(space.w_ValueError, "unsupported langinfo constant") #___________________________________________________________________ # HAVE_LIBINTL dependence diff --git a/pypy/module/_lsprof/interp_lsprof.py b/pypy/module/_lsprof/interp_lsprof.py --- a/pypy/module/_lsprof/interp_lsprof.py +++ b/pypy/module/_lsprof/interp_lsprof.py @@ -1,7 +1,7 @@ import py from pypy.interpreter.baseobjspace import W_Root -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.function import BuiltinFunction, Method, Function from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import (TypeDef, GetSetProperty, @@ -420,9 +420,9 @@ def getstats(self, space): if self.w_callable is None: if self.is_enabled: - raise OperationError(space.w_RuntimeError, - space.wrap("Profiler instance must be disabled " - "before getting the stats")) + raise oefmt(space.w_RuntimeError, + "Profiler instance must be disabled before " + "getting the stats") if self.total_timestamp: factor = self.total_real_time / float(self.total_timestamp) else: diff --git a/pypy/module/_multibytecodec/interp_multibytecodec.py b/pypy/module/_multibytecodec/interp_multibytecodec.py --- a/pypy/module/_multibytecodec/interp_multibytecodec.py +++ b/pypy/module/_multibytecodec/interp_multibytecodec.py @@ -1,7 +1,7 @@ from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.module._multibytecodec import c_codecs from pypy.module._codecs.interp_codecs import CodecState @@ -57,8 +57,7 @@ try: codec = c_codecs.getcodec(name) except KeyError: - raise OperationError(space.w_LookupError, - space.wrap("no such codec is supported.")) + raise oefmt(space.w_LookupError, "no such codec is supported.") return space.wrap(MultibyteCodec(name, codec)) @@ -83,5 +82,4 @@ space.wrap(e.reason)])) def wrap_runtimeerror(space): - raise OperationError(space.w_RuntimeError, - space.wrap("internal codec error")) + raise oefmt(space.w_RuntimeError, "internal codec error") diff --git a/pypy/module/_multiprocessing/interp_connection.py b/pypy/module/_multiprocessing/interp_connection.py --- a/pypy/module/_multiprocessing/interp_connection.py +++ b/pypy/module/_multiprocessing/interp_connection.py @@ -86,12 +86,10 @@ def _check_readable(self, space): if not self.flags & READABLE: - raise OperationError(space.w_IOError, - space.wrap("connection is write-only")) + raise oefmt(space.w_IOError, "connection is write-only") def _check_writable(self, space): if not self.flags & WRITABLE: - raise OperationError(space.w_IOError, - space.wrap("connection is read-only")) + raise oefmt(space.w_IOError, "connection is read-only") @unwrap_spec(offset='index', size='index') def send_bytes(self, space, w_buf, offset=0, size=PY_SSIZE_T_MIN): @@ -99,20 +97,16 @@ length = len(buf) self._check_writable(space) if offset < 0: - raise OperationError(space.w_ValueError, - space.wrap("offset is negative")) + raise oefmt(space.w_ValueError, "offset is negative") if length < offset: - raise OperationError(space.w_ValueError, - space.wrap("buffer length < offset")) + raise oefmt(space.w_ValueError, "buffer length < offset") if size == PY_SSIZE_T_MIN: size = length - offset elif size < 0: - raise OperationError(space.w_ValueError, - space.wrap("size is negative")) + raise oefmt(space.w_ValueError, "size is negative") elif offset + size > length: - raise OperationError(space.w_ValueError, - space.wrap("buffer length > offset + size")) + raise oefmt(space.w_ValueError, "buffer length > offset + size") self.do_send_string(space, buf, offset, size) @@ -120,8 +114,7 @@ def recv_bytes(self, space, maxlength=PY_SSIZE_T_MAX): self._check_readable(space) if maxlength < 0: - raise OperationError(space.w_ValueError, - space.wrap("maxlength < 0")) + raise oefmt(space.w_ValueError, "maxlength < 0") res, newbuf = self.do_recv_string( space, self.BUFFER_SIZE, maxlength) @@ -249,8 +242,7 @@ def __init__(self, space, fd, flags): if fd == self.INVALID_HANDLE_VALUE or fd < 0: - raise OperationError(space.w_IOError, - space.wrap("invalid handle %d" % fd)) + raise oefmt(space.w_IOError, "invalid handle %d", fd) W_BaseConnection.__init__(self, flags) self.fd = fd @@ -301,8 +293,7 @@ self.flags &= ~READABLE if self.flags == 0: self.close() - raise OperationError(space.w_IOError, space.wrap( - "bad message length")) + raise oefmt(space.w_IOError, "bad message length") if length <= buflength: self._recvall(space, self.buffer, length) @@ -342,8 +333,8 @@ if remaining == length: raise OperationError(space.w_EOFError, space.w_None) else: - raise OperationError(space.w_IOError, space.wrap( - "got end of file during message")) + raise oefmt(space.w_IOError, + "got end of file during message") # XXX inefficient for i in range(count): buf[i] = data[i] @@ -459,8 +450,7 @@ self.flags &= ~READABLE if self.flags == 0: self.close() - raise OperationError(space.w_IOError, space.wrap( - "bad message length")) + raise oefmt(space.w_IOError, "bad message length") newbuf = lltype.malloc(rffi.CCHARP.TO, length + 1, flavor='raw') for i in range(read_ptr[0]): diff --git a/pypy/module/_multiprocessing/interp_memory.py b/pypy/module/_multiprocessing/interp_memory.py --- a/pypy/module/_multiprocessing/interp_memory.py +++ b/pypy/module/_multiprocessing/interp_memory.py @@ -1,6 +1,6 @@ from rpython.rtyper.lltypesystem import rffi -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import oefmt from pypy.module.mmap.interp_mmap import W_MMap def address_of_buffer(space, w_obj): @@ -10,5 +10,4 @@ return space.newtuple([space.wrap(address), space.wrap(mmap.mmap.size)]) else: - raise OperationError(space.w_TypeError, space.wrap( - "cannot get address of buffer")) + raise oefmt(space.w_TypeError, "cannot get address of buffer") diff --git a/pypy/module/_multiprocessing/interp_semaphore.py b/pypy/module/_multiprocessing/interp_semaphore.py --- a/pypy/module/_multiprocessing/interp_semaphore.py +++ b/pypy/module/_multiprocessing/interp_semaphore.py @@ -10,7 +10,7 @@ from rpython.translator.tool.cbuild import ExternalCompilationInfo from pypy.interpreter.baseobjspace import W_Root -from pypy.interpreter.error import OperationError, wrap_oserror +from pypy.interpreter.error import oefmt, wrap_oserror from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import GetSetProperty, TypeDef from pypy.module._multiprocessing.interp_connection import w_handle @@ -250,8 +250,7 @@ if timeout < 0.0: timeout = 0.0 elif timeout >= 0.5 * rwin32.INFINITE: # 25 days - raise OperationError(space.w_OverflowError, - space.wrap("timeout is too large")) + raise oefmt(space.w_OverflowError, "timeout is too large") full_msecs = r_uint(int(timeout + 0.5)) # check whether we can acquire without blocking @@ -298,9 +297,8 @@ lltype.nullptr(rffi.LONGP.TO)): err = rwin32.GetLastError_saved() if err == 0x0000012a: # ERROR_TOO_MANY_POSTS - raise OperationError( - space.w_ValueError, - space.wrap("semaphore or lock released too many times")) + raise oefmt(space.w_ValueError, + "semaphore or lock released too many times") else: raise WindowsError(err, "ReleaseSemaphore") @@ -393,23 +391,21 @@ else: # it was not locked so undo wait and raise sem_post(self.handle) - raise OperationError( - space.w_ValueError, space.wrap( - "semaphore or lock released too many times")) + raise oefmt(space.w_ValueError, + "semaphore or lock released too many times") else: # This check is not an absolute guarantee that the semaphore does # not rise above maxvalue. if sem_getvalue(self.handle) >= self.maxvalue: - raise OperationError( - space.w_ValueError, space.wrap( - "semaphore or lock released too many times")) + raise oefmt(space.w_ValueError, + "semaphore or lock released too many times") sem_post(self.handle) def semlock_getvalue(self, space): if HAVE_BROKEN_SEM_GETVALUE: - raise OperationError(space.w_NotImplementedError, space.wrap( - 'sem_getvalue is not implemented on this system')) + raise oefmt(space.w_NotImplementedError, + "sem_getvalue is not implemented on this system") else: val = sem_getvalue(self.handle) # some posix implementations use negative numbers to indicate @@ -492,10 +488,9 @@ def release(self, space): if self.kind == RECURSIVE_MUTEX: if not self._ismine(): - raise OperationError( - space.w_AssertionError, - space.wrap("attempt to release recursive lock" - " not owned by thread")) + raise oefmt(space.w_AssertionError, + "attempt to release recursive lock not owned by " + "thread") if self.count > 1: self.count -= 1 return @@ -528,8 +523,7 @@ @unwrap_spec(kind=int, value=int, maxvalue=int) def descr_new(space, w_subtype, kind, value, maxvalue): if kind != RECURSIVE_MUTEX and kind != SEMAPHORE: - raise OperationError(space.w_ValueError, - space.wrap("unrecognized kind")) + raise oefmt(space.w_ValueError, "unrecognized kind") counter = space.fromcache(CounterState).getCount() name = "/mp%d-%d" % (os.getpid(), counter) diff --git a/pypy/module/_multiprocessing/interp_win32.py b/pypy/module/_multiprocessing/interp_win32.py --- a/pypy/module/_multiprocessing/interp_win32.py +++ b/pypy/module/_multiprocessing/interp_win32.py @@ -4,7 +4,7 @@ from rpython.rtyper.tool import rffi_platform from rpython.translator.tool.cbuild import ExternalCompilationInfo -from pypy.interpreter.error import OperationError, wrap_windowserror +from pypy.interpreter.error import oefmt, wrap_windowserror from pypy.interpreter.function import StaticMethod from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.module._multiprocessing.interp_connection import w_handle @@ -120,8 +120,7 @@ outputsize, inputsize, timeout, w_security): security = space.int_w(w_security) if security: - raise OperationError(space.w_NotImplementedError, - space.wrap("expected a NULL pointer")) + raise oefmt(space.w_NotImplementedError, "expected a NULL pointer") handle = _CreateNamedPipe( name, openmode, pipemode, maxinstances, outputsize, inputsize, timeout, rffi.NULL) @@ -135,8 +134,7 @@ handle = handle_w(space, w_handle) overlapped = space.int_w(w_overlapped) if overlapped: - raise OperationError(space.w_NotImplementedError, - space.wrap("expected a NULL pointer")) + raise oefmt(space.w_NotImplementedError, "expected a NULL pointer") if not _ConnectNamedPipe(handle, rffi.NULL): raise wrap_windowserror(space, rwin32.lastSavedWindowsError()) @@ -176,8 +174,7 @@ security = space.int_w(w_security) templatefile = space.int_w(w_templatefile) if security or templatefile: - raise OperationError(space.w_NotImplementedError, - space.wrap("expected a NULL pointer")) + raise oefmt(space.w_NotImplementedError, "expected a NULL pointer") handle = _CreateFile(filename, access, share, rffi.NULL, disposition, flags, rwin32.NULL_HANDLE) diff --git a/pypy/module/_pickle_support/maker.py b/pypy/module/_pickle_support/maker.py --- a/pypy/module/_pickle_support/maker.py +++ b/pypy/module/_pickle_support/maker.py @@ -1,4 +1,4 @@ -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import oefmt from pypy.interpreter.nestedscope import Cell from pypy.interpreter.pycode import PyCode from pypy.interpreter.function import Function, Method @@ -83,9 +83,8 @@ try: return gateway.BuiltinCode.find(identifier) except KeyError: - raise OperationError(space.w_RuntimeError, - space.wrap("cannot unpickle builtin code: "+ - identifier)) + raise oefmt(space.w_RuntimeError, + "cannot unpickle builtin code: %s", identifier) @unwrap_spec(identifier=str) def builtin_function(space, identifier): @@ -93,9 +92,8 @@ try: return function.Function.find(identifier) except KeyError: - raise OperationError(space.w_RuntimeError, - space.wrap("cannot unpickle builtin function: "+ - identifier)) + raise oefmt(space.w_RuntimeError, + "cannot unpickle builtin function: %s", identifier) # ___________________________________________________________________ diff --git a/pypy/module/_pypyjson/interp_decoder.py b/pypy/module/_pypyjson/interp_decoder.py --- a/pypy/module/_pypyjson/interp_decoder.py +++ b/pypy/module/_pypyjson/interp_decoder.py @@ -3,7 +3,7 @@ from rpython.rlib.objectmodel import specialize from rpython.rlib import rfloat, runicode from rpython.rtyper.lltypesystem import lltype, rffi -from pypy.interpreter.error import OperationError, oefmt +from pypy.interpreter.error import oefmt from pypy.interpreter import unicodehelper OVF_DIGITS = len(str(sys.maxint)) diff --git a/pypy/module/_random/interp_random.py b/pypy/module/_random/interp_random.py --- a/pypy/module/_random/interp_random.py +++ b/pypy/module/_random/interp_random.py @@ -1,6 +1,6 @@ import time -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import oefmt from pypy.interpreter.typedef import TypeDef from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.baseobjspace import W_Root @@ -58,11 +58,9 @@ def setstate(self, space, w_state): if not space.isinstance_w(w_state, space.w_tuple): - errstring = space.wrap("state vector must be tuple") - raise OperationError(space.w_TypeError, errstring) + raise oefmt(space.w_TypeError, "state vector must be tuple") if space.len_w(w_state) != rrandom.N + 1: - errstring = space.wrap("state vector is the wrong size") - raise OperationError(space.w_ValueError, errstring) + raise oefmt(space.w_ValueError, "state vector is the wrong size") w_zero = space.newint(0) # independent of platfrom, since the below condition is only # true on 32 bit platforms anyway @@ -78,8 +76,8 @@ @unwrap_spec(k=int) def getrandbits(self, space, k): if k <= 0: - strerror = space.wrap("number of bits must be greater than zero") - raise OperationError(space.w_ValueError, strerror) + raise oefmt(space.w_ValueError, + "number of bits must be greater than zero") bytes = ((k - 1) // 32 + 1) * 4 bytesarray = rstring.StringBuilder(bytes) for i in range(0, bytes, 4): diff --git a/pypy/module/_rawffi/alt/interp_ffitype.py b/pypy/module/_rawffi/alt/interp_ffitype.py --- a/pypy/module/_rawffi/alt/interp_ffitype.py +++ b/pypy/module/_rawffi/alt/interp_ffitype.py @@ -4,7 +4,7 @@ from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.typedef import TypeDef, interp_attrproperty from pypy.interpreter.gateway import interp2app -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import oefmt class W_FFIType(W_Root): @@ -39,8 +39,8 @@ try: return space.wrap(self.sizeof()) except ValueError: - msg = "Operation not permitted on an incomplete type" - raise OperationError(space.w_ValueError, space.wrap(msg)) + raise oefmt(space.w_ValueError, + "Operation not permitted on an incomplete type") def sizeof(self): return intmask(self.get_ffitype().c_size) diff --git a/pypy/module/_rawffi/alt/interp_funcptr.py b/pypy/module/_rawffi/alt/interp_funcptr.py --- a/pypy/module/_rawffi/alt/interp_funcptr.py +++ b/pypy/module/_rawffi/alt/interp_funcptr.py @@ -49,8 +49,8 @@ return W_FuncPtr(func, argtypes_w, w_restype) else: - raise OperationError(space.w_TypeError, space.wrap( - 'function name must be a string or integer')) + raise oefmt(space.w_TypeError, + "function name must be a string or integer") else: @unwrap_spec(name=str) def _getfunc(space, CDLL, w_name, w_argtypes, w_restype): @@ -71,8 +71,7 @@ def unwrap_ffitype(space, w_argtype, allow_void=False): res = w_argtype.get_ffitype() if res is libffi.types.void and not allow_void: - msg = 'void is not a valid argument type' - raise OperationError(space.w_TypeError, space.wrap(msg)) + raise oefmt(space.w_TypeError, "void is not a valid argument type") return res diff --git a/pypy/module/_rawffi/alt/type_converter.py b/pypy/module/_rawffi/alt/type_converter.py --- a/pypy/module/_rawffi/alt/type_converter.py +++ b/pypy/module/_rawffi/alt/type_converter.py @@ -1,7 +1,7 @@ from rpython.rlib import libffi from rpython.rlib import jit from rpython.rlib.rarithmetic import r_uint -from pypy.interpreter.error import OperationError, oefmt +from pypy.interpreter.error import oefmt from pypy.module._rawffi.structure import W_StructureInstance, W_Structure from pypy.module._rawffi.alt.interp_ffitype import app_types @@ -240,8 +240,7 @@ elif isinstance(w_structdescr, W_Structure): return self.get_struct_rawffi(w_ffitype, w_structdescr) else: - raise OperationError(self.space.w_TypeError, - self.space.wrap("Unsupported struct shape")) + raise oefmt(self.space.w_TypeError, "Unsupported struct shape") elif w_ffitype.is_void(): voidval = self.get_void(w_ffitype) assert voidval is None diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py --- a/pypy/module/_rawffi/array.py +++ b/pypy/module/_rawffi/array.py @@ -6,7 +6,7 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty from rpython.rtyper.lltypesystem import lltype, rffi -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.module._rawffi.interp_rawffi import segfault_exception from pypy.module._rawffi.interp_rawffi import W_DataShape, W_DataInstance from pypy.module._rawffi.interp_rawffi import unwrap_value, wrap_value @@ -43,9 +43,8 @@ items_w = space.unpackiterable(w_items) iterlength = len(items_w) if iterlength > length: - raise OperationError(space.w_ValueError, - space.wrap("too many items for specified" - " array length")) + raise oefmt(space.w_ValueError, + "too many items for specified array length") for num in range(iterlength): w_item = items_w[num] unwrap_value(space, write_ptr, result.ll_buffer, num, @@ -152,12 +151,10 @@ def decodeslice(self, space, w_slice): if not space.isinstance_w(w_slice, space.w_slice): - raise OperationError(space.w_TypeError, - space.wrap('index must be int or slice')) + raise oefmt(space.w_TypeError, "index must be int or slice") letter = self.shape.itemcode if letter != 'c': - raise OperationError(space.w_TypeError, - space.wrap("only 'c' arrays support slicing")) + raise oefmt(space.w_TypeError, "only 'c' arrays support slicing") w_start = space.getattr(w_slice, space.wrap('start')) w_stop = space.getattr(w_slice, space.wrap('stop')) w_step = space.getattr(w_slice, space.wrap('step')) @@ -173,11 +170,9 @@ if not space.is_w(w_step, space.w_None): step = space.int_w(w_step) if step != 1: - raise OperationError(space.w_ValueError, - space.wrap("no step support")) + raise oefmt(space.w_ValueError, "no step support") if not (0 <= start <= stop <= self.length): - raise OperationError(space.w_ValueError, - space.wrap("slice out of bounds")) + raise oefmt(space.w_ValueError, "slice out of bounds") if not self.ll_buffer: raise segfault_exception(space, "accessing a freed array") return start, stop @@ -192,8 +187,7 @@ start, stop = self.decodeslice(space, w_slice) value = space.str_w(w_value) if start + len(value) != stop: - raise OperationError(space.w_ValueError, - space.wrap("cannot resize array")) + raise oefmt(space.w_ValueError, "cannot resize array") ll_buffer = self.ll_buffer for i in range(len(value)): ll_buffer[start + i] = value[i] diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py --- a/pypy/module/_rawffi/interp_rawffi.py +++ b/pypy/module/_rawffi/interp_rawffi.py @@ -142,8 +142,7 @@ for w_arg in space.unpackiterable(w_argtypes)] def got_libffi_error(space): - raise OperationError(space.w_SystemError, - space.wrap("not supported by libffi")) + raise oefmt(space.w_SystemError, "not supported by libffi") def wrap_dlopenerror(space, e, filename): if e.msg: @@ -214,8 +213,8 @@ except LibFFIError: raise got_libffi_error(space) else: - raise OperationError(space.w_TypeError, space.wrap( - "function name must be string or integer")) + raise oefmt(space.w_TypeError, + "function name must be string or integer") w_funcptr = W_FuncPtr(space, ptr, argshapes, resshape) space.setitem(self.w_cache, w_key, w_funcptr) @@ -380,7 +379,6 @@ def unwrap_value(space, push_func, add_arg, argdesc, letter, w_arg): - w = space.wrap if letter in TYPEMAP_PTR_LETTERS: # check for NULL ptr if isinstance(w_arg, W_DataInstance): @@ -402,15 +400,16 @@ else: s = space.str_w(w_arg) if len(s) != 1: - raise OperationError(space.w_TypeError, w( - "Expected string of length one as character")) + raise oefmt(space.w_TypeError, + "Expected string of length one as character") val = s[0] push_func(add_arg, argdesc, val) elif letter == 'u': s = space.unicode_w(w_arg) if len(s) != 1: - raise OperationError(space.w_TypeError, w( - "Expected unicode string of length one as wide character")) + raise oefmt(space.w_TypeError, + "Expected unicode string of length one as wide " + "character") val = s[0] push_func(add_arg, argdesc, val) else: @@ -421,8 +420,7 @@ push_func(add_arg, argdesc, val) return else: - raise OperationError(space.w_TypeError, - space.wrap("cannot directly write value")) + raise oefmt(space.w_TypeError, "cannot directly write value") unwrap_value._annspecialcase_ = 'specialize:arg(1)' ll_typemap_iter = unrolling_iterable(LL_TYPEMAP.items()) @@ -439,8 +437,7 @@ return space.wrap(float(func(add_arg, argdesc, ll_type))) else: return space.wrap(func(add_arg, argdesc, ll_type)) - raise OperationError(space.w_TypeError, - space.wrap("cannot directly read value")) + raise oefmt(space.w_TypeError, "cannot directly read value") wrap_value._annspecialcase_ = 'specialize:arg(1)' NARROW_INTEGER_TYPES = 'cbhiBIH?' @@ -555,8 +552,7 @@ @unwrap_spec(tp_letter=str) def accessor(space, tp_letter): if len(tp_letter) != 1: - raise OperationError(space.w_ValueError, space.wrap( _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit