From: <fwi...@us...> - 2009-03-13 02:22:33
|
Revision: 6094 http://jython.svn.sourceforge.net/jython/?rev=6094&view=rev Author: fwierzbicki Date: 2009-03-13 01:33:46 +0000 (Fri, 13 Mar 2009) Log Message: ----------- Fix for http://bugs.jython.org/issue1215: extra spaces in import statement break importing. Modified Paths: -------------- trunk/jython/Lib/test/test_ast_jy.py trunk/jython/NEWS trunk/jython/grammar/Python.g trunk/jython/src/org/python/antlr/GrammarActions.java Modified: trunk/jython/Lib/test/test_ast_jy.py =================================================================== --- trunk/jython/Lib/test/test_ast_jy.py 2009-03-11 17:13:03 UTC (rev 6093) +++ trunk/jython/Lib/test/test_ast_jy.py 2009-03-13 01:33:46 UTC (rev 6094) @@ -11,6 +11,17 @@ node = compile("1/2", '<unknown>', 'exec', PyCF_ONLY_AST) compile(node, "<string>", 'exec') + def test_alias_trim(self): + node = compile("import os. path", '<unknown>', 'exec', PyCF_ONLY_AST) + self.assertEquals(node.body[0].names[0].name, "os.path") + + node = compile("import os .path", '<unknown>', 'exec', PyCF_ONLY_AST) + self.assertEquals(node.body[0].names[0].name, "os.path") + + node = compile("import os . path", '<unknown>', 'exec', PyCF_ONLY_AST) + self.assertEquals(node.body[0].names[0].name, "os.path") + + #============================================================================== def test_main(verbose=None): Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-03-11 17:13:03 UTC (rev 6093) +++ trunk/jython/NEWS 2009-03-13 01:33:46 UTC (rev 6094) @@ -1,7 +1,11 @@ Jython NEWS -Jython 2.5 +Jython 2.5.0 rc 1 Bugs fixed (new numbering due to move to Roundup) + - [ 1215 ] extra spaces in import statement break importing + +Jython 2.5.0 a0 - b3 + Bugs fixed (new numbering due to move to Roundup) - [ 1126 ] ImportError raised for Java subpackages import - [ 1111 ] keyword arguments not supported on __import__ - [ 1567212 ] Jython $py.class bytecode doesn't include the .py's mtime Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2009-03-11 17:13:03 UTC (rev 6093) +++ trunk/jython/grammar/Python.g 2009-03-13 01:33:46 UTC (rev 6094) @@ -739,13 +739,13 @@ import_from : FROM (d+=DOT* dotted_name | d+=DOT+) IMPORT (STAR - -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.name), actions.makeStarAlias($STAR), actions.makeLevel($d)]) | i1=import_as_names - -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.name), actions.makeAliases($i1.atypes), actions.makeLevel($d)]) | LPAREN i2=import_as_names COMMA? RPAREN - -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.name), actions.makeAliases($i2.atypes), actions.makeLevel($d)]) ) ; @@ -778,7 +778,7 @@ : dotted_name (AS NAME)? { - $atype = new alias($NAME, $dotted_name.text, $NAME.text); + $atype = new alias($NAME, $dotted_name.name, $NAME.text); } ; @@ -791,8 +791,10 @@ ; //dotted_name: NAME ('.' NAME)* -dotted_name - : NAME (DOT attr)* +dotted_name returns [String name] + : NAME (DOT dn+=attr)* { + $name = actions.makeDottedText($NAME, $dn); + } ; //global_stmt: 'global' NAME (',' NAME)* Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2009-03-11 17:13:03 UTC (rev 6093) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2009-03-13 01:33:46 UTC (rev 6094) @@ -723,4 +723,17 @@ return s; } + public String makeDottedText(Token name, List<PythonTree> c) { + final String dot = "."; + if (c == null || c.isEmpty()) { + return name.getText(); + } + StringBuilder b = new StringBuilder(name.getText()); + for (PythonTree t : c) { + b.append(dot); + b.append(t.getToken().getText()); + } + return b.toString(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |