Mercurial > cpython-lru_cache-weakref
diff Python/ast.c @ 39034:066aa42ce5f2 legacy-trunk
Fix SF bug #1519018: 'as' is now validated properly in import statements
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Sat, 08 Jul 2006 05:31:37 +0000 |
| parents | 8f7c7aeac3a5 |
| children | 9f70f6ba7b69 |
line wrap: on
line diff
--- a/Python/ast.c Fri Jul 07 08:15:12 2006 +0000 +++ b/Python/ast.c Sat Jul 08 05:31:37 2006 +0000 @@ -2142,7 +2142,14 @@ loop: switch (TYPE(n)) { case import_as_name: - str = (NCH(n) == 3) ? NEW_IDENTIFIER(CHILD(n, 2)) : NULL; + str = NULL; + if (NCH(n) == 3) { + if (strcmp(STR(CHILD(n, 1)), "as") != 0) { + ast_error(n, "must use 'as' in import"); + return NULL; + } + str = NEW_IDENTIFIER(CHILD(n, 2)); + } return alias(NEW_IDENTIFIER(CHILD(n, 0)), str, c->c_arena); case dotted_as_name: if (NCH(n) == 1) { @@ -2151,6 +2158,10 @@ } else { alias_ty a = alias_for_import_name(c, CHILD(n, 0)); + if (strcmp(STR(CHILD(n, 1)), "as") != 0) { + ast_error(n, "must use 'as' in import"); + return NULL; + } assert(!a->asname); a->asname = NEW_IDENTIFIER(CHILD(n, 2)); return a;
