From c31c0dfba3c87674e2ab991cfe94c31446b21eb9 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Mon, 10 Feb 2003 01:57:51 +0000 Subject: [PATCH] Partial backport for changes to fix SF bug #678518 (assert & global). --- Lib/test/test_parser.py | 13 +++++++++++++ Misc/NEWS | 2 ++ Modules/parsermodule.c | 6 ++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index cbe1de6aad66..d5c7583048f4 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -137,6 +137,9 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase): self.check_suite("import sys as system, math") self.check_suite("import sys, math as my_math") + def test_assert(self): + self.check_suite("assert alo < ahi and blo < bhi\n") + # # Second, we take *invalid* trees and make sure we get ParserError # rejections for them. @@ -357,6 +360,16 @@ class IllegalSyntaxTestCase(unittest.TestCase): (0, '')) self.check_bad_tree(tree, "a $= b") + def test_malformed_global(self): + #doesn't have global keyword in ast + tree = (257, + (264, + (265, + (266, + (282, (1, 'foo'))), (4, ''))), + (4, ''), + (0, '')) + self.check_bad_tree(tree, "malformed global ast") def test_main(): loader = unittest.TestLoader() diff --git a/Misc/NEWS b/Misc/NEWS index 6e6a34014db3..df94add92f1f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2,6 +2,8 @@ What's New in Python 2.2.3 ? Release date: XX-XXX-2003 ============================ +- SF bug #678518: fix some bugs in the parser module. + - Bastion.py and rexec.py are disabled. These modules are not safe in Python 2.2. or 2.3. diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 20db86e1fe2a..945c9231bf57 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -1692,6 +1692,9 @@ validate_global_stmt(node *tree) int res = (validate_ntype(tree, global_stmt) && is_even(nch) && (nch >= 2)); + if (!res && !PyErr_Occurred()) + err_string("illegal global statement"); + if (res) res = (validate_name(CHILD(tree, 0), "global") && validate_ntype(CHILD(tree, 1), NAME)); @@ -1739,8 +1742,7 @@ validate_assert_stmt(node *tree) int nch = NCH(tree); int res = (validate_ntype(tree, assert_stmt) && ((nch == 2) || (nch == 4)) - && (validate_name(CHILD(tree, 0), "__assert__") || - validate_name(CHILD(tree, 0), "assert")) + && (validate_name(CHILD(tree, 0), "assert")) && validate_test(CHILD(tree, 1))); if (!res && !PyErr_Occurred()) -- 2.47.3