Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: space-newtext Changeset: r88809:485d75d6a904 Date: 2016-12-02 10:13 +0100 http://bitbucket.org/pypy/pypy/changeset/485d75d6a904/
Log: progress: remove space.w_str completely (replaced by space.w_bytes and space.w_text). mark space.str_w as not_rpython, since many tests still use it diff too long, truncating to 2000 out of 2006 lines diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py --- a/pypy/interpreter/astcompiler/ast.py +++ b/pypy/interpreter/astcompiler/ast.py @@ -14,7 +14,7 @@ def check_string(space, w_obj): - if not (space.isinstance_w(w_obj, space.w_str) or + if not (space.isinstance_w(w_obj, space.w_bytes) or space.isinstance_w(w_obj, space.w_unicode)): raise oefmt(space.w_TypeError, "AST string must be of type str or unicode") diff --git a/pypy/interpreter/astcompiler/misc.py b/pypy/interpreter/astcompiler/misc.py --- a/pypy/interpreter/astcompiler/misc.py +++ b/pypy/interpreter/astcompiler/misc.py @@ -110,9 +110,9 @@ def intern_if_common_string(space, w_const): # only intern identifier-like strings - if not space.is_w(space.type(w_const), space.w_str): + if not space.is_w(space.type(w_const), space.w_text): return w_const - for c in space.str_w(w_const): + for c in space.text_w(w_const): if not (c.isalnum() or c == '_'): return w_const return space.new_interned_w_str(w_const) diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py b/pypy/interpreter/astcompiler/tools/asdl_py.py --- a/pypy/interpreter/astcompiler/tools/asdl_py.py +++ b/pypy/interpreter/astcompiler/tools/asdl_py.py @@ -401,7 +401,7 @@ def check_string(space, w_obj): - if not (space.isinstance_w(w_obj, space.w_str) or + if not (space.isinstance_w(w_obj, space.w_bytes) or space.isinstance_w(w_obj, space.w_unicode)): raise oefmt(space.w_TypeError, "AST string must be of type str or unicode") diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -5,7 +5,7 @@ from rpython.rlib import jit, types from rpython.rlib.debug import make_sure_not_resized from rpython.rlib.objectmodel import (we_are_translated, newlist_hint, - compute_unique_id, specialize) + compute_unique_id, specialize, not_rpython) from rpython.rlib.signature import signature from rpython.rlib.rarithmetic import r_uint, SHRT_MIN, SHRT_MAX, \ INT_MIN, INT_MAX, UINT_MAX, USHRT_MAX @@ -328,8 +328,8 @@ constructed before there is an object space instance. """ return self + @not_rpython def unwrap(self, space): - """NOT_RPYTHON""" # _____ this code is here to support testing only _____ return self @@ -412,8 +412,9 @@ """Base class for the interpreter-level implementations of object spaces. http://pypy.readthedocs.org/en/latest/objspace.html""" + @not_rpython def __init__(self, config=None): - "NOT_RPYTHON: Basic initialization of objects." + "Basic initialization of objects." self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit @@ -489,8 +490,9 @@ except AttributeError: return self.__class__.__name__ + @not_rpython def setbuiltinmodule(self, importname): - """NOT_RPYTHON. load a lazy pypy/module and put it into sys.modules""" + """load a lazy pypy/module and put it into sys.modules""" if '.' in importname: fullname = importname importname = fullname.rsplit('.', 1)[1] @@ -548,8 +550,8 @@ self.setitem(w_modules, w_name, w_mod) return w_mod + @not_rpython def get_builtinmodule_to_install(self): - """NOT_RPYTHON""" try: return self._builtinmodule_list except AttributeError: @@ -588,8 +590,9 @@ 'posix', 'nt', 'pwd', 'signal', 'sys', 'thread', 'zipimport', ], None) + @not_rpython def make_builtins(self): - "NOT_RPYTHON: only for initializing the space." + "only for initializing the space." from pypy.module.exceptions import Module w_name = self.newtext('exceptions') @@ -642,8 +645,8 @@ objects.""" raise NotImplementedError + @not_rpython def export_builtin_exceptions(self): - """NOT_RPYTHON""" w_dic = self.exceptions_module.getdict(self) w_keys = self.call_method(w_dic, "keys") exc_types_w = {} @@ -656,8 +659,8 @@ setattr(self, "w_" + excname, w_exc) return exc_types_w + @not_rpython def install_mixedmodule(self, mixedname, installed_builtin_modules): - """NOT_RPYTHON""" modname = self.setbuiltinmodule(mixedname) if modname: assert modname not in installed_builtin_modules, ( @@ -665,8 +668,9 @@ "app-level module %r" % (modname,)) installed_builtin_modules.append(modname) + @not_rpython def setup_builtin_modules(self): - "NOT_RPYTHON: only for initializing the space." + "only for initializing the space." if self.config.objspace.usemodules.cpyext: from pypy.module.cpyext.state import State self.fromcache(State).build_api(self) @@ -676,8 +680,9 @@ for mod in self.builtin_modules.values(): mod.setup_after_space_initialization() + @not_rpython def initialize(self): - """NOT_RPYTHON: Abstract method that should put some minimal + """Abstract method that should put some minimal content into the w_builtins.""" def getexecutioncontext(self): @@ -833,7 +838,7 @@ def new_interned_w_str(self, w_s): assert isinstance(w_s, W_Root) # and is not None - s = self.str_w(w_s) + s = self.bytes_w(w_s) if not we_are_translated(): assert type(s) is str w_s1 = self.interned_strings.get(s) @@ -1289,14 +1294,16 @@ def exception_issubclass_w(self, w_cls1, w_cls2): return self.issubtype_w(w_cls1, w_cls2) + @not_rpython def new_exception_class(self, *args, **kwargs): - "NOT_RPYTHON; convenience method to create excceptions in modules" + "convenience method to create excceptions in modules" return new_exception_class(self, *args, **kwargs) # end of special support code + @not_rpython def eval(self, expression, w_globals, w_locals, hidden_applevel=False): - "NOT_RPYTHON: For internal debugging." + "For internal debugging." if isinstance(expression, str): compiler = self.createcompiler() expression = compiler.compile(expression, '?', 'eval', 0, @@ -1305,9 +1312,10 @@ raise TypeError('space.eval(): expected a string, code or PyCode object') return expression.exec_code(self, w_globals, w_locals) + @not_rpython def exec_(self, statement, w_globals, w_locals, hidden_applevel=False, filename=None): - "NOT_RPYTHON: For internal debugging." + "For internal debugging." if filename is None: filename = '?' from pypy.interpreter.pycode import PyCode @@ -1523,7 +1531,7 @@ return None code = 's*' if code == 's*': - if self.isinstance_w(w_obj, self.w_str): + if self.isinstance_w(w_obj, self.w_bytes): return w_obj.readbuf_w(self) if self.isinstance_w(w_obj, self.w_unicode): return self.str(w_obj).readbuf_w(self) @@ -1536,7 +1544,7 @@ except BufferInterfaceNotFound: self._getarg_error("string or buffer", w_obj) elif code == 's#': - if self.isinstance_w(w_obj, self.w_str): + if self.isinstance_w(w_obj, self.w_bytes): return w_obj.str_w(self) if self.isinstance_w(w_obj, self.w_unicode): return self.str(w_obj).str_w(self) @@ -1592,13 +1600,18 @@ return buf.as_str() def str_or_None_w(self, w_obj): - return None if self.is_none(w_obj) else self.str_w(w_obj) + # YYY rename + return None if self.is_none(w_obj) else self.bytes_w(w_obj) + def bytes_w(self, w_obj): + return w_obj.str_w(self) + text_w = bytes_w # equivalent to identifier_w on Python3 + + @not_rpython def str_w(self, w_obj): - return w_obj.str_w(self) + # XXX there are still some tests that call it + return self.bytes_w(w_obj) - bytes_w = str_w # the same on Python3 - text_w = str_w # equivalent to identifier_w on Python3 def str0_w(self, w_obj): "Like str_w, but rejects strings with NUL bytes." @@ -1644,10 +1657,11 @@ return w_obj.float_w(self, allow_conversion) def realstr_w(self, w_obj): - # Like str_w, but only works if w_obj is really of type 'str'. - if not self.isinstance_w(w_obj, self.w_str): + # YYY rename + # Like bytes_w, but only works if w_obj is really of type 'str'. + if not self.isinstance_w(w_obj, self.w_bytes): raise oefmt(self.w_TypeError, "argument must be a string") - return self.str_w(w_obj) + return self.bytes_w(w_obj) def unicode_w(self, w_obj): return w_obj.unicode_w(self) @@ -1859,8 +1873,8 @@ class AppExecCache(SpaceCache): + @not_rpython def build(cache, source): - """ NOT_RPYTHON """ space = cache.space # XXX will change once we have our own compiler import py diff --git a/pypy/interpreter/interactive.py b/pypy/interpreter/interactive.py --- a/pypy/interpreter/interactive.py +++ b/pypy/interpreter/interactive.py @@ -152,7 +152,7 @@ if not k.startswith('w_')])) del local['locals'] for w_name in self.space.unpackiterable(self.w_globals): - local['w_' + self.space.str_w(w_name)] = ( + local['w_' + self.space.text_w(w_name)] = ( self.space.getitem(self.w_globals, w_name)) code.interact(banner=banner, local=local) # copy back 'w_' names diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py --- a/pypy/interpreter/main.py +++ b/pypy/interpreter/main.py @@ -137,7 +137,7 @@ exitcode = space.int_w(w_exitcode, allow_conversion=False) except OperationError: # not an integer: print it to stderr - msg = space.str_w(space.str(w_exitcode)) + msg = space.text_w(space.str(w_exitcode)) print >> sys.stderr, msg exitcode = 1 raise SystemExit(exitcode) diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py --- a/pypy/interpreter/module.py +++ b/pypy/interpreter/module.py @@ -91,7 +91,7 @@ def descr__reduce__(self, space): w_name = space.finditem(self.w_dict, space.newtext('__name__')) if (w_name is None or - not space.isinstance_w(w_name, space.w_str)): + not space.isinstance_w(w_name, space.w_text)): # maybe raise exception here (XXX this path is untested) return space.w_None w_modules = space.sys.get('modules') diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py --- a/pypy/interpreter/pycode.py +++ b/pypy/interpreter/pycode.py @@ -25,7 +25,7 @@ # helper -def unpack_str_tuple(space,w_str_tuple): +def unpack_text_tuple(space,w_str_tuple): return [space.text_w(w_el) for w_el in space.unpackiterable(w_str_tuple)] @@ -382,14 +382,14 @@ if not space.isinstance_w(w_constants, space.w_tuple): raise oefmt(space.w_TypeError, "Expected tuple for constants") consts_w = space.fixedview(w_constants) - names = unpack_str_tuple(space, w_names) - varnames = unpack_str_tuple(space, w_varnames) + names = unpack_text_tuple(space, w_names) + varnames = unpack_text_tuple(space, w_varnames) if w_freevars is not None: - freevars = unpack_str_tuple(space, w_freevars) + freevars = unpack_text_tuple(space, w_freevars) else: freevars = [] if w_cellvars is not None: - cellvars = unpack_str_tuple(space, w_cellvars) + cellvars = unpack_text_tuple(space, w_cellvars) else: cellvars = [] code = space.allocate_instance(PyCode, w_subtype) diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py --- a/pypy/interpreter/pyframe.py +++ b/pypy/interpreter/pyframe.py @@ -904,7 +904,7 @@ def unpickle_block(space, w_tup): w_opname, w_handlerposition, w_valuestackdepth = space.unpackiterable(w_tup) - opname = space.str_w(w_opname) + opname = space.text_w(w_opname) handlerposition = space.int_w(w_handlerposition) valuestackdepth = space.int_w(w_valuestackdepth) assert valuestackdepth >= 0 diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -956,10 +956,10 @@ space = self.space if space.isinstance_w(w_2, space.w_tuple): for w_t in space.fixedview(w_2): - if space.isinstance_w(w_t, space.w_str): + if space.isinstance_w(w_t, space.w_bytes): msg = "catching of string exceptions is deprecated" space.warn(space.newtext(msg), space.w_DeprecationWarning) - elif space.isinstance_w(w_2, space.w_str): + elif space.isinstance_w(w_2, space.w_bytes): msg = "catching of string exceptions is deprecated" space.warn(space.newtext(msg), space.w_DeprecationWarning) return space.newbool(space.exception_match(w_1, w_2)) 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 @@ -227,7 +227,7 @@ def decode_utf8_recode(space, s, ps, end, recode_encoding): u, ps = decode_utf8(space, s, ps, end) w_v = unicodehelper.encode(space, space.newunicode(u), recode_encoding) - v = space.str_w(w_v) + v = space.bytes_w(w_v) return v, ps def raise_app_valueerror(space, msg): diff --git a/pypy/interpreter/pyparser/pyparse.py b/pypy/interpreter/pyparser/pyparse.py --- a/pypy/interpreter/pyparser/pyparse.py +++ b/pypy/interpreter/pyparser/pyparse.py @@ -8,7 +8,7 @@ if not space.isinstance_w(w_text, space.w_unicode): raise error.SyntaxError("codec did not return a unicode object") w_recoded = space.call_method(w_text, "encode", space.newtext("utf-8")) - return space.str_w(w_recoded) + return space.bytes_w(w_recoded) def _normalize_encoding(encoding): """returns normalized name for <encoding> @@ -130,7 +130,7 @@ if e.match(space, space.w_UnicodeDecodeError): e.normalize_exception(space) w_message = space.str(e.get_w_value(space)) - raise error.SyntaxError(space.str_w(w_message)) + raise error.SyntaxError(space.text_w(w_message)) raise flags = compile_info.flags diff --git a/pypy/interpreter/pyparser/test/test_parsestring.py b/pypy/interpreter/pyparser/test/test_parsestring.py --- a/pypy/interpreter/pyparser/test/test_parsestring.py +++ b/pypy/interpreter/pyparser/test/test_parsestring.py @@ -6,7 +6,7 @@ space = self.space w_ret = parsestring.parsestr(space, encoding, literal) if isinstance(value, str): - assert space.type(w_ret) == space.w_str + assert space.type(w_ret) == space.w_bytes assert space.str_w(w_ret) == value elif isinstance(value, unicode): assert space.type(w_ret) == space.w_unicode @@ -58,7 +58,7 @@ w_ret = parsestring.parsestr(space, None, repr("hello"), True) assert space.isinstance_w(w_ret, space.w_unicode) w_ret = parsestring.parsestr(space, None, "b'hi'", True) - assert space.isinstance_w(w_ret, space.w_str) + assert space.isinstance_w(w_ret, space.w_bytes) w_ret = parsestring.parsestr(space, None, "r'hi'", True) assert space.isinstance_w(w_ret, space.w_unicode) diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py --- a/pypy/interpreter/test/test_function.py +++ b/pypy/interpreter/test/test_function.py @@ -649,7 +649,7 @@ assert meth4.call_args(args) == obj2 # Check method returned from unbound_method.__get__() # --- with an incompatible class - w_meth5 = meth3.descr_method_get(space.wrap('hello'), space.w_str) + w_meth5 = meth3.descr_method_get(space.wrap('hello'), space.w_text) assert space.is_w(w_meth5, w_meth3) # Same thing, with an old-style class w_oldclass = space.call_function( @@ -660,7 +660,7 @@ # Reverse order of old/new styles w_meth7 = descr_function_get(space, func, space.w_None, w_oldclass) meth7 = space.unwrap(w_meth7) - w_meth8 = meth7.descr_method_get(space.wrap('hello'), space.w_str) + w_meth8 = meth7.descr_method_get(space.wrap('hello'), space.w_text) assert space.is_w(w_meth8, w_meth7) class TestShortcuts(object): diff --git a/pypy/interpreter/test/test_gateway.py b/pypy/interpreter/test/test_gateway.py --- a/pypy/interpreter/test/test_gateway.py +++ b/pypy/interpreter/test/test_gateway.py @@ -551,7 +551,7 @@ space = self.space w = space.wrap def g_run(space, w_type): - assert space.is_w(w_type, space.w_str) + assert space.is_w(w_type, space.w_text) return w(42) app_g_run = gateway.interp2app_temp(g_run, @@ -559,7 +559,7 @@ gateway.W_Root], as_classmethod=True) w_app_g_run = space.wrap(app_g_run) - w_bound = space.get(w_app_g_run, w("hello"), space.w_str) + w_bound = space.get(w_app_g_run, w("hello"), space.w_text) assert space.eq_w(space.call_function(w_bound), w(42)) def test_interp2app_fastcall(self): diff --git a/pypy/interpreter/test/test_objspace.py b/pypy/interpreter/test/test_objspace.py --- a/pypy/interpreter/test/test_objspace.py +++ b/pypy/interpreter/test/test_objspace.py @@ -20,9 +20,9 @@ w_result = space.isinstance(w_i, space.w_int) assert space.is_true(w_result) assert space.isinstance_w(w_i, space.w_int) - w_result = space.isinstance(w_i, space.w_str) + w_result = space.isinstance(w_i, space.w_bytes) assert not space.is_true(w_result) - assert not space.isinstance_w(w_i, space.w_str) + assert not space.isinstance_w(w_i, space.w_bytes) def test_newlist(self): w = self.space.wrap diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py --- a/pypy/module/__builtin__/__init__.py +++ b/pypy/module/__builtin__/__init__.py @@ -36,7 +36,7 @@ 'None' : '(space.w_None)', 'False' : '(space.w_False)', 'True' : '(space.w_True)', - 'bytes' : '(space.w_str)', + 'bytes' : '(space.w_bytes)', 'file' : 'state.get(space).w_file', 'open' : 'state.get(space).w_file', diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py --- a/pypy/module/__builtin__/compiling.py +++ b/pypy/module/__builtin__/compiling.py @@ -44,7 +44,7 @@ if space.isinstance_w(w_source, space.w_unicode): w_utf_8_source = space.call_method(w_source, "encode", space.newtext("utf-8")) - source = space.str_w(w_utf_8_source) + source = space.bytes_w(w_utf_8_source) # This flag tells the parser to reject any coding cookies it sees. flags |= consts.PyCF_SOURCE_IS_UTF8 else: @@ -69,7 +69,7 @@ are dictionaries, defaulting to the current current globals and locals. If only globals is given, locals defaults to it. """ - if (space.isinstance_w(w_code, space.w_str) or + if (space.isinstance_w(w_code, space.w_bytes) or space.isinstance_w(w_code, space.w_unicode)): w_code = compile(space, space.call_method(w_code, 'lstrip', diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py --- a/pypy/module/__builtin__/interp_classobj.py +++ b/pypy/module/__builtin__/interp_classobj.py @@ -64,7 +64,7 @@ self.w_dict = w_dict def setname(self, space, w_newname): - if not space.isinstance_w(w_newname, space.w_str): + if not space.isinstance_w(w_newname, space.w_text): raise oefmt(space.w_TypeError, "__name__ must be a string object") self.name = space.text_w(w_newname) @@ -172,7 +172,7 @@ if not e.match(space, space.w_AttributeError): raise return "?" - if space.isinstance_w(w_mod, space.w_str): + if space.isinstance_w(w_mod, space.w_text): return space.text_w(w_mod) return "?" diff --git a/pypy/module/__builtin__/operation.py b/pypy/module/__builtin__/operation.py --- a/pypy/module/__builtin__/operation.py +++ b/pypy/module/__builtin__/operation.py @@ -44,7 +44,7 @@ # space.{get,set,del}attr()... # Note that if w_name is already an exact string it must be returned # unmodified (and not e.g. unwrapped-rewrapped). - if not space.is_w(space.type(w_name), space.w_str): + if not space.is_w(space.type(w_name), space.w_text): name = space.text_w(w_name) # typecheck w_name = space.newtext(name) # rewrap as a real string return w_name @@ -223,7 +223,7 @@ table of interned strings whose purpose is to speed up dictionary lookups. Return the string itself or the previously interned string object with the same value.""" - if space.is_w(space.type(w_str), space.w_str): + if space.is_w(space.type(w_str), space.w_bytes): return space.new_interned_w_str(w_str) raise oefmt(space.w_TypeError, "intern() argument must be string.") diff --git a/pypy/module/_cffi_backend/call_python.py b/pypy/module/_cffi_backend/call_python.py --- a/pypy/module/_cffi_backend/call_python.py +++ b/pypy/module/_cffi_backend/call_python.py @@ -91,7 +91,7 @@ if space.is_w(w_name, space.w_None): w_name = space.getattr(w_python_callable, space.newtext('__name__')) - name = space.str_w(w_name) + name = space.text_w(w_name) ctx = ffi.ctxobj.ctx index = parse_c_type.search_in_globals(ctx, name) diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py --- a/pypy/module/_cffi_backend/ccallback.py +++ b/pypy/module/_cffi_backend/ccallback.py @@ -98,7 +98,7 @@ def _repr_extra(self): space = self.space - return 'calling ' + space.str_w(space.repr(self.w_callable)) + return 'calling ' + space.text_w(space.repr(self.w_callable)) def write_error_return_value(self, ll_res): error_string = self.error_string diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py --- a/pypy/module/_cffi_backend/cdataobj.py +++ b/pypy/module/_cffi_backend/cdataobj.py @@ -232,10 +232,10 @@ from pypy.module._cffi_backend import ctypeprim space = self.space if isinstance(ctitem, ctypeprim.W_CTypePrimitive) and ctitem.size == 1: - if space.isinstance_w(w_value, space.w_str): + if space.isinstance_w(w_value, space.w_bytes): from rpython.rtyper.annlowlevel import llstr from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw - value = space.str_w(w_value) + value = space.bytes_w(w_value) if len(value) != length: raise oefmt(space.w_ValueError, "need a string of length %d, got %d", @@ -324,7 +324,7 @@ return self._add_or_sub(w_other, -1) def getcfield(self, w_attr): - return self.ctype.getcfield(self.space.str_w(w_attr)) + return self.ctype.getcfield(self.space.text_w(w_attr)) def getattr(self, w_attr): cfield = self.getcfield(w_attr) @@ -419,8 +419,8 @@ with self as ptr: if not ptr: raise oefmt(space.w_RuntimeError, - "cannot use unpack() on %s", - space.str_w(self.repr())) + "cannot use unpack() on %R", + self) w_result = ctype.ctitem.unpack_ptr(ctype, ptr, length) return w_result @@ -565,7 +565,7 @@ def _repr_extra(self): w_repr = self.space.repr(self.w_keepalive) - return "handle to %s" % (self.space.str_w(w_repr),) + return "handle to %s" % (self.space.text_w(w_repr),) class W_CDataFromBuffer(W_CData): diff --git a/pypy/module/_cffi_backend/cdlopen.py b/pypy/module/_cffi_backend/cdlopen.py --- a/pypy/module/_cffi_backend/cdlopen.py +++ b/pypy/module/_cffi_backend/cdlopen.py @@ -155,7 +155,7 @@ p = rffi.ptradd(p, llmemory.raw_malloc_usage(n * rffi.sizeof(GLOBAL_S))) nintconsts = rffi.cast(rffi.CArrayPtr(CDL_INTCONST_S), p) for i in range(n): - decoder = StringDecoder(ffi, space.str_w(globals_w[i * 2])) + decoder = StringDecoder(ffi, space.bytes_w(globals_w[i * 2])) nglobs[i].c_type_op = decoder.next_opcode() nglobs[i].c_name = decoder.next_name() op = getop(nglobs[i].c_type_op) @@ -185,7 +185,7 @@ # 'desc' is the tuple of strings (desc_struct, desc_field_1, ..) desc = space.fixedview(struct_unions_w[i]) nf1 = len(desc) - 1 - decoder = StringDecoder(ffi, space.str_w(desc[0])) + decoder = StringDecoder(ffi, space.bytes_w(desc[0])) rffi.setintfield(nstructs[i], 'c_type_index', decoder.next_4bytes()) flags = decoder.next_4bytes() rffi.setintfield(nstructs[i], 'c_flags', flags) @@ -202,7 +202,7 @@ rffi.setintfield(nstructs[i], 'c_first_field_index', nf) rffi.setintfield(nstructs[i], 'c_num_fields', nf1) for j in range(nf1): - decoder = StringDecoder(ffi, space.str_w(desc[j + 1])) + decoder = StringDecoder(ffi, space.bytes_w(desc[j + 1])) # this 'decoder' is for one of the other strings beyond # the first one, describing one field each type_op = decoder.next_opcode() @@ -226,7 +226,7 @@ n = len(enums_w) nenums = allocate_array(ffi, ENUM_S, n) for i in range(n): - decoder = StringDecoder(ffi, space.str_w(enums_w[i])) + decoder = StringDecoder(ffi, space.bytes_w(enums_w[i])) rffi.setintfield(nenums[i], 'c_type_index', decoder.next_4bytes()) rffi.setintfield(nenums[i], 'c_type_prim', decoder.next_4bytes()) nenums[i].c_name = decoder.next_name() @@ -241,7 +241,7 @@ n = len(typenames_w) ntypenames = allocate_array(ffi, TYPENAME_S, n) for i in range(n): - decoder = StringDecoder(ffi, space.str_w(typenames_w[i])) + decoder = StringDecoder(ffi, space.bytes_w(typenames_w[i])) rffi.setintfield(ntypenames[i],'c_type_index',decoder.next_4bytes()) ntypenames[i].c_name = decoder.next_name() ffi.ctxobj.ctx.c_typenames = ntypenames diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py --- a/pypy/module/_cffi_backend/ctypeobj.py +++ b/pypy/module/_cffi_backend/ctypeobj.py @@ -175,7 +175,7 @@ def direct_typeoffsetof(self, w_field_or_index, following=0): space = self.space try: - fieldname = space.str_w(w_field_or_index) + fieldname = space.text_w(w_field_or_index) except OperationError as e: if not e.match(space, space.w_TypeError): raise diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py --- a/pypy/module/_cffi_backend/ctypeprim.py +++ b/pypy/module/_cffi_backend/ctypeprim.py @@ -25,14 +25,14 @@ def extra_repr(self, cdata): w_ob = self.convert_to_object(cdata) - return self.space.str_w(self.space.repr(w_ob)) + return self.space.text_w(self.space.repr(w_ob)) def _alignof(self): return self.align def cast_str(self, w_ob): space = self.space - s = space.str_w(w_ob) + s = space.bytes_w(w_ob) if len(s) != 1: raise oefmt(space.w_TypeError, "cannot cast string of length %d to ctype '%s'", @@ -56,7 +56,7 @@ ptr = w_ob.unsafe_escaping_ptr() value = rffi.cast(lltype.Signed, ptr) value = self._cast_result(value) - elif space.isinstance_w(w_ob, space.w_str): + elif space.isinstance_w(w_ob, space.w_bytes): value = self.cast_str(w_ob) value = self._cast_result(value) elif space.isinstance_w(w_ob, space.w_unicode): @@ -76,7 +76,7 @@ def _overflow(self, w_ob): space = self.space - s = space.str_w(space.str(w_ob)) + s = space.text_w(space.str(w_ob)) raise oefmt(space.w_OverflowError, "integer %s does not fit '%s'", s, self.name) @@ -129,7 +129,7 @@ def _convert_to_char(self, w_ob): space = self.space - if space.isinstance_w(w_ob, space.w_str): + if space.isinstance_w(w_ob, space.w_bytes): s = space.bytes_w(w_ob) if len(s) == 1: return s[0] @@ -383,7 +383,7 @@ w_ob.ctype.name, self.name) w_ob = w_ob.convert_to_object() # - if space.isinstance_w(w_ob, space.w_str): + if space.isinstance_w(w_ob, space.w_bytes): value = self.cast_str(w_ob) elif space.isinstance_w(w_ob, space.w_unicode): value = self.cast_unicode(w_ob) diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py --- a/pypy/module/_cffi_backend/ctypeptr.py +++ b/pypy/module/_cffi_backend/ctypeptr.py @@ -74,9 +74,9 @@ else: self._convert_array_from_listview(cdata, space.listview(w_ob)) elif self.accept_str: - if not space.isinstance_w(w_ob, space.w_str): + if not space.isinstance_w(w_ob, space.w_bytes): raise self._convert_error("str or list or tuple", w_ob) - s = space.str_w(w_ob) + s = space.bytes_w(w_ob) n = len(s) if self.length >= 0 and n > self.length: raise oefmt(space.w_IndexError, @@ -107,8 +107,8 @@ with cdataobj as ptr: if not ptr: raise oefmt(space.w_RuntimeError, - "cannot use string() on %s", - space.str_w(cdataobj.repr())) + "cannot use string() on %R", + cdataobj) # from pypy.module._cffi_backend import ctypearray length = maxlen @@ -280,9 +280,9 @@ def _prepare_pointer_call_argument(self, w_init, cdata, keepalives, i): space = self.space - if self.accept_str and space.isinstance_w(w_init, space.w_str): + if self.accept_str and space.isinstance_w(w_init, space.w_bytes): # special case to optimize strings passed to a "char *" argument - value = w_init.str_w(space) + value = space.bytes_w(w_init) keepalives[i] = value buf, buf_flag = rffi.get_nonmovingbuffer_final_null(value) rffi.cast(rffi.CCHARPP, cdata)[0] = buf diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py --- a/pypy/module/_cffi_backend/ctypestruct.py +++ b/pypy/module/_cffi_backend/ctypestruct.py @@ -138,7 +138,7 @@ lst_w = space.fixedview(w_ob) for i in range(len(lst_w)): w_key = lst_w[i] - key = space.str_w(w_key) + key = space.text_w(w_key) try: cf = self._fields_dict[key] except KeyError: diff --git a/pypy/module/_cffi_backend/ffi_obj.py b/pypy/module/_cffi_backend/ffi_obj.py --- a/pypy/module/_cffi_backend/ffi_obj.py +++ b/pypy/module/_cffi_backend/ffi_obj.py @@ -152,7 +152,7 @@ space = self.space if (accept & ACCEPT_STRING) and ( space.isinstance_w(w_x, space.w_basestring)): - string = space.str_w(w_x) + string = space.text_w(w_x) consider_fn_as_fnptr = (accept & CONSIDER_FN_AS_FNPTR) != 0 if jit.isconstant(string): try: @@ -226,7 +226,7 @@ space = self.space if isinstance(w_arg, W_LibObject) and len(args_w) == 1: # case 3 in the docstring - return w_arg.address_of_func_or_global_var(space.str_w(args_w[0])) + return w_arg.address_of_func_or_global_var(space.text_w(args_w[0])) # w_ctype = self.ffi_type(w_arg, ACCEPT_CDATA) if len(args_w) == 0: diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py --- a/pypy/module/_cffi_backend/func.py +++ b/pypy/module/_cffi_backend/func.py @@ -137,7 +137,7 @@ def _from_buffer(space, w_ctype, w_x): buf = _fetch_as_read_buffer(space, w_x) - if space.isinstance_w(w_x, space.w_str): + if space.isinstance_w(w_x, space.w_bytes): _cdata = get_raw_address_of_string(space, w_x) else: try: @@ -178,7 +178,7 @@ cache = space.fromcache(RawBytesCache) rawbytes = cache.wdict.get(w_x) if rawbytes is None: - data = space.str_w(w_x) + data = space.bytes_w(w_x) if we_are_translated() and not rgc.can_move(data): lldata = llstr(data) data_start = (llmemory.cast_ptr_to_adr(lldata) + diff --git a/pypy/module/_cffi_backend/lib_obj.py b/pypy/module/_cffi_backend/lib_obj.py --- a/pypy/module/_cffi_backend/lib_obj.py +++ b/pypy/module/_cffi_backend/lib_obj.py @@ -222,7 +222,7 @@ else: raise oefmt(self.space.w_AttributeError, "cannot write to function or constant '%s'", - self.space.str_w(w_attr)) + self.space.text_w(w_attr)) def descr_delattr(self, w_attr): self._get_attr(w_attr) # for the possible AttributeError diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py --- a/pypy/module/_cffi_backend/newtype.py +++ b/pypy/module/_cffi_backend/newtype.py @@ -309,7 +309,7 @@ field_w = space.fixedview(w_field) if not (2 <= len(field_w) <= 4): raise oefmt(space.w_TypeError, "bad field descr") - fname = space.str_w(field_w[0]) + fname = space.text_w(field_w[0]) ftype = space.interp_w(ctypeobj.W_CType, field_w[1]) fbitsize = -1 foffset = -1 @@ -568,7 +568,7 @@ enumvalues_w = space.fixedview(w_enumvalues) if len(enumerators_w) != len(enumvalues_w): raise oefmt(space.w_ValueError, "tuple args must have the same size") - enumerators = [space.str_w(w) for w in enumerators_w] + enumerators = [space.text_w(w) for w in enumerators_w] # if (not isinstance(w_basectype, ctypeprim.W_CTypePrimitiveSigned) and not isinstance(w_basectype, ctypeprim.W_CTypePrimitiveUnsigned)): diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py --- a/pypy/module/_codecs/interp_codecs.py +++ b/pypy/module/_codecs/interp_codecs.py @@ -176,7 +176,7 @@ raise oefmt(space.w_TypeError, "wrong exception") delta = space.int_w(w_end) - space.int_w(w_start) - if delta < 0 or not (space.isinstance_w(w_obj, space.w_str) or + if delta < 0 or not (space.isinstance_w(w_obj, space.w_bytes) or space.isinstance_w(w_obj, space.w_unicode)): raise oefmt(space.w_TypeError, "wrong exception") @@ -561,7 +561,7 @@ raise return errorchar - if space.isinstance_w(w_ch, space.w_str): + if space.isinstance_w(w_ch, space.w_bytes): # Charmap may return a string return space.bytes_w(w_ch) elif space.isinstance_w(w_ch, space.w_int): diff --git a/pypy/module/_csv/interp_csv.py b/pypy/module/_csv/interp_csv.py --- a/pypy/module/_csv/interp_csv.py +++ b/pypy/module/_csv/interp_csv.py @@ -38,7 +38,7 @@ if w_src is None: return default try: - return space.str_w(w_src) + return space.text_w(w_src) except OperationError as e: if e.match(space, space.w_TypeError): raise oefmt(space.w_TypeError, '"%s" must be a string', attrname) @@ -49,9 +49,9 @@ return default if space.is_w(w_src, space.w_None): return '\0' - if not space.isinstance_w(w_src, space.w_str): + if not space.isinstance_w(w_src, space.w_text): raise oefmt(space.w_TypeError, '"%s" must be string, not %T', name, w_src) - src = space.str_w(w_src) + src = space.text_w(w_src) if len(src) == 1: return src[0] if len(src) == 0: diff --git a/pypy/module/_csv/interp_writer.py b/pypy/module/_csv/interp_writer.py --- a/pypy/module/_csv/interp_writer.py +++ b/pypy/module/_csv/interp_writer.py @@ -42,9 +42,9 @@ if space.is_w(w_field, space.w_None): field = "" elif space.isinstance_w(w_field, space.w_float): - field = space.str_w(space.repr(w_field)) + field = space.text_w(space.repr(w_field)) else: - field = space.str_w(space.str(w_field)) + field = space.text_w(space.str(w_field)) # if dialect.quoting == QUOTE_NONNUMERIC: try: diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py --- a/pypy/module/_file/interp_file.py +++ b/pypy/module/_file/interp_file.py @@ -56,7 +56,7 @@ return if self.space.sys.track_resources: w_repr = self.space.repr(self) - str_repr = self.space.str_w(w_repr) + str_repr = self.space.text_w(w_repr) w_msg = self.space.newtext("WARNING: unclosed file: " + str_repr) self.space.resource_warning(w_msg, self.w_tb) # @@ -493,7 +493,7 @@ if w_name is None: return '?' else: - return space.str_w(space.repr(w_name)) + return space.text_w(space.repr(w_name)) def file_write(self, w_data): """write(str) -> None. Write string str to file. @@ -526,7 +526,7 @@ self.check_writable() lines = space.fixedview(w_lines) for i, w_line in enumerate(lines): - if not space.isinstance_w(w_line, space.w_str): + if not space.isinstance_w(w_line, space.w_bytes): try: if self.binary: line = w_line.readbuf_w(space).as_str() diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py --- a/pypy/module/_io/interp_bufferedio.py +++ b/pypy/module/_io/interp_bufferedio.py @@ -89,7 +89,7 @@ length = rwbuffer.getlength() w_data = space.call_method(self, "read", space.newint(length)) - if not space.isinstance_w(w_data, space.w_str): + if not space.isinstance_w(w_data, space.w_bytes): raise oefmt(space.w_TypeError, "read() should return bytes") data = space.bytes_w(w_data) rwbuffer.setslice(0, data) diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py --- a/pypy/module/_io/interp_iobase.py +++ b/pypy/module/_io/interp_iobase.py @@ -185,7 +185,7 @@ if trap_eintr(space, e): continue raise - if not space.isinstance_w(w_readahead, space.w_str): + if not space.isinstance_w(w_readahead, space.w_bytes): raise oefmt(space.w_IOError, "peek() should have returned a bytes object, " "not '%T'", w_readahead) @@ -215,7 +215,7 @@ if trap_eintr(space, e): continue raise - if not space.isinstance_w(w_read, space.w_str): + if not space.isinstance_w(w_read, space.w_bytes): raise oefmt(space.w_IOError, "peek() should have returned a bytes object, not " "'%T'", w_read) @@ -337,7 +337,7 @@ return w_data break - if not space.isinstance_w(w_data, space.w_str): + if not space.isinstance_w(w_data, space.w_bytes): raise oefmt(space.w_TypeError, "read() should return bytes") data = space.bytes_w(w_data) if not data: diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py --- a/pypy/module/_io/interp_textio.py +++ b/pypy/module/_io/interp_textio.py @@ -284,7 +284,7 @@ raise return space.newtext('ascii') else: - if space.isinstance_w(w_encoding, space.w_str): + if space.isinstance_w(w_encoding, space.w_text): return w_encoding raise oefmt(space.w_IOError, "could not determine default encoding") @@ -565,7 +565,7 @@ w_input = space.call_method(self.w_buffer, "read1", space.newint(self.chunk_size)) - if not space.isinstance_w(w_input, space.w_str): + if not space.isinstance_w(w_input, space.w_bytes): msg = "decoder getstate() should have returned a bytes " \ "object not '%T'" raise oefmt(space.w_TypeError, msg, w_input) @@ -897,7 +897,7 @@ # Just like _read_chunk, feed the decoder and save a snapshot. w_chunk = space.call_method(self.w_buffer, "read", space.newint(cookie.bytes_to_feed)) - if not space.isinstance_w(w_chunk, space.w_str): + if not space.isinstance_w(w_chunk, space.w_bytes): msg = "underlying read() should have returned " \ "a bytes object, not '%T'" raise oefmt(space.w_TypeError, msg, w_chunk) diff --git a/pypy/module/_pypyjson/interp_encoder.py b/pypy/module/_pypyjson/interp_encoder.py --- a/pypy/module/_pypyjson/interp_encoder.py +++ b/pypy/module/_pypyjson/interp_encoder.py @@ -17,8 +17,8 @@ def raw_encode_basestring_ascii(space, w_string): - if space.isinstance_w(w_string, space.w_str): - s = space.str_w(w_string) + if space.isinstance_w(w_string, space.w_bytes): + s = space.bytes_w(w_string) for i in range(len(s)): c = s[i] if c >= ' ' and c <= '~' and c != '"' and c != '\\': diff --git a/pypy/module/_rawffi/alt/type_converter.py b/pypy/module/_rawffi/alt/type_converter.py --- a/pypy/module/_rawffi/alt/type_converter.py +++ b/pypy/module/_rawffi/alt/type_converter.py @@ -80,7 +80,7 @@ def maybe_handle_char_or_unichar_p(self, w_ffitype, w_obj): w_type = jit.promote(self.space.type(w_obj)) if w_ffitype.is_char_p() and w_type is self.space.w_bytes: - strval = self.space.str_w(w_obj) + strval = self.space.bytes_w(w_obj) self.handle_char_p(w_ffitype, w_obj, strval) return True elif w_ffitype.is_unichar_p() and (w_type is self.space.w_bytes or diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py --- a/pypy/module/_rawffi/interp_rawffi.py +++ b/pypy/module/_rawffi/interp_rawffi.py @@ -99,7 +99,7 @@ def unpack_simple_shape(space, w_shape): # 'w_shape' must be either a letter or a tuple (struct, 1). - if space.isinstance_w(w_shape, space.w_str): + if space.isinstance_w(w_shape, space.w_text): letter = space.text_w(w_shape) return letter2tp(space, letter) else: 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 @@ -262,7 +262,7 @@ # host can be None, string or unicode if space.is_w(w_host, space.w_None): host = None - elif space.isinstance_w(w_host, space.w_str): + elif space.isinstance_w(w_host, space.w_bytes): host = space.bytes_w(w_host) elif space.isinstance_w(w_host, space.w_unicode): w_shost = space.call_method(w_host, "encode", space.newtext("idna")) @@ -276,7 +276,7 @@ port = None elif space.isinstance_w(w_port, space.w_int) or space.isinstance_w(w_port, space.w_long): port = str(space.int_w(w_port)) - elif space.isinstance_w(w_port, space.w_str): + elif space.isinstance_w(w_port, space.w_bytes): port = space.bytes_w(w_port) else: raise oefmt(space.w_TypeError, 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 @@ -251,7 +251,7 @@ else: literal = '\\' not in filter_as_string use_builder = ( - space.isinstance_w(w_string, space.w_str) and literal) + space.isinstance_w(w_string, space.w_bytes) and literal) if literal: w_filter = w_ptemplate filter_is_callable = False diff --git a/pypy/module/_warnings/interp_warnings.py b/pypy/module/_warnings/interp_warnings.py --- a/pypy/module/_warnings/interp_warnings.py +++ b/pypy/module/_warnings/interp_warnings.py @@ -249,7 +249,7 @@ w_text = space.str(w_message) w_category = space.type(w_message) elif (not space.isinstance_w(w_message, space.w_unicode) or - not space.isinstance_w(w_message, space.w_str)): + not space.isinstance_w(w_message, space.w_bytes)): w_text = space.str(w_message) w_message = space.call_function(w_category, w_message) else: diff --git a/pypy/module/_winreg/interp_winreg.py b/pypy/module/_winreg/interp_winreg.py --- a/pypy/module/_winreg/interp_winreg.py +++ b/pypy/module/_winreg/interp_winreg.py @@ -217,7 +217,7 @@ if space.is_w(w_subkey, space.w_None): subkey = None else: - subkey = space.str_w(w_subkey) + subkey = space.text_w(w_subkey) with rffi.scoped_str2charp(value) as dataptr: ret = rwinreg.RegSetValue(hkey, subkey, rwinreg.REG_SZ, dataptr, len(value)) if ret != 0: @@ -238,7 +238,7 @@ if space.is_w(w_subkey, space.w_None): subkey = None else: - subkey = space.str_w(w_subkey) + subkey = space.text_w(w_subkey) with lltype.scoped_alloc(rwin32.PLONG.TO, 1) as bufsize_p: ret = rwinreg.RegQueryValue(hkey, subkey, None, bufsize_p) bufSize = intmask(bufsize_p[0]) @@ -286,7 +286,7 @@ if space.isinstance_w(w_value, space.w_unicode): w_value = space.call_method(w_value, 'encode', space.newtext('mbcs')) - buf = rffi.str2charp(space.str_w(w_value)) + buf = rffi.str2charp(space.text_w(w_value)) buflen = space.len_w(w_value) + 1 elif typ == rwinreg.REG_MULTI_SZ: @@ -306,7 +306,7 @@ if space.isinstance_w(w_item, space.w_unicode): w_item = space.call_method(w_item, 'encode', space.newtext('mbcs')) - item = space.str_w(w_item) + item = space.bytes_w(w_item) strings.append(item) buflen += len(item) + 1 except OperationError as e: @@ -438,7 +438,7 @@ if space.is_w(w_subkey, space.w_None): subkey = None else: - subkey = space.str_w(w_subkey) + subkey = space.text_w(w_subkey) null_dword = lltype.nullptr(rwin32.LPDWORD.TO) with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as retDataSize: ret = rwinreg.RegQueryValueEx(hkey, subkey, null_dword, null_dword, diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py --- a/pypy/module/array/interp_array.py +++ b/pypy/module/array/interp_array.py @@ -43,7 +43,7 @@ if len(__args__.arguments_w) > 0: w_initializer = __args__.arguments_w[0] w_initializer_type = space.type(w_initializer) - if w_initializer_type is space.w_str: + if w_initializer_type is space.w_bytes: a.descr_fromstring(space, w_initializer) elif w_initializer_type is space.w_list: a.descr_fromlist(space, w_initializer) diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -577,7 +577,7 @@ # Common types with their own struct for cpyname, pypyexpr in { "PyType_Type": "space.w_type", - "PyString_Type": "space.w_str", + "PyString_Type": "space.w_bytes", "PyUnicode_Type": "space.w_unicode", "PyBaseString_Type": "space.w_basestring", "PyDict_Type": "space.w_dict", diff --git a/pypy/module/cpyext/bytesobject.py b/pypy/module/cpyext/bytesobject.py --- a/pypy/module/cpyext/bytesobject.py +++ b/pypy/module/cpyext/bytesobject.py @@ -52,13 +52,13 @@ @bootstrap_function def init_bytesobject(space): "Type description of PyBytesObject" - make_typedescr(space.w_str.layout.typedef, + make_typedescr(space.w_bytes.layout.typedef, basestruct=PyBytesObject.TO, attach=bytes_attach, dealloc=bytes_dealloc, realize=bytes_realize) -PyString_Check, PyString_CheckExact = build_type_checkers("String", "w_str") +PyString_Check, PyString_CheckExact = build_type_checkers("String", "w_bytes") def new_empty_str(space, length): """ @@ -66,8 +66,8 @@ interpreter object. The ob_sval may be mutated, until bytes_realize() is called. Refcount of the result is 1. """ - typedescr = get_typedescr(space.w_str.layout.typedef) - py_obj = typedescr.allocate(space, space.w_str, length) + typedescr = get_typedescr(space.w_bytes.layout.typedef) + py_obj = typedescr.allocate(space, space.w_bytes, length) py_str = rffi.cast(PyBytesObject, py_obj) py_str.c_ob_shash = -1 py_str.c_ob_sstate = rffi.cast(rffi.INT, 0) # SSTATE_NOT_INTERNED @@ -132,7 +132,7 @@ return _PyString_AsString(space, ref) def _PyString_AsString(space, ref): - if from_ref(space, rffi.cast(PyObject, ref.c_ob_type)) is space.w_str: + if from_ref(space, rffi.cast(PyObject, ref.c_ob_type)) is space.w_bytes: pass # typecheck returned "ok" without forcing 'ref' at all elif not PyString_Check(space, ref): # otherwise, use the alternate way from pypy.module.cpyext.unicodeobject import ( @@ -182,7 +182,7 @@ @cpython_api([PyObject], Py_ssize_t, error=-1) def PyString_Size(space, ref): - if from_ref(space, rffi.cast(PyObject, ref.c_ob_type)) is space.w_str: + if from_ref(space, rffi.cast(PyObject, ref.c_ob_type)) is space.w_bytes: ref = rffi.cast(PyBytesObject, ref) return ref.c_ob_size else: diff --git a/pypy/module/cpyext/test/test_methodobject.py b/pypy/module/cpyext/test/test_methodobject.py --- a/pypy/module/cpyext/test/test_methodobject.py +++ b/pypy/module/cpyext/test/test_methodobject.py @@ -108,7 +108,7 @@ ml.c_ml_meth = rffi.cast(PyCFunction_typedef, c_func.get_llhelper(space)) - method = api.PyDescr_NewMethod(space.w_str, ml) + method = api.PyDescr_NewMethod(space.w_bytes, ml) assert repr(method).startswith( "<built-in method 'func' of 'str' object ") diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py --- a/pypy/module/cpyext/test/test_typeobject.py +++ b/pypy/module/cpyext/test/test_typeobject.py @@ -436,9 +436,9 @@ api.Py_DecRef(ref) def test_lookup(self, space, api): - w_type = space.w_str + w_type = space.w_bytes w_obj = api._PyType_Lookup(w_type, space.wrap("upper")) - assert space.is_w(w_obj, space.w_str.getdictvalue(space, "upper")) + assert space.is_w(w_obj, space.w_bytes.getdictvalue(space, "upper")) w_obj = api._PyType_Lookup(w_type, space.wrap("__invalid")) assert w_obj is None diff --git a/pypy/module/cpyext/test/test_unicodeobject.py b/pypy/module/cpyext/test/test_unicodeobject.py --- a/pypy/module/cpyext/test/test_unicodeobject.py +++ b/pypy/module/cpyext/test/test_unicodeobject.py @@ -231,7 +231,7 @@ def test_AsUTF8String(self, space, api): w_u = space.wrap(u'sp\x09m') w_res = api.PyUnicode_AsUTF8String(w_u) - assert space.type(w_res) is space.w_str + assert space.type(w_res) is space.w_bytes assert space.unwrap(w_res) == 'sp\tm' def test_decode_utf8(self, space, api): @@ -385,10 +385,10 @@ # This tests works at least on a Western Windows. unichars = u"abc" + unichr(12345) wbuf = rffi.unicode2wcharp(unichars) - w_str = api.PyUnicode_EncodeMBCS(wbuf, 4, None) + w_bytes = api.PyUnicode_EncodeMBCS(wbuf, 4, None) rffi.free_wcharp(wbuf) - assert space.type(w_str) is space.w_str - assert space.str_w(w_str) == "abc?" + assert space.type(w_bytes) is space.w_bytes + assert space.str_w(w_bytes) == "abc?" def test_escape(self, space, api): def test(ustr): diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -599,7 +599,7 @@ lltype.render_immortal(c_buf) c_buf.c_bf_getsegcount = llhelper(bf_segcount.api_func.functype, bf_segcount.api_func.get_wrapper(space)) - if space.is_w(w_type, space.w_str): + if space.is_w(w_type, space.w_bytes): # Special case: str doesn't support get_raw_address(), so we have a # custom get*buffer that instead gives the address of the char* in the # PyBytesObject*! @@ -703,7 +703,7 @@ pto.c_tp_dealloc = llhelper( subtype_dealloc.api_func.functype, subtype_dealloc.api_func.get_wrapper(space)) - if space.is_w(w_type, space.w_str): + if space.is_w(w_type, space.w_bytes): pto.c_tp_itemsize = 1 elif space.is_w(w_type, space.w_tuple): pto.c_tp_itemsize = rffi.sizeof(PyObject) @@ -945,7 +945,7 @@ w_type = from_ref(space, rffi.cast(PyObject, type)) assert isinstance(w_type, W_TypeObject) - if not space.isinstance_w(w_name, space.w_str): + if not space.isinstance_w(w_name, space.w_text): return None name = space.text_w(w_name) w_obj = w_type.lookup(name) diff --git a/pypy/module/micronumpy/casting.py b/pypy/module/micronumpy/casting.py --- a/pypy/module/micronumpy/casting.py +++ b/pypy/module/micronumpy/casting.py @@ -337,7 +337,7 @@ return float_dtype elif space.isinstance_w(w_obj, space.w_complex): return complex_dtype - elif space.isinstance_w(w_obj, space.w_str): + elif space.isinstance_w(w_obj, space.w_bytes): return variable_dtype(space, 'S%d' % space.len_w(w_obj)) elif space.isinstance_w(w_obj, space.w_unicode): return new_unicode_dtype(space, space.len_w(w_obj)) diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py --- a/pypy/module/micronumpy/compile.py +++ b/pypy/module/micronumpy/compile.py @@ -75,8 +75,8 @@ w_long = W_TypeObject("long") w_tuple = W_TypeObject('tuple') w_slice = W_TypeObject("slice") - w_str = W_TypeObject("str") - w_bytes = w_str + w_bytes = W_TypeObject("str") + w_text = w_bytes w_unicode = W_TypeObject("unicode") w_complex = W_TypeObject("complex") w_dict = W_TypeObject("dict") @@ -499,7 +499,7 @@ self.step = step class StringObject(W_Root): - tp = FakeSpace.w_str + tp = FakeSpace.w_bytes def __init__(self, v): self.v = v diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py --- a/pypy/module/micronumpy/concrete.py +++ b/pypy/module/micronumpy/concrete.py @@ -205,7 +205,7 @@ """ Return an index of single item if possible, otherwise raises IndexError """ - if (space.isinstance_w(w_idx, space.w_str) or + if (space.isinstance_w(w_idx, space.w_text) or space.isinstance_w(w_idx, space.w_slice) or space.is_w(w_idx, space.w_None)): raise IndexError @@ -238,7 +238,7 @@ @jit.unroll_safe def _prepare_slice_args(self, space, w_idx): from pypy.module.micronumpy import boxes - if space.isinstance_w(w_idx, space.w_str): + if space.isinstance_w(w_idx, space.w_text): raise oefmt(space.w_IndexError, "only integers, slices (`:`), " "ellipsis (`...`), numpy.newaxis (`None`) and integer or " "boolean arrays are valid indices") diff --git a/pypy/module/micronumpy/converters.py b/pypy/module/micronumpy/converters.py --- a/pypy/module/micronumpy/converters.py +++ b/pypy/module/micronumpy/converters.py @@ -60,7 +60,7 @@ def order_converter(space, w_order, default): if space.is_none(w_order): return default - if not space.isinstance_w(w_order, space.w_str): + if not space.isinstance_w(w_order, space.w_text): if space.is_true(w_order): return NPY.FORTRANORDER else: diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py --- a/pypy/module/micronumpy/ctors.py +++ b/pypy/module/micronumpy/ctors.py @@ -130,7 +130,7 @@ # object does not have buffer interface return w_object raise - format = space.getattr(w_buf,space.newbytes('format')) + format = space.getattr(w_buf, space.newtext('format')) if format: descr = _descriptor_from_pep3118_format(space, space.str_w(format)) if not descr: diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py --- a/pypy/module/micronumpy/descriptor.py +++ b/pypy/module/micronumpy/descriptor.py @@ -414,7 +414,7 @@ for i in range(len(names_w)): w_name = names_w[i] title = self.names[i][1] - if not space.isinstance_w(w_name, space.w_str): + if not space.isinstance_w(w_name, space.w_text): raise oefmt(space.w_ValueError, "item #%d of names is of type %T and not string", len(names), w_name) @@ -561,7 +561,7 @@ r = space.newtext("'" + byteorder + self.char + str(size) + "'") else: r = self.descr_get_name(space, quote=True) - if space.isinstance_w(r, space.w_str): + if space.isinstance_w(r, space.w_text): return space.newtext("dtype(%s)" % space.text_w(r)) return space.newtext("dtype(%s)" % space.text_w(space.repr(r))) @@ -756,7 +756,7 @@ titles[i] = space.text_w(fldlist[1]) if len(fldlist) != 2: raise oefmt(space.w_TypeError, "data type not understood") - elif space.isinstance_w(w_fldname, space.w_str): + elif space.isinstance_w(w_fldname, space.w_text): fldnames[i] = space.text_w(w_fldname) else: raise oefmt(space.w_TypeError, "data type not understood") @@ -942,7 +942,7 @@ if not e.match(space, space.w_ImportError): raise # handle only simple cases for testing - if space.isinstance_w(w_spec, space.w_str): + if space.isinstance_w(w_spec, space.w_text): spec = [s.strip() for s in space.text_w(w_spec).split(',')] w_lst = space.newlist([space.newtext(s) for s in spec]) if not space.isinstance_w(w_lst, space.w_list) or space.len_w(w_lst) < 1: @@ -1347,7 +1347,7 @@ space.gettypefor(boxes.W_FloatingBox)], NPY.CDOUBLE: [space.w_complex, space.gettypefor(boxes.W_ComplexFloatingBox)], - NPY.STRING: [space.w_str, + NPY.STRING: [space.w_bytes, space.gettypefor(boxes.W_CharacterBox)], NPY.UNICODE: [space.w_unicode], NPY.VOID: [space.gettypefor(boxes.W_GenericBox)], diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py --- a/pypy/module/mmap/interp_mmap.py +++ b/pypy/module/mmap/interp_mmap.py @@ -235,7 +235,7 @@ j = i elif j > self.mmap.size: j = self.mmap.size - if not space.isinstance_w(w_item, space.w_str): + if not space.isinstance_w(w_item, space.w_bytes): raise oefmt(space.w_IndexError, "mmap slice assignment must be a string") value = space.realstr_w(w_item) diff --git a/pypy/module/pypyjit/interp_jit.py b/pypy/module/pypyjit/interp_jit.py --- a/pypy/module/pypyjit/interp_jit.py +++ b/pypy/module/pypyjit/interp_jit.py @@ -149,14 +149,14 @@ "set_param() takes at most 1 non-keyword argument, %d " "given", len(args_w)) if len(args_w) == 1: - text = space.str_w(args_w[0]) + text = space.text_w(args_w[0]) try: jit.set_user_param(None, text) except ValueError: raise oefmt(space.w_ValueError, "error in JIT parameters string") for key, w_value in kwds_w.items(): if key == 'enable_opts': - jit.set_param(None, 'enable_opts', space.str_w(w_value)) + jit.set_param(None, 'enable_opts', space.text_w(w_value)) else: intval = space.int_w(w_value) for name, _ in unroll_parameters: diff --git a/pypy/module/pypyjit/interp_resop.py b/pypy/module/pypyjit/interp_resop.py --- a/pypy/module/pypyjit/interp_resop.py +++ b/pypy/module/pypyjit/interp_resop.py @@ -280,7 +280,7 @@ if self.type == "bridge": code_repr = 'bridge no %d' % self.bridge_no else: - code_repr = space.str_w(space.repr(self.w_green_key)) + code_repr = space.text_w(space.repr(self.w_green_key)) return space.newtext('<JitLoopInfo %s, %d operations, starting at <%s>>' % (self.jd_name, lgt, code_repr)) diff --git a/pypy/module/struct/formatiterator.py b/pypy/module/struct/formatiterator.py --- a/pypy/module/struct/formatiterator.py +++ b/pypy/module/struct/formatiterator.py @@ -98,7 +98,7 @@ def accept_str_arg(self): w_obj = self.accept_obj_arg() - return self.space.str_w(w_obj) + return self.space.bytes_w(w_obj) def accept_unicode_arg(self): w_obj = self.accept_obj_arg() diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py --- a/pypy/objspace/descroperation.py +++ b/pypy/objspace/descroperation.py @@ -45,9 +45,9 @@ return space.lookup_in_type(space.w_tuple, '__iter__') @specialize.memo() -def str_getitem(space): +def bytes_getitem(space): "Utility that returns the app-level descriptor str.__getitem__." - return space.lookup_in_type(space.w_str, '__getitem__') + return space.lookup_in_type(space.w_bytes, '__getitem__') @specialize.memo() def unicode_getitem(space): @@ -845,10 +845,10 @@ "'%%T'", w_obj) w_result = space.get_and_call_function(w_impl, w_obj) - if space.isinstance_w(w_result, space.w_str): + if space.isinstance_w(w_result, space.w_text): return w_result try: - result = space.str_w(w_result) # YYY + result = space.text_w(w_result) except OperationError, e: if not e.match(space, space.w_TypeError): raise diff --git a/pypy/objspace/fake/test/test_objspace.py b/pypy/objspace/fake/test/test_objspace.py --- a/pypy/objspace/fake/test/test_objspace.py +++ b/pypy/objspace/fake/test/test_objspace.py @@ -40,7 +40,7 @@ def test_constants(self): space = self.space space.translates(lambda: (space.w_None, space.w_True, space.w_False, - space.w_int, space.w_str, space.w_object, + space.w_int, space.w_bytes, space.w_object, space.w_TypeError)) def test_wrap(self): 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 @@ -18,8 +18,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_str) or # Most common path first - space.abstract_issubclass_w(w_lookup_type, space.w_str)): + if (space.is_w(w_lookup_type, space.w_text) or # Most common path first + space.abstract_issubclass_w(w_lookup_type, space.w_text)): return self.getitem_str(w_dict, space.text_w(w_key)) elif space.abstract_issubclass_w(w_lookup_type, space.w_unicode): try: @@ -38,7 +38,7 @@ def setitem(self, w_dict, w_key, w_value): space = self.space - if space.is_w(space.type(w_key), space.w_str): + 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, @@ -70,7 +70,7 @@ 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_str): + 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 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 @@ -175,7 +175,7 @@ return (space.float_w(real), space.float_w(imag)) # # Check that it is not a string (on which space.float() would succeed). - if (space.isinstance_w(w_complex, space.w_str) or + if (space.isinstance_w(w_complex, space.w_bytes) or space.isinstance_w(w_complex, space.w_unicode)): raise oefmt(space.w_TypeError, "complex number expected, got '%T'", w_complex) @@ -299,14 +299,14 @@ and space.is_w(space.type(w_real), space.w_complex)): return w_real - if space.isinstance_w(w_real, space.w_str) or \ + if space.isinstance_w(w_real, space.w_bytes) or \ space.isinstance_w(w_real, space.w_unicode): # a string argument if not noarg2: raise oefmt(space.w_TypeError, "complex() can't take second" " arg if first is a string") try: - realstr, imagstr = _split_complex(space.str_w(w_real)) + realstr, imagstr = _split_complex(space.text_w(w_real)) except ValueError: raise oefmt(space.w_ValueError, "complex() arg is a malformed string") 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 @@ -1060,7 +1060,7 @@ def is_correct_type(self, w_obj): space = self.space - return space.is_w(space.type(w_obj), space.w_str) + return space.is_w(space.type(w_obj), space.w_bytes) def get_empty_storage(self): res = {} @@ -1199,7 +1199,7 @@ space = self.space # XXX there are many more types return (space.is_w(w_lookup_type, space.w_NoneType) or - space.is_w(w_lookup_type, space.w_str) or + space.is_w(w_lookup_type, space.w_bytes) or space.is_w(w_lookup_type, space.w_unicode) ) diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py --- a/pypy/objspace/std/formatting.py +++ b/pypy/objspace/std/formatting.py @@ -334,19 +334,10 @@ def unknown_fmtchar(self): space = self.space c = self.fmt[self.fmtpos - 1] - if do_unicode: - w_defaultencoding = space.call_function( - space.sys.get('getdefaultencoding')) - w_s = space.call_method(space.newunicode(c), - "encode", - w_defaultencoding, - space.newtext('replace')) - s = space.str_w(w_s) - else: - s = c + w_s = space.newunicode(c) if do_unicode else space.newbytes(c) raise oefmt(space.w_ValueError, - "unsupported format character '%s' (%s) at index %d", - s, hex(ord(c)), self.fmtpos - 1) + "unsupported format character %R (%s) at index %d", + w_s, hex(ord(c)), self.fmtpos - 1) @specialize.argtype(1) def std_wp(self, r): @@ -437,7 +428,7 @@ if space.isinstance_w(w_result, space.w_unicode): raise NeedUnicodeFormattingError - return space.str_w(w_result) + return space.bytes_w(w_result) def fmt_s(self, w_value): space = self.space @@ -462,8 +453,8 @@ def fmt_c(self, w_value): self.prec = -1 # just because space = self.space - if space.isinstance_w(w_value, space.w_str): - s = space.str_w(w_value) + if space.isinstance_w(w_value, space.w_bytes): + s = space.bytes_w(w_value) if len(s) != 1: raise oefmt(space.w_TypeError, "%c requires int or char") self.std_wp(s) @@ -511,7 +502,7 @@ def format(space, w_fmt, values_w, w_valuedict, do_unicode): "Entry point" if not do_unicode: - fmt = space.str_w(w_fmt) + fmt = space.bytes_w(w_fmt) formatter = StringFormatter(space, fmt, values_w, w_valuedict) try: result = formatter.format() 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 @@ -694,7 +694,7 @@ # we cannot construct a subclass of int instance with an # an overflowing long value = space.int_w(w_obj, allow_conversion=False) - elif space.isinstance_w(w_value, space.w_str): + elif space.isinstance_w(w_value, space.w_bytes): value, w_longval = _string_to_int_or_long(space, w_value, space.text_w(w_value)) elif space.isinstance_w(w_value, space.w_unicode): diff --git a/pypy/objspace/std/kwargsdict.py b/pypy/objspace/std/kwargsdict.py --- a/pypy/objspace/std/kwargsdict.py +++ b/pypy/objspace/std/kwargsdict.py @@ -39,7 +39,7 @@ def is_correct_type(self, w_obj): space = self.space - return space.is_w(space.type(w_obj), space.w_str) + return space.is_w(space.type(w_obj), space.w_text) def _never_equal_to(self, w_lookup_type): return False 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 @@ -738,7 +738,7 @@ 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_str): + 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 @@ -757,7 +757,7 @@ def setitem(self, w_dict, w_key, w_value): space = self.space - if space.is_w(space.type(w_key), space.w_str): + 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: self.switch_to_object_strategy(w_dict) @@ -765,7 +765,7 @@ def setdefault(self, w_dict, w_key, w_default): space = self.space - if space.is_w(space.type(w_key), space.w_str): + if space.is_w(space.type(w_key), space.w_text): key = space.text_w(w_key) w_result = self.getitem_str(w_dict, key) if w_result is not None: @@ -780,7 +780,7 @@ space = self.space w_key_type = space.type(w_key) w_obj = self.unerase(w_dict.dstorage) - if space.is_w(w_key_type, space.w_str): + if space.is_w(w_key_type, space.w_text): key = self.space.text_w(w_key) flag = w_obj.deldictvalue(space, key) if not flag: diff --git a/pypy/objspace/std/marshal_impl.py b/pypy/objspace/std/marshal_impl.py --- a/pypy/objspace/std/marshal_impl.py +++ b/pypy/objspace/std/marshal_impl.py @@ -205,7 +205,7 @@ m.put(pack_float(w_float.floatval)) else: m.start(TYPE_FLOAT) - m.put_pascal(space.str_w(space.repr(w_float))) + m.put_pascal(space.text_w(space.repr(w_float))) @unmarshaller(TYPE_FLOAT) def unmarshal_float(space, u, tc): @@ -227,8 +227,8 @@ w_real = space.newfloat(w_complex.realval) w_imag = space.newfloat(w_complex.imagval) m.start(TYPE_COMPLEX) - m.put_pascal(space.str_w(space.repr(w_real))) - m.put_pascal(space.str_w(space.repr(w_imag))) + m.put_pascal(space.text_w(space.repr(w_real))) + m.put_pascal(space.text_w(space.repr(w_imag))) @unmarshaller(TYPE_COMPLEX) def unmarshal_complex(space, u, tc): @@ -248,7 +248,7 @@ @marshaller(W_BytesObject) def marshal_bytes(space, w_str, m): - s = space.str_w(w_str) + s = space.bytes_w(w_str) if m.version >= 1 and space.is_interned_str(s): # we use a native rtyper stringdict for speed try: @@ -363,7 +363,7 @@ def unmarshal_str(u): w_obj = u.get_w_obj() try: - return u.space.str_w(w_obj) + return u.space.bytes_w(w_obj) except OperationError as e: if e.match(u.space, u.space.w_TypeError): u.raise_exc('invalid marshal data for code object') 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 @@ -212,7 +212,7 @@ def descr___format__(space, w_obj, w_format_spec): if space.isinstance_w(w_format_spec, space.w_unicode): w_as_str = space.call_function(space.w_unicode, w_obj) - elif space.isinstance_w(w_format_spec, space.w_str): + elif space.isinstance_w(w_format_spec, space.w_bytes): w_as_str = space.str(w_obj) else: raise oefmt(space.w_TypeError, "format_spec must be a string") 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 @@ -89,10 +89,12 @@ for typedef, cls in builtin_type_classes.items(): w_type = self.gettypeobject(typedef) self.builtin_types[typedef.name] = w_type - setattr(self, 'w_' + typedef.name, w_type) + if typedef.name != "str": + setattr(self, 'w_' + typedef.name, w_type) + else: + self.w_bytes = w_type self._interplevel_classes[w_type] = cls - self.w_bytes = self.w_str - self.w_text = self.w_str # this is w_unicode on Py3 + self.w_text = self.w_bytes # this is w_unicode on Py3 self.w_dict.flag_map_or_seq = 'M' self.builtin_types["NotImplemented"] = self.w_NotImplemented self.builtin_types["Ellipsis"] = self.w_Ellipsis @@ -519,9 +521,9 @@ return self.lookup(w_obj, '__iter__') is tuple_iter(self) def _str_uses_no_iter(self, w_obj): - from pypy.objspace.descroperation import str_getitem + from pypy.objspace.descroperation import bytes_getitem return (self.lookup(w_obj, '__iter__') is None and - self.lookup(w_obj, '__getitem__') is str_getitem(self)) + self.lookup(w_obj, '__getitem__') is bytes_getitem(self)) def _uni_uses_no_iter(self, w_obj): from pypy.objspace.descroperation import unicode_getitem @@ -557,7 +559,7 @@ # fast path: XXX this is duplicating most of the logic # from the default __getattribute__ and the getattr() method... - name = self.str_w(w_name) + name = self.text_w(w_name) w_descr = w_type.lookup(name) e = None if w_descr is not None: 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 @@ -18,7 +18,7 @@ assert start >= 0 assert stop >= 0 #if start == 0 and stop == len(s) and space.is_w(space.type(orig_obj), - # space.w_str): + # space.w_bytes): # return orig_obj return self._new(s[start:stop]) 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 @@ -1093,7 +1093,7 @@ if isinstance(w_obj, FakeString): return str return type(w_obj) - w_str = str + w_bytes = str w_text = str def str_w(self, string): diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py --- a/pypy/objspace/std/test/test_newformat.py +++ b/pypy/objspace/std/test/test_newformat.py @@ -222,7 +222,7 @@ class AppTestStringFormat(BaseStringFormatTests): def setup_class(cls): - cls.w_s = cls.space.w_str + cls.w_s = cls.space.w_bytes def test_string_conversion(self): class x(object): diff --git a/pypy/objspace/std/test/test_obj.py b/pypy/objspace/std/test/test_obj.py --- a/pypy/objspace/std/test/test_obj.py +++ b/pypy/objspace/std/test/test_obj.py @@ -283,4 +283,4 @@ # if it crashes, it means that space._type_isinstance didn't go through # the fast path, and tries to call type() (which is set to None just # above) - space.isinstance_w(w_a, space.w_str) # does not crash + space.isinstance_w(w_a, space.w_bytes) # does not crash 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 @@ -43,7 +43,7 @@ from pypy.objspace.std.iterobject import W_SeqIterObject space = self.space - assert space._get_interplevel_cls(space.w_str) is W_BytesObject + assert space._get_interplevel_cls(space.w_bytes) is W_BytesObject assert space._get_interplevel_cls(space.w_int) is W_IntObject class X(W_BytesObject): def __init__(self): @@ -51,7 +51,7 @@ typedef = None - assert space.isinstance_w(X(), space.w_str) + assert space.isinstance_w(X(), space.w_bytes) w_sequenceiterator = space.gettypefor(W_SeqIterObject) cls = space._get_interplevel_cls(w_sequenceiterator) @@ -61,7 +61,7 @@ from pypy.objspace.std.bytesobject import W_AbstractBytesObject space = gettestobjspace(withstrbuf=True) - cls = space._get_interplevel_cls(space.w_str) + cls = space._get_interplevel_cls(space.w_bytes) assert cls is W_AbstractBytesObject def test_wrap_various_unsigned_types(self): 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 @@ -635,7 +635,7 @@ def descr_repr(self, space): w_mod = self.get_module() - if w_mod is None or not space.isinstance_w(w_mod, space.w_str): + if w_mod is None or not space.isinstance_w(w_mod, space.w_text): mod = None else: mod = space.text_w(w_mod) @@ -691,7 +691,7 @@ def _check_new_args(space, w_name, w_bases, w_dict): if w_bases is None or w_dict is None: raise oefmt(space.w_TypeError, "type() takes 1 or 3 arguments") - if not space.isinstance_w(w_name, space.w_str): + if not space.isinstance_w(w_name, space.w_text): raise oefmt(space.w_TypeError, "type() argument 1 must be string, not %T", w_name) if not space.isinstance_w(w_bases, space.w_tuple): @@ -775,7 +775,7 @@ w_type = _check(space, w_type) if not w_type.is_heaptype(): raise oefmt(space.w_TypeError, "can't set %N.__name__", w_type) - if not space.isinstance_w(w_value, space.w_str): + if not space.isinstance_w(w_value, space.w_text): raise oefmt(space.w_TypeError, "can only assign string to %N.__name__, not '%T'", w_type, w_value) @@ -1049,7 +1049,7 @@ wantdict = False wantweakref = False w_slots = dict_w['__slots__'] - if (space.isinstance_w(w_slots, space.w_str) or + if (space.isinstance_w(w_slots, space.w_bytes) or space.isinstance_w(w_slots, space.w_unicode)): slot_names_w = [w_slots] else: 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 @@ -129,7 +129,7 @@ def _op_val(space, w_other, strict=None): if isinstance(w_other, W_UnicodeObject): return w_other._value - if space.isinstance_w(w_other, space.w_str): + if space.isinstance_w(w_other, space.w_bytes): return unicode_from_string(space, w_other)._value if strict: raise oefmt(space.w_TypeError, @@ -374,7 +374,7 @@ return space.is_w(space.type(w_obj), space.w_unicode) def _join_check_item(self, space, w_obj): - if (space.isinstance_w(w_obj, space.w_str) or + if (space.isinstance_w(w_obj, space.w_bytes) or space.isinstance_w(w_obj, space.w_unicode)): return 0 return 1 @@ -490,7 +490,7 @@ w_errors = space.newtext(errors) w_restuple = space.call_function(w_encoder, w_object, w_errors) w_retval = space.getitem(w_restuple, space.newint(0)) - if not space.isinstance_w(w_retval, space.w_str): + if not space.isinstance_w(w_retval, space.w_bytes): raise oefmt(space.w_TypeError, "encoder did not return an string object (type '%T')", w_retval) @@ -545,7 +545,7 @@ def unicode_from_object(space, w_obj): if space.is_w(space.type(w_obj), space.w_unicode): return w_obj - elif space.is_w(space.type(w_obj), space.w_str): + elif space.is_w(space.type(w_obj), space.w_bytes): w_res = w_obj else: w_unicode_method = space.lookup(w_obj, "__unicode__") @@ -564,17 +564,17 @@ return unicode_from_encoded_object(space, w_res, None, "strict") -def unicode_from_string(space, w_str): +def unicode_from_string(space, w_bytes): # this is a performance and bootstrapping hack encoding = getdefaultencoding(space) if encoding != 'ascii': - return unicode_from_encoded_object(space, w_str, encoding, "strict") - s = space.bytes_w(w_str) + return unicode_from_encoded_object(space, w_bytes, encoding, "strict") + s = space.bytes_w(w_bytes) try: return W_UnicodeObject(s.decode("ascii")) except UnicodeDecodeError: # raising UnicodeDecodeError is messy, "please crash for me" - return unicode_from_encoded_object(space, w_str, "ascii", "strict") + return unicode_from_encoded_object(space, w_bytes, "ascii", "strict") class UnicodeDocstrings: 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 @@ -54,5 +54,5 @@ if isinstance(e, InvalidBaseError): raise OperationError(space.w_ValueError, space.newtext(e.msg)) else: - raise oefmt(space.w_ValueError, '%s: %s', - e.msg, space.str_w(space.repr(w_source))) + raise oefmt(space.w_ValueError, '%s: %R', + e.msg, w_source) diff --git a/pypy/tool/pytest/appsupport.py b/pypy/tool/pytest/appsupport.py --- a/pypy/tool/pytest/appsupport.py +++ b/pypy/tool/pytest/appsupport.py @@ -230,7 +230,7 @@ def pypyraises(space, w_ExpectedException, w_expr, __args__): """A built-in function providing the equivalent of py.test.raises().""" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit