Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r84164:f60d1a596389
Date: 2016-05-02 19:52 -0700
http://bitbucket.org/pypy/pypy/changeset/f60d1a596389/

Log:    oefmt

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1563,8 +1563,8 @@
         from rpython.rlib import rstring
         result = self.str_w(w_obj)
         if '\x00' in result:
-            raise OperationError(self.w_TypeError, self.wrap(
-                    'argument must be a string without NUL characters'))
+            raise oefmt(self.w_TypeError,
+                        "argument must be a string without NUL characters")
         return rstring.assert_str0(result)
 
     def bytes0_w(self, w_obj):
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -381,8 +381,7 @@
         if space.is_w(w_new, space.w_None):
             w_new = None
         elif not space.isinstance_w(w_new, space.w_dict):
-            msg = "__kwdefaults__ must be a dict"
-            raise OperationError(space.w_TypeError, space.wrap(msg))
+            raise oefmt(space.w_TypeError, "__kwdefaults__ must be a dict")
         self.w_kw_defs = w_new
 
     def fdel_func_kwdefaults(self, space):
@@ -414,9 +413,8 @@
             self.qualname = space.unicode_w(w_name)
         except OperationError as e:
             if e.match(space, space.w_TypeError):
-                raise OperationError(space.w_TypeError,
-                                     space.wrap("__qualname__ must be set "
-                                                "to a string object"))
+                raise oefmt(space.w_TypeError,
+                            "__qualname__ must be set to a string object")
             raise
 
     def fdel_func_doc(self, space):
@@ -471,8 +469,7 @@
         if space.is_w(w_new, space.w_None):
             w_new = None
         elif not space.isinstance_w(w_new, space.w_dict):
-            msg = "__annotations__ must be a dict"
-            raise OperationError(space.w_TypeError, space.wrap(msg))
+            raise oefmt(space.w_TypeError, "__annotations__ must be a dict")
         self.w_ann = w_new
 
     def fdel_func_annotations(self, space):
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -754,8 +754,7 @@
         w_build_class = self.get_builtin().getdictvalue(
             self.space, '__build_class__')
         if w_build_class is None:
-            raise OperationError(self.space.w_ImportError,
-                                 self.space.wrap("__build_class__ not found"))
+            raise oefmt(self.space.w_ImportError, "__build_class__ not found")
         self.pushvalue(w_build_class)
 
     def STORE_NAME(self, varindex, next_instr):
@@ -919,11 +918,9 @@
         if space.isinstance_w(w_2, space.w_tuple):
             for w_type in space.fixedview(w_2):
                 if not space.exception_is_valid_class_w(w_type):
-                    raise OperationError(space.w_TypeError,
-                                         space.wrap(CANNOT_CATCH_MSG))
+                    raise oefmt(space.w_TypeError, CANNOT_CATCH_MSG)
         elif not space.exception_is_valid_class_w(w_2):
-            raise OperationError(space.w_TypeError,
-                                 space.wrap(CANNOT_CATCH_MSG))
+            raise oefmt(space.w_TypeError, CANNOT_CATCH_MSG)
         return space.newbool(space.exception_match(w_1, w_2))
 
     def COMPARE_OP(self, testnum, next_instr):
@@ -970,8 +967,7 @@
 
         w_import = self.get_builtin().getdictvalue(space, '__import__')
         if w_import is None:
-            raise OperationError(space.w_ImportError,
-                                 space.wrap("__import__ not found"))
+            raise oefmt(space.w_ImportError, "__import__ not found")
         d = self.getdebug()
         if d is None:
             w_locals = None
diff --git a/pypy/interpreter/pyparser/parsestring.py 
b/pypy/interpreter/pyparser/parsestring.py
--- a/pypy/interpreter/pyparser/parsestring.py
+++ b/pypy/interpreter/pyparser/parsestring.py
@@ -80,8 +80,8 @@
         # Disallow non-ascii characters (but not escapes)
         for c in substr:
             if ord(c) > 0x80:
-                raise OperationError(space.w_SyntaxError, space.wrap(
-                        'bytes can only contain ASCII literal characters.'))
+                raise oefmt(space.w_SyntaxError,
+                            "bytes can only contain ASCII literal characters.")
 
     if rawmode or '\\' not in substr:
         if not unicode_literal:
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
@@ -56,30 +56,26 @@
         frame = ec.gettopframe()
         code = frame.pycode
         if not code:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                    "super(): no code object"))
+            raise oefmt(space.w_RuntimeError, "super(): no code object")
         if code.co_argcount == 0:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                    "super(): no arguments"))
+            raise oefmt(space.w_RuntimeError, "super(): no arguments")
         w_obj = frame.locals_cells_stack_w[0]
         if not w_obj:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                    "super(): arg[0] deleted"))
+            raise oefmt(space.w_RuntimeError, "super(): arg[0] deleted")
         index = 0
         for name in code.co_freevars:
             if name == "__class__":
                 break
             index += 1
         else:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                    "super(): __class__ cell not found"))
+            raise oefmt(space.w_RuntimeError,
+                        "super(): __class__ cell not found")
         # a kind of LOAD_DEREF
         cell = frame._getcell(len(code.co_cellvars) + index)
         try:
             w_starttype = cell.get()
         except ValueError:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                    "super(): empty __class__ cell"))
+            raise oefmt(space.w_RuntimeError, "super(): empty __class__ cell")
         w_obj_or_type = w_obj
 
     if space.is_none(w_obj_or_type):
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
@@ -388,8 +388,8 @@
             pass  # We know it's not zero
         else:
             if step == 0:
-                raise OperationError(space.w_ValueError, space.wrap(
-                        "step argument must not be zero"))
+                raise oefmt(space.w_ValueError,
+                            "step argument must not be zero")
         w_length = compute_range_length(space, w_start, w_stop, w_step)
         obj = space.allocate_instance(W_Range, w_subtype)
         W_Range.__init__(obj, w_start, w_stop, w_step, w_length, promote_step)
@@ -688,7 +688,9 @@
                 iterator_w = space.iter(iterable_w)
             except OperationError as e:
                 if e.match(self.space, self.space.w_TypeError):
-                    raise OperationError(space.w_TypeError, 
space.wrap(self._error_name + " argument #" + str(i + 1) + " must support 
iteration"))
+                    raise oefmt(space.w_TypeError,
+                                "%s argument #%d must support iteration",
+                                self._error_name, i + 1)
                 else:
                     raise
             else:
@@ -731,8 +733,8 @@
 
 def W_Map___new__(space, w_subtype, w_fun, args_w):
     if len(args_w) == 0:
-        raise OperationError(space.w_TypeError,
-                  space.wrap("map() must have at least two arguments"))
+        raise oefmt(space.w_TypeError,
+                    "map() must have at least two arguments")
     r = space.allocate_instance(W_Map, w_subtype)
     r.__init__(space, w_fun, args_w)
     return space.wrap(r)
diff --git a/pypy/module/_socket/interp_func.py 
b/pypy/module/_socket/interp_func.py
--- a/pypy/module/_socket/interp_func.py
+++ b/pypy/module/_socket/interp_func.py
@@ -2,7 +2,7 @@
 from rpython.rlib.rsocket import SocketError, INVALID_SOCKET
 from rpython.rlib.rarithmetic import intmask
 
-from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.error import oefmt
 from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
 from pypy.module._socket.interp_socket import (
     converted_error, W_Socket, addr_as_object, fill_from_object, get_error,
@@ -131,9 +131,8 @@
                                   rsocket.SOCK_DGRAM, 0,
                                   rsocket.AI_NUMERICHOST)
         if len(lst) > 1:
-            raise OperationError(
-                get_error(space, 'error'),
-                space.wrap("sockaddr resolved to multiple addresses"))
+            raise oefmt(get_error(space, 'error'),
+                        "sockaddr resolved to multiple addresses")
         addr = lst[0][4]
         fill_from_object(addr, space, w_sockaddr)
         host, servport = rsocket.getnameinfo(addr, flags)
diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py
--- a/pypy/module/_sre/interp_sre.py
+++ b/pypy/module/_sre/interp_sre.py
@@ -111,8 +111,9 @@
             unicodestr = space.unicode_w(w_string)
             if not (space.is_none(self.w_pattern) or
                     space.isinstance_w(self.w_pattern, space.w_unicode)):
-                raise OperationError(space.w_TypeError, space.wrap(
-                        "can't use a bytes pattern on a string-like object"))
+                raise oefmt(space.w_TypeError,
+                            "can't use a bytes pattern on a string-like "
+                            "object")
             if pos > len(unicodestr):
                 pos = len(unicodestr)
             if endpos > len(unicodestr):
@@ -122,8 +123,9 @@
         elif space.isinstance_w(w_string, space.w_str):
             if (not space.is_none(self.w_pattern) and
                 space.isinstance_w(self.w_pattern, space.w_unicode)):
-                raise OperationError(space.w_TypeError, space.wrap(
-                        "can't use a string pattern on a bytes-like object"))
+                raise oefmt(space.w_TypeError,
+                            "can't use a string pattern on a bytes-like "
+                            "object")
             str = space.str_w(w_string)
             if pos > len(str):
                 pos = len(str)
@@ -135,8 +137,9 @@
             buf = space.readbuf_w(w_string)
             if (not space.is_none(self.w_pattern) and
                 space.isinstance_w(self.w_pattern, space.w_unicode)):
-                raise OperationError(space.w_TypeError, space.wrap(
-                        "can't use a string pattern on a bytes-like object"))
+                raise oefmt(space.w_TypeError,
+                            "can't use a string pattern on a bytes-like "
+                            "object")
             size = buf.getlength()
             assert size >= 0
             if pos > size:
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -239,8 +239,7 @@
 
     def _RAND_bytes(space, n, pseudo):
         if n < 0:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "num must be positive"))
+            raise oefmt(space.w_ValueError, "num must be positive")
 
         with rffi.scoped_alloc_buffer(n) as buf:
             if pseudo:
@@ -1378,9 +1377,9 @@
                                   "encode", space.wrap("idna")))
 
         if hostname and not HAS_SNI:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("server_hostname is not supported "
-                                            "by your OpenSSL library"))
+            raise oefmt(space.w_ValueError,
+                        "server_hostname is not supported by your OpenSSL "
+                        "library")
 
         return new_sslobject(space, self.ctx, w_sock, server_side, hostname)
 
diff --git a/pypy/module/array/reconstructor.py 
b/pypy/module/array/reconstructor.py
--- a/pypy/module/array/reconstructor.py
+++ b/pypy/module/array/reconstructor.py
@@ -3,7 +3,7 @@
 # from its memory representation.
 import sys
 from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import oefmt
 from pypy.interpreter.argument import Arguments
 from rpython.rlib import runicode, rbigint
 from rpython.rlib.rstruct import ieee
@@ -80,12 +80,10 @@
             space, w_cls, typecode, Arguments(space, [w_items]))
 
     if typecode not in interp_array.types:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("invalid type code"))
+        raise oefmt(space.w_ValueError, "invalid type code")
     if (mformat_code < MACHINE_FORMAT_CODE_MIN or
         mformat_code > MACHINE_FORMAT_CODE_MAX):
-        raise OperationError(space.w_ValueError,
-                             space.wrap("invalid machine format code"))
+        raise oefmt(space.w_ValueError, "invalid machine format code")
 
     # Slow path: Decode the byte string according to the given machine
     # format code. This occurs when the computer unpickling the array
diff --git a/pypy/module/cpyext/unicodeobject.py 
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -441,8 +441,7 @@
         w_obj = PyUnicode_FromObject(space, w_obj)
         w_output = space.fsencode(w_obj)
         if not space.isinstance_w(w_output, space.w_bytes):
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("encoder failed to return bytes"))
+            raise oefmt(space.w_TypeError, "encoder failed to return bytes")
     data = space.bytes0_w(w_output)  # Check for NUL bytes
     result[0] = make_ref(space, w_output)
     return Py_CLEANUP_SUPPORTED
@@ -465,8 +464,7 @@
         w_obj = PyBytes_FromObject(space, w_obj)
         w_output = space.fsdecode(w_obj)
         if not space.isinstance_w(w_output, space.w_unicode):
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("decoder failed to return 
unicode"))
+            raise oefmt(space.w_TypeError, "decoder failed to return unicode")
     data = space.unicode0_w(w_output)  # Check for NUL bytes
     result[0] = make_ref(space, w_output)
     return Py_CLEANUP_SUPPORTED
diff --git a/pypy/module/exceptions/interp_exceptions.py 
b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -172,9 +172,9 @@
         if space.is_w(w_newcause, space.w_None):
             w_newcause = None
         elif not space.exception_is_valid_class_w(space.type(w_newcause)):
-            raise OperationError(space.w_TypeError, space.wrap(
-                    "exception cause must be None or "
-                    "derive from BaseException"))
+            raise oefmt(space.w_TypeError,
+                        "exception cause must be None or derive from "
+                        "BaseException")
         self.w_cause = w_newcause
         self.suppress_context = True
 
@@ -184,9 +184,9 @@
     def descr_setcontext(self, space, w_newcontext):
         if not (space.is_w(w_newcontext, space.w_None) or
                 space.exception_is_valid_class_w(space.type(w_newcontext))):
-            raise OperationError(space.w_TypeError, space.wrap(
-                    "exception context must be None or "
-                    "derive from BaseException"))
+            raise oefmt(space.w_TypeError,
+                        "exception context must be None or derive from "
+                        "BaseException")
         self.w_context = w_newcontext
 
     def descr_gettraceback(self, space):
@@ -319,9 +319,9 @@
         self.w_name = kw_w.pop('name', space.w_None)
         self.w_path = kw_w.pop('path', space.w_None)
         if kw_w:
-            raise OperationError(space.w_TypeError, space.wrap(
-                    # CPython displays this, but it's not quite right.
-                    "ImportError does not take keyword arguments"))
+            # CPython displays this, but it's not quite right.
+            raise oefmt(space.w_TypeError,
+                        "ImportError does not take keyword arguments")
         W_Exception.descr_init(self, space, args_w)
 
 
@@ -571,8 +571,7 @@
 
     def descr_get_written(self, space):
         if self.written == -1:
-            raise OperationError(space.w_AttributeError,
-                                 space.wrap("characters_written"))
+            raise oefmt(space.w_AttributeError, "characters_written")
         return space.wrap(self.written)
 
     def descr_set_written(self, space, w_written):
diff --git a/pypy/module/itertools/interp_itertools.py 
b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -1429,8 +1429,7 @@
     def descr_setstate(self, space, w_state):
         indices_w = space.fixedview(w_state)
         if len(indices_w) != self.r:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "invalid arguments"))
+            raise oefmt(space.w_ValueError, "invalid arguments")
         for i in range(self.r):
             index = space.int_w(indices_w[i])
             max = self.get_maximum(i)
diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -390,7 +390,7 @@
         # Python 2.x (and thus ll_math) raises a OverflowError improperly.
         if not e.match(space, space.w_OverflowError):
             raise
-        raise OperationError(space.w_ValueError, space.wrap("math domain 
error"))
+        raise oefmt(space.w_ValueError, "math domain error")
 
 def acosh(space, w_x):
     """Inverse hyperbolic cosine"""
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -256,5 +256,5 @@
 same value."""
     if space.is_w(space.type(w_str), space.w_unicode):
         return space.new_interned_w_str(w_str)
-    raise OperationError(space.w_TypeError, space.wrap("intern() argument must 
be string."))
+    raise oefmt(space.w_TypeError, "intern() argument must be string.")
 
diff --git a/pypy/module/thread/os_lock.py b/pypy/module/thread/os_lock.py
--- a/pypy/module/thread/os_lock.py
+++ b/pypy/module/thread/os_lock.py
@@ -88,8 +88,8 @@
         try:
             self.lock.release()
         except rthread.error:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                "cannot release un-acquired lock"))
+            raise oefmt(space.w_RuntimeError,
+                        "cannot release un-acquired lock")
 
     def descr_lock_locked(self, space):
         """Return whether the lock is in the locked state."""
@@ -183,8 +183,8 @@
             try:
                 self.rlock_count = ovfcheck(self.rlock_count + 1)
             except OverflowError:
-                raise OperationError(space.w_OverflowError, space.wrap(
-                        'internal lock count overflowed'))
+                raise oefmt(space.w_OverflowError,
+                            "internal lock count overflowed")
             return space.w_True
 
         r = True
@@ -212,8 +212,8 @@
         to be available for other threads."""
         tid = rthread.get_ident()
         if self.rlock_count == 0 or self.rlock_owner != tid:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                    "cannot release un-acquired lock"))
+            raise oefmt(space.w_RuntimeError,
+                        "cannot release un-acquired lock")
         self.rlock_count -= 1
         if self.rlock_count == 0:
             self.rlock_owner == 0
@@ -245,8 +245,8 @@
     def release_save_w(self, space):
         """For internal use by `threading.Condition`."""
         if self.rlock_count == 0:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                "cannot release un-acquired lock"))
+            raise oefmt(space.w_RuntimeError,
+                        "cannot release un-acquired lock")
         count, self.rlock_count = self.rlock_count, 0
         owner, self.rlock_owner = self.rlock_owner, 0
         self.lock.release()
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -484,25 +484,19 @@
     representation by some bad index (fixes bug #897625).  No check for
     year or wday since handled in _gettmarg()."""
     if not 0 <= rffi.getintfield(t_ref, 'c_tm_mon') <= 11:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("month out of range"))
+        raise oefmt(space.w_ValueError, "month out of range")
     if not 1 <= rffi.getintfield(t_ref, 'c_tm_mday') <= 31:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("day of month out of range"))
+        raise oefmt(space.w_ValueError, "day of month out of range")
     if not 0 <= rffi.getintfield(t_ref, 'c_tm_hour') <= 23:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("hour out of range"))
+        raise oefmt(space.w_ValueError, "hour out of range")
     if not 0 <= rffi.getintfield(t_ref, 'c_tm_min') <= 59:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("minute out of range"))
+        raise oefmt(space.w_ValueError, "minute out of range")
     if not 0 <= rffi.getintfield(t_ref, 'c_tm_sec') <= 61:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("seconds out of range"))
+        raise oefmt(space.w_ValueError, "seconds out of range")
     # tm_wday does not need checking: "% 7" in _gettmarg() automatically
     # restricts the range
     if not 0 <= rffi.getintfield(t_ref, 'c_tm_yday') <= 365:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("day of year out of range"))
+        raise oefmt(space.w_ValueError, "day of year out of range")
 
 def time(space):
     """time() -> floating point number
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -422,8 +422,8 @@
             except OperationError as e:
                 if not e.match(space, space.w_StopIteration):
                     raise
-                msg = "sequence.index(x): x not in sequence"
-                raise OperationError(space.w_ValueError, space.wrap(msg))
+                raise oefmt(space.w_ValueError,
+                            "sequence.index(x): x not in sequence")
             if space.eq_w(w_next, w_item):
                 return space.wrap(index)
             index += 1
diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -468,17 +468,20 @@
         if i >= length:
             break
         if i + 1 == length:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "non-hexadecimal number found in fromhex() arg at position %d" 
% i))
+            raise oefmt(space.w_ValueError,
+                        "non-hexadecimal number found in fromhex() arg at "
+                        "position %d", i)
 
         top = _hex_digit_to_int(s[i])
         if top == -1:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "non-hexadecimal number found in fromhex() arg at position %d" 
% i))
+            raise oefmt(space.w_ValueError,
+                        "non-hexadecimal number found in fromhex() arg at "
+                        "position %d", i)
         bot = _hex_digit_to_int(s[i+1])
         if bot == -1:
-            raise OperationError(space.w_ValueError, space.wrap(
-                "non-hexadecimal number found in fromhex() arg at position %d" 
% (i+1,)))
+            raise oefmt(space.w_ValueError,
+                        "non-hexadecimal number found in fromhex() arg at "
+                        "position %d", i + 1)
         data.append(chr(top*16 + bot))
     return data
 
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -650,16 +650,15 @@
     value = space.getindex_w(w_value, None)
     if not 0 <= value < 256:
         # this includes the OverflowError in case the long is too large
-        raise OperationError(space.w_ValueError, space.wrap(
-            "byte must be in range(0, 256)"))
+        raise oefmt(space.w_ValueError, "byte must be in range(0, 256)")
     return chr(value)
 
 def newbytesdata_w(space, w_source, encoding, errors):
     # None value
     if w_source is None:
         if encoding is not None or errors is not None:
-            raise OperationError(space.w_TypeError, space.wrap(
-                    "encoding or errors without string argument"))
+            raise oefmt(space.w_TypeError,
+                        "encoding or errors without string argument")
         return []
     # Some object with __bytes__ special method
     w_bytes_method = space.lookup(w_source, "__bytes__")
@@ -678,17 +677,16 @@
             raise
     else:
         if count < 0:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap("negative count"))
+            raise oefmt(space.w_ValueError, "negative count")
         if encoding is not None or errors is not None:
-            raise OperationError(space.w_TypeError, space.wrap(
-                    "encoding or errors without string argument"))
+            raise oefmt(space.w_TypeError,
+                        "encoding or errors without string argument")
         return ['\0'] * count
     # Unicode with encoding
     if space.isinstance_w(w_source, space.w_unicode):
         if encoding is None:
-            raise OperationError(space.w_TypeError, space.wrap(
-                    "string argument without an encoding"))
+            raise oefmt(space.w_TypeError,
+                        "string argument without an encoding")
         from pypy.objspace.std.unicodeobject import encode_object
         w_source = encode_object(space, w_source, encoding, errors)
         # and continue with the encoded string
@@ -716,9 +714,8 @@
         return [c for c in buf.as_str()]
 
     if space.isinstance_w(w_source, space.w_unicode):
-        raise OperationError(
-            space.w_TypeError,
-            space.wrap("cannot convert unicode object to bytes"))
+        raise oefmt(space.w_TypeError,
+                    "cannot convert unicode object to bytes")
 
     # sequence of bytes
     w_iter = space.iter(w_source)
diff --git a/pypy/objspace/std/memoryobject.py 
b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -164,8 +164,8 @@
         if self._hash == -1:
             self._check_released(space)
             if not self.buf.readonly:
-                raise OperationError(space.w_ValueError, space.wrap(
-                        "cannot hash writable memoryview object"))
+                raise oefmt(space.w_ValueError,
+                            "cannot hash writable memoryview object")
             self._hash = compute_hash(self.buf.as_str())
         return space.wrap(self._hash)
 
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -204,13 +204,13 @@
             except OperationError as e:
                 if not e.match(space, space.w_TypeError):
                     raise
-                raise OperationError(space.w_TypeError, space.wrap(
-                        "first maketrans argument must "
-                        "be a string if there is a second argument"))
+                raise oefmt(space.w_TypeError,
+                            "first maketrans argument must be a string if "
+                            "there is a second argument")
             if len(x) != ylen:
-                raise OperationError(space.w_ValueError, space.wrap(
-                        "the first two maketrans "
-                        "arguments must have equal length"))
+                raise oefmt(space.w_ValueError,
+                            "the first two maketrans arguments must have "
+                            "equal length")
             # create entries for translating chars in x to those in y
             for i in range(len(x)):
                 w_key = space.newint(ord(x[i]))
@@ -224,9 +224,9 @@
         else:
             # x must be a dict
             if not space.is_w(space.type(w_x), space.w_dict):
-                raise OperationError(space.w_TypeError, space.wrap(
-                        "if you give only one argument "
-                        "to maketrans it must be a dict"))
+                raise oefmt(space.w_TypeError,
+                            "if you give only one argument to maketrans it "
+                            "must be a dict")
             # copy entries into the new dict, converting string keys to int 
keys
             w_iter = space.iter(space.call_method(w_x, "items"))
             while True:
@@ -241,9 +241,9 @@
                     # convert string keys to integer keys
                     key = space.unicode_w(w_key)
                     if len(key) != 1:
-                        raise OperationError(space.w_ValueError, space.wrap(
-                                "string keys in translate "
-                                "table must be of length 1"))
+                        raise oefmt(space.w_ValueError,
+                                    "string keys in translate table must be "
+                                    "of length 1")
                     w_key = space.newint(ord(key[0]))
                 else:
                     # just keep integer keys
@@ -252,9 +252,9 @@
                     except OperationError as e:
                         if not e.match(space, space.w_TypeError):
                             raise
-                        raise OperationError(space.w_TypeError, space.wrap(
-                                "keys in translate table must "
-                                "be strings or integers"))
+                        raise oefmt(space.w_TypeError,
+                                    "keys in translate table must be strings "
+                                    "or integers")
                 space.setitem(w_new, w_key, w_value)
         return w_new
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to