Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r60490:16d93617dc0c
Date: 2013-01-25 13:32 -0800
http://bitbucket.org/pypy/pypy/changeset/16d93617dc0c/
Log: convert LookupErrors from find_module into SyntaxErrors
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -87,8 +87,14 @@
# object doesn't have a name attached. We do the same in PyPy, because
# there is no easy way to attach the filename -- too bad
fd = stream.try_to_find_file_descriptor()
- w_fileobj = interp_io.open(space, space.wrap(fd), find_info.filemode,
- encoding=encoding)
+ try:
+ w_fileobj = interp_io.open(space, space.wrap(fd),
+ find_info.filemode, encoding=encoding)
+ except OperationError as e:
+ if e.match(space, space.w_LookupError):
+ raise OperationError(space.w_SyntaxError,
+ space.str(e.get_w_value(space)))
+ raise
else:
w_fileobj = space.w_None
w_import_info = space.newtuple(
diff --git a/pypy/module/imp/test/test_import.py
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -92,7 +92,8 @@
'a=15\nb=16\rc="""foo\r\nbar"""\r', mode='wb')
setuppkg("encoded",
# actually a line 2, setuppkg() sets up a line1
- line2 = "# encoding: iso-8859-1\n")
+ line2 = "# encoding: iso-8859-1\n",
+ bad = "# encoding: uft-8\n")
# create compiled/x.py and a corresponding pyc file
p = setuppkg("compiled", x = "x = 84")
@@ -668,6 +669,11 @@
fd = imp.find_module('line2', encoded.__path__)[0]
assert fd.encoding == 'iso-8859-1'
+ def test_bad_source_encoding(self):
+ import imp
+ import encoded
+ raises(SyntaxError, imp.find_module, 'bad', encoded.__path__)
+
class TestAbi:
def test_abi_tag(self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit