[Python-checkins] r43227 - in python/branches/release24-maint: Lib/test/test_compile.py Misc/NEWS Python/compile.c
martin.v.loewis
python-checkins at python.org
Wed Mar 22 14:55:51 CET 2006
Author: martin.v.loewis
Date: Wed Mar 22 14:55:50 2006
New Revision: 43227
Modified:
python/branches/release24-maint/Lib/test/test_compile.py
python/branches/release24-maint/Misc/NEWS
python/branches/release24-maint/Python/compile.c
Log:
Change SystemError into SyntaxError, when a Unicode string
containing an encoding declaration is compile()d. Fixes
#1115379.
Modified: python/branches/release24-maint/Lib/test/test_compile.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_compile.py (original)
+++ python/branches/release24-maint/Lib/test/test_compile.py Wed Mar 22 14:55:50 2006
@@ -261,6 +261,10 @@
f1, f2 = f()
self.assertNotEqual(id(f1.func_code), id(f2.func_code))
+ def test_unicode_encoding(self):
+ # SF bug 1115379
+ self.assertRaises(SyntaxError, compile, u"# -*- coding: utf-8 -*-\npass\n", "tmp", "exec")
+
def test_main():
test_support.run_unittest(TestSpecifics)
Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS (original)
+++ python/branches/release24-maint/Misc/NEWS Wed Mar 22 14:55:50 2006
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- Bug #1115379: Compiling a Unicode string with an encoding declaration
+ now gives a SyntaxError.
+
- Fix missing check on whether the PendingDeprecationWarning for string
exceptions was re-raised as an actual PendingDeprecationWarning when
'warnings' is set to a filter action of "error"
Modified: python/branches/release24-maint/Python/compile.c
==============================================================================
--- python/branches/release24-maint/Python/compile.c (original)
+++ python/branches/release24-maint/Python/compile.c Wed Mar 22 14:55:50 2006
@@ -4952,6 +4952,12 @@
return NULL;
if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) {
sc.c_encoding = "utf-8";
+ if (TYPE(n) == encoding_decl) {
+ com_error(&sc, PyExc_SyntaxError,
+ "encoding declaration in Unicode string");
+ co = NULL;
+ goto exit;
+ }
} else if (TYPE(n) == encoding_decl) {
sc.c_encoding = STR(n);
n = CHILD(n, 0);
@@ -5044,7 +5050,7 @@
PyErr_SetString(PyExc_SystemError, "lost syntax error");
}
exit:
- if (base == NULL) {
+ if (base == NULL && sc.c_symtable != NULL) {
PySymtable_Free(sc.c_symtable);
sc.c_symtable = NULL;
}
More information about the Python-checkins
mailing list