Author: fijal Branch: unicode-utf8 Changeset: r93264:f312060a4a01 Date: 2017-12-03 16:27 +0100 http://bitbucket.org/pypy/pypy/changeset/f312060a4a01/
Log: fix the warnings module, add we_are_translated for now 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 @@ -596,9 +596,9 @@ return space.w_None wcharp_addr = rffi.cast(rffi.CWCHARP, address) if maxlength == -1: - s = rffi.wcharp2unicode(wcharp_addr) + s = rffi.wcharp2utf8(wcharp_addr) else: - s = rffi.wcharp2unicoden(wcharp_addr, maxlength) + s = rffi.wcharpsize2utf8(wcharp_addr, maxlength) return space.newunicode(s) @unwrap_spec(address=r_uint, maxlength=int) 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 @@ -1,3 +1,6 @@ + +from rpython.rlib import rutf8 + from pypy.interpreter.gateway import unwrap_spec, WrappedDefault from pypy.interpreter.error import OperationError, oefmt @@ -208,10 +211,11 @@ except OperationError as e: if e.async(space): raise - message = u"%s:%d: %s: %s\n" % (space.unicode_w(w_filename), lineno, - space.unicode_w(w_name), - space.unicode_w(w_text)) - w_message = space.newunicode(message) + message = "%s:%d: %s: %s\n" % (space.utf8_w(w_filename), lineno, + space.utf8_w(w_name), + space.utf8_w(w_text)) + lgt, flag = rutf8.check_utf8(message, True) + w_message = space.newutf8(message, lgt, flag) else: w_message = space.newtext(message) space.call_method(w_stderr, "write", w_message) 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 @@ -49,14 +49,15 @@ self._index_storage = rutf8.null_storage() # XXX checking, remove before any performance measurments # ifdef not_running_in_benchmark - lgt, flag_check = rutf8.check_utf8(utf8str, True) - assert lgt == length - if flag_check == rutf8.FLAG_ASCII: - # there are cases where we copy part of REULAR that happens - # to be ascii - assert flag in (rutf8.FLAG_ASCII, rutf8.FLAG_REGULAR) - else: - assert flag == flag_check + if not we_are_translated(): + lgt, flag_check = rutf8.check_utf8(utf8str, True) + assert lgt == length + if flag_check == rutf8.FLAG_ASCII: + # there are cases where we copy part of REULAR that happens + # to be ascii + assert flag in (rutf8.FLAG_ASCII, rutf8.FLAG_REGULAR) + else: + assert flag == flag_check # the storage can be one of: # - null, unicode with no surrogates # - rutf8.UTF8_HAS_SURROGATES @@ -1173,7 +1174,7 @@ s = space.charbuf_w(w_obj) unicodehelper.check_ascii_or_raise(space, s) return space.newutf8(s, len(s), rutf8.FLAG_ASCII) - if encoding == 'utf-8': + if encoding == 'utf-8' or encoding == 'utf8': s = space.charbuf_w(w_obj) lgt, flag = unicodehelper.check_utf8_or_raise(space, s) return space.newutf8(s, lgt, flag) diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py --- a/rpython/rtyper/lltypesystem/rffi.py +++ b/rpython/rtyper/lltypesystem/rffi.py @@ -1019,7 +1019,7 @@ s = StringBuilder(size) for i in range(size): rutf8.unichr_as_utf8_append(s, ord(w[i])) - return s.build() + return s.build() def utf82wcharp(utf8, utf8len): from rpython.rlib import rutf8 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit