pypy/interpreter/test/test_module.py::AppTest_ModuleObject::()::test_name_nonascii
self = <CallInfo when='call' exception: >
func = <function <lambda> at 0x00000000178d1358>, when = 'call'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
../_pytest/runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_call'>
kwargs = {'__multicall__': <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_name_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_name_nonascii'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../_pytest/vendored_packages/pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x00007fd96b08c6b0>
hook = <_HookCaller 'pytest_runtest_call'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000001312ee0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_name_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_name_nonascii'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
../_pytest/vendored_packages/pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_call'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000001312ee0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_name_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_name_nonascii'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
../_pytest/vendored_packages/pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_name_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
../_pytest/vendored_packages/pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_call at 0x000000000ad02b88>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 1 meths, kwargs={'i...e_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
../_pytest/vendored_packages/pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000115388e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000115388e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 1 meths, kwargs={'i...e_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
../_pytest/vendored_packages/pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_name_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
../_pytest/vendored_packages/pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_call at 0x000000000ad02908>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 1 meths, kwargs={'i...e_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
../_pytest/vendored_packages/pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000115388a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000115388a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 1 meths, kwargs={'i...e_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
../_pytest/vendored_packages/pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 1 meths, kwargs={'item': <AppTestMethod 'test_name_nonascii'>, '__multicall__': <_MultiCall 0 results, 1 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
../_pytest/vendored_packages/pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_name_nonascii'>
def pytest_runtest_call(item):
try:
> item.runtest()
../_pytest/runner.py:91:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <AppTestMethod 'test_name_nonascii'>
def runtest(self):
target = self.obj
src = extract_docstring_if_empty_function(target.im_func)
space = target.im_self.space
if self.config.option.runappdirect:
appexec_definitions = self.parent.obj.__dict__
spaceconfig = getattr(self.parent.obj, 'spaceconfig', None)
usemodules = spaceconfig.get('usemodules') if spaceconfig else None
return run_with_python(self.config.option.python, src, usemodules,
**appexec_definitions)
filename = self._getdynfilename(target)
func = app2interp_temp(src, filename=filename)
w_instance = self.parent.w_instance
> self.execute_appex(space, func, space, w_instance)
tool/pytest/apptest.py:331:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <AppTestMethod 'test_name_nonascii'>, space = StdObjSpace
target = <function test_name_nonascii at 0x00000000178d13d0>
args = (StdObjSpace, <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x0000000009a0b4b0>)
def execute_appex(self, space, target, *args):
self.space = space
space.getexecutioncontext().set_sys_exc_info(None)
try:
> target(*args)
tool/pytest/apptest.py:267:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
args_w = (<pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x0000000009a0b4b0>,)
def appcaller(space, *args_w):
if not isinstance(space, ObjSpace):
raise TypeError("first argument must be a space instance.")
# the last argument can be an Arguments
> w_func = self.wget(space, name)
interpreter/gateway.py:1402:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ApplevelClass filename='[/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/test/test_module.py:102]'>
space = StdObjSpace, name = 'test_name_nonascii'
def wget(self, space, name):
> w_globals = self.getwdict(space)
interpreter/gateway.py:1393:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ApplevelClass filename='[/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/test/test_module.py:102]'>
space = StdObjSpace
def getwdict(self, space): # no cache
> return build_applevel_dict(self, space)
interpreter/gateway.py:1498:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ApplevelClass filename='[/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/test/test_module.py:102]'>
space = StdObjSpace
@not_rpython
def build_applevel_dict(self, space):
w_glob = space.newdict(module=True)
space.setitem(w_glob, space.newtext('__name__'), space.newtext(self.modname))
space.exec_(self.source, w_glob, w_glob,
hidden_applevel=self.hidden_applevel,
> filename=self.filename)
interpreter/gateway.py:1448:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
statement = 'def test_name_nonascii(self):\n import sys\n m = type(sys)(\'\xe6\x97\xa5\xe6\x9c\xac\')\n assert m.__name__ == \'\xe6\x97\xa5\xe6\x9c\xac\'\n assert repr(m).startswith("<module \'\xe6\x97\xa5\xe6\x9c\xac\'")'
w_globals = W_ModuleDictObject(<pypy.objspace.std.celldict.ModuleDictStrategy object at 0x000000001456a598>)
w_locals = W_ModuleDictObject(<pypy.objspace.std.celldict.ModuleDictStrategy object at 0x000000001456a598>)
hidden_applevel = False
filename = '[/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/test/test_module.py:102]'
@not_rpython
def exec_(self, statement, w_globals, w_locals, hidden_applevel=False,
filename=None):
"For internal debugging."
if filename is None:
filename = '?'
from pypy.interpreter.pycode import PyCode
if isinstance(statement, str):
> statement = self._cached_compile(filename, statement, 'exec', 0, hidden_applevel)
interpreter/baseobjspace.py:1424:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
filename = '[/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/test/test_module.py:102]'
source = 'def test_name_nonascii(self):\n import sys\n m = type(sys)(\'\xe6\x97\xa5\xe6\x9c\xac\')\n assert m.__name__ == \'\xe6\x97\xa5\xe6\x9c\xac\'\n assert repr(m).startswith("<module \'\xe6\x97\xa5\xe6\x9c\xac\'")'
mode = 'exec', flags = 0, hidden_applevel = False, ast_transform = None
@not_rpython
def _cached_compile(self, filename, source, mode, flags, hidden_applevel, ast_transform=None):
import os
from hashlib import md5
from rpython.config.translationoption import CACHE_DIR
from rpython.tool.gcc_cache import try_atomic_write
from pypy.module.marshal import interp_marshal
from pypy.interpreter.pycode import default_magic
h = md5(str(default_magic))
h.update(filename)
h.update(source)
h.update(mode)
h.update(str(flags))
h.update(str(hidden_applevel))
addition = ''
if ast_transform:
addition = ast_transform.func_name
# Unlike rpython.tool.gcc_cache, the path below is used directly
# without going through cache_file_path(), so CACHE_DIR may not
# exist yet. Create it here, otherwise try_atomic_write() fails
# with ENOENT when this is the first writer to touch the cache.
if not os.path.isdir(CACHE_DIR):
try:
os.makedirs(CACHE_DIR)
except OSError:
pass # raced with another process; that is fine
cachename = os.path.join(
CACHE_DIR, "applevel_exec_%s_%s" % (addition, h.hexdigest()))
try:
if self.config.translating:
raise IOError("don't use the cache when translating pypy")
with open(cachename, 'rb') as f:
w_bin = self.newbytes(f.read())
w_code = interp_marshal._loads(self, w_bin, hidden_applevel)
except IOError:
# must (re)compile the source
ec = self.getexecutioncontext()
if ast_transform:
c = self.createcompiler()
tree = c.compile_to_ast(source, filename, "exec", 0)
tree = ast_transform(self, tree)
w_code = c.compile_ast(tree, filename, 'exec', 0)
else:
w_code = ec.compiler.compile(
> source, filename, mode, flags, hidden_applevel)
interpreter/baseobjspace.py:1478:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.pycompiler.PythonAstCompiler object at 0x0000000003e08aa0>
source = 'def test_name_nonascii(self):\n import sys\n m = type(sys)(\'\xe6\x97\xa5\xe6\x9c\xac\')\n assert m.__name__ == \'\xe6\x97\xa5\xe6\x9c\xac\'\n assert repr(m).startswith("<module \'\xe6\x97\xa5\xe6\x9c\xac\'")'
filename = '[/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/test/test_module.py:102]'
mode = 'exec', flags = 0, hidden_applevel = False, optimize = 0
def compile(self, source, filename, mode, flags=0, hidden_applevel=False,
optimize=-1):
if optimize == -1:
optimize = self.space.sys.get_optimize()
assert optimize >= 0
info = pyparse.CompileInfo(filename, mode, flags,
hidden_applevel=hidden_applevel, optimize=optimize)
> mod = self._compile_to_ast(source, info)
interpreter/pycompiler.py:182:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.interpreter.pycompiler.PythonAstCompiler object at 0x0000000003e08aa0>
source = 'def test_name_nonascii(self):\n import sys\n m = type(sys)(\'\xe6\x97\xa5\xe6\x9c\xac\')\n assert m.__name__ == \'\xe6\x97\xa5\xe6\x9c\xac\'\n assert repr(m).startswith("<module \'\xe6\x97\xa5\xe6\x9c\xac\'")'
info = <pypy.interpreter.pyparser.pyparse.CompileInfo object at 0x000000001456a720>
def _compile_to_ast(self, source, info):
space = self.space
self.parser.reset()
try:
mod = self.parser.parse_source(source, info)
except parseerror.TabError as e:
raise OperationError(space.w_TabError,
e.find_sourceline_and_wrap_info(space, source, info.filename))
except parseerror.IndentationError as e:
raise OperationError(space.w_IndentationError, e.find_sourceline_and_wrap_info(space, source, info.filename))
except parseerror.SyntaxError as e:
#import pdb;pdb.xpm()
> raise OperationError(space.w_SyntaxError, e.find_sourceline_and_wrap_info(space, source, info.filename))
interpreter/pycompiler.py:172:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = TokenError(), space = StdObjSpace
source = 'def test_name_nonascii(self):\n import sys\n m = type(sys)(\'\xe6\x97\xa5\xe6\x9c\xac\')\n assert m.__name__ == \'\xe6\x97\xa5\xe6\x9c\xac\'\n assert repr(m).startswith("<module \'\xe6\x97\xa5\xe6\x9c\xac\'")'
filename = '[/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/test/test_module.py:102]'
fill_text = True
def find_sourceline_and_wrap_info(self, space, source=None, filename=None,
fill_text=True):
""" search for the line of input that caused the error and then return
a wrapped tuple that can be used to construct a wrapped SyntaxError.
Optionally pass source, to get better error messages for the case where
this instance was constructed without a source line (.text
attribute). Pass fill_text=False for compile-stage errors."""
text = self.text
if fill_text and text is None and source is not None and self.lineno:
lines = source.splitlines(True)
text = lines[self.lineno - 1]
w_text = w_filename = space.w_None
w_lineno = space.newint(self.lineno)
if filename is None:
filename = self.filename
if filename is not None:
w_filename = space.newfilename(filename)
if text is None:
w_text = space.appexec([w_filename, w_lineno],
"""(filename, lineno):
try:
# tokenize.open honours the coding cookie and strips a BOM
import tokenize
with tokenize.open(filename) as f:
for _ in range(lineno - 1):
f.readline()
return f.readline()
except: # we can't allow any exceptions here!
return None""")
offset = self.offset
end_offset = self.end_offset
if text is not None:
# text may not be UTF-8 in case of decoding errors.
# adjust the encoded text offset to a decoded offset
# XXX do the right thing about continuation lines, which
# XXX are their own fun, sometimes giving offset >
# XXX len(text) for example (right now, avoid crashing)
# this also converts the byte-based self.offset to a
# codepoint-based index into the decoded unicode-version of
# self.text
replacedtext, unilength, _ = _str_decode_utf8_slowpath(space,
> text, space.newbytes(text), 'replace', False, make_replace_error_handler(space), True)
interpreter/pyparser/error.py:97:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, s = " m = type(sys)('\xe6\x97\xa5\xe6\x9c\xac')\n"
w_s = W_BytesObject(" m = type(sys)('\xe6\x97\xa5\xe6\x9c\xac')\n")
errors = 'replace', final = False
errorhandler = <function replace_error_handler at 0x00000000178d1628>
allow_surrogates = True
def _str_decode_utf8_slowpath(space, s, w_s, errors, final, errorhandler, allow_surrogates):
""" Same as checking for the valid utf8, but we know the utf8 is not
valid so we're trying to either raise or pack stuff with error handler.
The key difference is that this is call_may_force.
In CPython this is done in unicode_decode_utf8, which has no
allow_surrogates. That argument is used in at least decode_utf8sp, in
interpreter.error._compute_value.
"""
if errors is None:
errors = 'strict'
result = StringBuilder(len(s))
pos = 0
while pos < len(s):
ordch1 = ord(s[pos])
# fast path for ASCII
# XXX maybe use a while loop here
if ordch1 <= 0x7F:
pos += 1
result.append(chr(ordch1))
continue
n = ord(runicode._utf8_code_length[ordch1 - 0x80])
if pos + n > len(s):
# argh, this obscure block of code is mostly a copy of
# what follows :-(
charsleft = len(s) - pos - 1 # either 0, 1, 2
# note: when we get the 'unexpected end of data' we need
# to care about the pos returned; it can be lower than len(s),
# in case we need to continue running this loop
if not charsleft:
# there's only the start byte and nothing else
if not final:
break
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'unexpected end of data',
w_s, pos, pos+1)
result.append(r)
continue
ordch2 = ord(s[pos+1])
if n == 3:
# 3-bytes seq with only a continuation byte
if rutf8._invalid_byte_2_of_3(ordch1, ordch2, allow_surrogates):
# second byte invalid, take the first and continue
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+1)
result.append(r)
continue
else:
# second byte valid, but third byte missing
if not final:
break
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'unexpected end of data',
w_s, pos, pos+2)
result.append(r)
continue
elif n == 4:
# 4-bytes seq with 1 or 2 continuation bytes
if rutf8._invalid_byte_2_of_4(ordch1, ordch2):
# second byte invalid, take the first and continue
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+1)
result.append(r)
continue
elif charsleft == 2 and rutf8._invalid_byte_3_of_4(ord(s[pos+2])):
# third byte invalid, take the first two and continue
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+2)
result.append(r)
continue
else:
# there's only 1 or 2 valid cb, but the others are missing
if not final:
break
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'unexpected end of data',
w_s, pos, pos+charsleft+1)
result.append(r)
continue
raise AssertionError("unreachable")
if n == 0:
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid start byte',
w_s, pos, pos+1)
result.append(r)
elif n == 1:
assert 0, "ascii should have gone through the fast path"
elif n == 2:
ordch2 = ord(s[pos+1])
if rutf8._invalid_byte_2_of_2(ordch2):
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+1)
result.append(r)
continue
# 110yyyyy 10zzzzzz -> 00000000 00000yyy yyzzzzzz
result.append(chr(ordch1))
result.append(chr(ordch2))
pos += 2
elif n == 3:
ordch2 = ord(s[pos+1])
ordch3 = ord(s[pos+2])
if rutf8._invalid_byte_2_of_3(ordch1, ordch2, allow_surrogates):
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+1)
result.append(r)
continue
elif rutf8._invalid_byte_3_of_3(ordch3):
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+2)
result.append(r)
continue
# 1110xxxx 10yyyyyy 10zzzzzz -> 00000000 xxxxyyyy yyzzzzzz
result.append(chr(ordch1))
result.append(chr(ordch2))
result.append(chr(ordch3))
pos += 3
elif n == 4:
ordch2 = ord(s[pos+1])
ordch3 = ord(s[pos+2])
ordch4 = ord(s[pos+3])
if rutf8._invalid_byte_2_of_4(ordch1, ordch2):
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+1)
result.append(r)
continue
elif rutf8._invalid_byte_3_of_4(ordch3):
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+2)
result.append(r)
continue
elif rutf8._invalid_byte_4_of_4(ordch4):
r, pos, rettype, s, w_s = errorhandler(errors, 'utf-8',
'invalid continuation byte',
w_s, pos, pos+3)
result.append(r)
continue
# 11110www 10xxxxxx 10yyyyyy 10zzzzzz -> 000wwwxx xxxxyyyy yyzzzzzz
result.append(chr(ordch1))
result.append(chr(ordch2))
result.append(chr(ordch3))
result.append(chr(ordch4))
pos += 4
r = result.build()
# XXX can keep track of the resulting length without calling check_utf8
# here
> return r, rutf8.check_utf8(r, True), pos
interpreter/unicodehelper.py:537:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = " m = type(sys)('\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd')\n"
allow_surrogates = True, start = 0, stop = -1
def check_utf8(s, allow_surrogates, start=0, stop=-1):
"""Check that 's' is a utf-8-encoded byte string.
Returns the length (number of chars) or raise CheckError.
If allow_surrogates is False, then also raise if we see any.
Note also codepoints_in_utf8(), which also computes the length
faster by assuming that 's' is valid utf-8.
"""
res = _check_utf8(s, allow_surrogates, start, stop)
if res >= 0:
return res
> raise CheckError(~res)
E CheckError
../rpython/rlib/rutf8.py:362: CheckError
builder: own-linux-x86-64 build #10967+
test: pypy/interpreter/test/test_module.py::AppTest_ModuleObject::()::test_name_nonascii