]> granicus.if.org Git - python/commitdiff
backport r67077 from the trunk: parser module now correctly validates relative imports
authorBenjamin Peterson <benjamin@python.org>
Mon, 3 Nov 2008 15:19:35 +0000 (15:19 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 3 Nov 2008 15:19:35 +0000 (15:19 +0000)
Lib/test/test_parser.py
Misc/ACKS
Misc/NEWS
Modules/parsermodule.c

index 8aa1657e621a67d756a58f8b7f66d31bf074811e..d76db6ce686324726bea3c491d9c15332c46170d 100644 (file)
@@ -1,4 +1,5 @@
 import parser
+import os
 import unittest
 from test import test_support
 
@@ -168,6 +169,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
             "from sys.path import (dirname, basename as my_basename)")
         self.check_suite(
             "from sys.path import (dirname, basename as my_basename,)")
+        self.check_suite("from .bogus import x")
 
     def test_basic_import_statement(self):
         self.check_suite("import sys")
index c3a0942d292463c583a7ebd935c6b4f1013d29f9..dddc40db6cdc0d0faa45d7fc2274528fa66724d6 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -60,6 +60,7 @@ Eric Beser
 Steven Bethard
 Stephen Bevan
 Ron Bickers
+David Binger
 Dominic Binks
 Philippe Biondi
 Stuart Bishop
index 6e8a25ad60fd11b2077ed4fe082cb48b382c3e78..c8651c182059445d48be9153d9ca3c5f554b8861 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.5.3?
 Core and builtins
 -----------------
 
+- Issue #4048: The parser module now correctly validates relative imports.
+
 - Issue #4176: Fixed a crash when pickling an object which ``__reduce__``
   method does not return iterators for the 4th and 5th items.
 
index e33197e396e3a0ecf9c981f9c45d3cb104ca512d..e49e6000c4d04e899172463cb26ce14fff22b255 100644 (file)
@@ -1804,10 +1804,10 @@ static int
 count_from_dots(node *tree)
 {
         int i;
-        for (i = 0; i < NCH(tree); i++)
+        for (i = 1; i < NCH(tree); i++)
                if (TYPE(CHILD(tree, i)) != DOT)
                        break;
-        return i;
+        return i-1;
 }
 
 /* 'from' ('.'* dotted_name | '.') 'import' ('*' | '(' import_as_names ')' |