Author: Armin Rigo <ar...@tunes.org> Branch: py3.5-newtext Changeset: r90143:b1f56f360399 Date: 2017-02-15 10:01 +0100 http://bitbucket.org/pypy/pypy/changeset/b1f56f360399/
Log: hg merge 67d4325b8871 (but broken) diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -209,15 +209,15 @@ consts.CO_COROUTINE | consts.CO_ITERABLE_COROUTINE): e2 = OperationError(space.w_RuntimeError, - space.wrap("%s raised StopIteration" % - self.KIND)) + space.newtext("%s raised StopIteration" % + self.KIND)) e2.chain_exceptions(space, e) e2.set_cause(space, e.get_w_value(space)) e2.record_context(space, space.getexecutioncontext()) raise e2 else: - space.warn(space.wrap(u"generator '%s' raised StopIteration" - % self.get_qualname()), + space.warn(space.newunicode(u"generator '%s' raised StopIteration" + % self.get_qualname()), space.w_PendingDeprecationWarning) def descr_throw(self, w_type, w_val=None, w_tb=None): @@ -251,7 +251,7 @@ if tb is None: tb = space.getattr(operr.get_w_value(space), - space.wrap('__traceback__')) + space.newtext('__traceback__')) if not space.is_w(tb, space.w_None): operr.set_traceback(tb) return self.send_error(operr) @@ -297,7 +297,7 @@ return space.w_None def descr__name__(self, space): - return space.wrap(self.get_name().decode('utf-8')) + return space.newtext(self.get_name()) def descr_set__name__(self, space, w_name): if space.isinstance_w(w_name, space.w_unicode): @@ -307,7 +307,7 @@ "__name__ must be set to a string object") def descr__qualname__(self, space): - return space.wrap(self.get_qualname()) + return space.newunicode(self.get_qualname()) def descr_set__qualname__(self, space, w_name): try: @@ -343,7 +343,7 @@ def descr__iter__(self): """Implement iter(self).""" - return self.space.wrap(self) + return self def descr_next(self): """Implement next(self).""" @@ -390,7 +390,7 @@ KIND = "coroutine" def descr__await__(self, space): - return space.wrap(CoroutineWrapper(self)) + return CoroutineWrapper(self) def _finalize_(self): # If coroutine was never awaited on issue a RuntimeWarning. @@ -399,7 +399,7 @@ self.frame.last_instr == -1: space = self.space msg = u"coroutine '%s' was never awaited" % self.get_qualname() - space.warn(space.wrap(msg), space.w_RuntimeWarning) + space.warn(space.newunicode(msg), space.w_RuntimeWarning) GeneratorOrCoroutine._finalize_(self) @@ -410,7 +410,7 @@ self.coroutine = coroutine def descr__iter__(self, space): - return space.wrap(self) + return self def descr__next__(self, space): return self.coroutine.send_ex(space.w_None) @@ -436,10 +436,10 @@ self.w_aiter = w_aiter def descr__await__(self, space): - return space.wrap(self) + return self def descr__iter__(self, space): - return space.wrap(self) + return self def descr__next__(self, space): raise OperationError(space.w_StopIteration, self.w_aiter) @@ -457,7 +457,7 @@ w_yf.descr_close() else: try: - w_close = space.getattr(w_yf, space.wrap("close")) + w_close = space.getattr(w_yf, space.newtext("close")) except OperationError as e: if not e.match(space, space.w_AttributeError): # aaaaaaaah but that's what CPython does too @@ -470,7 +470,7 @@ if isinstance(w_inputvalue_or_err, SApplicationException): operr = w_inputvalue_or_err.operr try: - w_meth = space.getattr(w_yf, space.wrap("throw")) + w_meth = space.getattr(w_yf, space.newtext("throw")) except OperationError as e: if not e.match(space, space.w_AttributeError): raise @@ -481,7 +481,7 @@ operr.normalize_exception(space) w_exc = operr.w_type w_val = operr.get_w_value(space) - w_tb = space.wrap(operr.get_traceback()) + w_tb = operr.get_w_traceback(space) return space.call_function(w_meth, w_exc, w_val, w_tb) else: return space.call_method(w_yf, "send", w_inputvalue_or_err) diff --git a/pypy/interpreter/test/test_argument.py b/pypy/interpreter/test/test_argument.py --- a/pypy/interpreter/test/test_argument.py +++ b/pypy/interpreter/test/test_argument.py @@ -99,6 +99,8 @@ def str_w(self, s): return str(s) + def text_w(self, s): + return self.str_w(s) def text_w(self, s): return self.str_w(s) diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py --- a/pypy/module/_collections/interp_deque.py +++ b/pypy/module/_collections/interp_deque.py @@ -184,7 +184,7 @@ copy.maxlen = self.maxlen copy.extend(self.iter()) copy.extend(deque.iter()) - return self.space.wrap(copy) + return copy def iadd(self, w_iterable): self.extend(w_iterable) @@ -199,7 +199,7 @@ for _ in range(num): copied.extend(self) - return space.wrap(copied) + return copied def rmul(self, w_int): return self.mul(w_int) @@ -208,10 +208,10 @@ space = self.space num = space.int_w(w_int) if self.len == 0 or num == 1: - return space.wrap(self) + return self if num <= 0: self.clear() - return space.wrap(self) + return self # use a copy to extend self copy = W_Deque(space) copy.maxlen = self.maxlen @@ -220,7 +220,7 @@ for _ in range(num - 1): self.extend(copy) - return space.wrap(self) + return self def extendleft(self, w_iterable): "Extend the left side of the deque with elements from the iterable" @@ -369,7 +369,7 @@ if i < start: continue if space.eq_w(w_obj, w_x): - return space.wrap(i) + return space.newint(i) self.checklock(lock) except OperationError as e: if not e.match(space, space.w_StopIteration): @@ -642,7 +642,7 @@ return w_x def reduce(self): - w_i = self.space.wrap(self.deque.len - self.counter) + w_i = self.space.newint(self.deque.len - self.counter) return self.space.newtuple([self.space.gettypefor(W_DequeIter), self.space.newtuple([self.deque, w_i])]) @@ -710,7 +710,7 @@ return w_x def reduce(self): - w_i = self.space.wrap(self.deque.len - self.counter) + w_i = self.space.newint(self.deque.len - self.counter) return self.space.newtuple([self.space.gettypefor(W_DequeRevIter), self.space.newtuple([self.deque, w_i])]) 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 @@ -180,7 +180,7 @@ # XXX Hack to seperate rpython and pypy def ipaddr_from_object(space, w_sockaddr): - host = space.str_w(space.getitem(w_sockaddr, space.newint(0))) + host = space.text_w(space.getitem(w_sockaddr, space.newint(0))) addr = rsocket.makeipaddr(host) fill_from_object(addr, space, w_sockaddr) return addr diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py --- a/pypy/objspace/descroperation.py +++ b/pypy/objspace/descroperation.py @@ -408,7 +408,7 @@ except OperationError as e: if not e.match(space, space.w_StopIteration): raise - return space.wrap(count) + return space.newint(count) if space.eq_w(w_next, w_item): count += 1 @@ -424,7 +424,7 @@ raise oefmt(space.w_ValueError, "sequence.index(x): x not in sequence") if space.eq_w(w_next, w_item): - return space.wrap(index) + return space.newint(index) index += 1 def hash(space, w_obj): @@ -483,7 +483,7 @@ return w_result if space.isinstance_w(w_result, space.w_int): tp = space.type(w_result).name - space.warn(space.wrap( + space.warn(space.newtext( "__index__ returned non-int (type %s). " "The ability to return an instance of a strict subclass of int " "is deprecated, and may be removed in a future version of " 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 @@ -92,6 +92,8 @@ self.builtin_types[typedef.name] = w_type setattr(self, 'w_' + typedef.name, 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_dict.flag_map_or_seq = 'M' self.w_list.flag_map_or_seq = 'S' self.w_tuple.flag_map_or_seq = 'S' @@ -132,7 +134,6 @@ assert typedef is not None return self.fromcache(TypeCache).getorbuild(typedef) - @not_rpython # only for tests def wrap(self, x): """ Wraps the Python value 'x' into one of the wrapper classes. This should only be used for tests, in real code you need to use the @@ -153,7 +154,7 @@ try: unicode_x = x.decode('ascii') except UnicodeDecodeError: - unicode_x = self._wrap_ascii_replace(x) + unicode_x = self._wrap_string_old(x) return self.newunicode(unicode_x) if isinstance(x, unicode): return self.newunicode(x) @@ -167,24 +168,13 @@ return self.newint(x) return self._wrap_not_rpython(x) - def _wrap_ascii_replace(self, x): - # XXX should disappear soon? - # poor man's x.decode('ascii', 'replace'), since it's not - # supported by RPython - if not we_are_translated(): - print 'WARNING: space.wrap() called on a non-ascii byte string: %r' % x - lst = [] - for ch in x: - ch = ord(ch) - if ch > 127: - lst.append(u'\ufffd') - else: - lst.append(unichr(ch)) - unicode_x = u''.join(lst) - return unicode_x + def _wrap_string_old(self, x): + # XXX should disappear soon + print 'WARNING: space.wrap() called on a non-ascii byte string: %r' % x + return self.newtext(x) + @not_rpython # only for tests def _wrap_not_rpython(self, x): - "NOT_RPYTHON" # _____ this code is here to support testing only _____ # we might get there in non-translated versions if 'x' is @@ -577,7 +567,7 @@ if isinstance(w_slice, W_SliceObject): a, b, c = w_slice.indices3(self, self.int_w(w_length)) return (a, b, c) - w_indices = self.getattr(w_slice, self.newbytes('indices')) + w_indices = self.getattr(w_slice, self.newtext('indices')) w_tup = self.call_function(w_indices, w_length) l_w = self.unpackiterable(w_tup) if not len(l_w) == 3: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit