[pypy-commit] pypy py3.5-newtext: hg merge adb61bdfea7e

arigo pypy.commits at gmail.com
Tue Dec 20 07:00:14 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5-newtext
Changeset: r89200:f0b5bb097c0f
Date: 2016-12-20 12:59 +0100
http://bitbucket.org/pypy/pypy/changeset/f0b5bb097c0f/

Log:	hg merge adb61bdfea7e

diff --git a/pypy/doc/objspace.rst b/pypy/doc/objspace.rst
--- a/pypy/doc/objspace.rst
+++ b/pypy/doc/objspace.rst
@@ -208,6 +208,11 @@
    is the type of the argument (which is rpython.rlib.rbigint.rbigint). On PyPy3 this
    method will return an :py:class:`int` (PyPy2 it returns a :py:class:`long`).
 
+.. py:function:: newbytes(t)
+
+   The given argument is a rpython bytestring. Creates a wrapped object
+   of type :py:class:`bytes` (both on PyPy2 and PyPy3).
+
 .. py:function:: newtext(t)
 
    The given argument is a rpython bytestring. Creates a wrapped object
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -32,9 +32,9 @@
 
 def create_entry_point(space, w_dict):
     if w_dict is not None: # for tests
-        w_entry_point = space.getitem(w_dict, space.wrap('entry_point'))
-        w_run_toplevel = space.getitem(w_dict, space.wrap('run_toplevel'))
-        w_initstdio = space.getitem(w_dict, space.wrap('initstdio'))
+        w_entry_point = space.getitem(w_dict, space.newtext('entry_point'))
+        w_run_toplevel = space.getitem(w_dict, space.newtext('run_toplevel'))
+        w_initstdio = space.getitem(w_dict, space.newtext('initstdio'))
         withjit = space.config.objspace.usemodules.pypyjit
     else:
         w_initstdio = space.appexec([], """():
@@ -182,11 +182,11 @@
     def _pypy_execute_source(source, c_argument):
         try:
             w_globals = space.newdict(module=True)
-            space.setitem(w_globals, space.wrap('__builtins__'),
+            space.setitem(w_globals, space.newtext('__builtins__'),
                           space.builtin_modules['builtins'])
-            space.setitem(w_globals, space.wrap('c_argument'),
-                          space.wrap(c_argument))
-            space.appexec([space.wrap(source), w_globals], """(src, glob):
+            space.setitem(w_globals, space.newtext('c_argument'),
+                          space.newbytes(c_argument))
+            space.appexec([space.newtext(source), w_globals], """(src, glob):
                 import sys
                 stmt = compile(src, 'c callback', 'exec')
                 if not hasattr(sys, '_pypy_execute_source'):
@@ -322,7 +322,7 @@
         # obscure hack to stuff the translation options into the translated PyPy
         import pypy.module.sys
         options = make_dict(config)
-        wrapstr = 'space.wrap(%r)' % (options)
+        wrapstr = 'space.newtext(%r)' % (options)
         pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr
         if config.objspace.usemodules._cffi_backend:
             self.hack_for_cffi_modules(driver)
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -96,8 +96,8 @@
     def getaddrstring(self, space):
         # slowish
         w_id = space.id(self)
-        w_4 = space.wrap(4)
-        w_0x0F = space.wrap(0x0F)
+        w_4 = space.newint(4)
+        w_0x0F = space.newint(0x0F)
         i = 2 * HUGEVAL_BYTES
         addrstring = [' '] * i
         while True:
diff --git a/pypy/interpreter/interactive.py b/pypy/interpreter/interactive.py
--- a/pypy/interpreter/interactive.py
+++ b/pypy/interpreter/interactive.py
@@ -99,7 +99,7 @@
 
         # forbidden:
         #space.exec_("__pytrace__ = 0", self.w_globals, self.w_globals)
-        space.setitem(self.w_globals, space.wrap('__pytrace__'),space.wrap(0))
+        space.setitem(self.w_globals, space.wrap('__pytrace__'),space.newint(0))
         self.tracelevel = 0
         self.console_locals = {}
 
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
@@ -445,7 +445,7 @@
     def name_get(self, space):
         if self.name is None:
             return space.w_None
-        return space.newutf8(self.name)
+        return space.newtext(self.name)
 
     def kind_get(self, space):
         return space.newint(self.kind)
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -263,7 +263,7 @@
         if w_descr is None:
             raise oefmt(space.w_TypeError, "'%T' has no length", w_obj)
         w_res = space.get_and_call_function(w_descr, w_obj)
-        return space.wrap(space._check_len_result(w_res))
+        return space.newint(space._check_len_result(w_res))
 
     def _check_len_result(space, w_obj):
         # Will complain if result is too big.
@@ -459,7 +459,7 @@
         return space._type_issubtype(w_sub, w_type)
 
     def issubtype(space, w_sub, w_type):
-        return space.wrap(space._type_issubtype(w_sub, w_type))
+        return space.newbool(space._type_issubtype(w_sub, w_type))
 
     @specialize.arg_or_var(2)
     def isinstance_w(space, w_inst, w_type):
@@ -467,7 +467,7 @@
 
     @specialize.arg_or_var(2)
     def isinstance(space, w_inst, w_type):
-        return space.wrap(space.isinstance_w(w_inst, w_type))
+        return space.newbool(space.isinstance_w(w_inst, w_type))
 
     def index(space, w_obj):
         if space.isinstance_w(w_obj, space.w_int):
diff --git a/pypy/objspace/std/boolobject.py b/pypy/objspace/std/boolobject.py
--- a/pypy/objspace/std/boolobject.py
+++ b/pypy/objspace/std/boolobject.py
@@ -45,7 +45,7 @@
         return space.newbool(space.is_true(w_obj))
 
     def descr_repr(self, space):
-        return space.wrap('True' if self.intval else 'False')
+        return space.newtext('True' if self.intval else 'False')
     descr_str = func_with_new_name(descr_repr, 'descr_str')
 
     def descr_bool(self, space):
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
@@ -82,17 +82,17 @@
         if index >= 0:
             index += self._offset
             if index >= len(self._data):
-                raise OperationError(space.w_IndexError, space.wrap(errmsg))
+                raise OperationError(space.w_IndexError, space.newtext(errmsg))
         else:
             index += len(self._data)    # count from the end
             if index < self._offset:
-                raise OperationError(space.w_IndexError, space.wrap(errmsg))
+                raise OperationError(space.w_IndexError, space.newtext(errmsg))
         check_nonneg(index)
         return index
 
     def _getitem_result(self, space, index):
         character = self._data[self._fixindex(space, index)]
-        return space.wrap(ord(character))
+        return space.newint(ord(character))
 
     def _val(self, space):
         return self.getdata()
@@ -179,7 +179,7 @@
             raise oefmt(space.w_TypeError,
                         "ord() expected a character, but string of length %d "
                         "found", length)
-        return space.wrap(ord(self._data[self._offset]))
+        return space.newint(ord(self._data[self._offset]))
 
     @staticmethod
     def descr_new(space, w_bytearraytype, __args__):
@@ -192,8 +192,8 @@
             w_dict = space.w_None
         return space.newtuple([
             space.type(self), space.newtuple([
-                space.wrap(''.join(self.getdata()).decode('latin-1')),
-                space.wrap('latin-1')]),
+                space.newunicode(''.join(self.getdata()).decode('latin-1')),
+                space.newtext('latin-1')]),
             w_dict])
 
     @staticmethod
@@ -254,11 +254,11 @@
         buf.append(quote)
         buf.append(")")
 
-        return space.wrap(buf.build())
+        return space.newtext(buf.build())
 
     def descr_str(self, space):
         if space.sys.get_flag('bytes_warning'):
-            space.warn(space.wrap("str() on a bytearray instance"),
+            space.warn(space.newtext("str() on a bytearray instance"),
                        space.w_BytesWarning)
         return self.descr_repr(space)
 
@@ -441,7 +441,7 @@
             raise oefmt(space.w_IndexError, "pop from empty bytearray")
         index = self._fixindex(space, index, "pop index out of range")
         result = self._data.pop(index)
-        return space.wrap(ord(result))
+        return space.newint(ord(result))
 
     def descr_remove(self, space, w_char):
         char = space.int_w(space.index(w_char))
@@ -499,7 +499,7 @@
         return self._getitem_result(space, index)
 
     def descr_alloc(self, space):
-        return space.wrap(len(self._data) + 1)   # includes the _offset part
+        return space.newint(len(self._data) + 1)   # includes the _offset part
 
     def _convert_idx_params(self, space, w_start, w_end):
         # optimization: this version doesn't force getdata()
@@ -599,7 +599,7 @@
         c = (byte & 0xf)
         hexstring.append(HEXDIGITS[c])
 
-    return space.wrap(hexstring.build())
+    return space.newtext(hexstring.build())
 
 class BytearrayDocstrings:
     """bytearray(iterable_of_ints) -> bytearray
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
@@ -45,7 +45,7 @@
             else:
                 base = 256           # empty string: base value 256
             uid = (base << IDTAG_SHIFT) | IDTAG_SPECIAL
-        return space.wrap(uid)
+        return space.newint(uid)
 
     def descr_add(self, space, w_other):
         """x.__add__(y) <==> x+y"""
@@ -441,7 +441,7 @@
             raise oefmt(space.w_TypeError,
                         "ord() expected a character, but bytes of length %d "
                         "found", len(self._value))
-        return space.wrap(ord(self._value[0]))
+        return space.newint(ord(self._value[0]))
 
     def _new(self, value):
         return W_BytesObject(value)
@@ -574,7 +574,7 @@
         return W_BytesObject(bytes)
 
     def descr_repr(self, space):
-        return space.wrap(string_escape_encode(self._value, True))
+        return space.newtext(string_escape_encode(self._value, True))
 
     def descr_str(self, space):
         if space.sys.get_flag('bytes_warning'):
@@ -584,7 +584,7 @@
 
     def descr_hash(self, space):
         x = compute_hash(self._value)
-        return space.wrap(x)
+        return space.newint(x)
 
     def descr_eq(self, space, w_other):
         if space.config.objspace.std.withstrbuf:
diff --git a/pypy/objspace/std/callmethod.py b/pypy/objspace/std/callmethod.py
--- a/pypy/objspace/std/callmethod.py
+++ b/pypy/objspace/std/callmethod.py
@@ -138,6 +138,6 @@
                 # fast method path: a function object in the class,
                 # nothing in the instance
                 return space.call_function(w_descr, w_obj, *arg_w)
-    w_name = space.wrap(methname)
+    w_name = space.newtext(methname)
     w_meth = space.getattr(w_obj, w_name)
     return space.call_function(w_meth, *arg_w)
diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py
--- a/pypy/objspace/std/celldict.py
+++ b/pypy/objspace/std/celldict.py
@@ -23,7 +23,7 @@
 
 
 def _wrapkey(space, key):
-    return space.wrap(key.decode('utf-8'))
+    return space.newtext(key)
 
 
 class ModuleDictStrategy(DictStrategy):
@@ -56,8 +56,8 @@
 
     def setitem(self, w_dict, w_key, w_value):
         space = self.space
-        if space.is_w(space.type(w_key), space.w_unicode):
-            self.setitem_str(w_dict, space.str_w(w_key), w_value)
+        if space.is_w(space.type(w_key), space.w_text):
+            self.setitem_str(w_dict, space.text_w(w_key), w_value)
         else:
             self.switch_to_object_strategy(w_dict)
             w_dict.setitem(w_key, w_value)
@@ -75,8 +75,8 @@
 
     def setdefault(self, w_dict, w_key, w_default):
         space = self.space
-        if space.is_w(space.type(w_key), space.w_unicode):
-            key = space.str_w(w_key)
+        if space.is_w(space.type(w_key), space.w_text):
+            key = space.text_w(w_key)
             cell = self.getdictvalue_no_unwrapping(w_dict, key)
             w_result = unwrap_cell(self.space, cell)
             if w_result is not None:
@@ -90,8 +90,8 @@
     def delitem(self, w_dict, w_key):
         space = self.space
         w_key_type = space.type(w_key)
-        if space.is_w(w_key_type, space.w_unicode):
-            key = space.str_w(w_key)
+        if space.is_w(w_key_type, space.w_text):
+            key = space.text_w(w_key)
             dict_w = self.unerase(w_dict.dstorage)
             try:
                 del dict_w[key]
@@ -111,8 +111,8 @@
     def getitem(self, w_dict, w_key):
         space = self.space
         w_lookup_type = space.type(w_key)
-        if space.is_w(w_lookup_type, space.w_unicode):
-            return self.getitem_str(w_dict, space.str_w(w_key))
+        if space.is_w(w_lookup_type, space.w_text):
+            return self.getitem_str(w_dict, space.text_w(w_key))
 
         elif _never_equal_to_string(space, w_lookup_type):
             return None
@@ -126,8 +126,8 @@
 
     def w_keys(self, w_dict):
         space = self.space
-        keys = self.unerase(w_dict.dstorage).keys()
-        return space.newlist_unicode([key.decode('utf-8') for key in keys])
+        l = self.unerase(w_dict.dstorage).keys()
+        return space.newlist_text(l)
 
     def values(self, w_dict):
         iterator = self.unerase(w_dict.dstorage).itervalues
diff --git a/pypy/objspace/std/classdict.py b/pypy/objspace/std/classdict.py
--- a/pypy/objspace/std/classdict.py
+++ b/pypy/objspace/std/classdict.py
@@ -19,8 +19,8 @@
     def getitem(self, w_dict, w_key):
         space = self.space
         w_lookup_type = space.type(w_key)
-        if space.issubtype_w(w_lookup_type, space.w_unicode):
-            return self.getitem_str(w_dict, space.str_w(w_key))
+        if space.issubtype_w(w_lookup_type, space.w_text):
+            return self.getitem_str(w_dict, space.text_w(w_key))
         else:
             return None
 
@@ -29,8 +29,8 @@
 
     def setitem(self, w_dict, w_key, w_value):
         space = self.space
-        if space.is_w(space.type(w_key), space.w_unicode):
-            self.setitem_str(w_dict, self.space.str_w(w_key), w_value)
+        if space.is_w(space.type(w_key), space.w_text):
+            self.setitem_str(w_dict, self.space.text_w(w_key), w_value)
         else:
             raise oefmt(space.w_TypeError,
                         "cannot add non-string keys to dict of a type")
@@ -61,8 +61,8 @@
     def delitem(self, w_dict, w_key):
         space = self.space
         w_key_type = space.type(w_key)
-        if space.is_w(w_key_type, space.w_unicode):
-            key = self.space.str_w(w_key)
+        if space.is_w(w_key_type, space.w_text):
+            key = self.space.text_w(w_key)
             if not self.unerase(w_dict.dstorage).deldictvalue(space, key):
                 raise KeyError
         else:
@@ -73,9 +73,7 @@
 
     def w_keys(self, w_dict):
         space = self.space
-        w_type = self.unerase(w_dict.dstorage)
-        return space.newlist([_wrapkey(space, key)
-                              for key in w_type.dict_w.iterkeys()])
+        return space.newlist_text(self.unerase(w_dict.dstorage).dict_w.keys())
 
     def values(self, w_dict):
         return [unwrap_cell(self.space, w_value) for w_value in
@@ -83,10 +81,8 @@
 
     def items(self, w_dict):
         space = self.space
-        w_type = self.unerase(w_dict.dstorage)
-        return [space.newtuple([_wrapkey(space, key),
-                                unwrap_cell(space, w_value)])
-                for (key, w_value) in w_type.dict_w.iteritems()]
+        return [space.newtuple([space.newtext(key), unwrap_cell(self.space, w_value)])
+                    for (key, w_value) in self.unerase(w_dict.dstorage).dict_w.iteritems()]
 
     def clear(self, w_dict):
         space = self.space
@@ -107,13 +103,10 @@
         return iteritems_with_hash(self.unerase(w_dict.dstorage).dict_w)
 
     def wrapkey(space, key):
-        return _wrapkey(space, key)
+        # keys are utf-8 encoded identifiers from type's dict_w
+        return space.newtext(key)
 
     def wrapvalue(space, value):
         return unwrap_cell(space, value)
 
-def _wrapkey(space, key):
-    # keys are utf-8 encoded identifiers from type's dict_w
-    return space.wrap(key.decode('utf-8'))
-
 create_iterator_classes(ClassDictStrategy)
diff --git a/pypy/objspace/std/complexobject.py b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -159,8 +159,8 @@
     # no '__complex__' method, so we assume it is a float,
     # unless it is an instance of some subclass of complex.
     if space.isinstance_w(w_complex, space.gettypefor(W_ComplexObject)):
-        real = space.float(space.getattr(w_complex, space.wrap("real")))
-        imag = space.float(space.getattr(w_complex, space.wrap("imag")))
+        real = space.float(space.getattr(w_complex, space.newtext("real")))
+        imag = space.float(space.getattr(w_complex, space.newtext("imag")))
         return (space.float_w(real), space.float_w(imag))
     #
     # Check that it is not a string (on which space.float() would succeed).
@@ -231,10 +231,10 @@
             return False
         if self.user_overridden_class or w_other.user_overridden_class:
             return self is w_other
-        real1 = space.float_w(space.getattr(self, space.wrap("real")))
-        real2 = space.float_w(space.getattr(w_other, space.wrap("real")))
-        imag1 = space.float_w(space.getattr(self, space.wrap("imag")))
-        imag2 = space.float_w(space.getattr(w_other, space.wrap("imag")))
+        real1 = space.float_w(space.getattr(self, space.newtext("real")))
+        real2 = space.float_w(space.getattr(w_other, space.newtext("real")))
+        imag1 = space.float_w(space.getattr(self, space.newtext("imag")))
+        imag2 = space.float_w(space.getattr(w_other, space.newtext("imag")))
         real1 = float2longlong(real1)
         real2 = float2longlong(real2)
         imag1 = float2longlong(imag1)
@@ -247,8 +247,8 @@
         from rpython.rlib.longlong2float import float2longlong
         from pypy.objspace.std.util import IDTAG_COMPLEX as tag
         from pypy.objspace.std.util import IDTAG_SHIFT
-        real = space.float_w(space.getattr(self, space.wrap("real")))
-        imag = space.float_w(space.getattr(self, space.wrap("imag")))
+        real = space.float_w(space.getattr(self, space.newtext("real")))
+        imag = space.float_w(space.getattr(self, space.newtext("imag")))
         real_b = rbigint.fromrarith_int(float2longlong(real))
         imag_b = rbigint.fromrarith_int(r_ulonglong(float2longlong(imag)))
         val = real_b.lshift(64).or_(imag_b).lshift(IDTAG_SHIFT).int_or_(tag)
@@ -324,19 +324,19 @@
 
     def descr_repr(self, space):
         if self.realval == 0 and copysign(1., self.realval) == 1.:
-            return space.wrap(repr_format(self.imagval) + 'j')
+            return space.newtext(repr_format(self.imagval) + 'j')
         sign = (copysign(1., self.imagval) == 1. or
                 isnan(self.imagval)) and '+' or ''
-        return space.wrap('(' + repr_format(self.realval)
-                          + sign + repr_format(self.imagval) + 'j)')
+        return space.newtext('(' + repr_format(self.realval)
+                             + sign + repr_format(self.imagval) + 'j)')
 
     def descr_str(self, space):
         if self.realval == 0 and copysign(1., self.realval) == 1.:
-            return space.wrap(str_format(self.imagval) + 'j')
+            return space.newtext(str_format(self.imagval) + 'j')
         sign = (copysign(1., self.imagval) == 1. or
                 isnan(self.imagval)) and '+' or ''
-        return space.wrap('(' + str_format(self.realval)
-                          + sign + str_format(self.imagval) + 'j)')
+        return space.newtext('(' + str_format(self.realval)
+                             + sign + str_format(self.imagval) + 'j)')
 
     def descr_hash(self, space):
         hashreal = _hash_float(space, self.realval)
@@ -371,7 +371,7 @@
         try:
             return space.newfloat(math.hypot(self.realval, self.imagval))
         except OverflowError as e:
-            raise OperationError(space.w_OverflowError, space.wrap(str(e)))
+            raise OperationError(space.w_OverflowError, space.newtext(str(e)))
 
     def descr_eq(self, space, w_other):
         if isinstance(w_other, W_ComplexObject):
@@ -445,7 +445,7 @@
         try:
             return self.div(w_rhs)
         except ZeroDivisionError as e:
-            raise OperationError(space.w_ZeroDivisionError, space.wrap(str(e)))
+            raise OperationError(space.w_ZeroDivisionError, space.newtext(str(e)))
 
     def descr_rtruediv(self, space, w_lhs):
         w_lhs = self._to_complex(space, w_lhs)
@@ -454,7 +454,7 @@
         try:
             return w_lhs.div(self)
         except ZeroDivisionError as e:
-            raise OperationError(space.w_ZeroDivisionError, space.wrap(str(e)))
+            raise OperationError(space.w_ZeroDivisionError, space.newtext(str(e)))
 
     def descr_floordiv(self, space, w_rhs):
         raise oefmt(space.w_TypeError, "can't take floor of complex number.")
diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -12,6 +12,7 @@
 from pypy.interpreter.mixedmodule import MixedModule
 from pypy.interpreter.signature import Signature
 from pypy.interpreter.typedef import TypeDef
+from pypy.interpreter.unicodehelper import decode_utf8
 from pypy.objspace.std.util import negate
 
 
@@ -176,7 +177,7 @@
     descr_ne = negate(descr_eq)
 
     def descr_len(self, space):
-        return space.wrap(self.length())
+        return space.newint(self.length())
 
     def descr_iter(self, space):
         return W_DictMultiIterKeysObject(space, self.iterkeys())
@@ -419,9 +420,6 @@
     def get_empty_storage(self):
         raise NotImplementedError
 
-    def decodekey_str(self, key):
-        return key.decode('utf-8')
-
     @jit.look_inside_iff(lambda self, w_dict:
                          w_dict_unrolling_heuristic(w_dict))
     def w_keys(self, w_dict):
@@ -884,7 +882,7 @@
 
     def setitem_str(self, w_dict, key, w_value):
         self.switch_to_object_strategy(w_dict)
-        w_dict.setitem(self.space.wrap(self.decodekey_str(key)), w_value)
+        w_dict.setitem(self.space.newtext(key), w_value)
 
     def setdefault(self, w_dict, w_key, w_default):
         if self.is_correct_type(w_key):
@@ -906,7 +904,7 @@
         return len(self.unerase(w_dict.dstorage))
 
     def getitem_str(self, w_dict, key):
-        return self.getitem(w_dict, self.space.wrap(self.decodekey_str(key)))
+        return self.getitem(w_dict, self.space.newtext(key))
 
     def getitem(self, w_dict, w_key):
         space = self.space
@@ -997,7 +995,7 @@
         return self.space.newlist(self.unerase(w_dict.dstorage).keys())
 
     def setitem_str(self, w_dict, s, w_value):
-        self.setitem(w_dict, self.space.wrap(self.decodekey_str(s)), w_value)
+        self.setitem(w_dict, self.space.newtext(s), w_value)
 
     def switch_to_object_strategy(self, w_dict):
         assert 0, "should be unreachable"
@@ -1076,7 +1074,7 @@
     unerase = staticmethod(unerase)
 
     def wrap(self, unwrapped):
-        return self.space.wrap(unwrapped)
+        return self.space.newunicode(unwrapped)
 
     def unwrap(self, wrapped):
         return self.space.unicode_w(wrapped)
@@ -1095,6 +1093,9 @@
 
     # we should implement the same shortcuts as we do for BytesDictStrategy
 
+    def decodekey_str(self, key):
+        return decode_utf8(self.space, key, allow_surrogates=True)
+
     def setitem_str(self, w_dict, key, w_value):
         assert key is not None
         self.unerase(w_dict.dstorage)[self.decodekey_str(key)] = w_value
@@ -1118,7 +1119,7 @@
         return self.space.newlist_unicode(self.listview_unicode(w_dict))
 
     def wrapkey(space, key):
-        return space.wrap(key)
+        return space.newunicode(key)
 
     @jit.look_inside_iff(lambda self, w_dict:
                          w_dict_unrolling_heuristic(w_dict))
@@ -1150,7 +1151,7 @@
     unerase = staticmethod(unerase)
 
     def wrap(self, unwrapped):
-        return self.space.wrap(unwrapped)
+        return self.space.newint(unwrapped)
 
     def unwrap(self, wrapped):
         return self.space.int_w(wrapped)
@@ -1174,7 +1175,7 @@
         return self.unerase(w_dict.dstorage).keys()
 
     def wrapkey(space, key):
-        return space.wrap(key)
+        return space.newint(key)
 
     def w_keys(self, w_dict):
         return self.space.newlist_int(self.listview_int(w_dict))
@@ -1186,7 +1187,7 @@
     if isinstance(w_data, W_DictMultiObject):    # optimization case only
         update1_dict_dict(space, w_dict, w_data)
         return
-    w_method = space.findattr(w_data, space.wrap("keys"))
+    w_method = space.findattr(w_data, space.newtext("keys"))
     if w_method is None:
         # no 'keys' method, so we assume it is a sequence of pairs
         data_w = space.listview(w_data)
@@ -1244,7 +1245,7 @@
         return self
 
     def descr_length_hint(self, space):
-        return space.wrap(self.iteratorimplementation.length())
+        return space.newint(self.iteratorimplementation.length())
 
     def descr_reduce(self, space):
         """
@@ -1346,7 +1347,7 @@
         typename = space.type(self).getname(space)
         w_seq = space.call_function(space.w_list, self)
         seq_repr = space.unicode_w(space.repr(w_seq))
-        return space.wrap(u"%s(%s)" % (typename, seq_repr))
+        return space.newunicode(u"%s(%s)" % (typename, seq_repr))
 
     def descr_len(self, space):
         return space.len(self.w_dict)
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -238,9 +238,9 @@
     @unwrap_spec(kind=str)
     def descr___getformat__(space, w_cls, kind):
         if kind == "float":
-            return space.wrap(_float_format)
+            return space.newtext(_float_format)
         elif kind == "double":
-            return space.wrap(_double_format)
+            return space.newtext(_double_format)
         raise oefmt(space.w_ValueError, "only float and double are valid")
 
     @staticmethod
@@ -383,7 +383,7 @@
             i += 1
         if i != length:
             raise oefmt(space.w_ValueError, "invalid hex string")
-        w_float = space.wrap(sign * value)
+        w_float = space.newfloat(sign * value)
         return space.call_function(w_cls, w_float)
 
     def _to_float(self, space, w_obj):
@@ -396,13 +396,13 @@
         return _round_float(space, self, w_ndigits)
 
     def descr_repr(self, space):
-        return space.wrap(float2string(self.floatval, 'r', 0))
+        return space.newtext(float2string(self.floatval, 'r', 0))
     descr_str = func_with_new_name(descr_repr, 'descr_str')
 
     def descr_hash(self, space):
         h = _hash_float(space, self.floatval)
         h -= (h == -1)
-        return space.wrap(h)
+        return space.newint(h)
 
     def descr_format(self, space, w_spec):
         return newformat.run_formatter(space, w_spec, "format_float", self)
@@ -580,7 +580,7 @@
         return space.float(self)
 
     def descr_get_imag(self, space):
-        return space.wrap(0.0)
+        return space.newfloat(0.0)
 
     def descr_conjugate(self, space):
         return space.float(self)
@@ -589,7 +589,7 @@
         v = self.floatval
         if not rfloat.isfinite(v):
             return space.w_False
-        return space.wrap(math.floor(v) == v)
+        return space.newbool(math.floor(v) == v)
 
     def descr_as_integer_ratio(self, space):
         value = self.floatval
@@ -614,9 +614,9 @@
             return self.descr_str(space)
         if value == 0.0:
             if copysign(1., value) == -1.:
-                return space.wrap("-0x0.0p+0")
+                return space.newtext("-0x0.0p+0")
             else:
-                return space.wrap("0x0.0p+0")
+                return space.newtext("0x0.0p+0")
         mant, exp = math.frexp(value)
         shift = 1 - max(rfloat.DBL_MIN_EXP - exp, 0)
         mant = math.ldexp(mant, shift)
@@ -637,9 +637,9 @@
         exp = abs(exp)
         s = ''.join(result)
         if value < 0.0:
-            return space.wrap("-0x%sp%s%d" % (s, sign, exp))
+            return space.newtext("-0x%sp%s%d" % (s, sign, exp))
         else:
-            return space.wrap("0x%sp%s%d" % (s, sign, exp))
+            return space.newtext("0x%sp%s%d" % (s, sign, exp))
 
 
 W_FloatObject.typedef = TypeDef("float",
@@ -873,19 +873,19 @@
 
     # nans and infinities round to themselves
     if not rfloat.isfinite(x):
-        return space.wrap(x)
+        return space.newfloat(x)
 
     # Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x
     # always rounds to itself.  For ndigits < NDIGITS_MIN, x always
     # rounds to +-0.0
     if ndigits > NDIGITS_MAX:
-        return space.wrap(x)
+        return space.newfloat(x)
     elif ndigits < NDIGITS_MIN:
         # return 0.0, but with sign of x
-        return space.wrap(0.0 * x)
+        return space.newfloat(0.0 * x)
 
     # finite x, and ndigits is not unreasonably large
     z = rfloat.round_double(x, ndigits, half_even=True)
     if rfloat.isinf(z):
         raise oefmt(space.w_OverflowError, "overflow occurred during round")
-    return space.wrap(z)
+    return space.newfloat(z)
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -310,7 +310,7 @@
     # floating-point division
     a = float(x)
     b = float(y)
-    return space.wrap(a / b)
+    return space.newfloat(a / b)
 
 
 def _mod(space, x, y):
@@ -328,8 +328,7 @@
         raise oefmt(space.w_ZeroDivisionError, "integer divmod by zero")
     # no overflow possible
     m = x % y
-    w = space.wrap
-    return space.newtuple([w(z), w(m)])
+    return space.newtuple([space.newint(z), space.newint(m)])
 
 
 def _divmod_ovf2small(space, x, y):
@@ -564,11 +563,11 @@
         while val:
             bits += 1
             val >>= 1
-        return space.wrap(bits)
+        return space.newint(bits)
 
     def descr_repr(self, space):
         res = str(self.intval)
-        return space.wrap(res)
+        return space.newtext(res)
     descr_str = func_with_new_name(descr_repr, 'descr_str')
 
     def descr_format(self, space, w_format_spec):
@@ -606,7 +605,7 @@
             result = _pow(space, x, y, z)
         except (OverflowError, ValueError):
             return _pow_ovf2long(space, x, y, w_modulus)
-        return space.wrap(result)
+        return space.newint(result)
 
     @unwrap_spec(w_modulus=WrappedDefault(None))
     def descr_rpow(self, space, w_base, w_modulus=None):
diff --git a/pypy/objspace/std/iterobject.py b/pypy/objspace/std/iterobject.py
--- a/pypy/objspace/std/iterobject.py
+++ b/pypy/objspace/std/iterobject.py
@@ -15,12 +15,12 @@
 
     def getlength(self, space):
         if self.w_seq is None:
-            return space.wrap(0)
+            return space.newint(0)
         index = self.index
         w_length = space.len(self.w_seq)
-        w_len = space.sub(w_length, space.wrap(index))
-        if space.is_true(space.lt(w_len, space.wrap(0))):
-            w_len = space.wrap(0)
+        w_len = space.sub(w_length, space.newint(index))
+        if space.is_true(space.lt(w_len, space.newint(0))):
+            w_len = space.newint(0)
         return w_len
 
     def descr_iter(self, space):
@@ -34,7 +34,7 @@
         if w_seq is None:
             return _empty_iterable(space)
         w_callable = space.builtin.get('iter')
-        items = [w_callable, space.newtuple([w_seq]), space.wrap(self.index)]
+        items = [w_callable, space.newtuple([w_seq]), space.newint(self.index)]
         return space.newtuple(items)
 
     def descr_setstate(self, space, w_state):
@@ -71,7 +71,7 @@
         if self.w_seq is None:
             raise OperationError(space.w_StopIteration, space.w_None)
         try:
-            w_item = space.getitem(self.w_seq, space.wrap(self.index))
+            w_item = space.getitem(self.w_seq, space.newint(self.index))
         except OperationError as e:
             self.w_seq = None
             if not e.match(space, space.w_IndexError):
@@ -157,7 +157,7 @@
         if w_seq is None:
             return _empty_iterable(space)
         w_callable = space.builtin.get('reversed')
-        items = [w_callable, space.newtuple([w_seq]), space.wrap(self.index)]
+        items = [w_callable, space.newtuple([w_seq]), space.newint(self.index)]
         return space.newtuple(items)
 
     def descr_setstate(self, space, w_state):
@@ -171,14 +171,14 @@
         length = self.index + 1
         if self.w_seq is None or space.len_w(self.w_seq) < length:
             length = 0
-        return space.wrap(length)
+        return space.newint(length)
 
     def descr_iter(self, space):
         return self
 
     def descr_next(self, space):
         if self.index >= 0:
-            w_index = space.wrap(self.index)
+            w_index = space.newint(self.index)
             try:
                 w_item = space.getitem(self.w_seq, w_index)
             except OperationError as e:
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -437,7 +437,7 @@
 
     def descr_repr(self, space):
         if self.length() == 0:
-            return space.wrap('[]')
+            return space.newtext('[]')
         ec = space.getexecutioncontext()
         w_currently_in_repr = ec._py_repr
         if w_currently_in_repr is None:
@@ -617,7 +617,7 @@
             if space.eq_w(self.getitem(i), w_value):
                 count += 1
             i += 1
-        return space.wrap(count)
+        return space.newint(count)
 
     @unwrap_spec(index=int)
     def descr_insert(self, space, index, w_value):
@@ -674,7 +674,7 @@
             i = self.find(w_value, i, stop)
         except ValueError:
             raise oefmt(space.w_ValueError, "%R is not in list", w_value)
-        return space.wrap(i)
+        return space.newint(i)
 
     @unwrap_spec(reverse=int)
     def descr_sort(self, space, w_key=None, reverse=False):
@@ -1045,7 +1045,7 @@
         w_list.lstorage = strategy.erase(items)
 
     def wrap(self, intval):
-        return self.space.wrap(intval)
+        return self.space.newint(intval)
 
     def unwrap(self, w_int):
         return self.space.int_w(w_int)
@@ -1633,7 +1633,7 @@
     _none_value = 0
 
     def wrap(self, intval):
-        return self.space.wrap(intval)
+        return self.space.newint(intval)
 
     def unwrap(self, w_int):
         return self.space.int_w(w_int)
@@ -1729,7 +1729,7 @@
     _none_value = 0.0
 
     def wrap(self, floatval):
-        return self.space.wrap(floatval)
+        return self.space.newfloat(floatval)
 
     def unwrap(self, w_float):
         return self.space.float_w(w_float)
@@ -1840,10 +1840,10 @@
     def wrap(self, llval):
         if longlong2float.is_int32_from_longlong_nan(llval):
             intval = longlong2float.decode_int32_from_longlong_nan(llval)
-            return self.space.wrap(intval)
+            return self.space.newint(intval)
         else:
             floatval = longlong2float.longlong2float(llval)
-            return self.space.wrap(floatval)
+            return self.space.newfloat(floatval)
 
     def unwrap(self, w_int_or_float):
         if type(w_int_or_float) is W_IntObject:
@@ -1980,7 +1980,7 @@
     _none_value = None
 
     def wrap(self, stringval):
-        return self.space.wrap(stringval)
+        return self.space.newunicode(stringval)
 
     def unwrap(self, w_string):
         return self.space.unicode_w(w_string)
diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py
--- a/pypy/objspace/std/longobject.py
+++ b/pypy/objspace/std/longobject.py
@@ -47,7 +47,7 @@
     def descr_bit_length(self, space):
         bigint = space.bigint_w(self)
         try:
-            return space.wrap(bigint.bit_length())
+            return space.newint(bigint.bit_length())
         except OverflowError:
             raise oefmt(space.w_OverflowError, "too many digits in integer")
 
@@ -75,7 +75,7 @@
                                        newformat.LONG_KIND)
 
     def descr_hash(self, space):
-        return space.wrap(_hash_long(space, self.asbigint()))
+        return space.newint(_hash_long(space, self.asbigint()))
 
     def descr_str(self, space):
         return space.wrap(self.asbigint().str())
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -337,7 +337,7 @@
             space = self.space
             w_dict = obj.getdict(space)
             try:
-                space.delitem(w_dict, space.wrap(name.decode('utf-8')))
+                space.delitem(w_dict, space.newtext(name))
             except OperationError as ex:
                 if not ex.match(space, space.w_KeyError):
                     raise
@@ -402,7 +402,7 @@
     def materialize_r_dict(self, space, obj, dict_w):
         new_obj = self.back.materialize_r_dict(space, obj, dict_w)
         if self.index == DICT:
-            w_attr = space.wrap(self.name.decode('utf-8'))
+            w_attr = space.newtext(self.name)
             dict_w[w_attr] = obj._mapdict_read_storage(self.storageindex)
         else:
             self._copy_attr(obj, new_obj)
@@ -810,7 +810,7 @@
             raise KeyError
         key = curr.name
         w_value = self.getitem_str(w_dict, key)
-        w_key = self.space.wrap(key.decode('utf-8'))
+        w_key = self.space.newtext(key)
         self.delitem(w_dict, w_key)
         return (w_key, w_value)
 
@@ -867,7 +867,7 @@
         attrs = self.attrs
         if len(attrs) > 0:
             attr = attrs.pop()
-            w_attr = self.space.wrap(attr.decode('utf-8'))
+            w_attr = self.space.newtext(attr)
             return w_attr
         return None
 
@@ -904,7 +904,7 @@
         attrs = self.attrs
         if len(attrs) > 0:
             attr = attrs.pop()
-            w_attr = self.space.wrap(attr.decode('utf-8'))
+            w_attr = self.space.newtext(attr)
             return w_attr, self.w_obj.getdictvalue(self.space, attr)
         return None, None
 
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
@@ -88,12 +88,12 @@
     def _make_descr__cmp(name):
         def descr__cmp(self, space, w_other):
             if self.buf is None:
-                return space.wrap(getattr(operator, name)(self, w_other))
+                return space.newbool(getattr(operator, name)(self, w_other))
             if isinstance(w_other, W_MemoryView):
                 # xxx not the most efficient implementation
                 str1 = self.as_str()
                 str2 = w_other.as_str()
-                return space.wrap(getattr(operator, name)(str1, str2))
+                return space.newbool(getattr(operator, name)(str1, str2))
 
             try:
                 buf = space.buffer_w(w_other, space.BUF_CONTIG_RO)
@@ -104,7 +104,7 @@
             else:
                 str1 = self.as_str()
                 str2 = buf.as_str()
-                return space.wrap(getattr(operator, name)(str1, str2))
+                return space.newbool(getattr(operator, name)(str1, str2))
         descr__cmp.func_name = name
         return descr__cmp
 
@@ -244,8 +244,8 @@
         length = space.len_w(w_index)
         ndim = view.getndim()
         if length < ndim:
-            raise OperationError(space.w_NotImplementedError, \
-                    space.wrap("sub-views are not implemented"))
+            raise oefmt(space.w_NotImplementedError,
+                        "sub-views are not implemented")
 
         if length > ndim:
             raise oefmt(space.w_TypeError, \
@@ -402,23 +402,23 @@
         if dim == 0:
             return space.newint(1)
         shape = self.getshape()
-        return space.wrap(shape[0])
+        return space.newint(shape[0])
 
     def w_get_nbytes(self, space):
         self._check_released(space)
-        return space.wrap(self.getlength())
+        return space.newint(self.getlength())
 
     def w_get_format(self, space):
         self._check_released(space)
-        return space.wrap(self.getformat())
+        return space.newtext(self.getformat())
 
     def w_get_itemsize(self, space):
         self._check_released(space)
-        return space.wrap(self.getitemsize())
+        return space.newint(self.getitemsize())
 
     def w_get_ndim(self, space):
         self._check_released(space)
-        return space.wrap(self.getndim())
+        return space.newint(self.getndim())
 
     def w_is_readonly(self, space):
         self._check_released(space)
@@ -428,13 +428,13 @@
         self._check_released(space)
         if self.getndim() == 0:
             return space.w_None
-        return space.newtuple([space.wrap(x) for x in self.getshape()])
+        return space.newtuple([space.newint(x) for x in self.getshape()])
 
     def w_get_strides(self, space):
         self._check_released(space)
         if self.getndim() == 0:
             return space.w_None
-        return space.newtuple([space.wrap(x) for x in self.getstrides()])
+        return space.newtuple([space.newint(x) for x in self.getstrides()])
 
     def w_get_suboffsets(self, space):
         self._check_released(space)
@@ -454,7 +454,7 @@
                 raise oefmt(space.w_ValueError,
                             "cannot hash writable memoryview object")
             self._hash = compute_hash(self.buf.as_str())
-        return space.wrap(self._hash)
+        return space.newint(self._hash)
 
     def descr_release(self, space):
         self.buf = None
@@ -480,8 +480,8 @@
             # report the error using the RPython-level internal repr of self.buf
             msg = ("cannot find the underlying address of buffer that "
                    "is internally %r" % (self.buf,))
-            raise OperationError(space.w_ValueError, space.wrap(msg))
-        return space.wrap(rffi.cast(lltype.Signed, ptr))
+            raise OperationError(space.w_ValueError, space.newtext(msg))
+        return space.newint(rffi.cast(lltype.Signed, ptr))
 
     def get_native_fmtchar(self, fmt):
         from rpython.rtyper.lltypesystem import rffi
@@ -525,22 +525,22 @@
         self._check_released(space)
 
         if not space.isinstance_w(w_format, space.w_unicode):
-            raise OperationError(space.w_TypeError, \
-                    space.wrap("memoryview: format argument must be a string"))
+            raise oefmt(space.w_TypeError,
+                        "memoryview: format argument must be a string")
 
         fmt = space.str_w(w_format)
         buf = self.buf
         ndim = 1
 
         if not memory_view_c_contiguous(space, self.flags):
-            raise OperationError(space.w_TypeError, \
-                    space.wrap("memoryview: casts are restricted" \
-                               " to C-contiguous views"))
+            raise oefmt(space.w_TypeError,
+                        "memoryview: casts are restricted"
+                        " to C-contiguous views")
 
         if (w_shape or buf.getndim() != 1) and self._zero_in_shape():
-            raise OperationError(space.w_TypeError, \
-                    space.wrap("memoryview: cannot casts view with" \
-                               " zeros in shape or strides"))
+            raise oefmt(space.w_TypeError,
+                        "memoryview: cannot casts view with"
+                        " zeros in shape or strides")
 
         itemsize = self.get_native_fmtchar(fmt)
         if w_shape:
@@ -553,8 +553,8 @@
                         ndim)
             # yes access ndim as field
             if self.ndim > 1 and buf.getndim() != 1:
-                raise OperationError(space.w_TypeError, \
-                    space.wrap("memoryview: cast must be 1D -> ND or ND -> 1D"))
+                raise oefmt(space.w_TypeError,
+                            "memoryview: cast must be 1D -> ND or ND -> 1D")
 
         mv = W_MemoryView(buf, self.format, self.itemsize)
         origfmt = mv.getformat()
@@ -656,8 +656,8 @@
             self._init_strides_from_shape()
 
         if length != self.buf.getlength():
-            raise OperationError(space.w_TypeError,
-                    space.wrap("memoryview: product(shape) * itemsize != buffer size"))
+            raise oefmt(space.w_TypeError,
+                        "memoryview: product(shape) * itemsize != buffer size")
 
         self._init_flags()
 
diff --git a/pypy/objspace/std/noneobject.py b/pypy/objspace/std/noneobject.py
--- a/pypy/objspace/std/noneobject.py
+++ b/pypy/objspace/std/noneobject.py
@@ -16,7 +16,7 @@
         return space.w_False
 
     def descr_repr(self, space):
-        return space.wrap('None')
+        return space.newtext('None')
 
 
 W_NoneObject.w_None = W_NoneObject()
diff --git a/pypy/objspace/std/objectobject.py b/pypy/objspace/std/objectobject.py
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -196,14 +196,14 @@
 
 @unwrap_spec(proto=int)
 def descr__reduce__(space, w_obj, proto=0):
-    w_proto = space.wrap(proto)
+    w_proto = space.newint(proto)
     if proto >= 2:
         return reduce_2(space, w_obj, w_proto)
     return reduce_1(space, w_obj, w_proto)
 
 @unwrap_spec(proto=int)
 def descr__reduce_ex__(space, w_obj, proto=0):
-    w_st_reduce = space.wrap('__reduce__')
+    w_st_reduce = space.newtext('__reduce__')
     w_reduce = space.findattr(w_obj, w_st_reduce)
     if w_reduce is not None:
         # Check if __reduce__ has been overridden:
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -314,6 +314,10 @@
     def newlist_bytes(self, list_s):
         return W_ListObject.newlist_bytes(self, list_s)
 
+    def newlist_text(self, list_t):
+        # XXX improve!
+        return self.newlist([self.newtext(t) for t in list_t])
+
     def newlist_unicode(self, list_u):
         return W_ListObject.newlist_unicode(self, list_u)
 
@@ -354,15 +358,17 @@
         return W_MemoryView(w_obj)
 
     def newbytes(self, s):
+        assert isinstance(s, str)
         return W_BytesObject(s)
 
     def newbytearray(self, l):
         return W_BytearrayObject(l)
 
-    def newutf8(self, string):
-        return self.newunicode(decode_utf8(self, string))
+    def newtext(self, s):
+        return self.newunicode(decode_utf8(self, s, allow_surrogates=True))
 
     def newunicode(self, uni):
+        assert isinstance(uni, unicode)
         return W_UnicodeObject(uni)
 
     def type(self, w_obj):
diff --git a/pypy/objspace/std/proxyobject.py b/pypy/objspace/std/proxyobject.py
--- a/pypy/objspace/std/proxyobject.py
+++ b/pypy/objspace/std/proxyobject.py
@@ -12,7 +12,7 @@
 
         def descr_call_mismatch(self, space, name, reqcls, args):
             args_w = args.arguments_w[:]
-            args_w[0] = space.wrap(name)
+            args_w[0] = space.newtext(name)
             args = args.replace_arguments(args_w)
             return space.call_args(self.w_controller, args)
 
@@ -26,8 +26,8 @@
 
         def getdictvalue(self, space, attr):
             try:
-                return space.call_function(self.w_controller, space.wrap('__getattribute__'),
-                   space.wrap(attr))
+                return space.call_function(self.w_controller, space.newtext('__getattribute__'),
+                   space.newtext(attr))
             except OperationError as e:
                 if not e.match(space, space.w_AttributeError):
                     raise
@@ -35,8 +35,8 @@
 
         def setdictvalue(self, space, attr, w_value):
             try:
-                space.call_function(self.w_controller, space.wrap('__setattr__'),
-                   space.wrap(attr), w_value)
+                space.call_function(self.w_controller, space.newtext('__setattr__'),
+                   space.newtext(attr), w_value)
                 return True
             except OperationError as e:
                 if not e.match(space, space.w_AttributeError):
@@ -45,8 +45,8 @@
 
         def deldictvalue(self, space, attr):
             try:
-                space.call_function(self.w_controller, space.wrap('__delattr__'),
-                   space.wrap(attr))
+                space.call_function(self.w_controller, space.newtext('__delattr__'),
+                   space.newtext(attr))
                 return True
             except OperationError as e:
                 if not e.match(space, space.w_AttributeError):
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -173,25 +173,25 @@
 
     def descr_eq(self, space, w_other):
         if isinstance(w_other, W_BaseSetObject):
-            return space.wrap(self.equals(w_other))
+            return space.newbool(self.equals(w_other))
 
         if not space.isinstance_w(w_other, space.w_set):
             return space.w_NotImplemented
 
         # XXX do not make new setobject here
         w_other_as_set = self._newobj(space, w_other)
-        return space.wrap(self.equals(w_other_as_set))
+        return space.newbool(self.equals(w_other_as_set))
 
     def descr_ne(self, space, w_other):
         if isinstance(w_other, W_BaseSetObject):
-            return space.wrap(not self.equals(w_other))
+            return space.newbool(not self.equals(w_other))
 
         if not space.isinstance_w(w_other, space.w_set):
             return space.w_NotImplemented
 
         # XXX this is not tested
         w_other_as_set = self._newobj(space, w_other)
-        return space.wrap(not self.equals(w_other_as_set))
+        return space.newbool(not self.equals(w_other_as_set))
 
     # automatic registration of "lt(x, y)" as "not ge(y, x)" would not give the
     # correct answer here!
@@ -210,7 +210,7 @@
 
         if self.length() > w_other.length():
             return space.w_False
-        return space.wrap(self.issubset(w_other))
+        return space.newbool(self.issubset(w_other))
 
     def descr_gt(self, space, w_other):
         if not isinstance(w_other, W_BaseSetObject):
@@ -227,7 +227,7 @@
 
         if self.length() < w_other.length():
             return space.w_False
-        return space.wrap(w_other.issubset(self))
+        return space.newbool(w_other.issubset(self))
 
     def descr_len(self, space):
         return space.newint(self.length())
@@ -347,12 +347,12 @@
         if isinstance(w_other, W_BaseSetObject):
             if self.length() > w_other.length():
                 return space.w_False
-            return space.wrap(self.issubset(w_other))
+            return space.newbool(self.issubset(w_other))
 
         w_other_as_set = self._newobj(space, w_other)
         if self.length() > w_other_as_set.length():
             return space.w_False
-        return space.wrap(self.issubset(w_other_as_set))
+        return space.newbool(self.issubset(w_other_as_set))
 
     def descr_issuperset(self, space, w_other):
         """Report whether this set contains another set."""
@@ -362,12 +362,12 @@
         if isinstance(w_other, W_BaseSetObject):
             if self.length() < w_other.length():
                 return space.w_False
-            return space.wrap(w_other.issubset(self))
+            return space.newbool(w_other.issubset(self))
 
         w_other_as_set = self._newobj(space, w_other)
         if self.length() < w_other_as_set.length():
             return space.w_False
-        return space.wrap(w_other_as_set.issubset(self))
+        return space.newbool(w_other_as_set.issubset(self))
 
     def descr_symmetric_difference(self, space, w_other):
         """Return the symmetric difference of two sets as a new set.
@@ -578,7 +578,7 @@
             return None
         # empty frozenset: base value 259
         uid = (259 << IDTAG_SHIFT) | IDTAG_SPECIAL
-        return space.wrap(uid)
+        return space.newint(uid)
 
     def _newobj(self, space, w_iterable):
         """Make a new frozenset by taking ownership of 'w_iterable'."""
@@ -596,7 +596,7 @@
     def descr_hash(self, space):
         multi = r_uint(1822399083) + r_uint(1822399083) + 1
         if self.hash != 0:
-            return space.wrap(self.hash)
+            return space.newint(self.hash)
         hash = r_uint(1927868237)
         hash *= r_uint(self.length() + 1)
         w_iterator = self.iter()
@@ -613,7 +613,7 @@
         hash = intmask(hash)
         self.hash = hash
 
-        return space.wrap(hash)
+        return space.newint(hash)
 
 W_FrozensetObject.typedef = TypeDef("frozenset",
     __doc__ = """frozenset(iterable) --> frozenset object
@@ -1271,7 +1271,7 @@
         return self.space.unicode_w(w_item)
 
     def wrap(self, item):
-        return self.space.wrap(item)
+        return self.space.newunicode(item)
 
     def iter(self, w_set):
         return UnicodeIteratorImplementation(self.space, self, w_set)
@@ -1312,7 +1312,7 @@
         return self.space.int_w(w_item)
 
     def wrap(self, item):
-        return self.space.wrap(item)
+        return self.space.newint(item)
 
     def iter(self, w_set):
         return IntegerIteratorImplementation(self.space, self, w_set)
@@ -1475,7 +1475,7 @@
 
     def next_entry(self):
         for key in self.iterator:
-            return self.space.wrap(key)
+            return self.space.newunicode(key)
         else:
             return None
 
@@ -1490,7 +1490,7 @@
     def next_entry(self):
         # note that this 'for' loop only runs once, at most
         for key in self.iterator:
-            return self.space.wrap(key)
+            return self.space.newint(key)
         else:
             return None
 
@@ -1501,8 +1501,8 @@
         self.iterator = d.iterkeys()
 
     def next_entry(self):
-        for key in self.iterator:
-            return self.space.wrap(key)
+        for w_key in self.iterator:
+            return w_key
         else:
             return None
 
@@ -1527,7 +1527,7 @@
         self.iterimplementation = iterimplementation
 
     def descr_length_hint(self, space):
-        return space.wrap(self.iterimplementation.length())
+        return space.newint(self.iterimplementation.length())
 
     def descr_iter(self, space):
         return self
diff --git a/pypy/objspace/std/sliceobject.py b/pypy/objspace/std/sliceobject.py
--- a/pypy/objspace/std/sliceobject.py
+++ b/pypy/objspace/std/sliceobject.py
@@ -105,7 +105,7 @@
         return w_obj
 
     def descr_repr(self, space):
-        return space.wrap("slice(%s, %s, %s)" % (
+        return space.newtext("slice(%s, %s, %s)" % (
             space.str_w(space.repr(self.w_start)),
             space.str_w(space.repr(self.w_stop)),
             space.str_w(space.repr(self.w_step))))
diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -14,6 +14,16 @@
 
 def make_specialised_class(typetuple):
     assert type(typetuple) == tuple
+    wraps = []
+    for typ in typetuple:
+        if typ == int:
+            wraps.append(lambda space, x: space.newint(x))
+        elif typ == float:
+            wraps.append(lambda space, x: space.newfloat(x))
+        elif typ == object:
+            wraps.append(lambda space, w_x: w_x)
+        else:
+            assert 0
 
     typelen = len(typetuple)
     iter_n = unrolling_iterable(range(typelen))
@@ -46,8 +56,7 @@
             list_w = [None] * typelen
             for i in iter_n:
                 value = getattr(self, 'value%s' % i)
-                if typetuple[i] != object:
-                    value = self.space.wrap(value)
+                value = wraps[i](self.space, value)
                 list_w[i] = value
             return list_w
 
@@ -84,7 +93,7 @@
                 z -= 1
                 mult += 82520 + z + z
             x += 97531
-            return space.wrap(intmask(x))
+            return space.newint(intmask(x))
 
         def descr_eq(self, space, w_other):
             if not isinstance(w_other, W_AbstractTupleObject):
@@ -95,8 +104,7 @@
                 for i in iter_n:
                     myval = getattr(self, 'value%s' % i)
                     otherval = w_other.getitem(space, i)
-                    if typetuple[i] != object:
-                        myval = space.wrap(myval)
+                    myval = wraps[i](self.space, myval)
                     if not space.eq_w(myval, otherval):
                         return space.w_False
                 return space.w_True
@@ -125,8 +133,7 @@
             for i in iter_n:
                 if index == i:
                     value = getattr(self, 'value%s' % i)
-                    if typetuple[i] != object:
-                        value = space.wrap(value)
+                    value = wraps[i](self.space, value)
                     return value
             raise oefmt(space.w_IndexError, "tuple index out of range")
 
@@ -169,10 +176,10 @@
 # faster to move the decision out of the loop.
 
 @specialize.arg(1)
-def _build_zipped_spec(space, Cls, lst1, lst2):
+def _build_zipped_spec(space, Cls, lst1, lst2, wrap1, wrap2):
     length = min(len(lst1), len(lst2))
-    return [Cls(space, space.wrap(lst1[i]),
-                       space.wrap(lst2[i])) for i in range(length)]
+    return [Cls(space, wrap1(lst1[i]),
+                       wrap2(lst2[i])) for i in range(length)]
 
 def _build_zipped_spec_oo(space, w_list1, w_list2):
     strat1 = w_list1.strategy
@@ -198,15 +205,18 @@
         if intlist1 is not None:
             intlist2 = w_list2.getitems_int()
             if intlist2 is not None:
-                lst_w = _build_zipped_spec(space, Cls_ii, intlist1, intlist2)
+                lst_w = _build_zipped_spec(
+                        space, Cls_ii, intlist1, intlist2,
+                        space.newint, space.newint)
                 return space.newlist(lst_w)
         else:
             floatlist1 = w_list1.getitems_float()
             if floatlist1 is not None:
                 floatlist2 = w_list2.getitems_float()
                 if floatlist2 is not None:
-                    lst_w = _build_zipped_spec(space, Cls_ff, floatlist1,
-                                                              floatlist2)
+                    lst_w = _build_zipped_spec(
+                        space, Cls_ff, floatlist1, floatlist2, space.newfloat,
+                        space.newfloat)
                     return space.newlist(lst_w)
 
         lst_w = _build_zipped_spec_oo(space, w_list1, w_list2)
diff --git a/pypy/objspace/std/strbufobject.py b/pypy/objspace/std/strbufobject.py
--- a/pypy/objspace/std/strbufobject.py
+++ b/pypy/objspace/std/strbufobject.py
@@ -41,7 +41,7 @@
         return StringBuffer(self.force())
 
     def descr_len(self, space):
-        return space.wrap(self.length)
+        return space.newint(self.length)
 
     def descr_add(self, space, w_other):
         try:
diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -73,7 +73,7 @@
         return chr(char)
 
     def descr_len(self, space):
-        return space.wrap(self._len())
+        return space.newint(self._len())
 
     def descr_iter(self, space):
         from pypy.objspace.std.iterobject import W_StringIterObject
@@ -188,7 +188,7 @@
         else:
             res = count(value, sub, start, end)
             assert res >= 0
-        return space.wrap(res)
+        return space.newint(res)
 
     def descr_decode(self, space, w_encoding=None, w_errors=None):
         from pypy.objspace.std.unicodeobject import (
@@ -257,7 +257,7 @@
             res = find(value, sub, start, end)
         if ofs is not None and res >= 0:
             res -= ofs
-        return space.wrap(res)
+        return space.newint(res)
 
     def descr_rfind(self, space, w_sub, w_start=None, w_end=None):
         value, start, end, ofs = self._convert_idx_params(space, w_start, w_end)
@@ -269,7 +269,7 @@
             res = rfind(value, sub, start, end)
         if ofs is not None and res >= 0:
             res -= ofs
-        return space.wrap(res)
+        return space.newint(res)
 
     def descr_index(self, space, w_sub, w_start=None, w_end=None):
         value, start, end, ofs = self._convert_idx_params(space, w_start, w_end)
@@ -285,7 +285,7 @@
                         "substring not found in " + self._KIND2 + ".index")
         if ofs is not None:
             res -= ofs
-        return space.wrap(res)
+        return space.newint(res)
 
     def descr_rindex(self, space, w_sub, w_start=None, w_end=None):
         value, start, end, ofs = self._convert_idx_params(space, w_start, w_end)
@@ -301,7 +301,7 @@
                         "substring not found in " + self._KIND2 + ".rindex")
         if ofs is not None:
             res -= ofs
-        return space.wrap(res)
+        return space.newint(res)
 
     @specialize.arg(2)
     def _is_generic(self, space, func_name):
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -1148,6 +1148,7 @@
             return string.encode('utf-8')
         assert isinstance(string, str)
         return string
+    bytes_w = str_w
 
     def bytes_w(self, string):
         assert isinstance(string, str)
@@ -1165,6 +1166,7 @@
         if isinstance(obj, str):
             return obj.decode('ascii')
         return obj
+    newtext = newbytes = wrap
 
     def newbytes(self, obj):
         return obj
diff --git a/pypy/objspace/std/test/test_stdobjspace.py b/pypy/objspace/std/test/test_stdobjspace.py
--- a/pypy/objspace/std/test/test_stdobjspace.py
+++ b/pypy/objspace/std/test/test_stdobjspace.py
@@ -13,8 +13,8 @@
                           self.space.wrap(0))
 
     def test_utf8(self):
-        assert self.space.isinstance_w(self.space.newutf8("abc"), self.space.w_unicode)
-        assert self.space.eq_w(self.space.newutf8("üöä"), self.space.newunicode(u"üöä"))
+        assert self.space.isinstance_w(self.space.newtext("abc"), self.space.w_unicode)
+        assert self.space.eq_w(self.space.newtext("üöä"), self.space.newunicode(u"üöä"))
 
     def test_str_w_non_str(self):
         raises(OperationError,self.space.str_w,self.space.wrap(None))
diff --git a/pypy/objspace/std/transparent.py b/pypy/objspace/std/transparent.py
--- a/pypy/objspace/std/transparent.py
+++ b/pypy/objspace/std/transparent.py
@@ -39,8 +39,8 @@
 def setup(space):
     """Add proxy functions to the __pypy__ module."""
     w___pypy__ = space.getbuiltinmodule("__pypy__")
-    space.setattr(w___pypy__, space.wrap('tproxy'), space.wrap(app_proxy))
-    space.setattr(w___pypy__, space.wrap('get_tproxy_controller'),
+    space.setattr(w___pypy__, space.newtext('tproxy'), space.wrap(app_proxy))
+    space.setattr(w___pypy__, space.newtext('get_tproxy_controller'),
                   space.wrap(app_proxy_controller))
 
 
diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -53,7 +53,7 @@
             return None
         # empty tuple: base value 258
         uid = (258 << IDTAG_SHIFT) | IDTAG_SPECIAL
-        return space.wrap(uid)
+        return space.newint(uid)
 
     def __repr__(self):
         """representation for debugging purposes"""
@@ -102,11 +102,11 @@
     def descr_repr(self, space):
         items = self.tolist()
         if len(items) == 1:
-            return space.wrap(u"(" + space.unicode_w(space.repr(items[0])) +
-                              u",)")
+            return space.newunicode(
+                u"(" + space.unicode_w(space.repr(items[0])) + u",)")
         tmp = u", ".join([space.unicode_w(space.repr(item))
                           for item in items])
-        return space.wrap(u"(" + tmp + u")")
+        return space.newunicode(u"(" + tmp + u")")
 
     def descr_hash(self, space):
         raise NotImplementedError
@@ -213,7 +213,7 @@
         for w_item in self.tolist():
             if space.eq_w(w_item, w_obj):
                 count += 1
-        return space.wrap(count)
+        return space.newint(count)
 
     @unwrap_spec(w_start=WrappedDefault(0), w_stop=WrappedDefault(sys.maxint))
     @jit.look_inside_iff(lambda self, _1, _2, _3, _4: _unroll_condition(self))
@@ -226,7 +226,7 @@
         for i in range(start, min(stop, length)):
             w_item = self.tolist()[i]
             if space.eq_w(w_item, w_obj):
-                return space.wrap(i)
+                return space.newint(i)
         raise oefmt(space.w_ValueError, "tuple.index(x): x not in tuple")
 
 W_AbstractTupleObject.typedef = TypeDef(
@@ -296,7 +296,7 @@
             z -= 1
             mult += 82520 + z + z
         x += 97531
-        return space.wrap(intmask(x))
+        return space.newint(intmask(x))
 
     def _descr_hash_jitdriver(self, space):
         mult = 1000003
@@ -310,7 +310,7 @@
             z -= 1
             mult += 82520 + z + z
         x += 97531
-        return space.wrap(intmask(x))
+        return space.newint(intmask(x))
 
     def descr_eq(self, space, w_other):
         if not isinstance(w_other, W_AbstractTupleObject):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -35,7 +35,7 @@
         self.intvalue = intvalue
 
     def unwrap_cell(self, space):
-        return space.wrap(self.intvalue)
+        return space.newint(self.intvalue)
 
     def __repr__(self):
         return "<IntMutableCell: %s>" % (self.intvalue, )
@@ -344,7 +344,7 @@
         if name == "__del__" and name not in self.dict_w:
             msg = ("a __del__ method added to an existing type will not be "
                    "called")
-            space.warn(space.wrap(msg), space.w_RuntimeWarning)
+            space.warn(space.newtext(msg), space.w_RuntimeWarning)
         version_tag = self.version_tag()
         if version_tag is not None:
             w_curr = self._pure_getdictvalue_no_unwrapping(
@@ -540,7 +540,7 @@
                 mod = self.name[:dot]
             else:
                 mod = "builtins"
-            return space.wrap(mod)
+            return space.newtext(mod)
 
     def getname(self, space):
         if self.is_heaptype():
@@ -651,9 +651,9 @@
         else:
             mod = space.unicode_w(w_mod)
         if mod is not None and mod != u'builtins':
-            return space.wrap(u"<class '%s.%s'>" % (mod, self.getqualname(space)))
+            return space.newunicode(u"<class '%s.%s'>" % (mod, self.getqualname(space)))
         else:
-            return space.wrap(u"<class '%s'>" % (self.name.decode('utf-8')))
+            return space.newtext("<class '%s'>" % (self.name,))
 
     def descr_getattribute(self, space, w_name):
         name = space.str_w(w_name)
@@ -712,8 +712,8 @@
 
     w_winner = _calculate_metaclass(space, w_typetype, bases_w)
     if not space.is_w(w_winner, w_typetype):
-        newfunc = space.getattr(w_winner, space.wrap('__new__'))
-        if not space.is_w(newfunc, space.getattr(space.w_type, space.wrap('__new__'))):
+        newfunc = space.getattr(w_winner, space.newtext('__new__'))
+        if not space.is_w(newfunc, space.getattr(space.w_type, space.newtext('__new__'))):
             return space.call_function(newfunc, w_winner, w_name, w_bases, w_dict)
         w_typetype = w_winner
 
@@ -766,13 +766,13 @@
 
 def _check(space, w_type, msg="descriptor is for 'type'"):
     if not isinstance(w_type, W_TypeObject):
-        raise OperationError(space.w_TypeError, space.wrap(msg))
+        raise OperationError(space.w_TypeError, space.newtext(msg))
     return w_type
 
 
 def descr_get__name__(space, w_type):
     w_type = _check(space, w_type)
-    return space.wrap(w_type.getname(space))
+    return space.newtext(w_type.getname(space))
 
 def descr_set__name__(space, w_type, w_value):
     w_type = _check(space, w_type)
@@ -886,7 +886,7 @@
 
 def descr__doc(space, w_type):
     if space.is_w(w_type, space.w_type):
-        return space.wrap("""type(object) -> the object's type
+        return space.newtext("""type(object) -> the object's type
 type(name, bases, dict) -> a new type""")
     w_type = _check(space, w_type)
     if not w_type.is_heaptype():
@@ -920,7 +920,7 @@
         flags |= _CPYTYPE
     if w_type.flag_abstract:
         flags |= _ABSTRACT
-    return space.wrap(flags)
+    return space.newint(flags)
 
 def descr_get__module(space, w_type):
     w_type = _check(space, w_type)
@@ -1230,7 +1230,7 @@
         caller = space.getexecutioncontext().gettopframe_nohidden()
         if caller is not None:
             w_globals = caller.get_w_globals()
-            w_name = space.finditem(w_globals, space.wrap('__name__'))
+            w_name = space.finditem(w_globals, space.newtext('__name__'))
             if w_name is not None:
                 w_self.dict_w['__module__'] = w_name
 
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
@@ -74,7 +74,7 @@
             else:
                 base = 257       # empty unicode string: base value 257
             uid = (base << IDTAG_SHIFT) | IDTAG_SPECIAL
-        return space.wrap(uid)
+        return space.newint(uid)
 
     def unicode_w(self, space):
         return self._value
@@ -116,7 +116,7 @@
             raise oefmt(space.w_TypeError,
                          "ord() expected a character, but string of length %d "
                          "found", len(self._value))
-        return space.wrap(ord(self._value[0]))
+        return space.newint(ord(self._value[0]))
 
     def _new(self, value):
         return W_UnicodeObject(value)
@@ -327,7 +327,7 @@
         chars = self._value
         size = len(chars)
         s = _repr_function(chars, size, "strict")
-        return space.wrap(s)
+        return space.newtext(s)
 
     def descr_str(self, space):
         if space.is_w(space.type(self), space.w_unicode):
@@ -337,7 +337,7 @@
 
     def descr_hash(self, space):
         x = compute_hash(self._value)
-        return space.wrap(x)
+        return space.newint(x)
 
     def descr_eq(self, space, w_other):
         try:
@@ -426,11 +426,11 @@
         selfvalue = self._value
         w_sys = space.getbuiltinmodule('sys')
         maxunicode = space.int_w(space.getattr(w_sys,
-                                               space.wrap("maxunicode")))
+                                               space.newtext("maxunicode")))
         result = []
         for unichar in selfvalue:
             try:
-                w_newval = space.getitem(w_table, space.wrap(ord(unichar)))
+                w_newval = space.getitem(w_table, space.newint(ord(unichar)))
             except OperationError as e:
                 if e.match(space, space.w_LookupError):
                     result.append(unichar)
@@ -464,8 +464,8 @@
         l = space.listview_unicode(w_list)
         if l is not None:
             if len(l) == 1:
-                return space.wrap(l[0])
-            return space.wrap(self._val(space).join(l))
+                return space.newunicode(l[0])
+            return space.newunicode(self._val(space).join(l))
         return self._StringMethods_descr_join(space, w_list)
 
     def _join_return_one(self, space, w_obj):
@@ -600,11 +600,11 @@
 def wrap_encode_error(space, ue):
     raise OperationError(space.w_UnicodeEncodeError,
                          space.newtuple([
-        space.wrap(ue.encoding),
-        space.wrap(ue.object),
-        space.wrap(ue.start),
-        space.wrap(ue.end),
-        space.wrap(ue.reason)]))
+        space.newtext(ue.encoding),
+        space.newbytes(ue.object),
+        space.newint(ue.start),
+        space.newint(ue.end),
+        space.newtext(ue.reason)]))
 
 
 def decode_object(space, w_obj, encoding, errors):
@@ -620,11 +620,11 @@
                 eh = unicodehelper.decode_error_handler(space)
                 u = str_decode_ascii(     # try again, to get the error right
                     s, len(s), None, final=True, errorhandler=eh)[0]
-            return space.wrap(u)
+            return space.newunicode(u)
         if encoding == 'utf-8':
             s = space.charbuf_w(w_obj)
             eh = unicodehelper.decode_error_handler(space)
-            return space.wrap(str_decode_utf_8(
+            return space.newunicode(str_decode_utf_8(
                     s, len(s), None, final=True, errorhandler=eh)[0])
 
     from pypy.module._codecs.interp_codecs import decode_text
diff --git a/pypy/objspace/std/util.py b/pypy/objspace/std/util.py
--- a/pypy/objspace/std/util.py
+++ b/pypy/objspace/std/util.py
@@ -1,6 +1,6 @@
 from rpython.rlib.rstring import InvalidBaseError
 
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter import gateway
 
 IDTAG_SHIFT   = 4
@@ -53,12 +53,10 @@
 
 def wrap_parsestringerror(space, e, w_source):
     if isinstance(e, InvalidBaseError):
-        w_msg = space.wrap(e.msg)
+        raise OperationError(space.w_ValueError, space.newtext(e.msg))
     else:
-        w_msg = space.wrap(u'%s: %s' % (unicode(e.msg),
-                                        space.unicode_w(space.repr(w_source))))
-    return OperationError(space.w_ValueError, w_msg)
-
+        raise oefmt(space.w_ValueError, '%s: %R',
+                            e.msg, w_source)
 
 app = gateway.applevel(r'''
     def _classdir(klass):


More information about the pypy-commit mailing list