diff -r deda5b5160d2 Lib/test/test_pep263.py --- a/Lib/test/test_pep263.py Thu Dec 24 11:51:24 2015 +0200 +++ b/Lib/test/test_pep263.py Sat Dec 26 11:59:07 2015 +0100 @@ -15,18 +15,19 @@ class PEP263Test(unittest.TestCase): '\\\xd0\x9f' ) + def compile_exec(self, source): + code = compile(source, "dummy", "exec") + ns = {} + exec(code, ns) + return ns + def test_compilestring(self): # see #1882 - c = compile("\n# coding: utf-8\nu = u'\xc3\xb3'\n", "dummy", "exec") - d = {} - exec c in d + d = self.compile_exec("\n# coding: utf-8\nu = u'\xc3\xb3'\n") self.assertEqual(d['u'], u'\xf3') - def test_issue3297(self): - c = compile("a, b = '\U0001010F', '\\U0001010F'", "dummy", "exec") - d = {} - exec(c, d) + d = self.compile_exec("a, b = '\U0001010F', '\\U0001010F'") self.assertEqual(d['a'], d['b']) self.assertEqual(len(d['a']), len(d['b'])) @@ -63,6 +64,13 @@ class PEP263Test(unittest.TestCase): 'codec did not return a unicode'): from test import bad_coding3 + def test_utf8_encoding(self): + # issue #25937: "utf8" cookie should behave like "utf-8" + for encoding in ('utf-8', 'utf8'): + source = "# coding: %s\ns = '\xd6\xd0\xce\xc4'" % encoding + ns = self.compile_exec(source) + self.assertEqual(ns['s'], '\xd6\xd0\xce\xc4') + def test_main(): test_support.run_unittest(PEP263Test) diff -r deda5b5160d2 Parser/tokenizer.c --- a/Parser/tokenizer.c Thu Dec 24 11:51:24 2015 +0200 +++ b/Parser/tokenizer.c Sat Dec 26 11:59:07 2015 +0100 @@ -193,6 +193,9 @@ get_normal_name(char *s) /* for u if (strcmp(buf, "utf-8") == 0 || strncmp(buf, "utf-8-", 6) == 0) return "utf-8"; + else if (strcmp(buf, "utf8") == 0 || + strncmp(buf, "utf8-", 6) == 0) + return "utf-8"; else if (strcmp(buf, "latin-1") == 0 || strcmp(buf, "iso-8859-1") == 0 || strcmp(buf, "iso-latin-1") == 0 ||