[Python-checkins] r50489 - in python/trunk: Lib/test/test_compile.py Misc/NEWS Python/ast.c

neal.norwitz python-checkins at python.org
Sat Jul 8 07:31:38 CEST 2006


Author: neal.norwitz
Date: Sat Jul  8 07:31:37 2006
New Revision: 50489

Modified:
   python/trunk/Lib/test/test_compile.py
   python/trunk/Misc/NEWS
   python/trunk/Python/ast.c
Log:
Fix SF bug #1519018: 'as' is now validated properly in import statements

Modified: python/trunk/Lib/test/test_compile.py
==============================================================================
--- python/trunk/Lib/test/test_compile.py	(original)
+++ python/trunk/Lib/test/test_compile.py	Sat Jul  8 07:31:37 2006
@@ -238,6 +238,8 @@
         succeed = [
             'import sys',
             'import os, sys',
+            'import os as bar',
+            'import os.path as bar',
             'from __future__ import nested_scopes, generators',
             'from __future__ import (nested_scopes,\ngenerators)',
             'from __future__ import (nested_scopes,\ngenerators,)',
@@ -257,6 +259,8 @@
             'import (sys',
             'import sys)',
             'import (os,)',
+            'import os As bar',
+            'import os.path a bar',
             'from (sys) import stdin',
             'from __future__ import (nested_scopes',
             'from __future__ import nested_scopes)',

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat Jul  8 07:31:37 2006
@@ -22,6 +22,8 @@
   omit a default "error" argument for NULL pointer.  This allows
   the parser to take a codec from cjkcodecs again.
 
+- Bug #1519018: 'as' is now validated properly in import statements.
+
 Library
 -------
 

Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c	(original)
+++ python/trunk/Python/ast.c	Sat Jul  8 07:31:37 2006
@@ -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;


More information about the Python-checkins mailing list