changeset: 69548:bb62908896fe parent: 69544:996b9c9dc10a parent: 69541:b0385ec55e7e user: Jesus Cea date: Mon Apr 25 03:46:43 2011 +0200 files: Lib/collections/__init__.py Lib/test/test_imp.py Parser/tokenizer.c description: Correctly merging #9319 into 3.3? diff -r 996b9c9dc10a -r bb62908896fe Lib/test/test_imp.py --- a/Lib/test/test_imp.py Sun Apr 24 23:45:23 2011 +0200 +++ b/Lib/test/test_imp.py Mon Apr 25 03:46:43 2011 +0200 @@ -176,6 +176,10 @@ support.unlink(init_file_name + ext) support.rmtree(test_package_name) + def test_issue9319(self): + self.assertRaises(SyntaxError, + imp.find_module, "test/badsyntax_pep3120") + class ReloadTests(unittest.TestCase): diff -r 996b9c9dc10a -r bb62908896fe Parser/tokenizer.c --- a/Parser/tokenizer.c Sun Apr 24 23:45:23 2011 +0200 +++ b/Parser/tokenizer.c Mon Apr 25 03:46:43 2011 +0200 @@ -585,12 +585,19 @@ if (badchar) { /* Need to add 1 to the line number, since this line has not been counted, yet. */ - PyErr_Format(PyExc_SyntaxError, - "Non-UTF-8 code starting with '\\x%.2x' " - "in file %U on line %i, " - "but no encoding declared; " - "see http://python.org/dev/peps/pep-0263/ for details", - badchar, tok->filename, tok->lineno + 1); + if (tok->filename != NULL) + filename = PyUnicode_DecodeFSDefault(tok->filename); + else + filename = PyUnicode_FromString(""); + if (filename != NULL) { + PyErr_Format(PyExc_SyntaxError, + "Non-UTF-8 code starting with '\\x%.2x' " + "in file %U on line %i, " + "but no encoding declared; " + "see http://python.org/dev/peps/pep-0263/ for details", + badchar, filename, tok->lineno + 1); + Py_DECREF(filename); + } return error_ret(tok); } #endif