Author: Matti Picus <matti.pi...@gmail.com> Branch: unicode-utf8-py3 Changeset: r94825:0ff9a3ee6b88 Date: 2018-07-07 21:15 -0700 http://bitbucket.org/pypy/pypy/changeset/0ff9a3ee6b88/
Log: re-add text_w to differentiate W_Unicode (succeeds) from W_Bytes (fails) diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -245,6 +245,9 @@ def bytes_w(self, space): self._typed_unwrap_error(space, "bytes") + def text_w(self, space): + self._typed_unwrap_error(space, "unicode") + def utf8_w(self, space): self._typed_unwrap_error(space, "unicode") @@ -1615,18 +1618,20 @@ an utf-8 encoded rpython string. """ assert w_obj is not None - return w_obj.utf8_w(self) + return w_obj.text_w(self) @not_rpython # tests only; should be replaced with bytes_w or text_w def str_w(self, w_obj): """ - if w_obj is unicode, call text_w() (i.e., return the UTF-8-nosg + if w_obj is unicode, call utf8_w() (i.e., return the UTF-8-nosg encoded string). Else, call bytes_w(). We should kill str_w completely and manually substitute it with text_w/bytes_w at all call sites. It remains for now for tests only. """ + XXX # deprecated, leaving in place for clear errors if self.isinstance_w(w_obj, self.w_unicode): + # XXX lo text_w, but better to deprecate str_w than to fix this return w_obj.text_w(self) else: return w_obj.bytes_w(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 @@ -1158,9 +1158,10 @@ if not space.isinstance_w(w_name, space.w_text): raise oefmt(space.w_TypeError, "__slots__ items must be strings, not '%T'", w_name) - if not _isidentifier(space.utf8_w(w_name)): + s = space.utf8_w(w_name) + if not _isidentifier(s): raise oefmt(space.w_TypeError, "__slots__ must be identifiers") - return w_name.text_w(space) + return s def create_all_slots(w_self, hasoldstylebase, w_bestbase, force_new_layout): from pypy.interpreter.miscutils import string_sort 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 @@ -88,6 +88,9 @@ uid = (base << IDTAG_SHIFT) | IDTAG_SPECIAL return space.newint(uid) + def text_w(self, space): + return self._utf8 + def utf8_w(self, space): return self._utf8 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 @@ -23,11 +23,11 @@ # self.path = space.unwrap(space.getattr(self.w_file, space.wrap('__path__'))) #except OperationError: # self.path = space.unwrap(space.getattr( - self.path = py.path.local(space.str_w(self.w_file)) + self.path = py.path.local(space.utf8_w(self.w_file)) self.space = space def fullsource(self): - filename = self.space.str_w(self.w_file) + filename = self.space.utf8_w(self.w_file) source = py.code.Source(py.std.linecache.getlines(filename)) if source.lines: return source _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit