Author: Armin Rigo <ar...@tunes.org> Branch: py3.5-newtext Changeset: r90147:98a26e7ce3ed Date: 2017-02-15 13:13 +0100 http://bitbucket.org/pypy/pypy/changeset/98a26e7ce3ed/
Log: big hg merge 8e2bcfb77e80 diff too long, truncating to 2000 out of 3941 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 @@ -13,7 +13,7 @@ "field %s is required for %T", name, w_obj) 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") @@ -1445,7 +1445,7 @@ def to_object(self, space): w_node = space.call_function(get(space).w_ImportFrom) - w_module = space.newtext(self.module) if self.module is not None else space.w_None # identifier + w_module = space.newtext_or_none(self.module) # identifier space.setattr(w_node, space.newtext('module'), w_module) if self.names is None: names_w = [] @@ -1468,7 +1468,7 @@ w_level = get_field(space, w_node, 'level', True) w_lineno = get_field(space, w_node, 'lineno', False) w_col_offset = get_field(space, w_node, 'col_offset', False) - _module = space.str_or_None_w(w_module) + _module = space.text_or_None_w(w_module) names_w = space.unpackiterable(w_names) _names = [alias.from_object(space, w_item) for w_item in names_w] _level = space.int_w(w_level) @@ -2663,15 +2663,15 @@ def to_object(self, space): w_node = space.call_function(get(space).w_FormattedValue) w_value = self.value.to_object(space) # expr - space.setattr(w_node, space.wrap('value'), w_value) - w_conversion = space.wrap(self.conversion) # int - space.setattr(w_node, space.wrap('conversion'), w_conversion) + space.setattr(w_node, space.newtext('value'), w_value) + w_conversion = space.newint(self.conversion) # int + space.setattr(w_node, space.newtext('conversion'), w_conversion) w_format_spec = self.format_spec.to_object(space) if self.format_spec is not None else space.w_None # expr - space.setattr(w_node, space.wrap('format_spec'), w_format_spec) - w_lineno = space.wrap(self.lineno) # int - space.setattr(w_node, space.wrap('lineno'), w_lineno) - w_col_offset = space.wrap(self.col_offset) # int - space.setattr(w_node, space.wrap('col_offset'), w_col_offset) + space.setattr(w_node, space.newtext('format_spec'), w_format_spec) + w_lineno = space.newint(self.lineno) # int + space.setattr(w_node, space.newtext('lineno'), w_lineno) + w_col_offset = space.newint(self.col_offset) # int + space.setattr(w_node, space.newtext('col_offset'), w_col_offset) return w_node @staticmethod @@ -2716,11 +2716,11 @@ else: values_w = [node.to_object(space) for node in self.values] # expr w_values = space.newlist(values_w) - space.setattr(w_node, space.wrap('values'), w_values) - w_lineno = space.wrap(self.lineno) # int - space.setattr(w_node, space.wrap('lineno'), w_lineno) - w_col_offset = space.wrap(self.col_offset) # int - space.setattr(w_node, space.wrap('col_offset'), w_col_offset) + space.setattr(w_node, space.newtext('values'), w_values) + w_lineno = space.newint(self.lineno) # int + space.setattr(w_node, space.newtext('lineno'), w_lineno) + w_col_offset = space.newint(self.col_offset) # int + space.setattr(w_node, space.newtext('col_offset'), w_col_offset) return w_node @staticmethod @@ -2790,9 +2790,9 @@ w_node = space.call_function(get(space).w_NameConstant) w_value = self.value # singleton space.setattr(w_node, space.newtext('value'), w_value) - w_lineno = space.wrap(self.lineno) # int + w_lineno = space.newint(self.lineno) # int space.setattr(w_node, space.newtext('lineno'), w_lineno) - w_col_offset = space.wrap(self.col_offset) # int + w_col_offset = space.newint(self.col_offset) # int space.setattr(w_node, space.newtext('col_offset'), w_col_offset) return w_node @@ -3755,7 +3755,7 @@ w_node = space.call_function(get(space).w_ExceptHandler) w_type = self.type.to_object(space) if self.type is not None else space.w_None # expr space.setattr(w_node, space.newtext('type'), w_type) - w_name = space.newtext(self.name) if self.name is not None else space.w_None # identifier + w_name = space.newtext_or_none(self.name) # identifier space.setattr(w_node, space.newtext('name'), w_name) if self.body is None: body_w = [] @@ -3777,7 +3777,7 @@ w_lineno = get_field(space, w_node, 'lineno', False) w_col_offset = get_field(space, w_node, 'col_offset', False) _type = expr.from_object(space, w_type) - _name = space.str_or_None_w(w_name) + _name = space.text_or_None_w(w_name) body_w = space.unpackiterable(w_body) _body = [stmt.from_object(space, w_item) for w_item in body_w] _lineno = space.int_w(w_lineno) @@ -3899,9 +3899,9 @@ space.setattr(w_node, space.newtext('arg'), w_arg) w_annotation = self.annotation.to_object(space) if self.annotation is not None else space.w_None # expr space.setattr(w_node, space.newtext('annotation'), w_annotation) - w_lineno = space.wrap(self.lineno) # int + w_lineno = space.newint(self.lineno) # int space.setattr(w_node, space.newtext('lineno'), w_lineno) - w_col_offset = space.wrap(self.col_offset) # int + w_col_offset = space.newint(self.col_offset) # int space.setattr(w_node, space.newtext('col_offset'), w_col_offset) return w_node @@ -3936,7 +3936,7 @@ def to_object(self, space): w_node = space.call_function(get(space).w_keyword) - w_arg = space.newtext(self.arg) if self.arg is not None else space.w_None # identifier + w_arg = space.newtext_or_none(self.arg) # identifier space.setattr(w_node, space.newtext('arg'), w_arg) w_value = self.value.to_object(space) # expr space.setattr(w_node, space.newtext('value'), w_value) @@ -3946,7 +3946,7 @@ def from_object(space, w_node): w_arg = get_field(space, w_node, 'arg', True) w_value = get_field(space, w_node, 'value', False) - _arg = space.str_or_None_w(w_arg) + _arg = space.text_or_None_w(w_arg) _value = expr.from_object(space, w_value) if _value is None: raise_required_value(space, w_node, 'value') @@ -3970,7 +3970,7 @@ w_node = space.call_function(get(space).w_alias) w_name = space.newtext(self.name) # identifier space.setattr(w_node, space.newtext('name'), w_name) - w_asname = space.newtext(self.asname) if self.asname is not None else space.w_None # identifier + w_asname = space.newtext_or_none(self.asname) # identifier space.setattr(w_node, space.newtext('asname'), w_asname) return w_node @@ -3981,7 +3981,7 @@ _name = space.identifier_w(w_name) if _name is None: raise_required_value(space, w_node, 'name') - _asname = space.str_or_None_w(w_asname) + _asname = space.text_or_None_w(w_asname) return alias(_name, _asname) State.ast_type('alias', 'AST', ['name', 'asname']) 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 @@ -127,6 +127,6 @@ return name from pypy.module.unicodedata.interp_ucd import ucd - w_name = space.wrap(name.decode('utf-8')) - w_id = space.call_method(ucd, 'normalize', space.wrap('NFKC'), w_name) - return space.unicode_w(w_id).encode('utf-8') + w_name = space.newtext(name) + w_id = space.call_method(ucd, 'normalize', space.newtext('NFKC'), w_name) + return space.text_w(w_id) 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 @@ -137,10 +137,9 @@ elif field.type == "int": return "space.newint(%s)" % (value,) elif field.type == "identifier": - wrapper = "space.newtext(%s)" % (value,) if field.opt: - wrapper += " if %s is not None else space.w_None" % (value,) - return wrapper + return "space.newtext_or_none(%s)" % (value,) + return "space.newtext(%s)" % (value,) else: wrapper = "%s.to_object(space)" % (value,) allow_none = field.opt @@ -162,7 +161,7 @@ return "check_string(space, %s)" % (value,) elif field.type in ("identifier",): if field.opt: - return "space.str_or_None_w(%s)" % (value,) + return "space.text_or_None_w(%s)" % (value,) return "space.identifier_w(%s)" % (value,) elif field.type in ("int",): return "space.int_w(%s)" % (value,) @@ -442,7 +441,7 @@ "field %s is required for %T", name, w_obj) 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 @@ -312,8 +312,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 @@ -396,8 +396,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 @@ -473,8 +474,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] @@ -532,8 +534,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: @@ -562,8 +564,9 @@ 'parser', 'fcntl', '_codecs', 'binascii' ] + @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__') @@ -621,8 +624,8 @@ objects.""" raise NotImplementedError + @not_rpython def export_builtin_exceptions(self): - """NOT_RPYTHON""" w_dic = self.exceptions_module.getdict(self) exc_types_w = {} w_iter = self.iter(w_dic) @@ -641,8 +644,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, ( @@ -650,8 +653,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: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. @@ -664,8 +668,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): @@ -1260,14 +1265,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, @@ -1276,9 +1283,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 @@ -1509,7 +1517,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 StringBuffer(w_obj.bytes_w(self)) if self.isinstance_w(w_obj, self.w_unicode): return StringBuffer(w_obj.identifier_w(self)) # no surrogates @@ -1518,7 +1526,7 @@ except BufferInterfaceNotFound: self._getarg_error("bytes 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.bytes_w(self) if self.isinstance_w(w_obj, self.w_unicode): return w_obj.identifier_w(self) # no surrogates (forbidden) @@ -1559,8 +1567,6 @@ raise return self.buffer_w(w_obj, flags).as_str() - def str_or_None_w(self, w_obj): - return None if self.is_none(w_obj) else self.str_w(w_obj) def text_or_None_w(self, w_obj): return None if self.is_none(w_obj) else self.text_w(w_obj) @@ -1852,8 +1858,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/gateway.py b/pypy/interpreter/gateway.py --- a/pypy/interpreter/gateway.py +++ b/pypy/interpreter/gateway.py @@ -27,6 +27,9 @@ from rpython.rlib.rarithmetic import r_longlong, r_int, r_ulonglong, r_uint from rpython.tool.sourcetools import func_with_new_name, compile2 +from rpython.rlib.signature import signature, finishsigs +from rpython.rlib import types as sigtypes + NO_DEFAULT = object() @@ -153,7 +156,7 @@ def visit_bufferstr(self, el, app_sig): self.checked_space_method(el, app_sig) - def visit_str_or_None(self, el, app_sig): + def visit_str_or_None(self, el, app_sig): # XXX kill me self.checked_space_method(el, app_sig) def visit_text_or_None(self, el, app_sig): @@ -165,6 +168,9 @@ def visit_bytes(self, el, app_sig): self.checked_space_method(el, app_sig) + def visit_text(self, el, app_sig): + self.checked_space_method(el, app_sig) + def visit_fsencode(self, el, app_sig): self.checked_space_method(el, app_sig) @@ -296,8 +302,8 @@ def visit_bufferstr(self, typ): self.run_args.append("space.bufferstr_w(%s)" % (self.scopenext(),)) - def visit_str_or_None(self, typ): - self.run_args.append("space.str_or_None_w(%s)" % (self.scopenext(),)) + def visit_str_or_None(self, typ): #XXX kill me + self.run_args.append("space.text_or_None_w(%s)" % (self.scopenext(),)) def visit_text_or_None(self, typ): self.run_args.append("space.text_or_None_w(%s)" % (self.scopenext(),)) @@ -308,6 +314,9 @@ def visit_bytes(self, typ): self.run_args.append("space.bytes_w(%s)" % (self.scopenext(),)) + def visit_text(self, typ): + self.run_args.append("space.text_w(%s)" % (self.scopenext(),)) + def visit_fsencode(self, typ): self.run_args.append("space.fsencode_w(%s)" % (self.scopenext(),)) @@ -458,8 +467,8 @@ def visit_bufferstr(self, typ): self.unwrap.append("space.bufferstr_w(%s)" % (self.nextarg(),)) - def visit_str_or_None(self, typ): - self.unwrap.append("space.str_or_None_w(%s)" % (self.nextarg(),)) + def visit_str_or_None(self, typ): #XXX kill me + self.unwrap.append("space.text_or_None_w(%s)" % (self.nextarg(),)) def visit_text_or_None(self, typ): self.unwrap.append("space.text_or_None_w(%s)" % (self.nextarg(),)) @@ -470,6 +479,9 @@ def visit_bytes(self, typ): self.unwrap.append("space.bytes_w(%s)" % (self.nextarg(),)) + def visit_text(self, typ): + self.unwrap.append("space.text_w(%s)" % (self.nextarg(),)) + def visit_fsencode(self, typ): self.unwrap.append("space.fsencode_w(%s)" % (self.nextarg(),)) @@ -839,11 +851,17 @@ w_result = space.w_None return w_result +w_root_or_none = sigtypes.instance(W_Root, can_be_None=True) +@finishsigs class BuiltinCode1(BuiltinCode): _immutable_ = True fast_natural_arity = 1 + @signature(sigtypes.self(), sigtypes.any(), + w_root_or_none, + w_root_or_none, + returns=w_root_or_none) def fastcall_1(self, space, w_func, w1): try: w_result = self.fastfunc_1(space, w1) @@ -860,10 +878,16 @@ return w_result +@finishsigs class BuiltinCode2(BuiltinCode): _immutable_ = True fast_natural_arity = 2 + @signature(sigtypes.self(), sigtypes.any(), + w_root_or_none, + w_root_or_none, + w_root_or_none, + returns=w_root_or_none) def fastcall_2(self, space, w_func, w1, w2): try: w_result = self.fastfunc_2(space, w1, w2) @@ -880,10 +904,17 @@ return w_result +@finishsigs class BuiltinCode3(BuiltinCode): _immutable_ = True fast_natural_arity = 3 + @signature(sigtypes.self(), sigtypes.any(), + w_root_or_none, + w_root_or_none, + w_root_or_none, + w_root_or_none, + returns=w_root_or_none) def fastcall_3(self, space, func, w1, w2, w3): try: w_result = self.fastfunc_3(space, w1, w2, w3) @@ -899,12 +930,20 @@ w_result = space.w_None return w_result - +@finishsigs class BuiltinCode4(BuiltinCode): _immutable_ = True fast_natural_arity = 4 + @signature(sigtypes.self(), sigtypes.any(), + w_root_or_none, + w_root_or_none, + w_root_or_none, + w_root_or_none, + w_root_or_none, + returns=w_root_or_none) def fastcall_4(self, space, func, w1, w2, w3, w4): + from rpython.rlib.debug import check_annotation try: w_result = self.fastfunc_4(space, w1, w2, w3, w4) except DescrMismatch: @@ -1025,7 +1064,9 @@ if defaultval is not NO_DEFAULT: if name != '__args__' and name != 'args_w': if w_def is Ellipsis: - if isinstance(defaultval, str) and spec not in [str]: + if isinstance(defaultval, str) and ( + # XXX hackish + spec == 'bytes' or isinstance(spec, WrappedDefault)): w_def = space.newbytes(defaultval) else: w_def = space.wrap(defaultval) 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 @@ -169,13 +169,12 @@ def runsource(self, source, ignored_filename="<input>", symbol="single"): # the following hacked file name is recognized specially by error.py - hacked_filename = '<inline>\n' + source.encode( - 'ascii', 'backslashreplace') compiler = self.space.getexecutioncontext().compiler # CPython 2.6 turns console input into unicode if isinstance(source, unicode): source = source.encode(sys.stdin.encoding) + hacked_filename = '<inline>\n' + source def doit(): # compile the provided input diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py --- a/pypy/interpreter/main.py +++ b/pypy/interpreter/main.py @@ -125,7 +125,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 @@ -88,7 +88,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_unicode)): + 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)] @@ -375,9 +375,9 @@ return w_result @unwrap_spec(argcount=int, kwonlyargcount=int, nlocals=int, stacksize=int, flags=int, - codestring=str, - filename='str0', name=str, firstlineno=int, - lnotab=str, magic=int) + codestring='bytes', + filename='str0', name='text', firstlineno=int, + lnotab='bytes', magic=int) def descr_code__new__(space, w_subtype, argcount, kwonlyargcount, nlocals, stacksize, flags, codestring, w_constants, w_names, @@ -396,14 +396,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 @@ -857,7 +857,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/pyparser/pyparse.py b/pypy/interpreter/pyparser/pyparse.py --- a/pypy/interpreter/pyparser/pyparse.py +++ b/pypy/interpreter/pyparser/pyparse.py @@ -144,7 +144,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 @@ -82,7 +82,7 @@ w_ret = parsestring.parsestr(space, None, repr("hello")) assert space.isinstance_w(w_ret, space.w_unicode) w_ret = parsestring.parsestr(space, None, "b'hi'") - 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'") assert space.isinstance_w(w_ret, space.w_unicode) 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 @@ -260,7 +260,6 @@ # we can't use the "bytes" object for the unwrap_spec, because that's # an alias for "str" on the underlying Python2 space = self.space - w = space.wrap def g(space, b): return space.newbytes(b) app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, 'bytes']) @@ -270,6 +269,18 @@ assert self.space.eq_w(space.call_function(w_app_g, space.newbytes("abc")), space.newbytes("abc")) + def test_interp2app_unwrap_spec_text(self): + space = self.space + def g(space, b): + assert isinstance(b, str) + return space.newtext(b) + app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, 'text']) + app_g2 = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace, 'text']) + assert app_g is app_g2 + w_app_g = space.wrap(app_g) + assert self.space.eq_w(space.call_function(w_app_g, space.newtext("abc")), + space.newtext("abc")) + def test_caching_methods(self): class Base(gateway.W_Root): def f(self): @@ -583,7 +594,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, @@ -591,7 +602,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 @@ -21,9 +21,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__/compiling.py b/pypy/module/__builtin__/compiling.py --- a/pypy/module/__builtin__/compiling.py +++ b/pypy/module/__builtin__/compiling.py @@ -10,7 +10,7 @@ from pypy.interpreter.nestedscope import Cell from pypy.interpreter.function import Function -@unwrap_spec(filename='fsencode', mode=str, flags=int, dont_inherit=int, +@unwrap_spec(filename='fsencode', mode='text', flags=int, dont_inherit=int, optimize=int) def compile(space, w_source, filename, mode, flags=0, dont_inherit=0, optimize=0): 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,8 +44,8 @@ # 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_text): - name = space.text_w(w_name) # typecheck - w_name = space.newtext(name) # rewrap as a real string + name = space.text_w(w_name) # typecheck + w_name = space.newtext(name) # rewrap as a real string return w_name def delattr(space, w_object, w_name): diff --git a/pypy/module/__pypy__/interp_builders.py b/pypy/module/__pypy__/interp_builders.py --- a/pypy/module/__pypy__/interp_builders.py +++ b/pypy/module/__pypy__/interp_builders.py @@ -7,6 +7,10 @@ def create_builder(name, strtype, builder_cls): + if strtype is str: + unwrap = 'bytes' + else: + unwrap = unicode class W_Builder(W_Root): def __init__(self, space, size): if size < 0: @@ -23,12 +27,12 @@ def descr__new__(space, w_subtype, size=-1): return W_Builder(space, size) - @unwrap_spec(s=strtype) + @unwrap_spec(s=unwrap) def descr_append(self, space, s): self._check_done(space) self.builder.append(s) - @unwrap_spec(s=strtype, start=int, end=int) + @unwrap_spec(s=unwrap, start=int, end=int) def descr_append_slice(self, space, s, start, end): self._check_done(space) if not 0 <= start <= end <= len(s): diff --git a/pypy/module/__pypy__/interp_debug.py b/pypy/module/__pypy__/interp_debug.py --- a/pypy/module/__pypy__/interp_debug.py +++ b/pypy/module/__pypy__/interp_debug.py @@ -3,22 +3,22 @@ @jit.dont_look_inside -@unwrap_spec(category=str) +@unwrap_spec(category='text') def debug_start(space, category): debug.debug_start(category) @jit.dont_look_inside def debug_print(space, args_w): - parts = [space.str_w(space.str(w_item)) for w_item in args_w] + parts = [space.text_w(space.str(w_item)) for w_item in args_w] debug.debug_print(' '.join(parts)) @jit.dont_look_inside -@unwrap_spec(category=str) +@unwrap_spec(category='text') def debug_stop(space, category): debug.debug_stop(category) -@unwrap_spec(category=str) +@unwrap_spec(category='text') def debug_print_once(space, category, args_w): debug_start(space, category) debug_print(space, args_w) diff --git a/pypy/module/__pypy__/interp_dict.py b/pypy/module/__pypy__/interp_dict.py --- a/pypy/module/__pypy__/interp_dict.py +++ b/pypy/module/__pypy__/interp_dict.py @@ -2,7 +2,7 @@ from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import unwrap_spec -@unwrap_spec(type=str) +@unwrap_spec(type='text') def newdict(space, type): """ newdict(type) diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py --- a/pypy/module/__pypy__/interp_magic.py +++ b/pypy/module/__pypy__/interp_magic.py @@ -22,7 +22,7 @@ attach_gdb() -@unwrap_spec(name=str) +@unwrap_spec(name='text') def method_cache_counter(space, name): """Return a tuple (method_cache_hits, method_cache_misses) for calls to methods with the name.""" @@ -41,7 +41,7 @@ cache.misses = {} cache.hits = {} -@unwrap_spec(name=str) +@unwrap_spec(name='text') def mapdict_cache_counter(space, name): """Return a tuple (index_cache_hits, index_cache_misses) for lookups in the mapdict cache with the given attribute name.""" @@ -68,7 +68,7 @@ func.getcode().hidden_applevel = True return w_func -@unwrap_spec(meth=str) +@unwrap_spec(meth='text') def lookup_special(space, w_obj, meth): """Lookup up a special method on an object.""" w_descr = space.lookup(w_obj, meth) @@ -143,7 +143,7 @@ else: cache._code_hook = w_callable -@unwrap_spec(string=str, byteorder=str, signed=int) +@unwrap_spec(string='bytes', byteorder='text', signed=int) def decode_long(space, string, byteorder='little', signed=1): from rpython.rlib.rbigint import rbigint, InvalidEndiannessError try: @@ -163,8 +163,8 @@ jit.promote(space.int_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_float): jit.promote(space.float_w(w_obj)) - elif space.is_w(space.type(w_obj), space.w_str): - jit.promote_string(space.str_w(w_obj)) + elif space.is_w(space.type(w_obj), space.w_bytes): + jit.promote_string(space.bytes_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_unicode): raise oefmt(space.w_TypeError, "promoting unicode unsupported") else: 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", @@ -325,7 +325,7 @@ def getcfield(self, w_attr, mode): space = self.space - attr = space.str_w(w_attr) + attr = space.text_w(w_attr) try: cfield = self.ctype.getcfield(attr) except KeyError: @@ -430,8 +430,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 @@ -576,7 +576,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) @@ -396,7 +396,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 @@ -76,9 +76,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("bytes 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, @@ -118,8 +118,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 @@ -291,7 +291,7 @@ 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 = space.bytes_w(w_init) if isinstance(self.ctitem, ctypeprim.W_CTypePrimitiveBool): 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 @@ -139,7 +139,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 @@ -151,8 +151,8 @@ def ffi_type(self, w_x, accept): space = self.space if (accept & ACCEPT_STRING) and ( - space.isinstance_w(w_x, space.w_unicode)): - string = space.str_w(w_x) + space.isinstance_w(w_x, space.w_text)): + string = space.text_w(w_x) consider_fn_as_fnptr = (accept & CONSIDER_FN_AS_FNPTR) != 0 if jit.isconstant(string): try: @@ -174,7 +174,7 @@ m1, s12, m2, s23, m3, w_x) - @unwrap_spec(module_name=str, _version=int, _types=str) + @unwrap_spec(module_name='text', _version=int, _types='text') def descr_init(self, module_name='?', _version=-1, _types='', w__globals=None, w__struct_unions=None, w__enums=None, w__typenames=None, w__includes=None): @@ -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: @@ -361,7 +361,7 @@ return w_cdata.with_gc(w_destructor) - @unwrap_spec(replace_with=str) + @unwrap_spec(replace_with='text') def descr_getctype(self, w_cdecl, replace_with=''): """\ Return a string giving the C type 'cdecl', which may be itself a @@ -598,7 +598,7 @@ lib.cdlopen_close() - @unwrap_spec(name=str) + @unwrap_spec(name='text') def descr_integer_const(self, name): """\ Get the value of an integer constant. 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 @@ -64,7 +64,7 @@ # ____________________________________________________________ -@unwrap_spec(w_ctype=ctypeobj.W_CType, replace_with=str) +@unwrap_spec(w_ctype=ctypeobj.W_CType, replace_with='text') def getcname(space, w_ctype, replace_with): p = w_ctype.name_position s = '%s%s%s' % (w_ctype.name[:p], replace_with, w_ctype.name[p:]) @@ -140,7 +140,7 @@ raise oefmt(space.w_TypeError, "from_buffer() cannot return the address a unicode") 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: @@ -181,7 +181,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/libraryobj.py b/pypy/module/_cffi_backend/libraryobj.py --- a/pypy/module/_cffi_backend/libraryobj.py +++ b/pypy/module/_cffi_backend/libraryobj.py @@ -38,7 +38,7 @@ space = self.space return space.newtext("<clibrary '%s'>" % self.name) - @unwrap_spec(w_ctype=W_CType, name=str) + @unwrap_spec(w_ctype=W_CType, name='text') def load_function(self, w_ctype, name): from pypy.module._cffi_backend import ctypeptr, ctypearray space = self.space @@ -58,7 +58,7 @@ w_ctype = w_ctype.ctptr return W_CData(space, rffi.cast(rffi.CCHARP, cdata), w_ctype) - @unwrap_spec(w_ctype=W_CType, name=str) + @unwrap_spec(w_ctype=W_CType, name='text') def read_variable(self, w_ctype, name): space = self.space try: @@ -69,7 +69,7 @@ name, self.name) return w_ctype.convert_to_object(rffi.cast(rffi.CCHARP, cdata)) - @unwrap_spec(w_ctype=W_CType, name=str) + @unwrap_spec(w_ctype=W_CType, name='text') def write_variable(self, w_ctype, name, w_value): space = self.space try: 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 @@ -153,7 +153,7 @@ eptypesize("int_fast64_t", 8, _WCTSigned) eptypesize("uint_fast64_t", 8, _WCTUnsign) -@unwrap_spec(name=str) +@unwrap_spec(name='text') def new_primitive_type(space, name): return _new_primitive_type(space, name) @@ -280,11 +280,11 @@ # ____________________________________________________________ -@unwrap_spec(name=str) +@unwrap_spec(name='text') def new_struct_type(space, name): return ctypestruct.W_CTypeStruct(space, name) -@unwrap_spec(name=str) +@unwrap_spec(name='text') def new_union_type(space, name): return ctypestruct.W_CTypeUnion(space, name) @@ -331,7 +331,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 @@ -590,13 +590,13 @@ # ____________________________________________________________ -@unwrap_spec(name=str, w_basectype=ctypeobj.W_CType) +@unwrap_spec(name='text', w_basectype=ctypeobj.W_CType) def new_enum_type(space, name, w_enumerators, w_enumvalues, w_basectype): enumerators_w = space.fixedview(w_enumerators) 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 @@ -145,7 +145,7 @@ raise oefmt(space.w_TypeError, "argument must be callable") -@unwrap_spec(encoding=str) +@unwrap_spec(encoding='text') def lookup_codec(space, encoding): """lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer) Looks up a codec tuple in the Python codec registry and returns @@ -207,7 +207,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") @@ -504,7 +504,7 @@ "encoder must return a tuple (object, integer)") return space.getitem(w_res, space.newint(0)) -@unwrap_spec(errors=str) +@unwrap_spec(errors='text') def lookup_error(space, errors): """lookup_error(errors) -> handler @@ -521,7 +521,7 @@ return w_err_handler -@unwrap_spec(errors=str) +@unwrap_spec(errors='text') def encode(space, w_obj, w_encoding=None, errors='strict'): """encode(obj, [encoding[,errors]]) -> object @@ -544,7 +544,7 @@ s = space.getarg_w('s#', w_data) return space.newtuple([space.newbytes(s), space.newint(len(s))]) -@unwrap_spec(errors=str) +@unwrap_spec(errors='text') def decode(space, w_obj, w_encoding=None, errors='strict'): """decode(obj, [encoding[,errors]]) -> object @@ -562,7 +562,7 @@ w_decoder = space.getitem(lookup_codec(space, encoding), space.newint(1)) return _call_codec(space, w_decoder, w_obj, "decoding", encoding, errors) -@unwrap_spec(errors=str) +@unwrap_spec(errors='text') def register_error(space, errors, w_handler): """register_error(errors, handler) @@ -984,9 +984,8 @@ # support for the "string escape" translation # This is a bytes-to bytes transformation -@unwrap_spec(errors='str_or_None') -def escape_encode(space, w_data, errors='strict'): - data = space.bytes_w(w_data) +@unwrap_spec(data='bytes', errors='str_or_None') +def escape_encode(space, data, errors='strict'): from pypy.objspace.std.bytesobject import string_escape_encode result = string_escape_encode(data, False) return space.newtuple([space.newbytes(result), space.newint(len(data))]) 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 @@ -117,7 +117,7 @@ length = rwbuffer.getlength() w_data = space.call_method(self, methodname, 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, "%s() should return bytes", methodname) data = space.bytes_w(w_data) diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py --- a/pypy/module/_io/interp_fileio.py +++ b/pypy/module/_io/interp_fileio.py @@ -143,7 +143,7 @@ W_FileIO.__init__(self, space) return self - @unwrap_spec(mode=str, closefd=int) + @unwrap_spec(mode='text', closefd=int) def descr_init(self, space, w_name, mode='r', closefd=True, w_opener=None): if self.fd >= 0: if self.closefd: diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py --- a/pypy/module/_io/interp_io.py +++ b/pypy/module/_io/interp_io.py @@ -14,7 +14,7 @@ "io.UnsupportedOperation", space.newtuple([space.w_ValueError, space.w_IOError])) -@unwrap_spec(mode=str, buffering=int, +@unwrap_spec(mode='text', buffering=int, encoding="str_or_None", errors="str_or_None", newline="str_or_None", closefd=int) def open(space, w_file, mode="r", buffering=-1, encoding=None, errors=None, 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 @@ -218,7 +218,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) @@ -248,7 +248,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) 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 @@ -299,7 +299,7 @@ raise return space.newtext('ascii') else: - if space.isinstance_w(w_encoding, space.w_unicode): + if space.isinstance_w(w_encoding, space.w_text): return w_encoding raise oefmt(space.w_IOError, "could not determine default encoding") @@ -391,9 +391,8 @@ else: newline = space.unicode_w(w_newline) if newline and newline not in (u'\n', u'\r\n', u'\r'): - r = space.str_w(space.repr(w_newline)) raise oefmt(space.w_ValueError, - "illegal newline value: %s", r) + "illegal newline value: %R", w_newline) self.line_buffering = line_buffering self.write_through = write_through @@ -596,7 +595,7 @@ "read1" if self.has_read1 else "read", 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) @@ -908,9 +907,8 @@ whence) if space.is_true(space.lt(w_pos, space.newint(0))): - r = space.str_w(space.repr(w_pos)) raise oefmt(space.w_ValueError, - "negative seek position %s", r) + "negative seek position %R", w_pos) space.call_method(self, "flush") @@ -932,7 +930,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/_locale/interp_locale.py b/pypy/module/_locale/interp_locale.py --- a/pypy/module/_locale/interp_locale.py +++ b/pypy/module/_locale/interp_locale.py @@ -110,7 +110,7 @@ _strxfrm = rlocale.external('strxfrm', [rffi.CCHARP, rffi.CCHARP, rffi.SIZE_T], rffi.SIZE_T) -@unwrap_spec(s=str) +@unwrap_spec(s='text') def strxfrm(space, s): "string -> string. Returns a string that behaves for cmp locale-aware." n1 = len(s) + 1 @@ -155,7 +155,7 @@ if rlocale.HAVE_LIBINTL: _gettext = rlocale.external('gettext', [rffi.CCHARP], rffi.CCHARP) - @unwrap_spec(msg=str) + @unwrap_spec(msg='text') def gettext(space, msg): """gettext(msg) -> string Return translation of msg.""" @@ -167,7 +167,7 @@ _dgettext = rlocale.external('dgettext', [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP) - @unwrap_spec(msg=str) + @unwrap_spec(msg='text') def dgettext(space, w_domain, msg): """dgettext(domain, msg) -> string Return translation of msg in domain.""" @@ -201,7 +201,7 @@ _dcgettext = rlocale.external('dcgettext', [rffi.CCHARP, rffi.CCHARP, rffi.INT], rffi.CCHARP) - @unwrap_spec(msg=str, category=int) + @unwrap_spec(msg='text', category=int) def dcgettext(space, w_domain, msg, category): """dcgettext(domain, msg, category) -> string Return translation of msg in domain and category.""" @@ -263,7 +263,7 @@ rffi.CCHARP, save_err=rffi.RFFI_SAVE_ERRNO) - @unwrap_spec(domain=str) + @unwrap_spec(domain='text') def bindtextdomain(space, domain, w_dir): """bindtextdomain(domain, dir) -> string Bind the C library's domain to dir.""" @@ -294,7 +294,7 @@ [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP) if rlocale.HAVE_BIND_TEXTDOMAIN_CODESET: - @unwrap_spec(domain=str) + @unwrap_spec(domain='text') def bind_textdomain_codeset(space, domain, w_codeset): """bind_textdomain_codeset(domain, codeset) -> string Bind the C library's domain to codeset.""" diff --git a/pypy/module/_minimal_curses/interp_curses.py b/pypy/module/_minimal_curses/interp_curses.py --- a/pypy/module/_minimal_curses/interp_curses.py +++ b/pypy/module/_minimal_curses/interp_curses.py @@ -75,7 +75,7 @@ except _curses.error as e: raise curses_error(e.args[0]) -@unwrap_spec(capname=str) +@unwrap_spec(capname='text') def tigetstr(space, capname): try: result = _curses_tigetstr(capname) diff --git a/pypy/module/_multibytecodec/interp_multibytecodec.py b/pypy/module/_multibytecodec/interp_multibytecodec.py --- a/pypy/module/_multibytecodec/interp_multibytecodec.py +++ b/pypy/module/_multibytecodec/interp_multibytecodec.py @@ -52,7 +52,7 @@ MultibyteCodec.typedef.acceptable_as_base_class = False -@unwrap_spec(name=str) +@unwrap_spec(name='text') def getcodec(space, name): try: codec = c_codecs.getcodec(name) 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 @@ -525,9 +525,8 @@ def after_fork(self): self.count = 0 - @unwrap_spec(kind=int, maxvalue=int) - def rebuild(space, w_cls, w_handle, kind, maxvalue, w_name): - name = space.str_or_None_w(w_name) + @unwrap_spec(kind=int, maxvalue=int, name='text_or_None') + def rebuild(space, w_cls, w_handle, kind, maxvalue, name): # if sys_platform != 'win32' and name is not None: # like CPython, in this case ignore 'w_handle' diff --git a/pypy/module/_pickle_support/maker.py b/pypy/module/_pickle_support/maker.py --- a/pypy/module/_pickle_support/maker.py +++ b/pypy/module/_pickle_support/maker.py @@ -69,7 +69,7 @@ new_iter = W_IntRangeIterator(space, current, remaining, step) return new_iter -@unwrap_spec(identifier=str) +@unwrap_spec(identifier='text') def builtin_code(space, identifier): from pypy.interpreter import gateway try: @@ -78,7 +78,7 @@ raise oefmt(space.w_RuntimeError, "cannot unpickle builtin code: %s", identifier) -@unwrap_spec(identifier=str) +@unwrap_spec(identifier='text') def builtin_function(space, identifier): from pypy.interpreter import function try: diff --git a/pypy/module/_pypyjson/interp_decoder.py b/pypy/module/_pypyjson/interp_decoder.py --- a/pypy/module/_pypyjson/interp_decoder.py +++ b/pypy/module/_pypyjson/interp_decoder.py @@ -391,9 +391,7 @@ return 0x10000 + (((highsurr - 0xd800) << 10) | (lowsurr - 0xdc00)) def loads(space, w_s, w_errorcls=None): - if space.isinstance_w(w_s, space.w_bytes): - raise oefmt(space.w_TypeError, "Expected string, got %T", w_s) - s = space.str_w(w_s) + s = space.text_w(w_s) decoder = JSONDecoder(space, s) try: w_res = decoder.decode_any(0) @@ -405,8 +403,8 @@ except DecoderError as e: if w_errorcls is None: w_errorcls = space.w_ValueError - w_e = space.call_function(w_errorcls, space.wrap(e.msg), w_s, - space.wrap(e.pos)) + w_e = space.call_function(w_errorcls, space.newtext(e.msg), w_s, + space.newint(e.pos)) raise OperationError(w_errorcls, w_e) finally: decoder.close() 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/interp_funcptr.py b/pypy/module/_rawffi/alt/interp_funcptr.py --- a/pypy/module/_rawffi/alt/interp_funcptr.py +++ b/pypy/module/_rawffi/alt/interp_funcptr.py @@ -20,9 +20,9 @@ def _getfunc(space, CDLL, w_name, w_argtypes, w_restype): argtypes_w, argtypes, w_restype, restype = unpack_argtypes( space, w_argtypes, w_restype) - if space.isinstance_w(w_name, space.w_unicode): + if space.isinstance_w(w_name, space.w_text): # XXX: support LoadLibraryW - name = space.str_w(w_name) + name = space.text_w(w_name) try: func = CDLL.cdll.getpointer(name, argtypes, restype, flags = CDLL.flags) @@ -52,9 +52,9 @@ raise oefmt(space.w_TypeError, "function name must be a string or integer") else: - @unwrap_spec(name=str) + @unwrap_spec(name='text') def _getfunc(space, CDLL, w_name, w_argtypes, w_restype): - name = space.str_w(w_name) + name = space.text_w(w_name) argtypes_w, argtypes, w_restype, restype = unpack_argtypes( space, w_argtypes, w_restype) try: @@ -287,7 +287,7 @@ restype = unwrap_ffitype(space, w_restype, allow_void=True) return argtypes_w, argtypes, w_restype, restype -@unwrap_spec(addr=r_uint, name=str, flags=int) +@unwrap_spec(addr=r_uint, name='text', flags=int) def descr_fromaddr(space, w_cls, addr, name, w_argtypes, w_restype, flags=libffi.FUNCFLAG_CDECL): argtypes_w, argtypes, w_restype, restype = unpack_argtypes(space, @@ -331,7 +331,7 @@ def getfunc(self, space, w_name, w_argtypes, w_restype): return _getfunc(space, self, w_name, w_argtypes, w_restype) - @unwrap_spec(name=str) + @unwrap_spec(name='text') def getaddressindll(self, space, name): try: address_as_uint = rffi.cast(lltype.Unsigned, diff --git a/pypy/module/_rawffi/alt/interp_struct.py b/pypy/module/_rawffi/alt/interp_struct.py --- a/pypy/module/_rawffi/alt/interp_struct.py +++ b/pypy/module/_rawffi/alt/interp_struct.py @@ -21,7 +21,7 @@ def __repr__(self): return '<Field %s %s>' % (self.name, self.w_ffitype.name) -@unwrap_spec(name=str) +@unwrap_spec(name='text') def descr_new_field(space, w_type, name, w_ffitype): w_ffitype = space.interp_w(W_FFIType, w_ffitype) return W_Field(name, w_ffitype) @@ -115,7 +115,7 @@ -@unwrap_spec(name=str) +@unwrap_spec(name='text') def descr_new_structdescr(space, w_type, name, w_fields=None): descr = W__StructDescr(name) if not space.is_none(w_fields): 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 @@ -79,11 +79,11 @@ 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_str: - strval = self.space.str_w(w_obj) + if w_ffitype.is_char_p() and w_type is self.space.w_bytes: + 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_str or + elif w_ffitype.is_unichar_p() and (w_type is self.space.w_bytes or w_type is self.space.w_unicode): unicodeval = self.space.unicode_w(w_obj) self.handle_unichar_p(w_ffitype, w_obj, unicodeval) diff --git a/pypy/module/_rawffi/callback.py b/pypy/module/_rawffi/callback.py --- a/pypy/module/_rawffi/callback.py +++ b/pypy/module/_rawffi/callback.py @@ -79,7 +79,7 @@ self.argtypes = unpack_argshapes(space, w_args) ffiargs = [tp.get_basic_ffi_type() for tp in self.argtypes] if not space.is_w(w_result, space.w_None): - self.result = space.str_w(w_result) + self.result = space.text_w(w_result) ffiresult = letter2tp(space, self.result).get_basic_ffi_type() else: self.result = None 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 @@ -101,8 +101,8 @@ 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_unicode): - letter = space.str_w(w_shape) + if space.isinstance_w(w_shape, space.w_text): + letter = space.text_w(w_shape) return letter2tp(space, letter) else: w_shapetype, w_length = space.fixedview(w_shape, expected_length=2) @@ -112,8 +112,8 @@ def unpack_shape_with_length(space, w_shape): # Allow 'w_shape' to be a letter or any (shape, number). # The result is always a W_Array. - if space.isinstance_w(w_shape, space.w_unicode): - letter = space.str_w(w_shape) + if space.isinstance_w(w_shape, space.w_text): + letter = space.text_w(w_shape) return letter2tp(space, letter) else: w_shapetype, w_length = space.fixedview(w_shape, expected_length=2) @@ -193,8 +193,8 @@ else: ffi_restype = ffi_type_void - if space.isinstance_w(w_name, space.w_unicode): - name = space.str_w(w_name) + if space.isinstance_w(w_name, space.w_text): + name = space.text_w(w_name) try: ptr = self.cdll.getrawpointer(name, ffi_argtypes, ffi_restype, @@ -225,7 +225,7 @@ space.setitem(self.w_cache, w_key, w_funcptr) return w_funcptr - @unwrap_spec(name=str) + @unwrap_spec(name='text') def getaddressindll(self, space, name): try: address_as_uint = rffi.cast(lltype.Unsigned, @@ -411,10 +411,10 @@ if space.isinstance_w(w_arg, space.w_int): val = getbytevalue(space, w_arg) else: - s = space.str_w(w_arg) + s = space.bytes_w(w_arg) if len(s) != 1: raise oefmt(space.w_TypeError, - "Expected string of length one as character") + "Expected bytes of length one as character") val = s[0] push_func(add_arg, argdesc, val) elif letter == 'u': @@ -565,7 +565,7 @@ W_FuncPtr.typedef.acceptable_as_base_class = False def _create_new_accessor(func_name, name): - @unwrap_spec(tp_letter=str) + @unwrap_spec(tp_letter='text') def accessor(space, tp_letter): if len(tp_letter) != 1: raise oefmt(space.w_ValueError, "Expecting string of length one") diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py --- a/pypy/module/_rawffi/structure.py +++ b/pypy/module/_rawffi/structure.py @@ -37,7 +37,7 @@ "Expected list of 2- or 3-size tuples") try: - name = space.str_w(l_w[0]) + name = space.text_w(l_w[0]) except OperationError: raise oefmt(space.w_TypeError, "structure field name must be string not %T", l_w[0]) @@ -204,12 +204,12 @@ def fromaddress(self, space, address): return W_StructureInstance(space, self, address) - @unwrap_spec(attr=str) + @unwrap_spec(attr='text') def descr_fieldoffset(self, space, attr): index = self.getindex(space, attr) return space.newint(self.ll_positions[index]) - @unwrap_spec(attr=str) + @unwrap_spec(attr='text') def descr_fieldsize(self, space, attr): index = self.getindex(space, attr) if self.ll_bitsizes and index < len(self.ll_bitsizes): @@ -352,7 +352,7 @@ addr = rffi.cast(lltype.Unsigned, self.ll_buffer) return space.newtext("<_rawffi struct %x>" % (addr,)) - @unwrap_spec(attr=str) + @unwrap_spec(attr='text') def getattr(self, space, attr): if not self.ll_buffer: raise segfault_exception(space, "accessing NULL pointer") @@ -360,7 +360,7 @@ _, tp, _ = self.shape.fields[i] return wrap_value(space, cast_pos, self, i, tp.itemcode) - @unwrap_spec(attr=str) + @unwrap_spec(attr='text') def setattr(self, space, attr, w_value): if not self.ll_buffer: raise segfault_exception(space, "accessing NULL pointer") @@ -368,7 +368,7 @@ _, tp, _ = self.shape.fields[i] unwrap_value(space, push_field, self, i, tp.itemcode, w_value) - @unwrap_spec(attr=str) + @unwrap_spec(attr='text') def descr_fieldaddress(self, space, attr): i = self.shape.getindex(space, attr) ptr = rffi.ptradd(self.ll_buffer, self.shape.ll_positions[i]) 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 @@ -73,7 +73,7 @@ raise converted_error(space, e) return common_wrapgethost(space, res) -@unwrap_spec(name=str, w_proto = WrappedDefault(None)) +@unwrap_spec(name='text', w_proto = WrappedDefault(None)) def getservbyname(space, name, w_proto): """getservbyname(servicename[, protocolname]) -> integer @@ -84,7 +84,7 @@ if space.is_w(w_proto, space.w_None): proto = None else: - proto = space.str_w(w_proto) + proto = space.text_w(w_proto) try: port = rsocket.getservbyname(name, proto) except SocketError as e: @@ -102,7 +102,7 @@ if space.is_w(w_proto, space.w_None): proto = None else: - proto = space.str_w(w_proto) + proto = space.text_w(w_proto) if port < 0 or port > 0xffff: raise oefmt(space.w_OverflowError, @@ -114,7 +114,7 @@ raise converted_error(space, e) return space.newtext(service) -@unwrap_spec(name=str) +@unwrap_spec(name='text') def getprotobyname(space, name): """getprotobyname(name) -> integer @@ -229,7 +229,7 @@ raise oefmt(space.w_OverflowError, "long int larger than 32 bits") return space.newint(rsocket.htonl(r_uint32(x))) -@unwrap_spec(ip=str) +@unwrap_spec(ip='text') def inet_aton(space, ip): """inet_aton(string) -> packed 32-bit IP representation @@ -254,7 +254,7 @@ raise converted_error(space, e) return space.newtext(ip) -@unwrap_spec(family=int, ip=str) +@unwrap_spec(family=int, ip='text') def inet_pton(space, family, ip): """inet_pton(family, ip) -> packed IP address string @@ -267,7 +267,7 @@ raise converted_error(space, e) return space.newbytes(buf) -@unwrap_spec(family=int, packed="bufferstr") +@unwrap_spec(family=int, packed='bufferstr') def inet_ntop(space, family, packed): """inet_ntop(family, packed_ip) -> string formatted IP address diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py --- a/pypy/module/_socket/interp_socket.py +++ b/pypy/module/_socket/interp_socket.py @@ -149,14 +149,14 @@ raise oefmt(space.w_TypeError, "AF_PACKET address must be a tuple of length 2 " "to 5, not %d", len(pieces_w)) - ifname = space.str_w(pieces_w[0]) + ifname = space.text_w(pieces_w[0]) ifindex = rsocket.PacketAddress.get_ifindex_from_ifname(fd, ifname) protocol = space.int_w(pieces_w[1]) if len(pieces_w) > 2: pkttype = space.int_w(pieces_w[2]) else: pkttype = 0 if len(pieces_w) > 3: hatype = space.int_w(pieces_w[3]) else: hatype = 0 - if len(pieces_w) > 4: haddr = space.str_w(pieces_w[4]) + if len(pieces_w) > 4: haddr = space.text_w(pieces_w[4]) else: haddr = "" if len(haddr) > 8: raise oefmt(space.w_ValueError, 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 @@ -329,7 +329,7 @@ filter_as_string = buf.as_str() 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 @@ -291,7 +291,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 @@ -149,7 +149,7 @@ if ret != 0: raiseWindowsError(space, ret, 'RegFlushKey') -@unwrap_spec(subkey=str, filename=str) +@unwrap_spec(subkey="text", filename="text") def LoadKey(space, w_hkey, subkey, filename): """LoadKey(key, sub_key, file_name) - Creates a subkey under the specified key and stores registration information from a specified file into that subkey. @@ -174,7 +174,7 @@ if ret != 0: raiseWindowsError(space, ret, 'RegLoadKey') -@unwrap_spec(filename=str) +@unwrap_spec(filename="text") def SaveKey(space, w_hkey, filename): """SaveKey(key, file_name) - Saves the specified key, and all its subkeys to the specified file. @@ -193,7 +193,7 @@ if ret != 0: raiseWindowsError(space, ret, 'RegSaveKey') -@unwrap_spec(typ=int, value=str) +@unwrap_spec(typ=int, value="text") def SetValue(space, w_hkey, w_subkey, typ, value): """SetValue(key, sub_key, type, value) - Associates a value with a specified key. @@ -218,7 +218,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: @@ -239,7 +239,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]) @@ -285,7 +285,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: @@ -305,7 +305,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: @@ -387,7 +387,7 @@ else: # REG_BINARY and all other types return space.newbytes(rffi.charpsize2str(buf, buflen)) -@unwrap_spec(value_name=str, typ=int) +@unwrap_spec(value_name="text", typ=int) def SetValueEx(space, w_hkey, value_name, w_reserved, typ, w_value): """SetValueEx(key, value_name, reserved, type, value) - Stores data in the value field of an open registry key. @@ -437,7 +437,7 @@ if space.is_w(w_subkey, space.w_None): subkey = None else: - subkey = space.str_w(w_subkey) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit