summaryrefslogtreecommitdiffstats
path: root/Modules/parsermodule.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-01-07 05:59:59 (GMT)
committerFred Drake <fdrake@acm.org>2001-01-07 05:59:59 (GMT)
commit711370831afa0a50a2d4e59caebda622fc9fcb48 (patch)
tree2f8f76abe59cfa07488ca18a8f208df9fb818618 /Modules/parsermodule.c
parent1109db443efdc2451a01c3734c08fc224e9afa7e (diff)
downloadcpython-711370831afa0a50a2d4e59caebda622fc9fcb48.zip
cpython-711370831afa0a50a2d4e59caebda622fc9fcb48.tar.gz
cpython-711370831afa0a50a2d4e59caebda622fc9fcb48.tar.bz2
Fix problems with validation of import statement parse trees.
This closes SF bug #127271.
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r--Modules/parsermodule.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 8019c3a..030b5cd 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -1558,6 +1558,25 @@ validate_import_as_name(node *tree)
}
+/* dotted_name: NAME ("." NAME)*
+ */
+static int
+validate_dotted_name(node *tree)
+{
+ int nch = NCH(tree);
+ int res = (validate_ntype(tree, dotted_name)
+ && is_odd(nch)
+ && validate_name(CHILD(tree, 0), NULL));
+ int i;
+
+ for (i = 1; res && (i < nch); i += 2) {
+ res = (validate_dot(CHILD(tree, i))
+ && validate_name(CHILD(tree, i+1), NULL));
+ }
+ return res;
+}
+
+
/* dotted_as_name: dotted_name [NAME NAME]
*/
static int
@@ -1568,9 +1587,9 @@ validate_dotted_as_name(node *tree)
if (res) {
if (nch == 1)
- res = validate_ntype(CHILD(tree, 0), dotted_name);
+ res = validate_dotted_name(CHILD(tree, 0));
else if (nch == 3)
- res = (validate_ntype(CHILD(tree, 0), dotted_name)
+ res = (validate_dotted_name(CHILD(tree, 0))
&& validate_name(CHILD(tree, 1), "as")
&& validate_name(CHILD(tree, 2), NULL));
else {
@@ -1601,12 +1620,12 @@ validate_import_stmt(node *tree)
res = validate_dotted_as_name(CHILD(tree, 1));
for (j = 2; res && (j < nch); j += 2)
res = (validate_comma(CHILD(tree, j))
- && validate_ntype(CHILD(tree, j + 1), dotted_name));
+ && validate_dotted_as_name(CHILD(tree, j + 1)));
}
else if (res && (res = validate_name(CHILD(tree, 0), "from"))) {
res = ((nch >= 4) && is_even(nch)
- && validate_name(CHILD(tree, 2), "import")
- && validate_dotted_as_name(CHILD(tree, 1)));
+ && validate_dotted_name(CHILD(tree, 1))
+ && validate_name(CHILD(tree, 2), "import"));
if (nch == 4) {
if (TYPE(CHILD(tree, 3)) == import_as_name)
res = validate_import_as_name(CHILD(tree, 3));