You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <pj...@us...> - 2008-11-27 20:56:19
|
Revision: 5647 http://jython.svn.sourceforge.net/jython/?rev=5647&view=rev Author: pjenvey Date: 2008-11-27 20:56:10 +0000 (Thu, 27 Nov 2008) Log Message: ----------- o explicitly convert Strings returned from ExposedGet to str (instead of unicode), just as ExposedMethod does. restores the behavior it had before the big Java integration String/unicode change o add a TypeError message for PyDataDescr.__set__ failed conversions Modified Paths: -------------- trunk/jython/src/org/python/core/PyDataDescr.java trunk/jython/src/org/python/expose/generate/DescriptorExposer.java Modified: trunk/jython/src/org/python/core/PyDataDescr.java =================================================================== --- trunk/jython/src/org/python/core/PyDataDescr.java 2008-11-27 04:52:37 UTC (rev 5646) +++ trunk/jython/src/org/python/core/PyDataDescr.java 2008-11-27 20:56:10 UTC (rev 5647) @@ -75,9 +75,12 @@ @ExposedMethod public void getset_descriptor___set__(PyObject obj, PyObject value) { checkGetterType(obj.getType()); + // XXX: We may want to special case value being PyUnicode and ofType being String + // (then explicitly value.encode() first) Object converted = value.__tojava__(ofType); if(converted == Py.NoConversion) { - throw Py.TypeError(""); // xxx + throw Py.TypeError(String.format("unsupported type for assignment to %s: '%.200s'", + name, value.getType().fastGetName())); } invokeSet(obj, converted); } Modified: trunk/jython/src/org/python/expose/generate/DescriptorExposer.java =================================================================== --- trunk/jython/src/org/python/expose/generate/DescriptorExposer.java 2008-11-27 04:52:37 UTC (rev 5646) +++ trunk/jython/src/org/python/expose/generate/DescriptorExposer.java 2008-11-27 20:56:10 UTC (rev 5647) @@ -139,7 +139,7 @@ mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, onType.getInternalName()); call(onType, getterMethodName, ofType); - if(PRIMITIVES.containsKey(ofType)) { + if(PRIMITIVES.containsKey(ofType) || ofType.equals(STRING)) { toPy(ofType); } endMethod(ARETURN); @@ -153,7 +153,7 @@ onType.getInternalName(), getterFieldName, ofType.getDescriptor()); - if(PRIMITIVES.containsKey(ofType)) { + if(PRIMITIVES.containsKey(ofType) || ofType.equals(STRING)) { toPy(ofType); } endMethod(ARETURN); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-27 04:52:48
|
Revision: 5646 http://jython.svn.sourceforge.net/jython/?rev=5646&view=rev Author: pjenvey Date: 2008-11-27 04:52:37 +0000 (Thu, 27 Nov 2008) Log Message: ----------- temporarily store genexps in Java's frame instead of PyFrame. the latter could modify f_locals when cleaning up the temp slot, which causes an obscure bug if the genexp is iterating over that same f_locals (dict changed size during iteration). e.g., in a module's top level: __all__ = tuple(x for x in locals() if x.isupper()) Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Added Paths: ----------- trunk/jython/Lib/test/test_genexps_jy.py Added: trunk/jython/Lib/test/test_genexps_jy.py =================================================================== --- trunk/jython/Lib/test/test_genexps_jy.py (rev 0) +++ trunk/jython/Lib/test/test_genexps_jy.py 2008-11-27 04:52:37 UTC (rev 5646) @@ -0,0 +1,23 @@ +"""Misc generator expression tests + +Made for Jython. +""" +import unittest +from test import test_support + +locals_test = list(local for local in locals() if not local.startswith('_')) + +class GeneratorExpressionsTestCase(unittest.TestCase): + + def test_module_level_locals(self): + # NOTE: The locals_test genexp used to cause a 'dictionary + # changed size during iteration' RuntimeError. If we've gotten + # this far we've already passed + self.assert_(sorted(locals_test) == ['test_support', 'unittest']) + + +def test_main(): + test_support.run_unittest(GeneratorExpressionsTestCase) + +if __name__ == '__main__': + test_main() Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-11-27 04:01:27 UTC (rev 5645) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-11-27 04:52:37 UTC (rev 5646) @@ -2155,7 +2155,6 @@ @Override public Object visitGeneratorExp(GeneratorExp node) throws Exception { String bound_exp = "_(x)"; - String tmp_append ="_(" + node.getLine() + "_" + node.getCharPositionInLine() + ")"; setline(node); @@ -2189,7 +2188,7 @@ } } - module.PyCode(new Suite(node, new stmtType[]{n}), tmp_append, true, + module.PyCode(new Suite(node, new stmtType[]{n}), "<genexpr>", true, className, false, false, node.getLine(), scope, cflags).get(code); @@ -2199,17 +2198,15 @@ } else { code.invokespecial( "org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); } + int genExp = storeTop(); - set(new Name(node, tmp_append, expr_contextType.Store)); - visit(iter); - visit(new Name(node, tmp_append, expr_contextType.Load)); + code.aload(genExp); + code.freeLocal(genExp); code.swap(); code.invokevirtual("org/python/core/PyObject", "__iter__", "()Lorg/python/core/PyObject;"); code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); - visit(new Delete(n, new exprType[] { new Name(n, tmp_append, expr_contextType.Del) })); - return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-27 04:01:32
|
Revision: 5645 http://jython.svn.sourceforge.net/jython/?rev=5645&view=rev Author: fwierzbicki Date: 2008-11-27 04:01:27 +0000 (Thu, 27 Nov 2008) Log Message: ----------- Make PythonTree (and thus most of the ast nodes) extend PyObject instead of Antlr's CommonTree. This required pulling in much of the CommonTree code for now. Hopefully I can prune some of it out in time. Also PythonTreeAdaptor had to override more of CommonTreeAdaptor's methods. Modified Paths: -------------- trunk/jython/src/org/python/antlr/GrammarActions.java trunk/jython/src/org/python/antlr/ParseException.java trunk/jython/src/org/python/antlr/PythonErrorNode.java trunk/jython/src/org/python/antlr/PythonTree.java trunk/jython/src/org/python/antlr/PythonTreeAdaptor.java trunk/jython/src/org/python/compiler/ScopesCompiler.java Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2008-11-27 03:30:23 UTC (rev 5644) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2008-11-27 04:01:27 UTC (rev 5645) @@ -2,7 +2,6 @@ import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; -import org.antlr.runtime.tree.Tree; import org.python.core.Py; import org.python.core.PyComplex; @@ -300,7 +299,7 @@ return value; } - void recurseSetContext(Tree tree, expr_contextType context) { + void recurseSetContext(PythonTree tree, expr_contextType context) { if (tree instanceof Context) { ((Context)tree).setContext(context); } Modified: trunk/jython/src/org/python/antlr/ParseException.java =================================================================== --- trunk/jython/src/org/python/antlr/ParseException.java 2008-11-27 03:30:23 UTC (rev 5644) +++ trunk/jython/src/org/python/antlr/ParseException.java 2008-11-27 04:01:27 UTC (rev 5645) @@ -38,7 +38,7 @@ public ParseException(String message, PythonTree n) { this(message, n.getLine(), n.getCharPositionInLine()); this.node = n; - this.token = n.token; + this.token = n.getToken(); } public ParseException(String message, RecognitionException r) { Modified: trunk/jython/src/org/python/antlr/PythonErrorNode.java =================================================================== --- trunk/jython/src/org/python/antlr/PythonErrorNode.java 2008-11-27 03:30:23 UTC (rev 5644) +++ trunk/jython/src/org/python/antlr/PythonErrorNode.java 2008-11-27 04:01:27 UTC (rev 5645) @@ -24,7 +24,7 @@ return errorNode.isNil(); } - public int getType() { + public int getAntlrType() { return errorNode.getType(); } Modified: trunk/jython/src/org/python/antlr/PythonTree.java =================================================================== --- trunk/jython/src/org/python/antlr/PythonTree.java 2008-11-27 03:30:23 UTC (rev 5644) +++ trunk/jython/src/org/python/antlr/PythonTree.java 2008-11-27 04:01:27 UTC (rev 5645) @@ -1,35 +1,45 @@ package org.python.antlr; -import org.antlr.runtime.tree.BaseTree; -import org.antlr.runtime.tree.Tree; +import org.python.core.PyObject; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; +import org.antlr.runtime.tree.CommonTree; import org.python.antlr.ast.VisitorIF; -public class PythonTree extends BaseTree implements AST { +import java.util.ArrayList; +import java.util.List; +public class PythonTree extends PyObject implements AST { + public boolean from_future_checked = false; private int charStartIndex = -1; private int charStopIndex = -1; - + private CommonTree node; + private PythonTree parent; + /** A single token is the payload */ - public Token token; + //private Token token; /** What token indexes bracket all tokens associated with this node * and below? */ - protected int startIndex=-1, stopIndex=-1; + //protected int startIndex=-1, stopIndex=-1; /** Who is the parent node of this node; if null, implies node is root */ - public PythonTree parent; + //private PythonTree parent; /** What index is this node in the child list? Range: 0..n-1 */ - public int childIndex = -1; + //private int childIndex = -1; public PythonTree() { + node = new CommonTree(); } + public PythonTree(Token t) { + node = new CommonTree(t); + } + public PythonTree(int ttype, Token t) { CommonToken c = new CommonToken(ttype, t.getText()); c.setLine(t.getLine()); @@ -38,59 +48,45 @@ c.setChannel(t.getChannel()); c.setStartIndex(((CommonToken)t).getStartIndex()); c.setStopIndex(((CommonToken)t).getStopIndex()); - token = c; + node = new CommonTree(c); } - public PythonTree(Token t) { - this.token = t; + public PythonTree(PythonTree tree) { + node = new CommonTree(tree.getNode()); + charStartIndex = tree.getCharStartIndex(); + charStopIndex = tree.getCharStopIndex(); } + + public CommonTree getNode() { + return node; + } - public PythonTree(PythonTree node) { - super(node); - token = node.token; - startIndex = node.startIndex; - stopIndex = node.stopIndex; - charStartIndex = node.getCharStartIndex(); - charStopIndex = node.getCharStopIndex(); - } - public Token getToken() { - return token; + return node.getToken(); } - public Tree dupNode() { + public PythonTree dupNode() { return new PythonTree(this); } public boolean isNil() { - return token==null; + return node.isNil(); } - public int getType() { - if (token==null) { - return Token.INVALID_TOKEN_TYPE; - } - return token.getType(); + public int getAntlrType() { + return node.getType(); } public String getText() { - if (token==null) { - return null; - } - return token.getText(); + return node.getText(); } public int getLine() { - if (token==null || token.getLine()==0) { - if ( getChildCount()>0 ) { - return getChild(0).getLine(); - } - return 0; - } - return token.getLine(); + return node.getLine(); } public int getCharPositionInLine() { + Token token = node.getToken(); if (token==null || token.getCharPositionInLine()==-1) { if (getChildCount()>0) { return getChild(0).getCharPositionInLine(); @@ -107,46 +103,24 @@ } public int getTokenStartIndex() { - if ( startIndex==-1 && token!=null ) { - return token.getTokenIndex(); - } - return startIndex; + return node.getTokenStartIndex(); } public void setTokenStartIndex(int index) { - startIndex = index; + node.setTokenStartIndex(index); } public int getTokenStopIndex() { - if ( stopIndex==-1 && token!=null ) { - return token.getTokenIndex(); - } - return stopIndex; + return node.getTokenStopIndex(); } public void setTokenStopIndex(int index) { - stopIndex = index; + node.setTokenStopIndex(index); } - public int getChildIndex() { - return childIndex; - } - - public Tree getParent() { - return parent; - } - - public void setParent(Tree t) { - this.parent = (PythonTree)t; - } - - public void setChildIndex(int index) { - this.childIndex = index; - } - public int getCharStartIndex() { - if (charStartIndex == -1 && token != null) { - return ((CommonToken)token).getStartIndex(); + if (charStartIndex == -1 && node.getToken() != null) { + return ((CommonToken)node.getToken()).getStartIndex(); } return charStartIndex ; } @@ -166,8 +140,8 @@ */ public int getCharStopIndex() { - if (charStopIndex == -1 && token != null) { - return ((CommonToken)token).getStopIndex() + 1; + if (charStopIndex == -1 && node.getToken() != null) { + return ((CommonToken)node.getToken()).getStopIndex() + 1; } return charStopIndex; } @@ -176,24 +150,36 @@ charStopIndex = index; } + public int getChildIndex() { + return node.getChildIndex(); + } + + public PythonTree getParent() { + return parent; + } + + public void setParent(PythonTree t) { + this.parent = t; + } + + public void setChildIndex(int index) { + node.setChildIndex(index); + } + public String toString() { if (isNil()) { return "None"; } - if ( getType()==Token.INVALID_TOKEN_TYPE ) { + if ( getAntlrType()==Token.INVALID_TOKEN_TYPE ) { return "<errornode>"; } - if ( token==null ) { + if ( node.getToken()==null ) { return null; } - return token.getText() + "(" + this.getLine() + "," + this.getCharPositionInLine() + ")"; + return node.getToken().getText() + "(" + this.getLine() + "," + this.getCharPositionInLine() + ")"; } - public String info() { - return this.getCharStartIndex() + ":" + this.getCharStopIndex(); - } - public String toStringTree() { if (children == null || children.size() == 0) { return this.toString();// + "[" + this.info() + "]"; @@ -205,7 +191,7 @@ buf.append(' '); } for (int i = 0; children != null && i < children.size(); i++) { - BaseTree t = (BaseTree)children.get(i); + PythonTree t = (PythonTree)children.get(i); if (i > 0) { buf.append(' '); } @@ -260,4 +246,205 @@ public String[] get_attributes() { return emptyStringArray; } + + //Copied from org.antlr.runtime.tree.BaseTree + protected List children; + + public PythonTree getChild(int i) { + if ( children==null || i>=children.size() ) { + return null; + } + return (PythonTree)children.get(i); + } + + /** Get the children internal List; note that if you directly mess with + * the list, do so at your own risk. + */ + public List getChildren() { + return children; + } + + public PythonTree getFirstChildWithType(int type) { + for (int i = 0; children!=null && i < children.size(); i++) { + PythonTree t = (PythonTree) children.get(i); + if ( t.getAntlrType()==type ) { + return t; + } + } + return null; + } + + public int getChildCount() { + if ( children==null ) { + return 0; + } + return children.size(); + } + + /** Add t as child of this node. + * + * Warning: if t has no children, but child does + * and child isNil then this routine moves children to t via + * t.children = child.children; i.e., without copying the array. + */ + public void addChild(PythonTree t) { + //System.out.println("add child "+t.toStringTree()+" "+this.toStringTree()); + //System.out.println("existing children: "+children); + if ( t==null ) { + return; // do nothing upon addChild(null) + } + PythonTree childTree = (PythonTree)t; + if ( childTree.isNil() ) { // t is an empty node possibly with children + if ( this.children!=null && this.children == childTree.children ) { + throw new RuntimeException("attempt to add child list to itself"); + } + // just add all of childTree's children to this + if ( childTree.children!=null ) { + if ( this.children!=null ) { // must copy, this has children already + int n = childTree.children.size(); + for (int i = 0; i < n; i++) { + PythonTree c = (PythonTree)childTree.children.get(i); + this.children.add(c); + // handle double-link stuff for each child of nil root + c.setParent(this); + c.setChildIndex(children.size()-1); + } + } + else { + // no children for this but t has children; just set pointer + // call general freshener routine + this.children = childTree.children; + this.freshenParentAndChildIndexes(); + } + } + } + else { // child is not nil (don't care about children) + if ( children==null ) { + children = createChildrenList(); // create children list on demand + } + children.add(t); + childTree.setParent(this); + childTree.setChildIndex(children.size()-1); + } + // System.out.println("now children are: "+children); + } + + /** Add all elements of kids list as children of this node */ + public void addChildren(List kids) { + for (int i = 0; i < kids.size(); i++) { + PythonTree t = (PythonTree) kids.get(i); + addChild(t); + } + } + + public void setChild(int i, PythonTree t) { + if ( t==null ) { + return; + } + if ( t.isNil() ) { + throw new IllegalArgumentException("Can't set single child to a list"); + } + if ( children==null ) { + children = createChildrenList(); + } + children.set(i, t); + t.setParent(this); + t.setChildIndex(i); + } + + public Object deleteChild(int i) { + if ( children==null ) { + return null; + } + PythonTree killed = (PythonTree)children.remove(i); + // walk rest and decrement their child indexes + this.freshenParentAndChildIndexes(i); + return killed; + } + + /** Delete children from start to stop and replace with t even if t is + * a list (nil-root tree). num of children can increase or decrease. + * For huge child lists, inserting children can force walking rest of + * children to set their childindex; could be slow. + */ + public void replaceChildren(int startChildIndex, int stopChildIndex, Object t) { + /* + System.out.println("replaceChildren "+startChildIndex+", "+stopChildIndex+ + " with "+((PythonTree)t).toStringTree()); + System.out.println("in="+toStringTree()); + */ + if ( children==null ) { + throw new IllegalArgumentException("indexes invalid; no children in list"); + } + int replacingHowMany = stopChildIndex - startChildIndex + 1; + int replacingWithHowMany; + PythonTree newTree = (PythonTree)t; + List newChildren = null; + // normalize to a list of children to add: newChildren + if ( newTree.isNil() ) { + newChildren = newTree.children; + } + else { + newChildren = new ArrayList(1); + newChildren.add(newTree); + } + replacingWithHowMany = newChildren.size(); + int numNewChildren = newChildren.size(); + int delta = replacingHowMany - replacingWithHowMany; + // if same number of nodes, do direct replace + if ( delta == 0 ) { + int j = 0; // index into new children + for (int i=startChildIndex; i<=stopChildIndex; i++) { + PythonTree child = (PythonTree)newChildren.get(j); + children.set(i, child); + child.setParent(this); + child.setChildIndex(i); + j++; + } + } + else if ( delta > 0 ) { // fewer new nodes than there were + // set children and then delete extra + for (int j=0; j<numNewChildren; j++) { + children.set(startChildIndex+j, newChildren.get(j)); + } + int indexToDelete = startChildIndex+numNewChildren; + for (int c=indexToDelete; c<=stopChildIndex; c++) { + // delete same index, shifting everybody down each time + PythonTree killed = (PythonTree)children.remove(indexToDelete); + } + freshenParentAndChildIndexes(startChildIndex); + } + else { // more new nodes than were there before + // fill in as many children as we can (replacingHowMany) w/o moving data + for (int j=0; j<replacingHowMany; j++) { + children.set(startChildIndex+j, newChildren.get(j)); + } + int numToInsert = replacingWithHowMany-replacingHowMany; + for (int j=replacingHowMany; j<replacingWithHowMany; j++) { + children.add(startChildIndex+j, newChildren.get(j)); + } + freshenParentAndChildIndexes(startChildIndex); + } + //System.out.println("out="+toStringTree()); + } + + /** Override in a subclass to change the impl of children list */ + protected List createChildrenList() { + return new ArrayList(); + } + + /** Set the parent and child index values for all child of t */ + public void freshenParentAndChildIndexes() { + freshenParentAndChildIndexes(0); + } + + public void freshenParentAndChildIndexes(int offset) { + int n = getChildCount(); + for (int c = offset; c < n; c++) { + PythonTree child = (PythonTree)getChild(c); + child.setChildIndex(c); + child.setParent(this); + } + } + } Modified: trunk/jython/src/org/python/antlr/PythonTreeAdaptor.java =================================================================== --- trunk/jython/src/org/python/antlr/PythonTreeAdaptor.java 2008-11-27 03:30:23 UTC (rev 5644) +++ trunk/jython/src/org/python/antlr/PythonTreeAdaptor.java 2008-11-27 04:01:27 UTC (rev 5645) @@ -49,6 +49,104 @@ if (t == null) { return null; } - return create(((PythonTree) t).token); + return create(((PythonTree) t).getToken()); } + + public boolean isNil(Object tree) { + return ((PythonTree)tree).isNil(); + } + + public void addChild(Object t, Object child) { + if ( t!=null && child!=null ) { + ((PythonTree)t).addChild((PythonTree)child); + } + } + + public Object becomeRoot(Object newRoot, Object oldRoot) { + //System.out.println("becomeroot new "+newRoot.toString()+" old "+oldRoot); + PythonTree newRootTree = (PythonTree)newRoot; + PythonTree oldRootTree = (PythonTree)oldRoot; + if ( oldRoot==null ) { + return newRoot; + } + // handle ^(nil real-node) + if ( newRootTree.isNil() ) { + int nc = newRootTree.getChildCount(); + if ( nc==1 ) newRootTree = (PythonTree)newRootTree.getChild(0); + else if ( nc >1 ) { + // TODO: make tree run time exceptions hierarchy + throw new RuntimeException("more than one node as root (TODO: make exception hierarchy)"); + } + } + // add oldRoot to newRoot; addChild takes care of case where oldRoot + // is a flat list (i.e., nil-rooted tree). All children of oldRoot + // are added to newRoot. + newRootTree.addChild(oldRootTree); + return newRootTree; + } + + public Object rulePostProcessing(Object root) { + //System.out.println("rulePostProcessing: "+((PythonTree)root).toStringTree()); + PythonTree r = (PythonTree)root; + if ( r!=null && r.isNil() ) { + if ( r.getChildCount()==0 ) { + r = null; + } + else if ( r.getChildCount()==1 ) { + r = (PythonTree)r.getChild(0); + // whoever invokes rule will set parent and child index + r.setParent(null); + r.setChildIndex(-1); + } + } + return r; + } + + public Object create(int tokenType, Token fromToken) { + fromToken = createToken(fromToken); + //((ClassicToken)fromToken).setType(tokenType); + fromToken.setType(tokenType); + PythonTree t = (PythonTree)create(fromToken); + return t; + } + + public Object create(int tokenType, Token fromToken, String text) { + fromToken = createToken(fromToken); + fromToken.setType(tokenType); + fromToken.setText(text); + PythonTree t = (PythonTree)create(fromToken); + return t; + } + + public Object create(int tokenType, String text) { + Token fromToken = createToken(tokenType, text); + PythonTree t = (PythonTree)create(fromToken); + return t; + } + + public int getType(Object t) { + ((PythonTree)t).getType(); + return 0; + } + + public String getText(Object t) { + return ((PythonTree)t).getText(); + } + + public Object getChild(Object t, int i) { + return ((PythonTree)t).getChild(i); + } + + public void setChild(Object t, int i, Object child) { + ((PythonTree)t).setChild(i, (PythonTree)child); + } + + public Object deleteChild(Object t, int i) { + return ((PythonTree)t).deleteChild(i); + } + + public int getChildCount(Object t) { + return ((PythonTree)t).getChildCount(); + } + } Modified: trunk/jython/src/org/python/compiler/ScopesCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/ScopesCompiler.java 2008-11-27 03:30:23 UTC (rev 5644) +++ trunk/jython/src/org/python/compiler/ScopesCompiler.java 2008-11-27 04:01:27 UTC (rev 5645) @@ -290,7 +290,7 @@ def(tmp); ArgListCompiler ac = new ArgListCompiler(); ac.visitArgs(new argumentsType(node, new exprType[] { new Name( - node.token, bound_exp, expr_contextType.Param) }, null, null, + node.getToken(), bound_exp, expr_contextType.Param) }, null, null, new exprType[0])); beginScope(tmp, FUNCSCOPE, node, ac); cur.addParam(bound_exp); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-27 03:30:29
|
Revision: 5644 http://jython.svn.sourceforge.net/jython/?rev=5644&view=rev Author: pjenvey Date: 2008-11-27 03:30:23 +0000 (Thu, 27 Nov 2008) Log Message: ----------- update/clarify comment Modified Paths: -------------- trunk/jython/Lib/test/test_genexps.py Modified: trunk/jython/Lib/test/test_genexps.py =================================================================== --- trunk/jython/Lib/test/test_genexps.py 2008-11-26 19:43:27 UTC (rev 5643) +++ trunk/jython/Lib/test/test_genexps.py 2008-11-27 03:30:23 UTC (rev 5644) @@ -1,9 +1,8 @@ -#From http://svn.python.org/projects/python/branches/release25-maint/Lib/test_genexps.py@51333 +# From http://svn.python.org/projects/python/branches/release25-maint/Lib/test_genexps.py@51333 -#Ignoring details of SyntaxError for now -- justified I think for "invalid +# Ignoring details of SyntaxError for now -- justified I think for "invalid # syntax" since that #message has very little info, where Antlr provides more -# detail. The others really are #differences that should be addressed, but I -# want to concentrate on the other errors for now. +# detail. doctests = """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-26 19:43:32
|
Revision: 5643 http://jython.svn.sourceforge.net/jython/?rev=5643&view=rev Author: fwierzbicki Date: 2008-11-26 19:43:27 +0000 (Wed, 26 Nov 2008) Log Message: ----------- Migrated to Python.asdl from CPython 2.6. Modified Paths: -------------- branches/astwrite/Lib/inspect.py branches/astwrite/Lib/test/test_ast.py branches/astwrite/ast/Python.asdl branches/astwrite/ast/asdl_antlr.py branches/astwrite/grammar/Python.g branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java branches/astwrite/src/org/python/antlr/ast/ClassDef.java branches/astwrite/src/org/python/antlr/ast/FunctionDef.java branches/astwrite/src/org/python/antlr/ast/VisitorBase.java branches/astwrite/src/org/python/antlr/ast/VisitorIF.java branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java branches/astwrite/src/org/python/compiler/CodeCompiler.java branches/astwrite/src/org/python/compiler/ScopesCompiler.java Added Paths: ----------- branches/astwrite/src/org/python/antlr/ast/ExceptHandler.java Modified: branches/astwrite/Lib/inspect.py =================================================================== --- branches/astwrite/Lib/inspect.py 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/Lib/inspect.py 2008-11-26 19:43:27 UTC (rev 5643) @@ -315,6 +315,13 @@ return None if not isinstance(doc, types.StringTypes): return None + return cleandoc(doc) + +def cleandoc(doc): + """Clean up indentation from docstrings. + + Any whitespace that can be uniformly removed from the second line + onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: Modified: branches/astwrite/Lib/test/test_ast.py =================================================================== --- branches/astwrite/Lib/test/test_ast.py 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/Lib/test/test_ast.py 2008-11-26 19:43:27 UTC (rev 5643) @@ -250,12 +250,12 @@ [ast.Str('eggs')], [], None, None))) self.assertEqual(src, ast.fix_missing_locations(src)) self.assertEqual(ast.dump(src, include_attributes=True), - "Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), " + u"Module(body=[Expr(value=Call(func=Name(id=u'write', ctx=Load(), " "lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, " "col_offset=6)], keywords=[], starargs=None, kwargs=None, " "lineno=1, col_offset=0), lineno=1, col_offset=0), " - "Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, " - "col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], " + "Expr(value=Call(func=Name(id=u'spam', ctx=Load(), lineno=1, " + "col_offset=0), args=[Str(s=u'eggs', lineno=1, col_offset=0)], " "keywords=[], starargs=None, kwargs=None, lineno=1, " "col_offset=0), lineno=1, col_offset=0)])" ) @@ -280,11 +280,11 @@ node = ast.parse("spam(23, 42, eggs='leek')", mode='eval') self.assertEqual(len(list(ast.iter_child_nodes(node.body))), 4) iterator = ast.iter_child_nodes(node.body) - self.assertEqual(next(iterator).id, 'spam') - self.assertEqual(next(iterator).n, 23) - self.assertEqual(next(iterator).n, 42) - self.assertEqual(ast.dump(next(iterator)), - "keyword(arg='eggs', value=Str(s='leek'))" + self.assertEqual(iterator.next().id, 'spam') + self.assertEqual(iterator.next().n, 23) + self.assertEqual(iterator.next().n, 42) + self.assertEqual(ast.dump(iterator.next()), + u"keyword(arg=u'eggs', value=Str(s='leek'))" ) def test_get_docstring(self): Modified: branches/astwrite/ast/Python.asdl =================================================================== --- branches/astwrite/ast/Python.asdl 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/ast/Python.asdl 2008-11-26 19:43:27 UTC (rev 5643) @@ -1,6 +1,6 @@ -- ASDL's five builtin types are identifier, int, string, object, bool -module Python version "$Revision: 53731 $" +module Python version "$Revision: 62047 $" { mod = Module(stmt* body) | Interactive(stmt* body) @@ -10,9 +10,8 @@ | Suite(stmt* body) stmt = FunctionDef(identifier name, arguments args, - stmt* body, expr* decorators) - | ClassDef(identifier name, expr* bases, - stmt* body, expr* decorators) + stmt* body, expr* decorator_list) + | ClassDef(identifier name, expr* bases, stmt* body, expr *decorator_list) | Return(expr? value) | Delete(expr* targets) @@ -29,6 +28,7 @@ | With(expr context_expr, expr? optional_vars, stmt* body) -- 'type' is a bad name + -- changed to 'type' to excepttype for Jython | Raise(expr? excepttype, expr? inst, expr? tback) | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse) | TryFinally(stmt* body, stmt* finalbody) @@ -99,11 +99,9 @@ comprehension = (expr target, expr iter, expr* ifs) -- not sure what to call the first argument for raise and except - -- TODO(jhylton): Figure out if there is a better way to handle - -- lineno and col_offset fields, particularly when - -- ast is exposed to Python. - excepthandler = (expr? excepttype, expr? name, stmt* body, int lineno, - int col_offset) + -- changed to 'type' to excepttype for Jython + excepthandler = ExceptHandler(expr? excepttype, expr? name, stmt* body) + attributes (int lineno, int col_offset) arguments = (expr* args, identifier? vararg, identifier? kwarg, expr* defaults) Modified: branches/astwrite/ast/asdl_antlr.py =================================================================== --- branches/astwrite/ast/asdl_antlr.py 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/ast/asdl_antlr.py 2008-11-26 19:43:27 UTC (rev 5643) @@ -134,7 +134,7 @@ self.visit(type.value, type.name, depth) def visitSum(self, sum, name, depth): - if sum.simple: + if sum.simple and not name == "excepthandler": self.simple_sum(sum, name, depth) else: self.sum_with_constructor(sum, name, depth) @@ -261,7 +261,7 @@ self.emit("}", depth + 1) self.emit("", 0) - if str(name) in ('stmt', 'expr'): + if str(name) in ('stmt', 'expr', 'excepthandler'): # The lineno property self.emit("private int lineno = -1;", depth + 1) self.emit("public int getLineno() {", depth + 1) @@ -290,6 +290,7 @@ self.emit("}", depth + 1) self.emit("", 0) + self.emit("}", depth) self.close() Modified: branches/astwrite/grammar/Python.g =================================================================== --- branches/astwrite/grammar/Python.g 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/grammar/Python.g 2008-11-26 19:43:27 UTC (rev 5643) @@ -102,7 +102,7 @@ import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; import org.python.antlr.ast.Ellipsis; -import org.python.antlr.ast.excepthandlerType; +import org.python.antlr.ast.ExceptHandler; import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; import org.python.antlr.ast.Expression; @@ -918,8 +918,8 @@ //except_clause: 'except' [test [',' test]] except_clause : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite[!$suite.isEmpty() && $suite::continueIllegal] - -> ^(EXCEPT<excepthandlerType>[$EXCEPT, actions.castExpr($t1.tree), actions.castExpr($t2.tree), - actions.castStmts($suite.stypes), $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine()]) + -> ^(EXCEPT<ExceptHandler>[$EXCEPT, actions.castExpr($t1.tree), actions.castExpr($t2.tree), + actions.castStmts($suite.stypes)]) ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT Modified: branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -3,7 +3,7 @@ import org.python.core.Py; import org.python.core.PyJavaInstance; -import org.python.antlr.ast.excepthandlerType; +import org.python.antlr.ast.ExceptHandler; import org.python.antlr.ast.Num; import java.util.ArrayList; @@ -16,9 +16,9 @@ return o; } if (o instanceof PyJavaInstance) { - o = ((PyJavaInstance)o).__tojava__(excepthandlerType.class); + o = ((PyJavaInstance)o).__tojava__(ExceptHandler.class); } - if (o instanceof excepthandlerType) { + if (o instanceof ExceptHandler) { return o; } @@ -27,9 +27,9 @@ } public Object adaptIter(Object iter) { - List<excepthandlerType> excepthandlers = new ArrayList<excepthandlerType>(); + List<ExceptHandler> excepthandlers = new ArrayList<ExceptHandler>(); for(Object o : (Iterable)iter) { - excepthandlers.add((excepthandlerType)adapt(o)); + excepthandlers.add((ExceptHandler)adapt(o)); } return excepthandlers; } Modified: branches/astwrite/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -43,32 +43,34 @@ this.body = AstAdapters.to_stmtList(body); } - private java.util.List<exprType> decorators; - public java.util.List<exprType> getInternalDecorators() { - return decorators; + private java.util.List<exprType> decorator_list; + public java.util.List<exprType> getInternalDecorator_list() { + return decorator_list; } - public Object getDecorators() { - return new ListWrapper(decorators, AstAdapters.exprAdapter); + public Object getDecorator_list() { + return new ListWrapper(decorator_list, AstAdapters.exprAdapter); } - public void setDecorators(Object decorators) { - this.decorators = AstAdapters.to_exprList(decorators); + public void setDecorator_list(Object decorator_list) { + this.decorator_list = AstAdapters.to_exprList(decorator_list); } private final static String[] fields = new String[] {"name", "bases", - "body", "decorators"}; + "body", + "decorator_list"}; public String[] get_fields() { return fields; } public ClassDef() {} - public ClassDef(Object name, Object bases, Object body, Object decorators) { + public ClassDef(Object name, Object bases, Object body, Object + decorator_list) { setName(name); setBases(bases); setBody(body); - setDecorators(decorators); + setDecorator_list(decorator_list); } public ClassDef(Token token, String name, java.util.List<exprType> bases, - java.util.List<stmtType> body, java.util.List<exprType> decorators) { + java.util.List<stmtType> body, java.util.List<exprType> decorator_list) { super(token); this.name = name; this.bases = bases; @@ -85,18 +87,18 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } public ClassDef(Integer ttype, Token token, String name, java.util.List<exprType> bases, java.util.List<stmtType> body, - java.util.List<exprType> decorators) { + java.util.List<exprType> decorator_list) { super(ttype, token); this.name = name; this.bases = bases; @@ -113,17 +115,18 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } public ClassDef(PythonTree tree, String name, java.util.List<exprType> - bases, java.util.List<stmtType> body, java.util.List<exprType> decorators) { + bases, java.util.List<stmtType> body, java.util.List<exprType> + decorator_list) { super(tree); this.name = name; this.bases = bases; @@ -140,11 +143,11 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } @@ -164,8 +167,8 @@ sb.append("body="); sb.append(dumpThis(body)); sb.append(","); - sb.append("decorators="); - sb.append(dumpThis(decorators)); + sb.append("decorator_list="); + sb.append(dumpThis(decorator_list)); sb.append(","); sb.append(")"); return sb.toString(); @@ -188,8 +191,8 @@ t.accept(visitor); } } - if (decorators != null) { - for (PythonTree t : decorators) { + if (decorator_list != null) { + for (PythonTree t : decorator_list) { if (t != null) t.accept(visitor); } Added: branches/astwrite/src/org/python/antlr/ast/ExceptHandler.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ExceptHandler.java (rev 0) +++ branches/astwrite/src/org/python/antlr/ast/ExceptHandler.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -0,0 +1,166 @@ +// Autogenerated AST node +package org.python.antlr.ast; +import java.util.ArrayList; +import org.python.antlr.PythonTree; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.Token; +import java.io.DataOutputStream; +import java.io.IOException; + +public class ExceptHandler extends excepthandlerType { + private exprType excepttype; + public exprType getInternalExcepttype() { + return excepttype; + } + public Object getExcepttype() { + return excepttype; + } + public void setExcepttype(Object excepttype) { + this.excepttype = AstAdapters.to_expr(excepttype); + } + + private exprType name; + public exprType getInternalName() { + return name; + } + public Object getName() { + return name; + } + public void setName(Object name) { + this.name = AstAdapters.to_expr(name); + } + + private java.util.List<stmtType> body; + public java.util.List<stmtType> getInternalBody() { + return body; + } + public Object getBody() { + return new ListWrapper(body, AstAdapters.stmtAdapter); + } + public void setBody(Object body) { + this.body = AstAdapters.to_stmtList(body); + } + + + private final static String[] fields = new String[] {"excepttype", "name", + "body"}; + public String[] get_fields() { return fields; } + + public ExceptHandler() {} + public ExceptHandler(Object excepttype, Object name, Object body) { + setExcepttype(excepttype); + setName(name); + setBody(body); + } + + public ExceptHandler(Token token, exprType excepttype, exprType name, + java.util.List<stmtType> body) { + super(token); + this.excepttype = excepttype; + addChild(excepttype); + this.name = name; + addChild(name); + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); + } + for(PythonTree t : this.body) { + addChild(t); + } + } + + public ExceptHandler(Integer ttype, Token token, exprType excepttype, + exprType name, java.util.List<stmtType> body) { + super(ttype, token); + this.excepttype = excepttype; + addChild(excepttype); + this.name = name; + addChild(name); + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); + } + for(PythonTree t : this.body) { + addChild(t); + } + } + + public ExceptHandler(PythonTree tree, exprType excepttype, exprType name, + java.util.List<stmtType> body) { + super(tree); + this.excepttype = excepttype; + addChild(excepttype); + this.name = name; + addChild(name); + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); + } + for(PythonTree t : this.body) { + addChild(t); + } + } + + public String toString() { + return "ExceptHandler"; + } + + public String toStringTree() { + StringBuffer sb = new StringBuffer("ExceptHandler("); + sb.append("excepttype="); + sb.append(dumpThis(excepttype)); + sb.append(","); + sb.append("name="); + sb.append(dumpThis(name)); + sb.append(","); + sb.append("body="); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); + return sb.toString(); + } + + public <R> R accept(VisitorIF<R> visitor) throws Exception { + return visitor.visitExceptHandler(this); + } + + public void traverse(VisitorIF visitor) throws Exception { + if (excepttype != null) + excepttype.accept(visitor); + if (name != null) + name.accept(visitor); + if (body != null) { + for (PythonTree t : body) { + if (t != null) + t.accept(visitor); + } + } + } + + private int lineno = -1; + public int getLineno() { + if (lineno != -1) { + return lineno; + } + return getLine(); + } + + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; + public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } + return getCharPositionInLine(); + } + + public void setCol_offset(int num) { + col_offset = num; + } + +} Modified: branches/astwrite/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -43,33 +43,34 @@ this.body = AstAdapters.to_stmtList(body); } - private java.util.List<exprType> decorators; - public java.util.List<exprType> getInternalDecorators() { - return decorators; + private java.util.List<exprType> decorator_list; + public java.util.List<exprType> getInternalDecorator_list() { + return decorator_list; } - public Object getDecorators() { - return new ListWrapper(decorators, AstAdapters.exprAdapter); + public Object getDecorator_list() { + return new ListWrapper(decorator_list, AstAdapters.exprAdapter); } - public void setDecorators(Object decorators) { - this.decorators = AstAdapters.to_exprList(decorators); + public void setDecorator_list(Object decorator_list) { + this.decorator_list = AstAdapters.to_exprList(decorator_list); } private final static String[] fields = new String[] {"name", "args", - "body", "decorators"}; + "body", + "decorator_list"}; public String[] get_fields() { return fields; } public FunctionDef() {} public FunctionDef(Object name, Object args, Object body, Object - decorators) { + decorator_list) { setName(name); setArgs(args); setBody(body); - setDecorators(decorators); + setDecorator_list(decorator_list); } public FunctionDef(Token token, String name, argumentsType args, - java.util.List<stmtType> body, java.util.List<exprType> decorators) { + java.util.List<stmtType> body, java.util.List<exprType> decorator_list) { super(token); this.name = name; this.args = args; @@ -80,17 +81,18 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } public FunctionDef(Integer ttype, Token token, String name, argumentsType - args, java.util.List<stmtType> body, java.util.List<exprType> decorators) { + args, java.util.List<stmtType> body, java.util.List<exprType> + decorator_list) { super(ttype, token); this.name = name; this.args = args; @@ -101,17 +103,17 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } public FunctionDef(PythonTree tree, String name, argumentsType args, - java.util.List<stmtType> body, java.util.List<exprType> decorators) { + java.util.List<stmtType> body, java.util.List<exprType> decorator_list) { super(tree); this.name = name; this.args = args; @@ -122,11 +124,11 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } @@ -146,8 +148,8 @@ sb.append("body="); sb.append(dumpThis(body)); sb.append(","); - sb.append("decorators="); - sb.append(dumpThis(decorators)); + sb.append("decorator_list="); + sb.append(dumpThis(decorator_list)); sb.append(","); sb.append(")"); return sb.toString(); @@ -166,8 +168,8 @@ t.accept(visitor); } } - if (decorators != null) { - for (PythonTree t : decorators) { + if (decorator_list != null) { + for (PythonTree t : decorator_list) { if (t != null) t.accept(visitor); } Modified: branches/astwrite/src/org/python/antlr/ast/VisitorBase.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/VisitorBase.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/VisitorBase.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -308,6 +308,12 @@ return ret; } + public R visitExceptHandler(ExceptHandler node) throws Exception { + R ret = unhandled_node(node); + traverse(node); + return ret; + } + abstract protected R unhandled_node(PythonTree node) throws Exception; abstract public void traverse(PythonTree node) throws Exception; } Modified: branches/astwrite/src/org/python/antlr/ast/VisitorIF.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/VisitorIF.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/VisitorIF.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -52,4 +52,5 @@ public R visitSlice(Slice node) throws Exception; public R visitExtSlice(ExtSlice node) throws Exception; public R visitIndex(Index node) throws Exception; + public R visitExceptHandler(ExceptHandler node) throws Exception; } Modified: branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -6,177 +6,26 @@ import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; -import java.io.DataOutputStream; -import java.io.IOException; -public class excepthandlerType extends PythonTree { - private exprType excepttype; - public exprType getInternalExcepttype() { - return excepttype; - } - public Object getExcepttype() { - return excepttype; - } - public void setExcepttype(Object excepttype) { - this.excepttype = AstAdapters.to_expr(excepttype); - } +public abstract class excepthandlerType extends PythonTree { - private exprType name; - public exprType getInternalName() { - return name; - } - public Object getName() { - return name; - } - public void setName(Object name) { - this.name = AstAdapters.to_expr(name); - } + private final static String[] attributes = new String[] {"lineno", + "col_offset"}; + public String[] get_attributes() { return attributes; } - private java.util.List<stmtType> body; - public java.util.List<stmtType> getInternalBody() { - return body; + public excepthandlerType() { } - public Object getBody() { - return new ListWrapper(body, AstAdapters.stmtAdapter); - } - public void setBody(Object body) { - this.body = AstAdapters.to_stmtList(body); - } - private Integer lineno; - public Integer getInternalLineno() { - return lineno; + public excepthandlerType(int ttype, Token token) { + super(ttype, token); } - public Object getLineno() { - return lineno; - } - public void setLineno(Object lineno) { - this.lineno = AstAdapters.to_int(lineno); - } - private Integer col_offset; - public Integer getInternalCol_offset() { - return col_offset; - } - public Object getCol_offset() { - return col_offset; - } - public void setCol_offset(Object col_offset) { - this.col_offset = AstAdapters.to_int(col_offset); - } - - - private final static String[] fields = new String[] {"excepttype", "name", - "body", "lineno", - "col_offset"}; - public String[] get_fields() { return fields; } - - public excepthandlerType() {} - public excepthandlerType(Object excepttype, Object name, Object body, - Object lineno, Object col_offset) { - setExcepttype(excepttype); - setName(name); - setBody(body); - setLineno(lineno); - setCol_offset(col_offset); - } - - public excepthandlerType(Token token, exprType excepttype, exprType name, - java.util.List<stmtType> body, Integer lineno, Integer col_offset) { + public excepthandlerType(Token token) { super(token); - this.excepttype = excepttype; - addChild(excepttype); - this.name = name; - addChild(name); - this.body = body; - if (body == null) { - this.body = new ArrayList<stmtType>(); - } - for(PythonTree t : this.body) { - addChild(t); - } - this.lineno = lineno; - this.col_offset = col_offset; } - public excepthandlerType(Integer ttype, Token token, exprType excepttype, - exprType name, java.util.List<stmtType> body, Integer lineno, Integer - col_offset) { - super(ttype, token); - this.excepttype = excepttype; - addChild(excepttype); - this.name = name; - addChild(name); - this.body = body; - if (body == null) { - this.body = new ArrayList<stmtType>(); - } - for(PythonTree t : this.body) { - addChild(t); - } - this.lineno = lineno; - this.col_offset = col_offset; + public excepthandlerType(PythonTree node) { + super(node); } - public excepthandlerType(PythonTree tree, exprType excepttype, exprType - name, java.util.List<stmtType> body, Integer lineno, Integer col_offset) { - super(tree); - this.excepttype = excepttype; - addChild(excepttype); - this.name = name; - addChild(name); - this.body = body; - if (body == null) { - this.body = new ArrayList<stmtType>(); - } - for(PythonTree t : this.body) { - addChild(t); - } - this.lineno = lineno; - this.col_offset = col_offset; - } - - public String toString() { - return "excepthandler"; - } - - public String toStringTree() { - StringBuffer sb = new StringBuffer("excepthandler("); - sb.append("excepttype="); - sb.append(dumpThis(excepttype)); - sb.append(","); - sb.append("name="); - sb.append(dumpThis(name)); - sb.append(","); - sb.append("body="); - sb.append(dumpThis(body)); - sb.append(","); - sb.append("lineno="); - sb.append(dumpThis(lineno)); - sb.append(","); - sb.append("col_offset="); - sb.append(dumpThis(col_offset)); - sb.append(","); - sb.append(")"); - return sb.toString(); - } - - public <R> R accept(VisitorIF<R> visitor) throws Exception { - traverse(visitor); - return null; - } - - public void traverse(VisitorIF visitor) throws Exception { - if (excepttype != null) - excepttype.accept(visitor); - if (name != null) - name.accept(visitor); - if (body != null) { - for (PythonTree t : body) { - if (t != null) - t.accept(visitor); - } - } - } - } Modified: branches/astwrite/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/astwrite/src/org/python/compiler/CodeCompiler.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/compiler/CodeCompiler.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -27,6 +27,7 @@ import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; import org.python.antlr.ast.Ellipsis; +import org.python.antlr.ast.ExceptHandler; import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; import org.python.antlr.ast.Expression; @@ -419,7 +420,7 @@ } set(new Name(node,node.getInternalName(), expr_contextType.Store)); - doDecorators(node,node.getInternalDecorators(), node.getInternalName()); + doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); return null; } @@ -1124,7 +1125,7 @@ throws Exception { for (int i = 0; i < node.getInternalHandlers().size(); i++) { - excepthandlerType handler = node.getInternalHandlers().get(i); + ExceptHandler handler = (ExceptHandler)node.getInternalHandlers().get(i); //setline(name); Label end_of_self = new Label(); @@ -2024,7 +2025,7 @@ //Assign this new class to the given name set(new Name(node,node.getInternalName(), expr_contextType.Store)); - doDecorators(node,node.getInternalDecorators(), node.getInternalName()); + doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); return null; } Modified: branches/astwrite/src/org/python/compiler/ScopesCompiler.java =================================================================== --- branches/astwrite/src/org/python/compiler/ScopesCompiler.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/compiler/ScopesCompiler.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -130,7 +130,7 @@ visit(defaults.get(i)); } - List<exprType> decs = node.getInternalDecorators(); + List<exprType> decs = node.getInternalDecorator_list(); for (int i = decs.size() - 1; i >= 0; i--) { visit(decs.get(i)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-26 05:19:44
|
Revision: 5642 http://jython.svn.sourceforge.net/jython/?rev=5642&view=rev Author: fwierzbicki Date: 2008-11-26 05:19:41 +0000 (Wed, 26 Nov 2008) Log Message: ----------- Applied Geoffrey French's collection fixes as this gets me further along in my experiments and I expect Geoffrey's fixes will make it into trunk via the java-newsytle branch. I'm not planning to do a direct merge from this branch back to trunk anyway. Thanks Geoffrey for the patch! Modified Paths: -------------- branches/astwrite/Lib/test/test_ast.py branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java branches/astwrite/src/org/python/core/AbstractArray.java branches/astwrite/src/org/python/core/CollectionProxy.java branches/astwrite/src/org/python/core/PyInstance.java branches/astwrite/src/org/python/core/PyList.java Modified: branches/astwrite/Lib/test/test_ast.py =================================================================== --- branches/astwrite/Lib/test/test_ast.py 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/Lib/test/test_ast.py 2008-11-26 05:19:41 UTC (rev 5642) @@ -34,7 +34,7 @@ return t elif isinstance(t, ast_list): return [to_tuple(e) for e in t] - result = [t.__class__.__name__] + result = [get_class_name(t)] if hasattr(t, 'lineno') and hasattr(t, 'col_offset'): result.append((t.lineno, t.col_offset)) if t._fields is None: @@ -219,17 +219,17 @@ def test_dump(self): node = ast.parse('spam(eggs, "and cheese")') self.assertEqual(ast.dump(node), - "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), " - "args=[Name(id='eggs', ctx=Load()), Str(s='and cheese')], " + u"Module(body=[Expr(value=Call(func=Name(id=u'spam', ctx=Load()), " + "args=[Name(id=u'eggs', ctx=Load()), Str(s='and cheese')], " "keywords=[], starargs=None, kwargs=None))])" ) self.assertEqual(ast.dump(node, annotate_fields=False), - "Module([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), " + "Module([Expr(Call(Name(u'spam', Load()), [Name(u'eggs', Load()), " "Str('and cheese')], [], None, None))])" ) self.assertEqual(ast.dump(node, include_attributes=True), - "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), " - "lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), " + "Module(body=[Expr(value=Call(func=Name(id=u'spam', ctx=Load(), " + "lineno=1, col_offset=0), args=[Name(id=u'eggs', ctx=Load(), " "lineno=1, col_offset=5), Str(s='and cheese', lineno=1, " "col_offset=11)], keywords=[], starargs=None, kwargs=None, " "lineno=1, col_offset=0), lineno=1, col_offset=0)])" Modified: branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -2,10 +2,12 @@ import org.python.core.Py; import org.python.core.PyInteger; +import org.python.core.PyString; import org.python.core.PyJavaInstance; import org.python.antlr.ast.exprType; import org.python.antlr.ast.Num; +import org.python.antlr.ast.Str; import java.util.ArrayList; import java.util.List; @@ -23,6 +25,8 @@ return o; } else if (o instanceof Integer) { return new Num(new PyInteger((Integer)o)); + } else if (o instanceof String) { + return new Str(new PyString((String)o)); } //FIXME: investigate the right exception Modified: branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -8,6 +8,7 @@ import org.python.core.Py; import org.python.core.PyObject; +import org.python.core.PySequence; public class ListWrapper implements List { @@ -15,15 +16,15 @@ private AstAdapter adapter; public ListWrapper(List list) { + this(list, null); + } + + public ListWrapper(List list, AstAdapter adapter) { if (list == null) { throw Py.TypeError("AST list can't be None"); } this.list = list; - } - - public ListWrapper(List list, AstAdapter adapter) { this.adapter = adapter; - this.list = list; } public boolean containsAll(Collection c) { @@ -118,6 +119,7 @@ return list.subList(fromIndex, toIndex); } + /* public ListWrapper __add__(Object o) { List newList = new ArrayList(); newList.addAll(list); @@ -125,10 +127,6 @@ return new ListWrapper(newList); } - public void __iadd__(PyObject o) { - extend(o); - } - public int __len__() { return list.size(); } @@ -138,87 +136,91 @@ } public PyObject __imul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("1 Not supported yet."); } public PyObject __iter__() { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("2 Not supported yet."); } public PyObject __mul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("3 Not supported yet."); } public PyObject __radd__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("4 Not supported yet."); } public PyObject __rmul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("5 Not supported yet."); } + */ public void append(PyObject o) { list.add(adapter.adapt(o)); } public int count(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("6 Not supported yet."); } protected void del(int i) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("7 Not supported yet."); } protected void delRange(int start, int stop, int step) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("8 Not supported yet."); } public void extend(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("9 Not supported yet."); } public int index(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("10 Not supported yet."); } public int index(PyObject o, int start) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("11 Not supported yet."); } public int index(PyObject o, int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("12 Not supported yet."); } public void insert(int index, PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("13 Not supported yet."); } public PyObject pop() { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("14 Not supported yet."); } public PyObject pop(int n) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("15 Not supported yet."); } public void remove(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("16 Not supported yet."); } public void reverse() { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("17 Not supported yet."); } public void sort(PyObject compare) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("18 Not supported yet."); } public void sort() { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("19 Not supported yet."); } public void sort(PyObject cmp, PyObject key, PyObject reverse) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("20 Not supported yet."); } - + + public String toString() { + return list.toString(); + } } Modified: branches/astwrite/src/org/python/core/AbstractArray.java =================================================================== --- branches/astwrite/src/org/python/core/AbstractArray.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/core/AbstractArray.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -383,7 +383,7 @@ } throw new IndexOutOfBoundsException("start and stop must follow: 0 <= start <= stop <= " + - (this.size - 1) + ", but found start= " + start + " and stop=" + stop); + this.size + ", but found start= " + start + " and stop=" + stop); } /** Modified: branches/astwrite/src/org/python/core/CollectionProxy.java =================================================================== --- branches/astwrite/src/org/python/core/CollectionProxy.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/core/CollectionProxy.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -2,6 +2,7 @@ package org.python.core; +import java.util.Arrays; import java.util.Collection; import java.util.Dictionary; import java.util.Enumeration; @@ -17,6 +18,9 @@ if (object == null) return NoProxy; + if (object instanceof Vector) { + return new VectorProxy(((Vector) object)); + } if (object instanceof List) { return new ListProxy(((List) object)); } @@ -31,9 +35,6 @@ } - if (object instanceof Vector) { - return new VectorProxy(((Vector) object)); - } if (object instanceof Enumeration) { return new EnumerationProxy(((Enumeration) object)); } @@ -112,10 +113,13 @@ } } -class VectorProxy extends CollectionProxy { - Vector proxy; - public VectorProxy(Vector proxy) { + + +class ListProxy extends CollectionProxy { + List proxy; + + public ListProxy(List proxy) { this.proxy = proxy; } @@ -124,71 +128,222 @@ } public PyObject __finditem__(int key) { + int k = key < 0 ? key + this.proxy.size() : key; try { - return Py.java2py(this.proxy.elementAt(key)); - } catch (ArrayIndexOutOfBoundsException exc) { - return null; + return Py.java2py(this.proxy.get(k)); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("index out of range: " + String.valueOf(key)); } } + protected PyObject __finditem__(int start, int stop, int step, int n) { + if(step > 0 && stop < start) { + stop = start; + } + PyObject[] newList = new PyObject[n]; + if(step == 1) { + for (int i = start; i < stop; i++) + { + newList[i-start] = Py.java2py(this.proxy.get(i)); + } + return new PyList(newList); + } + int j = 0; + for(int i = start; j < n; i += step) { + newList[j] = Py.java2py(this.proxy.get(i)); + j++; + } + return new PyList(newList); + } + public PyObject __finditem__(PyObject key) { if (key instanceof PyInteger) { return __finditem__(((PyInteger) key).getValue()); + } else if (key instanceof PySlice) { + PySlice slice = (PySlice)key; + int indices[] = slice.indicesEx(this.proxy.size()); + return __finditem__(indices[0], indices[1], indices[2], indices[3]); } else { - throw Py.TypeError("only integer keys accepted"); + throw Py.TypeError("only integer or slice keys accepted"); } } + public void __setitem__(int key, PyObject value) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + this.proxy.set(k, Py.tojava(value, Object.class)); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("assignment index out of range: " + String.valueOf(key)); + } + } + public void __setitem__(PyObject key, PyObject value) { if (key instanceof PyInteger) { - this.proxy.setElementAt(Py.tojava(value, Object.class), - ((PyInteger) key).getValue()); + __setitem__(((PyInteger) key).getValue(), value); + } else if (key instanceof PySlice) { + PySlice slice = (PySlice)key; + int indices[] = slice.indicesEx(this.proxy.size()); + __setitem__(slice, indices[0], indices[1], indices[2], indices[3], value); } else { throw Py.TypeError("only integer keys accepted"); } } + public void __delitem__(int key) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + this.proxy.remove(k); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("assignment index out of range: " + String.valueOf(key)); + } + } + + protected void __delitem__(int start, int stop, int step, int n) { + if(step == 1) { + for (int i = stop - 1; i >= start; i--) { + this.proxy.remove(i); + } + } else if(step > 1) { + for(int i = start; i < stop; i += step) { + this.proxy.remove(i); + i--; + stop--; + } + } else if(step < 0) { + for(int i = start; i >= 0 && i >= stop; i += step) { + this.proxy.remove(i); + } + } + } + public void __delitem__(PyObject key) { if (key instanceof PyInteger) { - this.proxy.removeElementAt(((PyInteger) key).getValue()); + __delitem__(((PyInteger) key).getValue()); + } else if (key instanceof PySlice) { + PySlice slice = (PySlice)key; + int indices[] = slice.indicesEx(this.proxy.size()); + __delitem__(indices[0], indices[1], indices[2], indices[3]); } else { throw Py.TypeError("only integer keys accepted"); } } -} -class DictionaryProxy extends CollectionProxy { - Dictionary proxy; - public DictionaryProxy(Dictionary proxy) { - this.proxy = proxy; + + + protected void __setitem__(PySlice slice, int start, int stop, int step, int n, PyObject value) { + if(stop < start) { + stop = start; + } + if(value instanceof PySequence) { + PySequence sequence = (PySequence) value; + setslicePySequence(slice, start, stop, step, n, sequence); + } else if(value instanceof List) { + List list = (List)value.__tojava__(List.class); + if(list != null && list != Py.NoConversion) { + setsliceList(slice, start, stop, step, list); + } + } else { + setsliceIterable(slice, start, stop, step, n, value); + } } - public int __len__() { - return this.proxy.size(); + protected void setslicePySequence(PySlice slice, int start, int stop, int step, int n, PySequence value) { + if(slice.step != Py.None) { + if(n != value.__len__()) { + throw Py.ValueError("attempt to assign sequence of size " + value.__len__() + " to extended slice of size " + n); + } + } + if(step == 1) { + PyObject[] srcArray; + Object[] jArray; + + if(value instanceof PySequenceList) { + srcArray = ((PySequenceList)value).getArray(); + } else { + srcArray = Py.unpackSequence(value, value.__len__()); + } + jArray = new Object[srcArray.length]; + for (int i = 0; i < srcArray.length; i++) { + jArray[i] = Py.tojava(srcArray[i], Object.class); + } + List sub = this.proxy.subList(start, stop); + sub.clear(); + this.proxy.addAll( start, Arrays.asList(jArray) ); + } else if(step != 0) { + for (int i = 0, j = start; i < n; i++, j += step) { + this.proxy.set(j, Py.tojava(value.pyget(i), Object.class)); + } + } } - public PyObject __finditem__(int key) { - throw Py.TypeError("loop over non-sequence"); + protected void setsliceList(PySlice slice, int start, int stop, int step, List value) { + if(step != 1) { + throw Py.TypeError("setslice with java.util.List and step != 1 not supported yet"); + } + int n = value.size(); + for(int i = 0; i < n; i++) { + this.proxy.add(i + start, value.get(i)); + } } - public PyObject __finditem__(PyObject key) { - return Py.java2py(this.proxy.get(Py.tojava(key, Object.class))); + protected void setsliceIterable(PySlice slice, int start, int stop, int step, int n, PyObject value) { + PyObject[] seq; + try { + seq = Py.make_array(value); + } catch (PyException pye) { + if (Py.matchException(pye, Py.TypeError)) { + throw Py.TypeError("can only assign an iterable"); + } + throw pye; + } + setslicePySequence(slice, start, stop, step, n, new PyList(seq)); } +} - public void __setitem__(PyObject key, PyObject value) { - this.proxy.put(Py.tojava(key, Object.class), Py.tojava(value, - Object.class)); + + + +class VectorProxy extends ListProxy { + public VectorProxy(Vector proxy) { + super(proxy); } - public void __delitem__(PyObject key) { - this.proxy.remove(Py.tojava(key, Object.class)); + public PyObject __finditem__(int key) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + return Py.java2py(((Vector)this.proxy).elementAt(k)); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("index out of range: " + String.valueOf(key)); + } } + + public void __setitem__(int key, PyObject value) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + ((Vector)this.proxy).setElementAt(Py.tojava(value, Object.class), k); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("assignment index out of range: " + String.valueOf(key)); + } + } + + public void __delitem__(int key) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + ((Vector)this.proxy).removeElementAt(k); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("assignment index out of range: " + String.valueOf(key)); + } + } } -class ListProxy extends CollectionProxy { - List proxy; - public ListProxy(List proxy) { + + + +class DictionaryProxy extends CollectionProxy { + Dictionary proxy; + + public DictionaryProxy(Dictionary proxy) { this.proxy = proxy; } @@ -197,46 +352,22 @@ } public PyObject __finditem__(int key) { - try { - return Py.java2py(this.proxy.get(key)); - } catch (IndexOutOfBoundsException exc) { - return null; - } + throw Py.TypeError("loop over non-sequence"); } public PyObject __finditem__(PyObject key) { - if (key instanceof PyInteger) { - return __finditem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } + return Py.java2py(this.proxy.get(Py.tojava(key, Object.class))); } - public void __setitem__(int key, PyObject value) { - this.proxy.set(key, Py.tojava(value, Object.class)); - } - public void __setitem__(PyObject key, PyObject value) { - if (key instanceof PyInteger) { - __setitem__(((PyInteger) key).getValue(), value); - } else { - throw Py.TypeError("only integer keys accepted"); - } + this.proxy.put(Py.tojava(key, Object.class), Py.tojava(value, + Object.class)); } - public void __delitem__(int key) { - this.proxy.remove(key); - } - public void __delitem__(PyObject key) { - if (key instanceof PyInteger) { - __delitem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } + this.proxy.remove(Py.tojava(key, Object.class)); } } - class MapProxy extends CollectionProxy { Map proxy; Modified: branches/astwrite/src/org/python/core/PyInstance.java =================================================================== --- branches/astwrite/src/org/python/core/PyInstance.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/core/PyInstance.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -10,6 +10,10 @@ public class PyInstance extends PyObject { + // Collection proxy invoke no method found error code - return an error + // code instead of using slower exceptions + public static PyObject collectionProxyNoMethodError = new PyObject(); + // xxx doc, final name public transient PyClass instclass; @@ -251,6 +255,61 @@ return __findattr__("__index__") != null; } + + public PyObject iinvoke_collectionProxy(String name) { + PyObject f = ifindlocal(name); + if (f == null) { + f = ifindclass(name, false); + if (f != null) { + if (f instanceof PyFunction) { + return f.__call__(this); + } else { + f = f.__get__(this, instclass); + } + } + } + if (f == null) f = ifindfunction(name); + if (f == null) return collectionProxyNoMethodError; + return f.__call__(); + } + + public PyObject iinvoke_collectionProxy(String name, PyObject arg1) { + PyObject f = ifindlocal(name); + if (f == null) { + f = ifindclass(name, false); + if (f != null) { + if (f instanceof PyFunction) { + return f.__call__(this, arg1); + } else { + f = f.__get__(this, instclass); + } + } + } + if (f == null) f = ifindfunction(name); + if (f == null) return collectionProxyNoMethodError; + return f.__call__(arg1); + } + + public PyObject iinvoke_collectionProxy(String name, PyObject arg1, PyObject arg2) { + PyObject f = ifindlocal(name); + if (f == null) { + f = ifindclass(name, false); + if (f != null) { + if (f instanceof PyFunction) { + return f.__call__(this, arg1, arg2); + } else { + f = f.__get__(this, instclass); + } + } + } + if (f == null) f = ifindfunction(name); + if (f == null) return collectionProxyNoMethodError; + return f.__call__(arg1, arg2); + } + + + + public PyObject invoke(String name) { PyObject f = ifindlocal(name); if (f == null) { @@ -548,16 +607,18 @@ } catch (PyException exc) { } if (meth == null) { - // Copied form __len__() - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__len__() != 0 ? true : false; - } try { meth = __findattr__("__len__"); } catch (PyException exc) { } - if (meth == null) - return true; + if (meth == null) { + // Copied form __len__() + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + return proxy.__len__() != 0 ? true : false; + } else { + return true; + } + } } PyObject ret = meth.__call__(); @@ -573,22 +634,21 @@ } public int __len__() { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__len__(); + PyObject ret = iinvoke_collectionProxy("__len__"); + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + return proxy.__len__(); + } else { + noAttributeError("__len__"); + } } - - PyObject ret = invoke("__len__"); if (ret instanceof PyInteger) return ((PyInteger)ret).getValue(); throw Py.TypeError("__len__() should return an int"); } public PyObject __finditem__(int key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__finditem__(key); - } return __finditem__(new PyInteger(key)); } @@ -614,13 +674,9 @@ } public PyObject __finditem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__finditem__(key); - } - + PyObject ret = null; try { - return invoke("__getitem__", key); + ret = iinvoke_collectionProxy("__getitem__", key); } catch (PyException e) { if (Py.matchException(e, Py.IndexError)) return null; @@ -628,36 +684,64 @@ return null; throw e; } + + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + return proxy.__finditem__(key); + } else { + noAttributeError("__getitem__"); + } + } + + return ret; } public PyObject __getitem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - PyObject ret = proxy.__finditem__(key); - if (ret == null) { - throw Py.KeyError(key.toString()); + PyObject ret = iinvoke_collectionProxy("__getitem__", key); + + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + ret = proxy.__finditem__(key); + if (ret == null) { + throw Py.KeyError(key.toString()); + } + return ret; + } else { + noAttributeError("__getitem__"); } - return ret; } - return invoke("__getitem__", key); + + return ret; } public void __setitem__(PyObject key, PyObject value) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - proxy.__setitem__(key, value); - return; + PyObject ret = iinvoke_collectionProxy("__setitem__", key, value); + + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + proxy.__setitem__(key, value); + return; + } else { + noAttributeError("__setitem__"); + } } - invoke("__setitem__", key, value); } public void __delitem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - proxy.__delitem__(key); - return; + PyObject ret = iinvoke_collectionProxy("__delitem__", key); + + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + proxy.__delitem__(key); + return; + } else { + noAttributeError("__delitem__"); + } } - invoke("__delitem__", key); } public PyObject __getslice__(PyObject start, PyObject stop, PyObject step) { @@ -688,16 +772,18 @@ } public PyObject __iter__() { - PyObject iter = getCollectionIter(); - if (iter != null) { - return iter; - } PyObject func = __findattr__("__iter__"); if (func != null) return func.__call__(); func = __findattr__("__getitem__"); - if (func == null) - return super.__iter__(); + if (func == null) { + PyObject iter = getCollectionIter(); + if (iter != null) { + return iter; + } else { + return super.__iter__(); + } + } return new PySequenceIter(this); } Modified: branches/astwrite/src/org/python/core/PyList.java =================================================================== --- branches/astwrite/src/org/python/core/PyList.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/core/PyList.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -114,7 +114,9 @@ protected void delRange(int start, int stop, int step) { if(step == 1) { - remove(start, stop); + if ( stop > start ) { + remove(start, stop); + } } else if(step > 1) { for(int i = start; i < stop; i += step) { remove(i); @@ -164,13 +166,7 @@ otherArray = otherArray.clone(); } list.replaceSubArray(start, stop, otherArray, 0, n); - } else if(step > 1) { - int n = value.__len__(); - for(int i = 0, j = 0; i < n; i++, j += step) { - list.pyset(j + start, value.pyget(i)); - } - } else if(step < 0) { - int n = value.__len__(); + } else if(step != 0) { if(value == this) { PyList newseq = new PyList(); PyObject iter = value.__iter__(); @@ -179,7 +175,8 @@ } value = newseq; } - for(int i = 0, j = list.size() - 1; i < n; i++, j += step) { + int n = value.__len__(); + for (int i = 0, j = start; i < n; i++, j += step) { list.pyset(j, value.pyget(i)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-26 03:42:11
|
Revision: 5641 http://jython.svn.sourceforge.net/jython/?rev=5641&view=rev Author: fwierzbicki Date: 2008-11-26 03:42:02 +0000 (Wed, 26 Nov 2008) Log Message: ----------- Round out the ast adapters. Modified Paths: -------------- branches/astwrite/ast/asdl_antlr.py branches/astwrite/src/org/python/antlr/PythonTree.java branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java branches/astwrite/src/org/python/antlr/ast/Assign.java branches/astwrite/src/org/python/antlr/ast/BoolOp.java branches/astwrite/src/org/python/antlr/ast/Call.java branches/astwrite/src/org/python/antlr/ast/ClassDef.java branches/astwrite/src/org/python/antlr/ast/Compare.java branches/astwrite/src/org/python/antlr/ast/Delete.java branches/astwrite/src/org/python/antlr/ast/Dict.java branches/astwrite/src/org/python/antlr/ast/ExtSlice.java branches/astwrite/src/org/python/antlr/ast/For.java branches/astwrite/src/org/python/antlr/ast/FunctionDef.java branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java branches/astwrite/src/org/python/antlr/ast/Global.java branches/astwrite/src/org/python/antlr/ast/If.java branches/astwrite/src/org/python/antlr/ast/Import.java branches/astwrite/src/org/python/antlr/ast/ImportFrom.java branches/astwrite/src/org/python/antlr/ast/Interactive.java branches/astwrite/src/org/python/antlr/ast/List.java branches/astwrite/src/org/python/antlr/ast/ListComp.java branches/astwrite/src/org/python/antlr/ast/Module.java branches/astwrite/src/org/python/antlr/ast/Print.java branches/astwrite/src/org/python/antlr/ast/Suite.java branches/astwrite/src/org/python/antlr/ast/TryExcept.java branches/astwrite/src/org/python/antlr/ast/TryFinally.java branches/astwrite/src/org/python/antlr/ast/Tuple.java branches/astwrite/src/org/python/antlr/ast/While.java branches/astwrite/src/org/python/antlr/ast/With.java branches/astwrite/src/org/python/antlr/ast/argumentsType.java branches/astwrite/src/org/python/antlr/ast/comprehensionType.java branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java Added Paths: ----------- branches/astwrite/src/org/python/antlr/adapter/AliasAdapter.java branches/astwrite/src/org/python/antlr/adapter/AstAdapter.java branches/astwrite/src/org/python/antlr/adapter/CmpopAdapter.java branches/astwrite/src/org/python/antlr/adapter/ComprehensionAdapter.java branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java branches/astwrite/src/org/python/antlr/adapter/IdentifierAdapter.java branches/astwrite/src/org/python/antlr/adapter/KeywordAdapter.java branches/astwrite/src/org/python/antlr/adapter/SliceAdapter.java branches/astwrite/src/org/python/antlr/adapter/StmtAdapter.java Removed Paths: ------------- branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java Modified: branches/astwrite/ast/asdl_antlr.py =================================================================== --- branches/astwrite/ast/asdl_antlr.py 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/ast/asdl_antlr.py 2008-11-26 03:42:02 UTC (rev 5641) @@ -422,7 +422,7 @@ self.emit("}", depth) self.emit("public Object get%s() {" % (str(field.name).capitalize()), depth) if field.seq: - self.emit("return new ListWrapper(%s);" % field.name, depth+1) + self.emit("return new ListWrapper(%s, AstAdapters.%sAdapter);" % (field.name, field.type), depth+1) else: self.emit("return %s;" % field.name, depth+1) self.emit("}", depth) Modified: branches/astwrite/src/org/python/antlr/PythonTree.java =================================================================== --- branches/astwrite/src/org/python/antlr/PythonTree.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/PythonTree.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -85,7 +85,7 @@ if ( getChildCount()>0 ) { return getChild(0).getLine(); } - return 0; + return 1; } return token.getLine(); } Added: branches/astwrite/src/org/python/antlr/adapter/AliasAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AliasAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/AliasAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,34 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.aliasType; + +import java.util.ArrayList; +import java.util.List; + +public class AliasAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(aliasType.class); + } + if (o instanceof aliasType) { + return o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to alias node"); + } + + public Object adaptIter(Object iter) { + List<aliasType> aliases = new ArrayList<aliasType>(); + for(Object o : (Iterable)iter) { + aliases.add((aliasType)adapt(o)); + } + return aliases; + } +} Copied: branches/astwrite/src/org/python/antlr/adapter/AstAdapter.java (from rev 5636, branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AstAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/AstAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,13 @@ +package org.python.antlr.adapter; + +/** + * AstAdapters turn Objects into Ast nodes. + */ +public interface AstAdapter { + + /** + * @return Ast node version of o. + */ + public abstract Object adapt(Object o); + +} Modified: branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -3,55 +3,59 @@ import org.python.antlr.ast.*; import org.python.core.*; +import java.util.ArrayList; /** * AstAdapter turns Python and Java objects into ast nodes. */ public class AstAdapters { + public static AliasAdapter aliasAdapter = new AliasAdapter(); + public static CmpopAdapter cmpopAdapter = new CmpopAdapter(); + public static ComprehensionAdapter comprehensionAdapter = new ComprehensionAdapter(); + public static ExcepthandlerAdapter excepthandlerAdapter = new ExcepthandlerAdapter(); + public static ExprAdapter exprAdapter = new ExprAdapter(); + public static IdentifierAdapter identifierAdapter = new IdentifierAdapter(); + public static KeywordAdapter keywordAdapter = new KeywordAdapter(); + public static SliceAdapter sliceAdapter = new SliceAdapter(); + public static StmtAdapter stmtAdapter = new StmtAdapter(); public static java.util.List<aliasType> to_aliasList(Object o) { - return null; + return (java.util.List<aliasType>)aliasAdapter.adaptIter(o); } public static java.util.List<cmpopType> to_cmpopList(Object o) { - return null; + return (java.util.List<cmpopType>)cmpopAdapter.adaptIter(o); } public static java.util.List<comprehensionType> to_comprehensionList(Object o) { - return null; + return (java.util.List<comprehensionType>)comprehensionAdapter.adaptIter(o); } public static java.util.List<excepthandlerType> to_excepthandlerList(Object o) { - return null; + return (java.util.List<excepthandlerType>)excepthandlerAdapter.adaptIter(o); } public static java.util.List<exprType> to_exprList(Object o) { - return null; + return (java.util.List<exprType>)exprAdapter.adaptIter(o); } public static java.util.List<String> to_identifierList(Object o) { - return null; + return (java.util.List<String>)identifierAdapter.adaptIter(o); } public static java.util.List<keywordType> to_keywordList(Object o) { - return null; + return (java.util.List<keywordType>)keywordAdapter.adaptIter(o); } public static java.util.List<sliceType> to_sliceList(Object o) { - return null; + return (java.util.List<sliceType>)sliceAdapter.adaptIter(o); } public static java.util.List<stmtType> to_stmtList(Object o) { - return null; + return (java.util.List<stmtType>)stmtAdapter.adaptIter(o); } public static exprType to_expr(Object o) { - if (o == null || o instanceof exprType) { - return (exprType)o; - } else if (o instanceof Integer) { - return new Num(new PyInteger((Integer)o)); - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); + return (exprType)exprAdapter.adapt(o); } public static int to_int(Object o) { @@ -63,11 +67,7 @@ } public static String to_identifier(Object o) { - if (o == null || o instanceof String) { - return (String)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); + return (String)identifierAdapter.adapt(o); } public static expr_contextType to_expr_context(Object o) { @@ -79,22 +79,11 @@ } public static sliceType to_slice(Object o) { - if (o == null || o instanceof sliceType) { - return (sliceType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); + return (sliceType)sliceAdapter.adapt(o); } public static stmtType to_stmt(Object o) { - if (o instanceof PyJavaInstance) { - o = ((PyJavaInstance)o).__tojava__(stmtType.class); - } - if (o == null || o instanceof stmtType) { - return (stmtType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to stmt node"); + return (stmtType)stmtAdapter.adapt(o); } public static String to_string(Object o) { @@ -129,12 +118,9 @@ throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arguments node"); } + //XXX: clearly this isn't necessary -- need to adjust the code generation. public static Object to_object(Object o) { - if (o == null || o instanceof Object) { - return (Object)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to object node"); + return o; } public static Boolean to_bool(Object o) { Deleted: branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -1,5 +0,0 @@ -package org.python.antlr.adapter; - -public interface AstObjectAdapter { - public Object adapt(Object o); -} Added: branches/astwrite/src/org/python/antlr/adapter/CmpopAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/CmpopAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/CmpopAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,34 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.cmpopType; + +import java.util.ArrayList; +import java.util.List; + +public class CmpopAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(cmpopType.class); + } + if (o instanceof cmpopType) { + return o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to cmpop node"); + } + + public Object adaptIter(Object iter) { + List<cmpopType> cmpops = new ArrayList<cmpopType>(); + for(Object o : (Iterable)iter) { + cmpops.add((cmpopType)adapt(o)); + } + return cmpops; + } +} Added: branches/astwrite/src/org/python/antlr/adapter/ComprehensionAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ComprehensionAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/ComprehensionAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,34 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.comprehensionType; + +import java.util.ArrayList; +import java.util.List; + +public class ComprehensionAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(comprehensionType.class); + } + if (o instanceof comprehensionType) { + return o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to comprehension node"); + } + + public Object adaptIter(Object iter) { + List<comprehensionType> comprehensions = new ArrayList<comprehensionType>(); + for(Object o : (Iterable)iter) { + comprehensions.add((comprehensionType)adapt(o)); + } + return comprehensions; + } +} Added: branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,37 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.excepthandlerType; +import org.python.antlr.ast.Num; + +import java.util.ArrayList; +import java.util.List; + +public class ExcepthandlerAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(excepthandlerType.class); + } + if (o instanceof excepthandlerType) { + return o; + } + + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to excepthandler node"); + } + + public Object adaptIter(Object iter) { + List<excepthandlerType> excepthandlers = new ArrayList<excepthandlerType>(); + for(Object o : (Iterable)iter) { + excepthandlers.add((excepthandlerType)adapt(o)); + } + return excepthandlers; + } + +} Added: branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,40 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyInteger; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.exprType; +import org.python.antlr.ast.Num; + +import java.util.ArrayList; +import java.util.List; + +public class ExprAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(exprType.class); + } + if (o instanceof exprType) { + return o; + } else if (o instanceof Integer) { + return new Num(new PyInteger((Integer)o)); + } + + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); + } + + public Object adaptIter(Object iter) { + List<exprType> exprs = new ArrayList<exprType>(); + for(Object o : (Iterable)iter) { + exprs.add((exprType)adapt(o)); + } + return exprs; + } + +} Added: branches/astwrite/src/org/python/antlr/adapter/IdentifierAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/IdentifierAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/IdentifierAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,36 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.Num; + +import java.util.ArrayList; +import java.util.List; + +public class IdentifierAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(String.class); + } + if (o instanceof String) { + return o; + } + + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); + } + + public Object adaptIter(Object iter) { + List<String> identifiers = new ArrayList<String>(); + for(Object o : (Iterable)iter) { + identifiers.add((String)adapt(o)); + } + return identifiers; + } + +} Added: branches/astwrite/src/org/python/antlr/adapter/KeywordAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/KeywordAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/KeywordAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,35 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.keywordType; + +import java.util.ArrayList; +import java.util.List; + +public class KeywordAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(keywordType.class); + } + if (o instanceof keywordType) { + return o; + } + + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to keyword node"); + } + + public Object adaptIter(Object iter) { + List<keywordType> keywords = new ArrayList<keywordType>(); + for(Object o : (Iterable)iter) { + keywords.add((keywordType)adapt(o)); + } + return keywords; + } +} Modified: branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -5,18 +5,23 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; + +import org.python.core.Py; import org.python.core.PyObject; public class ListWrapper implements List { private List list; - private AstObjectAdapter adapter; + private AstAdapter adapter; public ListWrapper(List list) { + if (list == null) { + throw Py.TypeError("AST list can't be None"); + } this.list = list; } - public ListWrapper(List list, AstObjectAdapter adapter) { + public ListWrapper(List list, AstAdapter adapter) { this.adapter = adapter; this.list = list; } Added: branches/astwrite/src/org/python/antlr/adapter/SliceAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/SliceAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/SliceAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,37 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.sliceType; +import org.python.antlr.ast.Num; + +import java.util.ArrayList; +import java.util.List; + +public class SliceAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(sliceType.class); + } + if (o instanceof sliceType) { + return o; + } + + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); + } + + public Object adaptIter(Object iter) { + List<sliceType> slices = new ArrayList<sliceType>(); + for(Object o : (Iterable)iter) { + slices.add((sliceType)adapt(o)); + } + return slices; + } + +} Copied: branches/astwrite/src/org/python/antlr/adapter/StmtAdapter.java (from rev 5636, branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/StmtAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/StmtAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -0,0 +1,34 @@ +package org.python.antlr.adapter; + +import org.python.core.Py; +import org.python.core.PyJavaInstance; + +import org.python.antlr.ast.stmtType; + +import java.util.ArrayList; +import java.util.List; + +public class StmtAdapter implements AstAdapter { + + public Object adapt(Object o) { + if (o == null) { + return o; + } + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(stmtType.class); + } + if (o instanceof stmtType) { + return o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to stmt node"); + } + + public Object adaptIter(Object iter) { + List<stmtType> stmts = new ArrayList<stmtType>(); + for(Object o : (Iterable)iter) { + stmts.add((stmtType)adapt(o)); + } + return stmts; + } +} Deleted: branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -1,22 +0,0 @@ -package org.python.antlr.adapter; - -import org.python.antlr.ast.stmtType; - -import java.util.ArrayList; -import java.util.List; - -public class StmtListAdapter implements AstObjectAdapter { - public Object adaptList(Object list) { - List<stmtType> s = new ArrayList<stmtType>(); - if (list instanceof List) { - for (Object o : (List)list) { - s.add(AstAdapters.to_stmt(o)); - } - } - return s; - } - - public Object adapt(Object o) { - return AstAdapters.to_stmt(o); - } -} Modified: branches/astwrite/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return targets; } public Object getTargets() { - return new ListWrapper(targets); + return new ListWrapper(targets, AstAdapters.exprAdapter); } public void setTargets(Object targets) { this.targets = AstAdapters.to_exprList(targets); Modified: branches/astwrite/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return values; } public Object getValues() { - return new ListWrapper(values); + return new ListWrapper(values, AstAdapters.exprAdapter); } public void setValues(Object values) { this.values = AstAdapters.to_exprList(values); Modified: branches/astwrite/src/org/python/antlr/ast/Call.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return args; } public Object getArgs() { - return new ListWrapper(args); + return new ListWrapper(args, AstAdapters.exprAdapter); } public void setArgs(Object args) { this.args = AstAdapters.to_exprList(args); @@ -37,7 +37,7 @@ return keywords; } public Object getKeywords() { - return new ListWrapper(keywords); + return new ListWrapper(keywords, AstAdapters.keywordAdapter); } public void setKeywords(Object keywords) { this.keywords = AstAdapters.to_keywordList(keywords); Modified: branches/astwrite/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return bases; } public Object getBases() { - return new ListWrapper(bases); + return new ListWrapper(bases, AstAdapters.exprAdapter); } public void setBases(Object bases) { this.bases = AstAdapters.to_exprList(bases); @@ -37,7 +37,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); @@ -48,7 +48,7 @@ return decorators; } public Object getDecorators() { - return new ListWrapper(decorators); + return new ListWrapper(decorators, AstAdapters.exprAdapter); } public void setDecorators(Object decorators) { this.decorators = AstAdapters.to_exprList(decorators); Modified: branches/astwrite/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return ops; } public Object getOps() { - return new ListWrapper(ops); + return new ListWrapper(ops, AstAdapters.cmpopAdapter); } public void setOps(Object ops) { this.ops = AstAdapters.to_cmpopList(ops); @@ -37,7 +37,7 @@ return comparators; } public Object getComparators() { - return new ListWrapper(comparators); + return new ListWrapper(comparators, AstAdapters.exprAdapter); } public void setComparators(Object comparators) { this.comparators = AstAdapters.to_exprList(comparators); Modified: branches/astwrite/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return targets; } public Object getTargets() { - return new ListWrapper(targets); + return new ListWrapper(targets, AstAdapters.exprAdapter); } public void setTargets(Object targets) { this.targets = AstAdapters.to_exprList(targets); Modified: branches/astwrite/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return keys; } public Object getKeys() { - return new ListWrapper(keys); + return new ListWrapper(keys, AstAdapters.exprAdapter); } public void setKeys(Object keys) { this.keys = AstAdapters.to_exprList(keys); @@ -26,7 +26,7 @@ return values; } public Object getValues() { - return new ListWrapper(values); + return new ListWrapper(values, AstAdapters.exprAdapter); } public void setValues(Object values) { this.values = AstAdapters.to_exprList(values); Modified: branches/astwrite/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return dims; } public Object getDims() { - return new ListWrapper(dims); + return new ListWrapper(dims, AstAdapters.sliceAdapter); } public void setDims(Object dims) { this.dims = AstAdapters.to_sliceList(dims); Modified: branches/astwrite/src/org/python/antlr/ast/For.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -37,7 +37,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); @@ -48,7 +48,7 @@ return orelse; } public Object getOrelse() { - return new ListWrapper(orelse); + return new ListWrapper(orelse, AstAdapters.stmtAdapter); } public void setOrelse(Object orelse) { this.orelse = AstAdapters.to_stmtList(orelse); Modified: branches/astwrite/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -37,7 +37,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); @@ -48,7 +48,7 @@ return decorators; } public Object getDecorators() { - return new ListWrapper(decorators); + return new ListWrapper(decorators, AstAdapters.exprAdapter); } public void setDecorators(Object decorators) { this.decorators = AstAdapters.to_exprList(decorators); Modified: branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return generators; } public Object getGenerators() { - return new ListWrapper(generators); + return new ListWrapper(generators, AstAdapters.comprehensionAdapter); } public void setGenerators(Object generators) { this.generators = AstAdapters.to_comprehensionList(generators); Modified: branches/astwrite/src/org/python/antlr/ast/Global.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return names; } public Object getNames() { - return new ListWrapper(names); + return new ListWrapper(names, AstAdapters.identifierAdapter); } public void setNames(Object names) { this.names = AstAdapters.to_identifierList(names); Modified: branches/astwrite/src/org/python/antlr/ast/If.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); @@ -37,7 +37,7 @@ return orelse; } public Object getOrelse() { - return new ListWrapper(orelse); + return new ListWrapper(orelse, AstAdapters.stmtAdapter); } public void setOrelse(Object orelse) { this.orelse = AstAdapters.to_stmtList(orelse); Modified: branches/astwrite/src/org/python/antlr/ast/Import.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Import.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Import.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return names; } public Object getNames() { - return new ListWrapper(names); + return new ListWrapper(names, AstAdapters.aliasAdapter); } public void setNames(Object names) { this.names = AstAdapters.to_aliasList(names); Modified: branches/astwrite/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ImportFrom.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/ImportFrom.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return names; } public Object getNames() { - return new ListWrapper(names); + return new ListWrapper(names, AstAdapters.aliasAdapter); } public void setNames(Object names) { this.names = AstAdapters.to_aliasList(names); Modified: branches/astwrite/src/org/python/antlr/ast/Interactive.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Interactive.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Interactive.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); Modified: branches/astwrite/src/org/python/antlr/ast/List.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/List.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/List.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return elts; } public Object getElts() { - return new ListWrapper(elts); + return new ListWrapper(elts, AstAdapters.exprAdapter); } public void setElts(Object elts) { this.elts = AstAdapters.to_exprList(elts); Modified: branches/astwrite/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ListComp.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/ListComp.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return generators; } public Object getGenerators() { - return new ListWrapper(generators); + return new ListWrapper(generators, AstAdapters.comprehensionAdapter); } public void setGenerators(Object generators) { this.generators = AstAdapters.to_comprehensionList(generators); Modified: branches/astwrite/src/org/python/antlr/ast/Module.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Module.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Module.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); Modified: branches/astwrite/src/org/python/antlr/ast/Print.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Print.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Print.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return values; } public Object getValues() { - return new ListWrapper(values); + return new ListWrapper(values, AstAdapters.exprAdapter); } public void setValues(Object values) { this.values = AstAdapters.to_exprList(values); Modified: branches/astwrite/src/org/python/antlr/ast/Suite.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Suite.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Suite.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); Modified: branches/astwrite/src/org/python/antlr/ast/TryExcept.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/TryExcept.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/TryExcept.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); @@ -26,7 +26,7 @@ return handlers; } public Object getHandlers() { - return new ListWrapper(handlers); + return new ListWrapper(handlers, AstAdapters.excepthandlerAdapter); } public void setHandlers(Object handlers) { this.handlers = AstAdapters.to_excepthandlerList(handlers); @@ -37,7 +37,7 @@ return orelse; } public Object getOrelse() { - return new ListWrapper(orelse); + return new ListWrapper(orelse, AstAdapters.stmtAdapter); } public void setOrelse(Object orelse) { this.orelse = AstAdapters.to_stmtList(orelse); Modified: branches/astwrite/src/org/python/antlr/ast/TryFinally.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/TryFinally.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/TryFinally.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); @@ -26,7 +26,7 @@ return finalbody; } public Object getFinalbody() { - return new ListWrapper(finalbody); + return new ListWrapper(finalbody, AstAdapters.stmtAdapter); } public void setFinalbody(Object finalbody) { this.finalbody = AstAdapters.to_stmtList(finalbody); Modified: branches/astwrite/src/org/python/antlr/ast/Tuple.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Tuple.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/Tuple.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return elts; } public Object getElts() { - return new ListWrapper(elts); + return new ListWrapper(elts, AstAdapters.exprAdapter); } public void setElts(Object elts) { this.elts = AstAdapters.to_exprList(elts); Modified: branches/astwrite/src/org/python/antlr/ast/While.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/While.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/While.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -26,7 +26,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); @@ -37,7 +37,7 @@ return orelse; } public Object getOrelse() { - return new ListWrapper(orelse); + return new ListWrapper(orelse, AstAdapters.stmtAdapter); } public void setOrelse(Object orelse) { this.orelse = AstAdapters.to_stmtList(orelse); Modified: branches/astwrite/src/org/python/antlr/ast/With.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/With.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/With.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -37,7 +37,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); Modified: branches/astwrite/src/org/python/antlr/ast/argumentsType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/argumentsType.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/argumentsType.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -15,7 +15,7 @@ return args; } public Object getArgs() { - return new ListWrapper(args); + return new ListWrapper(args, AstAdapters.exprAdapter); } public void setArgs(Object args) { this.args = AstAdapters.to_exprList(args); @@ -48,7 +48,7 @@ return defaults; } public Object getDefaults() { - return new ListWrapper(defaults); + return new ListWrapper(defaults, AstAdapters.exprAdapter); } public void setDefaults(Object defaults) { this.defaults = AstAdapters.to_exprList(defaults); Modified: branches/astwrite/src/org/python/antlr/ast/comprehensionType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/comprehensionType.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/comprehensionType.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -37,7 +37,7 @@ return ifs; } public Object getIfs() { - return new ListWrapper(ifs); + return new ListWrapper(ifs, AstAdapters.exprAdapter); } public void setIfs(Object ifs) { this.ifs = AstAdapters.to_exprList(ifs); Modified: branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java 2008-11-25 21:09:57 UTC (rev 5640) +++ branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java 2008-11-26 03:42:02 UTC (rev 5641) @@ -37,7 +37,7 @@ return body; } public Object getBody() { - return new ListWrapper(body); + return new ListWrapper(body, AstAdapters.stmtAdapter); } public void setBody(Object body) { this.body = AstAdapters.to_stmtList(body); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-11-25 21:10:03
|
Revision: 5640 http://jython.svn.sourceforge.net/jython/?rev=5640&view=rev Author: otmarhumbel Date: 2008-11-25 21:09:57 +0000 (Tue, 25 Nov 2008) Log Message: ----------- check for both jython-complete.jar and jython.jar in findRoot() Modified Paths: -------------- trunk/jython/src/org/python/core/PySystemState.java Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-11-25 14:11:53 UTC (rev 5639) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-11-25 21:09:57 UTC (rev 5640) @@ -34,6 +34,7 @@ protected static final String CACHEDIR_DEFAULT_NAME = "cachedir"; public static final String JYTHON_JAR = "jython.jar"; + public static final String JYTHON_COMPLETE_JAR = "jython-complete.jar"; private static final String JAR_URL_PREFIX = "jar:file:"; private static final String JAR_SEPARATOR = "!"; @@ -392,10 +393,14 @@ if (root == null) { String classpath = preProperties.getProperty("java.class.path"); if (classpath != null) { - int jpy = classpath.toLowerCase().indexOf(JYTHON_JAR); - if (jpy >= 0) { - int start = classpath.lastIndexOf(java.io.File.pathSeparator, jpy) + 1; - root = classpath.substring(start, jpy); + String lowerCaseClasspath = classpath.toLowerCase(); + int jarIndex = lowerCaseClasspath.indexOf(JYTHON_COMPLETE_JAR); + if (jarIndex < 0) { + jarIndex = lowerCaseClasspath.indexOf(JYTHON_JAR); + } + if (jarIndex >= 0) { + int start = classpath.lastIndexOf(java.io.File.pathSeparator, jarIndex) + 1; + root = classpath.substring(start, jarIndex); } else { // in case JYTHON_JAR is referenced from a MANIFEST inside another jar on the classpath root = jarFileName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-11-25 14:12:03
|
Revision: 5639 http://jython.svn.sourceforge.net/jython/?rev=5639&view=rev Author: otmarhumbel Date: 2008-11-25 14:11:53 +0000 (Tue, 25 Nov 2008) Log Message: ----------- to enable virtualenv again: do not hardcode JYTHON_HOME this fixes issue #1180 Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java trunk/installer/src/java/org/python/util/install/driver/jython_test.bat.template trunk/installer/src/java/org/python/util/install/driver/jython_test.template trunk/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java trunk/jython/src/shell/jython trunk/jython/src/shell/jython.bat Modified: trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java =================================================================== --- trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java 2008-11-25 14:00:26 UTC (rev 5638) +++ trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java 2008-11-25 14:11:53 UTC (rev 5639) @@ -15,6 +15,11 @@ protected final static String WIN_CR_LF; + private final static String JAVA_HOME = "JAVA_HOME"; + + /** do not hard-wire JYTHON_HOME */ + private final static String JYTHON_HOME_FALLBACK = "JYTHON_HOME_FALLBACK"; + private final static String JYTHON = "jython"; private final static String JYTHON_BAT = "jython.bat"; @@ -128,11 +133,17 @@ * @see getStartScript */ private String getWindowsJythonTemplate() { - StringBuffer buffer = getWindowsHeaderTemplate(); - buffer.append("set JAVA_HOME=\"{2}\"" + WIN_CR_LF); - buffer.append("set JYTHON_HOME=\"{3}\"" + WIN_CR_LF); - buffer.append(WIN_CR_LF); - return buffer.toString(); + StringBuilder builder = getWindowsHeaderTemplate(); + builder.append("set "); + builder.append(JAVA_HOME); + builder.append("=\"{2}\""); + builder.append(WIN_CR_LF); + builder.append("set "); + builder.append(JYTHON_HOME_FALLBACK); + builder.append("=\"{3}\""); + builder.append(WIN_CR_LF); + builder.append(WIN_CR_LF); + return builder.toString(); } /** @@ -140,13 +151,16 @@ * * @see getStartScript */ - private StringBuffer getWindowsHeaderTemplate() { - StringBuffer buffer = new StringBuffer(1000); - buffer.append("@echo off" + WIN_CR_LF); - buffer.append("rem This file was generated by the Jython installer" + WIN_CR_LF); - buffer.append("rem Created on {0} by {1}" + WIN_CR_LF); - buffer.append(WIN_CR_LF); - return buffer; + private StringBuilder getWindowsHeaderTemplate() { + StringBuilder builder = new StringBuilder(1000); + builder.append("@echo off"); + builder.append(WIN_CR_LF); + builder.append("rem This file was generated by the Jython installer"); + builder.append(WIN_CR_LF); + builder.append("rem Created on {0} by {1}"); + builder.append(WIN_CR_LF); + builder.append(WIN_CR_LF); + return builder; } /** @@ -155,11 +169,13 @@ * @see getStartScript */ private String getUnixJythonTemplate() { - StringBuffer buffer = getUnixHeaderTemplate(); - buffer.append("JAVA_HOME=\"{2}\"\n"); - buffer.append("JYTHON_HOME=\"{3}\"\n"); - buffer.append("\n"); - return buffer.toString(); + StringBuilder builder = getUnixHeaderTemplate(); + builder.append(JAVA_HOME); + builder.append("=\"{2}\"\n"); + builder.append(JYTHON_HOME_FALLBACK); + builder.append("=\"{3}\"\n"); + builder.append("\n"); + return builder.toString(); } /** @@ -167,14 +183,14 @@ * * @see getStartScript */ - private StringBuffer getUnixHeaderTemplate() { - StringBuffer buffer = new StringBuffer(1000); - buffer.append("#!/usr/bin/env bash\n"); - buffer.append("\n"); - buffer.append("# This file was generated by the Jython installer\n"); - buffer.append("# Created on {0} by {1}\n"); - buffer.append("\n"); - return buffer; + private StringBuilder getUnixHeaderTemplate() { + StringBuilder builder = new StringBuilder(1000); + builder.append("#!/usr/bin/env bash\n"); + builder.append("\n"); + builder.append("# This file was generated by the Jython installer\n"); + builder.append("# Created on {0} by {1}\n"); + builder.append("\n"); + return builder; } /** Modified: trunk/installer/src/java/org/python/util/install/driver/jython_test.bat.template =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/jython_test.bat.template 2008-11-25 14:00:26 UTC (rev 5638) +++ trunk/installer/src/java/org/python/util/install/driver/jython_test.bat.template 2008-11-25 14:11:53 UTC (rev 5639) @@ -35,6 +35,28 @@ call jython.bat "%_SCRIPT%" set E=%ERRORLEVEL% +cd .. + +echo {3}: no home, calling in home dir: +set JAVA_HOME= +set JYTHON_HOME= +call jython.bat "%_SCRIPT%" +set E=%ERRORLEVEL% + +cd .. + +echo {3}: no home, calling /jython.bat from another working dir:" +set JAVA_HOME= +set JYTHON_HOME= +call "%_INSTALL_DIR%\jython.bat" "%_SCRIPT%" +set E=%ERRORLEVEL% + +echo {3}: no home, calling bin/jython.bat from another working dir:" +set JAVA_HOME= +set JYTHON_HOME= +call "%_INSTALL_DIR%\bin\jython.bat" "%_SCRIPT%" +set E=%ERRORLEVEL% + rem cleanup: set JAVA_HOME=%_OLD_JAVA_HOME% set JYTHON_HOME=%_OLD_JYTHON_HOME% Modified: trunk/installer/src/java/org/python/util/install/driver/jython_test.template =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/jython_test.template 2008-11-25 14:00:26 UTC (rev 5638) +++ trunk/installer/src/java/org/python/util/install/driver/jython_test.template 2008-11-25 14:11:53 UTC (rev 5639) @@ -33,11 +33,23 @@ export JYTHON_HOME="$_INSTALL_DIR" ./jython "$_SCRIPT" +cd .. + +echo "{3}: no home, calling in home dir:" +export JAVA_HOME= +export JYTHON_HOME= +./jython "$_SCRIPT" + cd ~ -echo "{3}: no home, calling from another working dir:" +echo "{3}: no home, calling /jython from another working dir:" export JAVA_HOME= export JYTHON_HOME= +"$_INSTALL_DIR/jython" "$_SCRIPT" + +echo "{3}: no home, calling /bin/jython from another working dir:" +export JAVA_HOME= +export JYTHON_HOME= "$_INSTALL_DIR/bin/jython" "$_SCRIPT" # cleanup: Modified: trunk/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java 2008-11-25 14:00:26 UTC (rev 5638) +++ trunk/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java 2008-11-25 14:11:53 UTC (rev 5639) @@ -49,7 +49,7 @@ buf.append("JAVA_HOME=\""); buf.append(System.getProperty("java.home")); buf.append("\"\n"); - buf.append("JYTHON_HOME=\""); + buf.append("JYTHON_HOME_FALLBACK=\""); buf.append(_targetDir.getAbsolutePath()); buf.append("\"\n"); // some rudimentary tests - feel free to do more @@ -59,6 +59,11 @@ assertTrue(unixScript.length() > 3500); assertTrue(unixScript.indexOf("-Dpython.home=") > start.length()); assertTrue(unixScript.indexOf("-Dpython.executable=") > start.length()); + // no hard coding of JYTHON_HOME + int jythonHomeIndex = unixScript.indexOf("if [ -z \"$JYTHON_HOME\" ] ; then"); + assertTrue(jythonHomeIndex >= 0); + int definitionIndex = unixScript.indexOf("JYTHON_HOME="); + assertTrue(definitionIndex > jythonHomeIndex || definitionIndex < 0); } public void testWindows() throws IOException { @@ -72,7 +77,7 @@ winBuf.append(System.getProperty("java.home")); winBuf.append("\""); winBuf.append(WIN_CR_LF); - winBuf.append("set JYTHON_HOME=\""); + winBuf.append("set JYTHON_HOME_FALLBACK=\""); winBuf.append(_targetDir.getAbsolutePath()); winBuf.append("\""); winBuf.append(WIN_CR_LF); @@ -84,6 +89,11 @@ assertTrue(winScript.indexOf("if not \"%_TRIMMED_JAVA_HOME%\"==\"\"") > start.length()); assertTrue(winScript.indexOf("-Dpython.home=") > start.length()); assertTrue(winScript.indexOf("-Dpython.executable=") > start.length()); + // no hard coding of JYTHON_HOME + int jythonHomeIndex = winScript.indexOf("if not \"%_TRIMMED_JYTHON_HOME%\"==\"\""); + assertTrue(jythonHomeIndex >= 0); + int definitionIndex = winScript.indexOf("set JYTHON_HOME="); + assertTrue(definitionIndex > jythonHomeIndex || definitionIndex < 0); } public void testFlavour() { Modified: trunk/jython/src/shell/jython =================================================================== --- trunk/jython/src/shell/jython 2008-11-25 14:00:26 UTC (rev 5638) +++ trunk/jython/src/shell/jython 2008-11-25 14:11:53 UTC (rev 5639) @@ -43,16 +43,24 @@ JAVA_CMD=("$JAVA_HOME/bin/java") fi +# try to dynamically determine jython home +# (this script typically resides in jython home, or in the /bin subdirectory) if [ -z "$JYTHON_HOME" ] ; then if [ "$PRG" = "./jython" ] ; then - # current dir is /bin dir - JYTHON_HOME_1=`pwd` # the ./bin dir - JYTHON_HOME=`dirname "$JYTHON_HOME_1"` # the . dir + # current dir is the script dir + JYTHON_HOME_1=`pwd` else - # current dir is not /bin dir - JYTHON_HOME_1=`dirname "$PRG"` # the ./bin dir - JYTHON_HOME=`dirname "$JYTHON_HOME_1"` # the . dir + # current dir is not the script dir + JYTHON_HOME_1=`dirname "$PRG"` fi + if [ -f "$JYTHON_HOME_1"/jython-complete.jar -o -f "$JYTHON_HOME_1"/jython.jar ] ; then + JYTHON_HOME="$JYTHON_HOME_1" + else + JYTHON_HOME=`dirname "$JYTHON_HOME_1"` + fi + if [ ! -f "$JYTHON_HOME"/jython-complete.jar -a ! -f "$JYTHON_HOME"/jython.jar ] ; then + JYTHON_HOME="$JYTHON_HOME_FALLBACK" + fi fi if [ -z "$JYTHON_OPTS" ] ; then @@ -189,7 +197,7 @@ [ -n "$profile_requested" ] && echo "Running with instrumented profiler" java_args=("${java_args[@]}" -classpath "$CP$CP_DELIMITER$CLASSPATH") else - if [ -z $help_requested ] ; then + if [ -z "$help_requested" ] ; then JAVA_CMD=(exec "${JAVA_CMD[@]}") fi java_args=("${java_args[@]}" -Xbootclasspath/a:"$CP" -classpath "$CLASSPATH") Modified: trunk/jython/src/shell/jython.bat =================================================================== --- trunk/jython/src/shell/jython.bat 2008-11-25 14:00:26 UTC (rev 5638) +++ trunk/jython/src/shell/jython.bat 2008-11-25 14:11:53 UTC (rev 5639) @@ -31,9 +31,22 @@ set _JYTHON_HOME="%_TRIMMED_JYTHON_HOME%" goto gotHome ) + +rem try to dynamically determine jython home +rem (this script typically resides in jython home, or in the /bin subdirectory) +pushd "%~dp0%" +set _JYTHON_HOME="%CD%" +popd +if exist %_JYTHON_HOME%\jython.jar goto gotHome +if exist %_JYTHON_HOME%\jython-complete.jar goto gotHome pushd "%~dp0%\.." set _JYTHON_HOME="%CD%" popd +if exist %_JYTHON_HOME%\jython.jar goto gotHome +if exist %_JYTHON_HOME%\jython-complete.jar goto gotHome +rem jython home fallback (if all else fails) +rem if present, %JYTHON_HOME_FALLBACK% is already quoted +set _JYTHON_HOME=%JYTHON_HOME_FALLBACK% :gotHome if not exist %_JYTHON_HOME%\jython.jar goto tryComplete @@ -49,7 +62,7 @@ if exist %_JYTHON_HOME%/jython-complete.jar goto run echo Cannot find jython.jar or jython-complete.jar in %_JYTHON_HOME% -echo Try running this batch file from the 'bin' directory of an installed Jython +echo Try running this batch file from the 'bin' directory of an installed Jython, echo or setting JYTHON_HOME. goto cleanup This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-11-25 14:00:28
|
Revision: 5638 http://jython.svn.sourceforge.net/jython/?rev=5638&view=rev Author: otmarhumbel Date: 2008-11-25 14:00:26 +0000 (Tue, 25 Nov 2008) Log Message: ----------- stronger verification: also import os Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java Modified: trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java 2008-11-25 04:27:25 UTC (rev 5637) +++ trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java 2008-11-25 14:00:26 UTC (rev 5638) @@ -242,6 +242,7 @@ private String getTestScript() { StringBuilder b = new StringBuilder(80); b.append("import sys\n"); + b.append("import os\n"); b.append("print '"); b.append(JYTHON_UP); b.append("'\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-25 04:27:36
|
Revision: 5637 http://jython.svn.sourceforge.net/jython/?rev=5637&view=rev Author: fwierzbicki Date: 2008-11-25 04:27:25 +0000 (Tue, 25 Nov 2008) Log Message: ----------- run asdl_antlr.py for last commit. Modified Paths: -------------- branches/astwrite/src/org/python/antlr/ast/Assert.java branches/astwrite/src/org/python/antlr/ast/Assign.java branches/astwrite/src/org/python/antlr/ast/Attribute.java branches/astwrite/src/org/python/antlr/ast/AugAssign.java branches/astwrite/src/org/python/antlr/ast/BinOp.java branches/astwrite/src/org/python/antlr/ast/BoolOp.java branches/astwrite/src/org/python/antlr/ast/Break.java branches/astwrite/src/org/python/antlr/ast/Call.java branches/astwrite/src/org/python/antlr/ast/ClassDef.java branches/astwrite/src/org/python/antlr/ast/Compare.java branches/astwrite/src/org/python/antlr/ast/Continue.java branches/astwrite/src/org/python/antlr/ast/Delete.java branches/astwrite/src/org/python/antlr/ast/Dict.java branches/astwrite/src/org/python/antlr/ast/Ellipsis.java branches/astwrite/src/org/python/antlr/ast/Exec.java branches/astwrite/src/org/python/antlr/ast/Expr.java branches/astwrite/src/org/python/antlr/ast/Expression.java branches/astwrite/src/org/python/antlr/ast/ExtSlice.java branches/astwrite/src/org/python/antlr/ast/For.java branches/astwrite/src/org/python/antlr/ast/FunctionDef.java branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java branches/astwrite/src/org/python/antlr/ast/Global.java branches/astwrite/src/org/python/antlr/ast/If.java branches/astwrite/src/org/python/antlr/ast/IfExp.java branches/astwrite/src/org/python/antlr/ast/Import.java branches/astwrite/src/org/python/antlr/ast/ImportFrom.java branches/astwrite/src/org/python/antlr/ast/Index.java branches/astwrite/src/org/python/antlr/ast/Interactive.java branches/astwrite/src/org/python/antlr/ast/Lambda.java branches/astwrite/src/org/python/antlr/ast/List.java branches/astwrite/src/org/python/antlr/ast/ListComp.java branches/astwrite/src/org/python/antlr/ast/Module.java branches/astwrite/src/org/python/antlr/ast/Name.java branches/astwrite/src/org/python/antlr/ast/Num.java branches/astwrite/src/org/python/antlr/ast/Pass.java branches/astwrite/src/org/python/antlr/ast/Print.java branches/astwrite/src/org/python/antlr/ast/Raise.java branches/astwrite/src/org/python/antlr/ast/Repr.java branches/astwrite/src/org/python/antlr/ast/Return.java branches/astwrite/src/org/python/antlr/ast/Slice.java branches/astwrite/src/org/python/antlr/ast/Str.java branches/astwrite/src/org/python/antlr/ast/Subscript.java branches/astwrite/src/org/python/antlr/ast/Suite.java branches/astwrite/src/org/python/antlr/ast/TryExcept.java branches/astwrite/src/org/python/antlr/ast/TryFinally.java branches/astwrite/src/org/python/antlr/ast/Tuple.java branches/astwrite/src/org/python/antlr/ast/UnaryOp.java branches/astwrite/src/org/python/antlr/ast/VisitorBase.java branches/astwrite/src/org/python/antlr/ast/While.java branches/astwrite/src/org/python/antlr/ast/With.java branches/astwrite/src/org/python/antlr/ast/Yield.java branches/astwrite/src/org/python/antlr/ast/aliasType.java branches/astwrite/src/org/python/antlr/ast/argumentsType.java branches/astwrite/src/org/python/antlr/ast/comprehensionType.java branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java branches/astwrite/src/org/python/antlr/ast/exprType.java branches/astwrite/src/org/python/antlr/ast/keywordType.java branches/astwrite/src/org/python/antlr/ast/modType.java branches/astwrite/src/org/python/antlr/ast/sliceType.java branches/astwrite/src/org/python/antlr/ast/stmtType.java Modified: branches/astwrite/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assert.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Assert.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Attribute.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Attribute.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/AugAssign.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/AugAssign.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BinOp.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/BinOp.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Break.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Break.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Break.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Call.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Continue.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Continue.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Continue.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Ellipsis.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Ellipsis.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Exec.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Exec.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Expr.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Expr.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Expression.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Expression.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/For.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Global.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/If.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/IfExp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/IfExp.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/IfExp.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Import.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Import.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Import.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ImportFrom.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/ImportFrom.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Index.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Index.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Index.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Interactive.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Interactive.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Interactive.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Lambda.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Lambda.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Lambda.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/List.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/List.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/List.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ListComp.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/ListComp.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Module.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Module.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Module.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Name.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Name.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Name.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Num.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Num.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Num.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Pass.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Pass.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Pass.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Print.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Print.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Print.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Raise.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Raise.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Raise.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Repr.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Repr.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Repr.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Return.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Return.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Return.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Slice.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Slice.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Slice.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Str.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Str.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Str.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Subscript.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Subscript.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Subscript.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Suite.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Suite.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Suite.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/TryExcept.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/TryExcept.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/TryExcept.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/TryFinally.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/TryFinally.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/TryFinally.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Tuple.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Tuple.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Tuple.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/UnaryOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/UnaryOp.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/UnaryOp.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/VisitorBase.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/VisitorBase.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/VisitorBase.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; Modified: branches/astwrite/src/org/python/antlr/ast/While.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/While.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/While.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/With.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/With.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/With.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/Yield.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Yield.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/Yield.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/aliasType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/aliasType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/aliasType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/argumentsType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/argumentsType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/argumentsType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/comprehensionType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/comprehensionType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/comprehensionType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/exprType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/exprType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/exprType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; Modified: branches/astwrite/src/org/python/antlr/ast/keywordType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/keywordType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/keywordType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; Modified: branches/astwrite/src/org/python/antlr/ast/modType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/modType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/modType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; Modified: branches/astwrite/src/org/python/antlr/ast/sliceType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/sliceType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/sliceType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; Modified: branches/astwrite/src/org/python/antlr/ast/stmtType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/stmtType.java 2008-11-25 04:24:40 UTC (rev 5636) +++ branches/astwrite/src/org/python/antlr/ast/stmtType.java 2008-11-25 04:27:25 UTC (rev 5637) @@ -1,9 +1,9 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; -import org.python.antlr.ListWrapper; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-25 04:24:42
|
Revision: 5636 http://jython.svn.sourceforge.net/jython/?rev=5636&view=rev Author: fwierzbicki Date: 2008-11-25 04:24:40 +0000 (Tue, 25 Nov 2008) Log Message: ----------- Creating an adapter package under antlr for obj->ast conversions. Modified Paths: -------------- branches/astwrite/ast/asdl_antlr.py Added Paths: ----------- branches/astwrite/src/org/python/antlr/adapter/ branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java Removed Paths: ------------- branches/astwrite/src/org/python/antlr/AstAdapters.java branches/astwrite/src/org/python/antlr/AstObjectAdapter.java branches/astwrite/src/org/python/antlr/ListWrapper.java branches/astwrite/src/org/python/antlr/StmtListAdapter.java Modified: branches/astwrite/ast/asdl_antlr.py =================================================================== --- branches/astwrite/ast/asdl_antlr.py 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/ast/asdl_antlr.py 2008-11-25 04:24:40 UTC (rev 5636) @@ -57,9 +57,9 @@ print >> self.file, 'package org.python.antlr.ast;' if refersToPythonTree: print >> self.file, 'import java.util.ArrayList;' - print >> self.file, 'import org.python.antlr.AstAdapters;' print >> self.file, 'import org.python.antlr.PythonTree;' - print >> self.file, 'import org.python.antlr.ListWrapper;' + print >> self.file, 'import org.python.antlr.adapter.AstAdapters;' + print >> self.file, 'import org.python.antlr.adapter.ListWrapper;' print >> self.file, 'import org.antlr.runtime.CommonToken;' print >> self.file, 'import org.antlr.runtime.Token;' if useDataOutput: Deleted: branches/astwrite/src/org/python/antlr/AstAdapters.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstAdapters.java 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/src/org/python/antlr/AstAdapters.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -1,156 +0,0 @@ -package org.python.antlr; - -import org.python.antlr.ast.*; -import org.python.core.*; - -/** - * AstAdapter turns Python and Java objects into ast nodes. - */ -public class AstAdapters { - - public static java.util.List<aliasType> to_aliasList(Object o) { - return null; - } - - public static java.util.List<cmpopType> to_cmpopList(Object o) { - return null; - } - - public static java.util.List<comprehensionType> to_comprehensionList(Object o) { - return null; - } - - public static java.util.List<excepthandlerType> to_excepthandlerList(Object o) { - return null; - } - - public static java.util.List<exprType> to_exprList(Object o) { - return null; - } - - public static java.util.List<String> to_identifierList(Object o) { - return null; - } - - public static java.util.List<keywordType> to_keywordList(Object o) { - return null; - } - - public static java.util.List<sliceType> to_sliceList(Object o) { - return null; - } - - public static java.util.List<stmtType> to_stmtList(Object o) { - return null; - } - - public static exprType to_expr(Object o) { - if (o == null || o instanceof exprType) { - return (exprType)o; - } else if (o instanceof Integer) { - return new Num(new PyInteger((Integer)o)); - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); - } - - public static int to_int(Object o) { - if (o == null || o instanceof Integer) { - return (Integer)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to int node"); - } - - public static String to_identifier(Object o) { - if (o == null || o instanceof String) { - return (String)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); - } - - public static expr_contextType to_expr_context(Object o) { - if (o == null || o instanceof expr_contextType) { - return (expr_contextType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr_context node"); - } - - public static sliceType to_slice(Object o) { - if (o == null || o instanceof sliceType) { - return (sliceType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); - } - - public static stmtType to_stmt(Object o) { - if (o instanceof PyJavaInstance) { - o = ((PyJavaInstance)o).__tojava__(stmtType.class); - } - if (o == null || o instanceof stmtType) { - return (stmtType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to stmt node"); - } - - public static String to_string(Object o) { - if (o == null || o instanceof String) { - return (String)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to string node"); - } - - public static operatorType to_operator(Object o) { - if (o == null || o instanceof operatorType) { - return (operatorType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to operator node"); - } - - public static boolopType to_boolop(Object o) { - if (o == null || o instanceof boolopType) { - return (boolopType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to boolop node"); - } - - public static argumentsType to_arguments(Object o) { - if (o == null || o instanceof argumentsType) { - return (argumentsType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arguments node"); - } - - public static Object to_object(Object o) { - if (o == null || o instanceof Object) { - return (Object)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to object node"); - } - - public static Boolean to_bool(Object o) { - if (o == null || o instanceof Boolean) { - return (Boolean)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to Boolean node"); - } - - public static unaryopType to_unaryop(Object o) { - if (o == null || o instanceof unaryopType) { - return (unaryopType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to unaryop node"); - } - -} Deleted: branches/astwrite/src/org/python/antlr/AstObjectAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstObjectAdapter.java 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/src/org/python/antlr/AstObjectAdapter.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -1,5 +0,0 @@ -package org.python.antlr; - -public interface AstObjectAdapter { - public Object adapt(Object o); -} Deleted: branches/astwrite/src/org/python/antlr/ListWrapper.java =================================================================== --- branches/astwrite/src/org/python/antlr/ListWrapper.java 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/src/org/python/antlr/ListWrapper.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -1,219 +0,0 @@ -package org.python.antlr; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.python.core.PyObject; - -public class ListWrapper implements List { - - private List list; - private AstObjectAdapter adapter; - - public ListWrapper(List list) { - this.list = list; - } - - public ListWrapper(List list, AstObjectAdapter adapter) { - this.adapter = adapter; - this.list = list; - } - - public boolean containsAll(Collection c) { - return containsAll(c); - } - - public boolean removeAll(Collection c) { - return list.removeAll(c); - } - - public boolean retainAll(Collection c) { - return list.retainAll(c); - } - - public boolean add(Object e) { - return list.add(e); - } - - public void add(int index, Object e) { - list.add(index, e); - } - - public boolean addAll(Collection c) { - return list.addAll(c); - } - - public boolean addAll(int index, Collection c) { - return list.addAll(index, c); - } - - public void clear() { - list.clear(); - } - - public boolean contains(Object elem) { - return list.contains(elem); - } - - public Object get(int index) { - return list.get(index); - } - - public int indexOf(Object elem) { - return list.indexOf(elem); - } - - public boolean isEmpty() { - return list.isEmpty(); - } - - public int lastIndexOf(Object elem) { - return list.lastIndexOf(elem); - } - - public Object remove(int index) { - return list.remove(index); - } - - public boolean remove(Object o) { - return list.remove(o); - } - - public Object set(int index, Object element) { - return list.set(index, element); - } - - public int size() { - return list.size(); - } - - public Object[] toArray() { - return list.toArray(); - } - - public Object[] toArray(Object[] a) { - return list.toArray(a); - } - - public Iterator iterator() { - return list.iterator(); - } - - public ListIterator listIterator() { - return list.listIterator(); - } - - public ListIterator listIterator(int index) { - return list.listIterator(index); - } - - public List subList(int fromIndex, int toIndex) { - return list.subList(fromIndex, toIndex); - } - - public ListWrapper __add__(Object o) { - List newList = new ArrayList(); - newList.addAll(list); - newList.add(o); - return new ListWrapper(newList); - } - - public void __iadd__(PyObject o) { - extend(o); - } - - public int __len__() { - return list.size(); - } - - public boolean __contains__(Object o) { - return list.contains(o); - } - - public PyObject __imul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject __iter__() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject __mul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject __radd__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject __rmul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void append(PyObject o) { - list.add(adapter.adapt(o)); - } - - public int count(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void del(int i) { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void delRange(int start, int stop, int step) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void extend(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public int index(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public int index(PyObject o, int start) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public int index(PyObject o, int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void insert(int index, PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject pop() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject pop(int n) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void remove(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void reverse() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void sort(PyObject compare) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void sort() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void sort(PyObject cmp, PyObject key, PyObject reverse) { - throw new UnsupportedOperationException("Not supported yet."); - } - -} Deleted: branches/astwrite/src/org/python/antlr/StmtListAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/StmtListAdapter.java 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/src/org/python/antlr/StmtListAdapter.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -1,22 +0,0 @@ -package org.python.antlr; - -import org.python.antlr.ast.stmtType; - -import java.util.ArrayList; -import java.util.List; - -public class StmtListAdapter implements AstObjectAdapter { - public Object adaptList(Object list) { - List<stmtType> s = new ArrayList<stmtType>(); - if (list instanceof List) { - for (Object o : (List)list) { - s.add(AstAdapters.to_stmt(o)); - } - } - return s; - } - - public Object adapt(Object o) { - return AstAdapters.to_stmt(o); - } -} Copied: branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java (from rev 5634, branches/astwrite/src/org/python/antlr/AstAdapters.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -0,0 +1,156 @@ +package org.python.antlr.adapter; + +import org.python.antlr.ast.*; +import org.python.core.*; + +/** + * AstAdapter turns Python and Java objects into ast nodes. + */ +public class AstAdapters { + + public static java.util.List<aliasType> to_aliasList(Object o) { + return null; + } + + public static java.util.List<cmpopType> to_cmpopList(Object o) { + return null; + } + + public static java.util.List<comprehensionType> to_comprehensionList(Object o) { + return null; + } + + public static java.util.List<excepthandlerType> to_excepthandlerList(Object o) { + return null; + } + + public static java.util.List<exprType> to_exprList(Object o) { + return null; + } + + public static java.util.List<String> to_identifierList(Object o) { + return null; + } + + public static java.util.List<keywordType> to_keywordList(Object o) { + return null; + } + + public static java.util.List<sliceType> to_sliceList(Object o) { + return null; + } + + public static java.util.List<stmtType> to_stmtList(Object o) { + return null; + } + + public static exprType to_expr(Object o) { + if (o == null || o instanceof exprType) { + return (exprType)o; + } else if (o instanceof Integer) { + return new Num(new PyInteger((Integer)o)); + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); + } + + public static int to_int(Object o) { + if (o == null || o instanceof Integer) { + return (Integer)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to int node"); + } + + public static String to_identifier(Object o) { + if (o == null || o instanceof String) { + return (String)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); + } + + public static expr_contextType to_expr_context(Object o) { + if (o == null || o instanceof expr_contextType) { + return (expr_contextType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr_context node"); + } + + public static sliceType to_slice(Object o) { + if (o == null || o instanceof sliceType) { + return (sliceType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); + } + + public static stmtType to_stmt(Object o) { + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(stmtType.class); + } + if (o == null || o instanceof stmtType) { + return (stmtType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to stmt node"); + } + + public static String to_string(Object o) { + if (o == null || o instanceof String) { + return (String)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to string node"); + } + + public static operatorType to_operator(Object o) { + if (o == null || o instanceof operatorType) { + return (operatorType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to operator node"); + } + + public static boolopType to_boolop(Object o) { + if (o == null || o instanceof boolopType) { + return (boolopType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to boolop node"); + } + + public static argumentsType to_arguments(Object o) { + if (o == null || o instanceof argumentsType) { + return (argumentsType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arguments node"); + } + + public static Object to_object(Object o) { + if (o == null || o instanceof Object) { + return (Object)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to object node"); + } + + public static Boolean to_bool(Object o) { + if (o == null || o instanceof Boolean) { + return (Boolean)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to Boolean node"); + } + + public static unaryopType to_unaryop(Object o) { + if (o == null || o instanceof unaryopType) { + return (unaryopType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to unaryop node"); + } + +} Copied: branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java (from rev 5634, branches/astwrite/src/org/python/antlr/AstObjectAdapter.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -0,0 +1,5 @@ +package org.python.antlr.adapter; + +public interface AstObjectAdapter { + public Object adapt(Object o); +} Copied: branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java (from rev 5634, branches/astwrite/src/org/python/antlr/ListWrapper.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -0,0 +1,219 @@ +package org.python.antlr.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import org.python.core.PyObject; + +public class ListWrapper implements List { + + private List list; + private AstObjectAdapter adapter; + + public ListWrapper(List list) { + this.list = list; + } + + public ListWrapper(List list, AstObjectAdapter adapter) { + this.adapter = adapter; + this.list = list; + } + + public boolean containsAll(Collection c) { + return containsAll(c); + } + + public boolean removeAll(Collection c) { + return list.removeAll(c); + } + + public boolean retainAll(Collection c) { + return list.retainAll(c); + } + + public boolean add(Object e) { + return list.add(e); + } + + public void add(int index, Object e) { + list.add(index, e); + } + + public boolean addAll(Collection c) { + return list.addAll(c); + } + + public boolean addAll(int index, Collection c) { + return list.addAll(index, c); + } + + public void clear() { + list.clear(); + } + + public boolean contains(Object elem) { + return list.contains(elem); + } + + public Object get(int index) { + return list.get(index); + } + + public int indexOf(Object elem) { + return list.indexOf(elem); + } + + public boolean isEmpty() { + return list.isEmpty(); + } + + public int lastIndexOf(Object elem) { + return list.lastIndexOf(elem); + } + + public Object remove(int index) { + return list.remove(index); + } + + public boolean remove(Object o) { + return list.remove(o); + } + + public Object set(int index, Object element) { + return list.set(index, element); + } + + public int size() { + return list.size(); + } + + public Object[] toArray() { + return list.toArray(); + } + + public Object[] toArray(Object[] a) { + return list.toArray(a); + } + + public Iterator iterator() { + return list.iterator(); + } + + public ListIterator listIterator() { + return list.listIterator(); + } + + public ListIterator listIterator(int index) { + return list.listIterator(index); + } + + public List subList(int fromIndex, int toIndex) { + return list.subList(fromIndex, toIndex); + } + + public ListWrapper __add__(Object o) { + List newList = new ArrayList(); + newList.addAll(list); + newList.add(o); + return new ListWrapper(newList); + } + + public void __iadd__(PyObject o) { + extend(o); + } + + public int __len__() { + return list.size(); + } + + public boolean __contains__(Object o) { + return list.contains(o); + } + + public PyObject __imul__(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject __iter__() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject __mul__(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject __radd__(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject __rmul__(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void append(PyObject o) { + list.add(adapter.adapt(o)); + } + + public int count(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void del(int i) { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void delRange(int start, int stop, int step) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void extend(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int index(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int index(PyObject o, int start) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int index(PyObject o, int start, int stop) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void insert(int index, PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject pop() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject pop(int n) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void remove(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void reverse() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void sort(PyObject compare) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void sort() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void sort(PyObject cmp, PyObject key, PyObject reverse) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} Copied: branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java (from rev 5634, branches/astwrite/src/org/python/antlr/StmtListAdapter.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -0,0 +1,22 @@ +package org.python.antlr.adapter; + +import org.python.antlr.ast.stmtType; + +import java.util.ArrayList; +import java.util.List; + +public class StmtListAdapter implements AstObjectAdapter { + public Object adaptList(Object list) { + List<stmtType> s = new ArrayList<stmtType>(); + if (list instanceof List) { + for (Object o : (List)list) { + s.add(AstAdapters.to_stmt(o)); + } + } + return s; + } + + public Object adapt(Object o) { + return AstAdapters.to_stmt(o); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-25 04:19:49
|
Revision: 5635 http://jython.svn.sourceforge.net/jython/?rev=5635&view=rev Author: fwierzbicki Date: 2008-11-25 04:19:42 +0000 (Tue, 25 Nov 2008) Log Message: ----------- Merged revisions 5616,5618-5621,5624,5626-5627,5629-5630 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython Modified Paths: -------------- branches/astwrite/Lib/popen2.py branches/astwrite/Lib/test/test_bool.py branches/astwrite/Lib/test/test_descr.py branches/astwrite/build.xml branches/astwrite/src/org/python/core/Py.java branches/astwrite/src/org/python/core/PyBoolean.java branches/astwrite/src/org/python/core/PyBuiltinCallable.java branches/astwrite/src/org/python/core/PyCell.java branches/astwrite/src/org/python/core/PyClassMethodDescr.java branches/astwrite/src/org/python/core/PyDataDescr.java branches/astwrite/src/org/python/core/PyDictProxy.java branches/astwrite/src/org/python/core/PyEllipsis.java branches/astwrite/src/org/python/core/PyFunction.java branches/astwrite/src/org/python/core/PyGenerator.java branches/astwrite/src/org/python/core/PyMethod.java branches/astwrite/src/org/python/core/PyMethodDescr.java branches/astwrite/src/org/python/core/PyNone.java branches/astwrite/src/org/python/core/PyNotImplemented.java branches/astwrite/src/org/python/core/PySlice.java branches/astwrite/src/org/python/core/PySlot.java branches/astwrite/src/org/python/core/PySystemState.java branches/astwrite/src/org/python/core/PyTraceback.java branches/astwrite/src/org/python/core/PyType.java branches/astwrite/src/org/python/core/PyXRange.java branches/astwrite/src/org/python/expose/BaseTypeBuilder.java branches/astwrite/src/org/python/expose/ExposedType.java branches/astwrite/src/org/python/expose/TypeBuilder.java branches/astwrite/src/org/python/expose/generate/ExposedTypeProcessor.java branches/astwrite/src/org/python/expose/generate/ExposedTypeVisitor.java branches/astwrite/src/org/python/expose/generate/InstanceMethodExposer.java branches/astwrite/src/org/python/expose/generate/TypeExposer.java branches/astwrite/src/org/python/modules/PyTeeIterator.java branches/astwrite/src/org/python/modules/_codecs.java branches/astwrite/src/org/python/modules/_weakref/CallableProxyType.java branches/astwrite/src/org/python/modules/_weakref/ProxyType.java branches/astwrite/src/org/python/modules/operator.java branches/astwrite/src/org/python/modules/time/PyTimeTuple.java branches/astwrite/tests/java/org/python/expose/generate/DescriptorExposerTest.java branches/astwrite/tests/java/org/python/expose/generate/ExposedTypeProcessorTest.java branches/astwrite/tests/java/org/python/expose/generate/ExposedTypeVisitorTest.java branches/astwrite/tests/java/org/python/expose/generate/SimpleExposed.java branches/astwrite/tests/java/org/python/expose/generate/TypeExposerTest.java Added Paths: ----------- branches/astwrite/Lib/test/test_zipfile.py branches/astwrite/Lib/zipfile.py branches/astwrite/tests/java/org/python/util/ branches/astwrite/tests/java/org/python/util/InterpreterTest.java Removed Paths: ------------- branches/astwrite/tests/java/org/python/util/InterpreterTest.java Property Changed: ---------------- branches/astwrite/ Property changes on: branches/astwrite ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5614 + /trunk/jython:1-5634 Modified: branches/astwrite/Lib/popen2.py =================================================================== --- branches/astwrite/Lib/popen2.py 2008-11-25 03:03:43 UTC (rev 5634) +++ branches/astwrite/Lib/popen2.py 2008-11-25 04:19:42 UTC (rev 5635) @@ -44,7 +44,7 @@ the close method. """ def __init__(self, stream, process, name): - self._file = FileUtil.wrap(stream) + self._file = FileUtil.wrap(stream, 0) self._process = process def __getattr__(self, name): @@ -93,10 +93,10 @@ bufsize ) - self.tochild = FileUtil.wrap(self._tochild) - self.fromchild = FileUtil.wrap(self._fromchild) + self.tochild = FileUtil.wrap(self._tochild, 0) + self.fromchild = FileUtil.wrap(self._fromchild, 0) if self._childerr: - self.childerr = FileUtil.wrap(self._childerr) + self.childerr = FileUtil.wrap(self._childerr, 0) def _startChildWaiter(self): """Start a subthread that waits for the child process to exit.""" @@ -198,7 +198,7 @@ "%s-stderr" % self.process, self._close ) - return FileUtil.wrap(joinedStream) + return FileUtil.wrap(joinedStream, 0) def _close( self ): """Must be closed twice (once for each of the two joined pipes)""" Modified: branches/astwrite/Lib/test/test_bool.py =================================================================== --- branches/astwrite/Lib/test/test_bool.py 2008-11-25 03:03:43 UTC (rev 5634) +++ branches/astwrite/Lib/test/test_bool.py 2008-11-25 04:19:42 UTC (rev 5635) @@ -343,9 +343,6 @@ # StackOverflow if __nonzero__ returns self # http://jython.org/bugs/1758318 del BoolTest.test_convert_to_bool -# bool should not be subclassable -# http://jython.org/bugs/1758319 -del BoolTest.test_subclass def test_main(): test_support.run_unittest(BoolTest) Modified: branches/astwrite/Lib/test/test_descr.py =================================================================== --- branches/astwrite/Lib/test/test_descr.py 2008-11-25 03:03:43 UTC (rev 5634) +++ branches/astwrite/Lib/test/test_descr.py 2008-11-25 04:19:42 UTC (rev 5635) @@ -4404,11 +4404,6 @@ classmethods_in_c, staticmethods_in_c, - # Jython allows subclassing of classes it shouldn't (like - # builtin_function_or_method): - # http://bugs.jython.org/issue1758319 - errors, - # CPython's unicode.__cmp__ is derived from type (and only # takes 1 arg) specials, Copied: branches/astwrite/Lib/test/test_zipfile.py (from rev 5630, trunk/jython/Lib/test/test_zipfile.py) =================================================================== --- branches/astwrite/Lib/test/test_zipfile.py (rev 0) +++ branches/astwrite/Lib/test/test_zipfile.py 2008-11-25 04:19:42 UTC (rev 5635) @@ -0,0 +1,375 @@ +# We can test part of the module without zlib. +try: + import zlib +except ImportError: + zlib = None + +import zipfile, os, unittest, sys, shutil + +from StringIO import StringIO +from tempfile import TemporaryFile + +from test.test_support import TESTFN, is_jython, run_unittest + +TESTFN2 = TESTFN + "2" + +class TestsWithSourceFile(unittest.TestCase): + def setUp(self): + line_gen = ("Test of zipfile line %d." % i for i in range(0, 1000)) + self.data = '\n'.join(line_gen) + + # Make a source file with some lines + fp = open(TESTFN, "wb") + fp.write(self.data) + fp.close() + + def zipTest(self, f, compression): + # Create the ZIP archive + zipfp = zipfile.ZipFile(f, "w", compression) + zipfp.write(TESTFN, "another"+os.extsep+"name") + zipfp.write(TESTFN, TESTFN) + zipfp.writestr("strfile", self.data) + zipfp.close() + + # Read the ZIP archive + zipfp = zipfile.ZipFile(f, "r", compression) + self.assertEqual(zipfp.read(TESTFN), self.data) + self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data) + self.assertEqual(zipfp.read("strfile"), self.data) + + # Print the ZIP directory + fp = StringIO() + stdout = sys.stdout + try: + sys.stdout = fp + + zipfp.printdir() + finally: + sys.stdout = stdout + + directory = fp.getvalue() + lines = directory.splitlines() + self.assertEquals(len(lines), 4) # Number of files + header + + self.assert_('File Name' in lines[0]) + self.assert_('Modified' in lines[0]) + self.assert_('Size' in lines[0]) + + fn, date, time, size = lines[1].split() + self.assertEquals(fn, 'another.name') + # XXX: timestamp is not tested + self.assertEquals(size, str(len(self.data))) + + # Check the namelist + names = zipfp.namelist() + self.assertEquals(len(names), 3) + self.assert_(TESTFN in names) + self.assert_("another"+os.extsep+"name" in names) + self.assert_("strfile" in names) + + # Check infolist + infos = zipfp.infolist() + names = [ i.filename for i in infos ] + self.assertEquals(len(names), 3) + self.assert_(TESTFN in names) + self.assert_("another"+os.extsep+"name" in names) + self.assert_("strfile" in names) + for i in infos: + self.assertEquals(i.file_size, len(self.data)) + + # check getinfo + for nm in (TESTFN, "another"+os.extsep+"name", "strfile"): + info = zipfp.getinfo(nm) + self.assertEquals(info.filename, nm) + self.assertEquals(info.file_size, len(self.data)) + + # Check that testzip doesn't raise an exception + zipfp.testzip() + + + zipfp.close() + + + + + def testStored(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zipTest(f, zipfile.ZIP_STORED) + + if zlib: + def testDeflated(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zipTest(f, zipfile.ZIP_DEFLATED) + + def testAbsoluteArcnames(self): + zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) + zipfp.write(TESTFN, "/absolute") + zipfp.close() + + zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) + self.assertEqual(zipfp.namelist(), ["absolute"]) + zipfp.close() + + + def tearDown(self): + os.remove(TESTFN) + os.remove(TESTFN2) + +class TestZip64InSmallFiles(unittest.TestCase): + # These tests test the ZIP64 functionality without using large files, + # see test_zipfile64 for proper tests. + + def setUp(self): + self._limit = zipfile.ZIP64_LIMIT + zipfile.ZIP64_LIMIT = 5 + + line_gen = ("Test of zipfile line %d." % i for i in range(0, 1000)) + self.data = '\n'.join(line_gen) + + # Make a source file with some lines + fp = open(TESTFN, "wb") + fp.write(self.data) + fp.close() + + def largeFileExceptionTest(self, f, compression): + zipfp = zipfile.ZipFile(f, "w", compression) + self.assertRaises(zipfile.LargeZipFile, + zipfp.write, TESTFN, "another"+os.extsep+"name") + zipfp.close() + + def largeFileExceptionTest2(self, f, compression): + zipfp = zipfile.ZipFile(f, "w", compression) + self.assertRaises(zipfile.LargeZipFile, + zipfp.writestr, "another"+os.extsep+"name", self.data) + zipfp.close() + + def testLargeFileException(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.largeFileExceptionTest(f, zipfile.ZIP_STORED) + self.largeFileExceptionTest2(f, zipfile.ZIP_STORED) + + def zipTest(self, f, compression): + # Create the ZIP archive + zipfp = zipfile.ZipFile(f, "w", compression, allowZip64=True) + zipfp.write(TESTFN, "another"+os.extsep+"name") + zipfp.write(TESTFN, TESTFN) + zipfp.writestr("strfile", self.data) + zipfp.close() + + # Read the ZIP archive + zipfp = zipfile.ZipFile(f, "r", compression) + self.assertEqual(zipfp.read(TESTFN), self.data) + self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data) + self.assertEqual(zipfp.read("strfile"), self.data) + + # Print the ZIP directory + fp = StringIO() + stdout = sys.stdout + try: + sys.stdout = fp + + zipfp.printdir() + finally: + sys.stdout = stdout + + directory = fp.getvalue() + lines = directory.splitlines() + self.assertEquals(len(lines), 4) # Number of files + header + + self.assert_('File Name' in lines[0]) + self.assert_('Modified' in lines[0]) + self.assert_('Size' in lines[0]) + + fn, date, time, size = lines[1].split() + self.assertEquals(fn, 'another.name') + # XXX: timestamp is not tested + self.assertEquals(size, str(len(self.data))) + + # Check the namelist + names = zipfp.namelist() + self.assertEquals(len(names), 3) + self.assert_(TESTFN in names) + self.assert_("another"+os.extsep+"name" in names) + self.assert_("strfile" in names) + + # Check infolist + infos = zipfp.infolist() + names = [ i.filename for i in infos ] + self.assertEquals(len(names), 3) + self.assert_(TESTFN in names) + self.assert_("another"+os.extsep+"name" in names) + self.assert_("strfile" in names) + for i in infos: + self.assertEquals(i.file_size, len(self.data)) + + # check getinfo + for nm in (TESTFN, "another"+os.extsep+"name", "strfile"): + info = zipfp.getinfo(nm) + self.assertEquals(info.filename, nm) + self.assertEquals(info.file_size, len(self.data)) + + # Check that testzip doesn't raise an exception + zipfp.testzip() + + + zipfp.close() + + def testStored(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zipTest(f, zipfile.ZIP_STORED) + + + if zlib: + def testDeflated(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zipTest(f, zipfile.ZIP_DEFLATED) + + def testAbsoluteArcnames(self): + zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED, allowZip64=True) + zipfp.write(TESTFN, "/absolute") + zipfp.close() + + zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) + self.assertEqual(zipfp.namelist(), ["absolute"]) + zipfp.close() + + + def tearDown(self): + zipfile.ZIP64_LIMIT = self._limit + os.remove(TESTFN) + os.remove(TESTFN2) + +class PyZipFileTests(unittest.TestCase): + def testWritePyfile(self): + zipfp = zipfile.PyZipFile(TemporaryFile(), "w") + fn = __file__ + if fn.endswith('.pyc') or fn.endswith('.pyo'): + fn = fn[:-1] + elif fn.endswith('$py.class'): + fn = fn[:-9] + '.py' + + zipfp.writepy(fn) + + bn = os.path.basename(fn) + self.assert_(bn not in zipfp.namelist()) + if not is_jython: + self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) + else: + self.assert_(bn[:-3] + '$py.class' in zipfp.namelist()) + zipfp.close() + + + zipfp = zipfile.PyZipFile(TemporaryFile(), "w") + fn = __file__ + if fn.endswith('.pyc') or fn.endswith('.pyo'): + fn = fn[:-1] + elif fn.endswith('$py.class'): + fn = fn[:-9] + '.py' + + zipfp.writepy(fn, "testpackage") + + bn = "%s/%s"%("testpackage", os.path.basename(fn)) + self.assert_(bn not in zipfp.namelist()) + if not is_jython: + self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) + else: + self.assert_(bn[:-3] + '$py.class' in zipfp.namelist()) + zipfp.close() + + def testWritePythonPackage(self): + import email + packagedir = os.path.dirname(email.__file__) + + zipfp = zipfile.PyZipFile(TemporaryFile(), "w") + zipfp.writepy(packagedir) + + # Check for a couple of modules at different levels of the hieararchy + names = zipfp.namelist() + if not is_jython: + self.assert_('email/__init__.pyo' in names or 'email/__init__.pyc' in names) + self.assert_('email/mime/text.pyo' in names or 'email/mime/text.pyc' in names) + else: + self.assert_('email/__init__$py.class' in names) + self.assert_('email/mime/text$py.class' in names) + + def testWritePythonDirectory(self): + os.mkdir(TESTFN2) + try: + fp = open(os.path.join(TESTFN2, "mod1.py"), "w") + fp.write("print 42\n") + fp.close() + + fp = open(os.path.join(TESTFN2, "mod2.py"), "w") + fp.write("print 42 * 42\n") + fp.close() + + fp = open(os.path.join(TESTFN2, "mod2.txt"), "w") + fp.write("bla bla bla\n") + fp.close() + + zipfp = zipfile.PyZipFile(TemporaryFile(), "w") + zipfp.writepy(TESTFN2) + + names = zipfp.namelist() + if not is_jython: + self.assert_('mod1.pyc' in names or 'mod1.pyo' in names) + self.assert_('mod2.pyc' in names or 'mod2.pyo' in names) + else: + self.assert_('mod1$py.class' in names) + self.assert_('mod2$py.class' in names) + self.assert_('mod2.txt' not in names) + + finally: + shutil.rmtree(TESTFN2) + + + +class OtherTests(unittest.TestCase): + def testCloseErroneousFile(self): + # This test checks that the ZipFile constructor closes the file object + # it opens if there's an error in the file. If it doesn't, the traceback + # holds a reference to the ZipFile object and, indirectly, the file object. + # On Windows, this causes the os.unlink() call to fail because the + # underlying file is still open. This is SF bug #412214. + # + fp = open(TESTFN, "w") + fp.write("this is not a legal zip file\n") + fp.close() + try: + zf = zipfile.ZipFile(TESTFN) + except zipfile.BadZipfile: + os.unlink(TESTFN) + + def testNonExistentFileRaisesIOError(self): + # make sure we don't raise an AttributeError when a partially-constructed + # ZipFile instance is finalized; this tests for regression on SF tracker + # bug #403871. + + # The bug we're testing for caused an AttributeError to be raised + # when a ZipFile instance was created for a file that did not + # exist; the .fp member was not initialized but was needed by the + # __del__() method. Since the AttributeError is in the __del__(), + # it is ignored, but the user should be sufficiently annoyed by + # the message on the output that regression will be noticed + # quickly. + self.assertRaises(IOError, zipfile.ZipFile, TESTFN) + + def testClosedZipRaisesRuntimeError(self): + # Verify that testzip() doesn't swallow inappropriate exceptions. + data = StringIO() + zipf = zipfile.ZipFile(data, mode="w") + zipf.writestr("foo.txt", "O, for a Muse of Fire!") + zipf.close() + + # This is correct; calling .read on a closed ZipFile should throw + # a RuntimeError, and so should calling .testzip. An earlier + # version of .testzip would swallow this exception (and any other) + # and report that the first file in the archive was corrupt. + self.assertRaises(RuntimeError, zipf.testzip) + +def test_main(): + run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests, PyZipFileTests) + #run_unittest(TestZip64InSmallFiles) + +if __name__ == "__main__": + test_main() Copied: branches/astwrite/Lib/zipfile.py (from rev 5630, trunk/jython/Lib/zipfile.py) =================================================================== --- branches/astwrite/Lib/zipfile.py (rev 0) +++ branches/astwrite/Lib/zipfile.py 2008-11-25 04:19:42 UTC (rev 5635) @@ -0,0 +1,902 @@ +""" +Read and write ZIP files. +""" +import struct, os, time, sys +import binascii, cStringIO + +try: + import zlib # We may need its compression method +except ImportError: + zlib = None + +__all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", + "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] + +is_jython = sys.platform.startswith('java') + +class BadZipfile(Exception): + pass + + +class LargeZipFile(Exception): + """ + Raised when writing a zipfile, the zipfile requires ZIP64 extensions + and those extensions are disabled. + """ + +error = BadZipfile # The exception raised by this module + +ZIP64_LIMIT= (1 << 31) - 1 + +# constants for Zip file compression methods +ZIP_STORED = 0 +ZIP_DEFLATED = 8 +# Other ZIP compression methods not supported + +# Here are some struct module formats for reading headers +structEndArchive = "<4s4H2LH" # 9 items, end of archive, 22 bytes +stringEndArchive = "PK\005\006" # magic number for end of archive record +structCentralDir = "<4s4B4HlLL5HLL"# 19 items, central directory, 46 bytes +stringCentralDir = "PK\001\002" # magic number for central directory +structFileHeader = "<4s2B4HlLL2H" # 12 items, file header record, 30 bytes +stringFileHeader = "PK\003\004" # magic number for file header +structEndArchive64Locator = "<4slql" # 4 items, locate Zip64 header, 20 bytes +stringEndArchive64Locator = "PK\x06\x07" # magic token for locator header +structEndArchive64 = "<4sqhhllqqqq" # 10 items, end of archive (Zip64), 56 bytes +stringEndArchive64 = "PK\x06\x06" # magic token for Zip64 header + + +# indexes of entries in the central directory structure +_CD_SIGNATURE = 0 +_CD_CREATE_VERSION = 1 +_CD_CREATE_SYSTEM = 2 +_CD_EXTRACT_VERSION = 3 +_CD_EXTRACT_SYSTEM = 4 # is this meaningful? +_CD_FLAG_BITS = 5 +_CD_COMPRESS_TYPE = 6 +_CD_TIME = 7 +_CD_DATE = 8 +_CD_CRC = 9 +_CD_COMPRESSED_SIZE = 10 +_CD_UNCOMPRESSED_SIZE = 11 +_CD_FILENAME_LENGTH = 12 +_CD_EXTRA_FIELD_LENGTH = 13 +_CD_COMMENT_LENGTH = 14 +_CD_DISK_NUMBER_START = 15 +_CD_INTERNAL_FILE_ATTRIBUTES = 16 +_CD_EXTERNAL_FILE_ATTRIBUTES = 17 +_CD_LOCAL_HEADER_OFFSET = 18 + +# indexes of entries in the local file header structure +_FH_SIGNATURE = 0 +_FH_EXTRACT_VERSION = 1 +_FH_EXTRACT_SYSTEM = 2 # is this meaningful? +_FH_GENERAL_PURPOSE_FLAG_BITS = 3 +_FH_COMPRESSION_METHOD = 4 +_FH_LAST_MOD_TIME = 5 +_FH_LAST_MOD_DATE = 6 +_FH_CRC = 7 +_FH_COMPRESSED_SIZE = 8 +_FH_UNCOMPRESSED_SIZE = 9 +_FH_FILENAME_LENGTH = 10 +_FH_EXTRA_FIELD_LENGTH = 11 + +def is_zipfile(filename): + """Quickly see if file is a ZIP file by checking the magic number.""" + try: + fpin = open(filename, "rb") + endrec = _EndRecData(fpin) + fpin.close() + if endrec: + return True # file has correct magic number + except IOError: + pass + return False + +def _EndRecData64(fpin, offset, endrec): + """ + Read the ZIP64 end-of-archive records and use that to update endrec + """ + locatorSize = struct.calcsize(structEndArchive64Locator) + fpin.seek(offset - locatorSize, 2) + data = fpin.read(locatorSize) + sig, diskno, reloff, disks = struct.unpack(structEndArchive64Locator, data) + if sig != stringEndArchive64Locator: + return endrec + + if diskno != 0 or disks != 1: + raise BadZipfile("zipfiles that span multiple disks are not supported") + + # Assume no 'zip64 extensible data' + endArchiveSize = struct.calcsize(structEndArchive64) + fpin.seek(offset - locatorSize - endArchiveSize, 2) + data = fpin.read(endArchiveSize) + sig, sz, create_version, read_version, disk_num, disk_dir, \ + dircount, dircount2, dirsize, diroffset = \ + struct.unpack(structEndArchive64, data) + if sig != stringEndArchive64: + return endrec + + # Update the original endrec using data from the ZIP64 record + endrec[1] = disk_num + endrec[2] = disk_dir + endrec[3] = dircount + endrec[4] = dircount2 + endrec[5] = dirsize + endrec[6] = diroffset + return endrec + + +def _EndRecData(fpin): + """Return data from the "End of Central Directory" record, or None. + + The data is a list of the nine items in the ZIP "End of central dir" + record followed by a tenth item, the file seek offset of this record.""" + fpin.seek(-22, 2) # Assume no archive comment. + filesize = fpin.tell() + 22 # Get file size + data = fpin.read() + if data[0:4] == stringEndArchive and data[-2:] == "\000\000": + endrec = struct.unpack(structEndArchive, data) + endrec = list(endrec) + endrec.append("") # Append the archive comment + endrec.append(filesize - 22) # Append the record start offset + if endrec[-4] == -1 or endrec[-4] == 0xffffffff: + return _EndRecData64(fpin, -22, endrec) + return endrec + # Search the last END_BLOCK bytes of the file for the record signature. + # The comment is appended to the ZIP file and has a 16 bit length. + # So the comment may be up to 64K long. We limit the search for the + # signature to a few Kbytes at the end of the file for efficiency. + # also, the signature must not appear in the comment. + END_BLOCK = min(filesize, 1024 * 4) + fpin.seek(filesize - END_BLOCK, 0) + data = fpin.read() + start = data.rfind(stringEndArchive) + if start >= 0: # Correct signature string was found + endrec = struct.unpack(structEndArchive, data[start:start+22]) + endrec = list(endrec) + comment = data[start+22:] + if endrec[7] == len(comment): # Comment length checks out + # Append the archive comment and start offset + endrec.append(comment) + endrec.append(filesize - END_BLOCK + start) + if endrec[-4] == -1 or endrec[-4] == 0xffffffff: + return _EndRecData64(fpin, - END_BLOCK + start, endrec) + return endrec + return # Error, return None + + +class ZipInfo (object): + """Class with attributes describing each file in the ZIP archive.""" + + __slots__ = ( + 'orig_filename', + 'filename', + 'date_time', + 'compress_type', + 'comment', + 'extra', + 'create_system', + 'create_version', + 'extract_version', + 'reserved', + 'flag_bits', + 'volume', + 'internal_attr', + 'external_attr', + 'header_offset', + 'CRC', + 'compress_size', + 'file_size', + ) + + def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)): + self.orig_filename = filename # Original file name in archive + + # Terminate the file name at the first null byte. Null bytes in file + # names are used as tricks by viruses in archives. + null_byte = filename.find(chr(0)) + if null_byte >= 0: + filename = filename[0:null_byte] + # This is used to ensure paths in generated ZIP files always use + # forward slashes as the directory separator, as required by the + # ZIP format specification. + if os.sep != "/" and os.sep in filename: + filename = filename.replace(os.sep, "/") + + self.filename = filename # Normalized file name + self.date_time = date_time # year, month, day, hour, min, sec + # Standard values: + self.compress_type = ZIP_STORED # Type of compression for the file + self.comment = "" # Comment for each file + self.extra = "" # ZIP extra data + if sys.platform == 'win32': + self.create_system = 0 # System which created ZIP archive + else: + # Assume everything else is unix-y + self.create_system = 3 # System which created ZIP archive + self.create_version = 20 # Version which created ZIP archive + self.extract_version = 20 # Version needed to extract archive + self.reserved = 0 # Must be zero + self.flag_bits = 0 # ZIP flag bits + self.volume = 0 # Volume number of file header + self.internal_attr = 0 # Internal attributes + self.external_attr = 0 # External file attributes + # Other attributes are set by class ZipFile: + # header_offset Byte offset to the file header + # CRC CRC-32 of the uncompressed file + # compress_size Size of the compressed file + # file_size Size of the uncompressed file + + def FileHeader(self): + """Return the per-file header as a string.""" + dt = self.date_time + dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2] + dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2) + if self.flag_bits & 0x08: + # Set these to zero because we write them after the file data + CRC = compress_size = file_size = 0 + else: + CRC = self.CRC + compress_size = self.compress_size + file_size = self.file_size + + extra = self.extra + + if file_size > ZIP64_LIMIT or compress_size > ZIP64_LIMIT: + # File is larger than what fits into a 4 byte integer, + # fall back to the ZIP64 extension + fmt = '<hhqq' + extra = extra + struct.pack(fmt, + 1, struct.calcsize(fmt)-4, file_size, compress_size) + file_size = 0xffffffff # -1 + compress_size = 0xffffffff # -1 + self.extract_version = max(45, self.extract_version) + self.create_version = max(45, self.extract_version) + + header = struct.pack(structFileHeader, stringFileHeader, + self.extract_version, self.reserved, self.flag_bits, + self.compress_type, dostime, dosdate, CRC, + compress_size, file_size, + len(self.filename), len(extra)) + return header + self.filename + extra + + def _decodeExtra(self): + # Try to decode the extra field. + extra = self.extra + unpack = struct.unpack + while extra: + tp, ln = unpack('<hh', extra[:4]) + if tp == 1: + if ln >= 24: + counts = unpack('<qqq', extra[4:28]) + elif ln == 16: + counts = unpack('<qq', extra[4:20]) + elif ln == 8: + counts = unpack('<q', extra[4:12]) + elif ln == 0: + counts = () + else: + raise RuntimeError, "Corrupt extra field %s"%(ln,) + + idx = 0 + + # ZIP64 extension (large files and/or large archives) + if self.file_size == -1 or self.file_size == 0xFFFFFFFFL: + self.file_size = counts[idx] + idx += 1 + + if self.compress_size == -1 or self.compress_size == 0xFFFFFFFFL: + self.compress_size = counts[idx] + idx += 1 + + if self.header_offset == -1 or self.header_offset == 0xffffffffL: + old = self.header_offset + self.header_offset = counts[idx] + idx+=1 + + extra = extra[ln+4:] + + +class ZipFile: + """ Class with methods to open, read, write, close, list zip files. + + z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) + + file: Either the path to the file, or a file-like object. + If it is a path, the file will be opened and closed by ZipFile. + mode: The mode can be either read "r", write "w" or append "a". + compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). + allowZip64: if True ZipFile will create files with ZIP64 extensions when + needed, otherwise it will raise an exception when this would + be necessary. + + """ + + fp = None # Set here since __del__ checks it + + def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False): + """Open the ZIP file with mode read "r", write "w" or append "a".""" + self._allowZip64 = allowZip64 + self._didModify = False + if compression == ZIP_STORED: + pass + elif compression == ZIP_DEFLATED: + if not zlib: + raise RuntimeError,\ + "Compression requires the (missing) zlib module" + else: + raise RuntimeError, "That compression method is not supported" + self.debug = 0 # Level of printing: 0 through 3 + self.NameToInfo = {} # Find file info given name + self.filelist = [] # List of ZipInfo instances for archive + self.compression = compression # Method of compression + self.mode = key = mode.replace('b', '')[0] + + # Check if we were passed a file-like object + if isinstance(file, basestring): + self._filePassed = 0 + self.filename = file + modeDict = {'r' : 'rb', 'w': 'wb', 'a' : 'r+b'} + self.fp = open(file, modeDict[mode]) + else: + self._filePassed = 1 + self.fp = file + self.filename = getattr(file, 'name', None) + + if key == 'r': + self._GetContents() + elif key == 'w': + pass + elif key == 'a': + try: # See if file is a zip file + self._RealGetContents() + # seek to start of directory and overwrite + self.fp.seek(self.start_dir, 0) + except BadZipfile: # file is not a zip file, just append + self.fp.seek(0, 2) + else: + if not self._filePassed: + self.fp.close() + self.fp = None + raise RuntimeError, 'Mode must be "r", "w" or "a"' + + def _GetContents(self): + """Read the directory, making sure we close the file if the format + is bad.""" + try: + self._RealGetContents() + except BadZipfile: + if not self._filePassed: + self.fp.close() + self.fp = None + raise + + def _RealGetContents(self): + """Read in the table of contents for the ZIP file.""" + fp = self.fp + endrec = _EndRecData(fp) + if not endrec: + raise BadZipfile, "File is not a zip file" + if self.debug > 1: + print endrec + size_cd = endrec[5] # bytes in central directory + offset_cd = endrec[6] # offset of central directory + self.comment = endrec[8] # archive comment + # endrec[9] is the offset of the "End of Central Dir" record + if endrec[9] > ZIP64_LIMIT: + x = endrec[9] - size_cd - 56 - 20 + else: + x = endrec[9] - size_cd + # "concat" is zero, unless zip was concatenated to another file + concat = x - offset_cd + if self.debug > 2: + print "given, inferred, offset", offset_cd, x, concat + # self.start_dir: Position of start of central directory + self.start_dir = offset_cd + concat + fp.seek(self.start_dir, 0) + data = fp.read(size_cd) + fp = cStringIO.StringIO(data) + total = 0 + while total < size_cd: + centdir = fp.read(46) + total = total + 46 + if centdir[0:4] != stringCentralDir: + raise BadZipfile, "Bad magic number for central directory" + centdir = struct.unpack(structCentralDir, centdir) + if self.debug > 2: + print centdir + filename = fp.read(centdir[_CD_FILENAME_LENGTH]) + # Create ZipInfo instance to store file information + x = ZipInfo(filename) + x.extra = fp.read(centdir[_CD_EXTRA_FIELD_LENGTH]) + x.comment = fp.read(centdir[_CD_COMMENT_LENGTH]) + total = (total + centdir[_CD_FILENAME_LENGTH] + + centdir[_CD_EXTRA_FIELD_LENGTH] + + centdir[_CD_COMMENT_LENGTH]) + x.header_offset = centdir[_CD_LOCAL_HEADER_OFFSET] + (x.create_version, x.create_system, x.extract_version, x.reserved, + x.flag_bits, x.compress_type, t, d, + x.CRC, x.compress_size, x.file_size) = centdir[1:12] + x.volume, x.internal_attr, x.external_attr = centdir[15:18] + # Convert date/time code to (year, month, day, hour, min, sec) + x.date_time = ( (d>>9)+1980, (d>>5)&0xF, d&0x1F, + t>>11, (t>>5)&0x3F, (t&0x1F) * 2 ) + + x._decodeExtra() + x.header_offset = x.header_offset + concat + self.filelist.append(x) + self.NameToInfo[x.filename] = x + if self.debug > 2: + print "total", total + + + def namelist(self): + """Return a list of file names in the archive.""" + l = [] + for data in self.filelist: + l.append(data.filename) + return l + + def infolist(self): + """Return a list of class ZipInfo instances for files in the + archive.""" + return self.filelist + + def printdir(self): + """Print a table of contents for the zip file.""" + print "%-46s %19s %12s" % ("File Name", "Modified ", "Size") + for zinfo in self.filelist: + date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time[:6] + print "%-46s %s %12d" % (zinfo.filename, date, zinfo.file_size) + + def testzip(self): + """Read all the files and check the CRC.""" + for zinfo in self.filelist: + try: + self.read(zinfo.filename) # Check CRC-32 + except BadZipfile: + return zinfo.filename + + + def getinfo(self, name): + """Return the instance of ZipInfo given 'name'.""" + return self.NameToInfo[name] + + def read(self, name): + """Return file bytes (as a string) for name.""" + if self.mode not in ("r", "a"): + raise RuntimeError, 'read() requires mode "r" or "a"' + if not self.fp: + raise RuntimeError, \ + "Attempt to read ZIP archive that was already closed" + zinfo = self.getinfo(name) + filepos = self.fp.tell() + + self.fp.seek(zinfo.header_offset, 0) + + # Skip the file header: + fheader = self.fp.read(30) + if fheader[0:4] != stringFileHeader: + raise BadZipfile, "Bad magic number for file header" + + fheader = struct.unpack(structFileHeader, fheader) + fname = self.fp.read(fheader[_FH_FILENAME_LENGTH]) + if fheader[_FH_EXTRA_FIELD_LENGTH]: + self.fp.read(fheader[_FH_EXTRA_FIELD_LENGTH]) + + if fname != zinfo.orig_filename: + raise BadZipfile, \ + 'File name in directory "%s" and header "%s" differ.' % ( + zinfo.orig_filename, fname) + + bytes = self.fp.read(zinfo.compress_size) + self.fp.seek(filepos, 0) + if zinfo.compress_type == ZIP_STORED: + pass + elif zinfo.compress_type == ZIP_DEFLATED: + if not zlib: + raise RuntimeError, \ + "De-compression requires the (missing) zlib module" + # zlib compress/decompress code by Jeremy Hylton of CNRI + dc = zlib.decompressobj(-15) + bytes = dc.decompress(bytes) + # need to feed in unused pad byte so that zlib won't choke + ex = dc.decompress('Z') + dc.flush() + if ex: + bytes = bytes + ex + else: + raise BadZipfile, \ + "Unsupported compression method %d for file %s" % \ + (zinfo.compress_type, name) + crc = binascii.crc32(bytes) + if crc != zinfo.CRC: + raise BadZipfile, "Bad CRC-32 for file %s" % name + return bytes + + def _writecheck(self, zinfo): + """Check for errors before writing a file to the archive.""" + if zinfo.filename in self.NameToInfo: + if self.debug: # Warning for duplicate names + print "Duplicate name:", zinfo.filename + if self.mode not in ("w", "a"): + raise RuntimeError, 'write() requires mode "w" or "a"' + if not self.fp: + raise RuntimeError, \ + "Attempt to write ZIP archive that was already closed" + if zinfo.compress_type == ZIP_DEFLATED and not zlib: + raise RuntimeError, \ + "Compression requires the (missing) zlib module" + if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): + raise RuntimeError, \ + "That compression method is not supported" + if zinfo.file_size > ZIP64_LIMIT: + if not self._allowZip64: + raise LargeZipFile("Filesize would require ZIP64 extensions") + if zinfo.header_offset > ZIP64_LIMIT: + if not self._allowZip64: + raise LargeZipFile("Zipfile size would require ZIP64 extensions") + + def write(self, filename, arcname=None, compress_type=None): + """Put the bytes from filename into the archive under the name + arcname.""" + st = os.stat(filename) + mtime = time.localtime(st.st_mtime) + date_time = mtime[0:6] + # Create ZipInfo instance to store file information + if arcname is None: + arcname = filename + arcname = os.path.normpath(os.path.splitdrive(arcname)[1]) + while arcname[0] in (os.sep, os.altsep): + arcname = arcname[1:] + zinfo = ZipInfo(arcname, date_time) + zinfo.external_attr = (st[0] & 0xFFFF) << 16L # Unix attributes + if compress_type is None: + zinfo.compress_type = self.compression + else: + zinfo.compress_type = compress_type + + zinfo.file_size = st.st_size + zinfo.flag_bits = 0x00 + zinfo.header_offset = self.fp.tell() # Start of header bytes + + self._writecheck(zinfo) + self._didModify = True + fp = open(filename, "rb") + # Must overwrite CRC and sizes with correct data later + zinfo.CRC = CRC = 0 + zinfo.compress_size = compress_size = 0 + zinfo.file_size = file_size = 0 + self.fp.write(zinfo.FileHeader()) + if zinfo.compress_type == ZIP_DEFLATED: + cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, + zlib.DEFLATED, -15) + else: + cmpr = None + while 1: + buf = fp.read(1024 * 8) + if not buf: + break + file_size = file_size + len(buf) + CRC = binascii.crc32(buf, CRC) + if cmpr: + buf = cmpr.compress(buf) + compress_size = compress_size + len(buf) + self.fp.write(buf) + fp.close() + if cmpr: + buf = cmpr.flush() + compress_size = compress_size + len(buf) + self.fp.write(buf) + zinfo.compress_size = compress_size + else: + zinfo.compress_size = file_size + zinfo.CRC = CRC + zinfo.file_size = file_size + # Seek backwards and write CRC and file sizes + position = self.fp.tell() # Preserve current position in file + self.fp.seek(zinfo.header_offset + 14, 0) + self.fp.write(struct.pack("<lLL", zinfo.CRC, zinfo.compress_size, + zinfo.file_size)) + self.fp.seek(position, 0) + self.filelist.append(zinfo) + self.NameToInfo[zinfo.filename] = zinfo + + def writestr(self, zinfo_or_arcname, bytes): + """Write a file into the archive. The contents is the string + 'bytes'. 'zinfo_or_arcname' is either a ZipInfo instance or + the name of the file in the archive.""" + if not isinstance(zinfo_or_arcname, ZipInfo): + zinfo = ZipInfo(filename=zinfo_or_arcname, + date_time=time.localtime(time.time())[:6]) + zinfo.compress_type = self.compression + else: + zinfo = zinfo_or_arcname + zinfo.file_size = len(bytes) # Uncompressed size + zinfo.header_offset = self.fp.tell() # Start of header bytes + self._writecheck(zinfo) + self._didModify = True + zinfo.CRC = binascii.crc32(bytes) # CRC-32 checksum + if zinfo.compress_type == ZIP_DEFLATED: + co = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, + zlib.DEFLATED, -15) + bytes = co.compress(bytes) + co.flush() + zinfo.compress_size = len(bytes) # Compressed size + else: + zinfo.compress_size = zinfo.file_size + zinfo.header_offset = self.fp.tell() # Start of header bytes + self.fp.write(zinfo.FileHeader()) + self.fp.write(bytes) + self.fp.flush() + if zinfo.flag_bits & 0x08: + # Write CRC and file sizes after the file data + self.fp.write(struct.pack("<lLL", zinfo.CRC, zinfo.compress_size, + zinfo.file_size)) + self.filelist.append(zinfo) + self.NameToInfo[zinfo.filename] = zinfo + + def __del__(self): + """Call the "close()" method in case the user forgot.""" + self.close() + + def close(self): + """Close the file, and for mode "w" and "a" write the ending + records.""" + if self.fp is None: + return + + if self.mode in ("w", "a") and self._didModify: # write ending records + count = 0 + pos1 = self.fp.tell() + for zinfo in self.filelist: # write central directory + count = count + 1 + dt = zinfo.date_time + dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2] + dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2) + extra = [] + if zinfo.file_size > ZIP64_LIMIT \ + or zinfo.compress_size > ZIP64_LIMIT: + extra.append(zinfo.file_size) + extra.append(zinfo.compress_size) + file_size = 0xffffffff #-1 + compress_size = 0xffffffff #-1 + else: + file_size = zinfo.file_size + compress_size = zinfo.compress_size + + if zinfo.header_offset > ZIP64_LIMIT: + extra.append(zinfo.header_offset) + header_offset = -1 # struct "l" format: 32 one bits + else: + header_offset = zinfo.header_offset + + extra_data = zinfo.extra + if extra: + # Append a ZIP64 field to the extra's + extra_data = struct.pack( + '<hh' + 'q'*len(extra), + 1, 8*len(extra), *extra) + extra_data + + extract_version = max(45, zinfo.extract_version) + create_version = max(45, zinfo.create_version) + else: + extract_version = zinfo.extract_version + create_version = zinfo.create_version + + centdir = struct.pack(structCentralDir, + stringCentralDir, create_version, + zinfo.create_system, extract_version, zinfo.reserved, + zinfo.flag_bits, zinfo.compress_type, dostime, dosdate, + zinfo.CRC, compress_size, file_size, + len(zinfo.filename), len(extra_data), len(zinfo.comment), + 0, zinfo.internal_attr, zinfo.external_attr, + header_offset) + self.fp.write(centdir) + self.fp.write(zinfo.filename) + self.fp.write(extra_data) + self.fp.write(zinfo.comment) + + pos2 = self.fp.tell() + # Write end-of-zip-archive record + if pos1 > ZIP64_LIMIT: + # Need to write the ZIP64 end-of-archive records + zip64endrec = struct.pack( + structEndArchive64, stringEndArchive64, + 44, 45, 45, 0, 0, count, count, pos2 - pos1, pos1) + self.fp.write(zip64endrec) + + zip64locrec = struct.pack( + structEndArchive64Locator, + stringEndArchive64Locator, 0, pos2, 1) + self.fp.write(zip64locrec) + + # XXX Why is `pos3` computed next? It's never referenced. + pos3 = self.fp.tell() + endrec = struct.pack(structEndArchive, stringEndArchive, + 0, 0, count, count, pos2 - pos1, -1, 0) + self.fp.write(endrec) + + else: + endrec = struct.pack(structEndArchive, stringEndArchive, + 0, 0, count, count, pos2 - pos1, pos1, 0) + self.fp.write(endrec) + self.fp.flush() + if not self._filePassed: + self.fp.close() + self.fp = None + + +class PyZipFile(ZipFile): + """Class to create ZIP archives with Python library files and packages.""" + + def writepy(self, pathname, basename = ""): + """Add all files from "pathname" to the ZIP archive. + + If pathname is a package directory, search the directory and + all package subdirectories recursively for all *.py and enter + the modules into the archive. If pathname is a plain + directory, listdir *.py and enter all modules. Else, pathname + must be a Python *.py file and the module will be put into the + archive. Added modules are always module.pyo or module.pyc. + This method will compile the module.py into module.pyc if + necessary. + """ + dir, name = os.path.split(pathname) + if os.path.isdir(pathname): + initname = os.path.join(pathname, "__init__.py") + if os.path.isfile(initname): + # This is a package directory, add it + if basename: + basename = "%s/%s" % (basename, name) + else: + basename = name + if self.debug: + print "Adding package in", pathname, "as", basename + fname, arcname = self._get_codename(initname[0:-3], basename) + if self.debug: + print "Adding", arcname + self.write(fname, arcname) + dirlist = os.listdir(pathname) + dirlist.remove("__init__.py") + # Add all *.py files and package subdirectories + for filename in dirlist: + path = os.path.join(pathname, filename) + root, ext = os.path.splitext(filename) + if os.path.isdir(path): + if os.path.isfile(os.path.join(path, "__init__.py")): + # This is a package directory, add it + self.writepy(path, basename) # Recursive call + elif ext == ".py": + fname, arcname = self._get_codename(path[0:-3], + basename) + if self.debug: + print "Adding", arcname + self.write(fname, arcname) + else: + # This is NOT a package directory, add its files at top level + if self.debug: + print "Adding files from directory", pathname + for filename in os.listdir(pathname): + path = os.path.join(pathname, filename) + root, ext = os.path.splitext(filename) + if ext == ".py": + fname, arcname = self._get_codename(path[0:-3], + basename) + if self.debug: + print "Adding", arcname + self.write(fname, arcname) + else: + if pathname[-3:] != ".py": + raise RuntimeError, \ + 'Files added with writepy() must end with ".py"' + fname, arcname = self._get_codename(pathname[0:-3], basename) + if self.debug: + print "Adding file", arcname + self.write(fname, arcname) + + def _get_codename(self, pathname, basename): + """Return (filename, archivename) for the path. + + Given a module name path, return the correct file path and + archive name, compiling if necessary. For example, given + /python/lib/string, return (/python/lib/string.pyc, string). + """ + file_py = pathname + ".py" + file_pyc = pathname + (".pyc" if not is_jython else "$py.class") + file_pyo = pathname + ".pyo" + if os.path.isfile(file_pyo) and \ + os.stat(file_pyo).st_mtime >= os.stat(file_py).st_mtime: + fname = file_pyo # Use .pyo file + elif not os.path.isfile(file_pyc) or \ + os.stat(file_pyc).st_mtime < os.stat(file_py).st_mtime: + import py_compile + if self.debug: + print "Compiling", file_py + try: + py_compile.compile(file_py, file_pyc, None, True) + except py_compile.PyCompileError,err: + print err.msg + fname = file_pyc + else: + fname = file_pyc + archivename = os.path.split(fname)[1] + if basename: + archivename = "%s/%s" % (basename, archivename) + return (fname, archivename) + + +def main(args = None): + import textwrap + USAGE=textwrap.dedent("""\ + Usage: + zipfile.py -l zipfile.zip # Show listing of a zipfile + zipfile.py -t zipfile.zip # Test if a zipfile is valid + zipfile.py -e zipfile.zip target # Extract zipfile into target dir + zipfile.py -c zipfile.zip src ... # Create zipfile from sources + """) + if args is None: + args = sys.argv[1:] + + if not args or args[0] not in ('-l', '-c', '-e', '-t'): + print USAGE + sys.exit(1) + + if args[0] == '-l': + if len(args) != 2: + print USAGE + sys.exit(1) + zf = ZipFile(args[1], 'r') + zf.printdir() + zf.close() + + elif args[0] == '-t': + if len(args) != 2: + print USAGE + sys.exit(1) + zf = ZipFile(args[1], 'r') + zf.testzip() + print "Done testing" + + elif args[0] == '-e': + if len(args) != 3: + print USAGE + sys.exit(1) + + zf = ZipFile(args[1], 'r') + out = args[2] + for path in zf.namelist(): + if path.startswith('./'): + tgt = os.path.join(out, path[2:]) + else: + tgt = os.path.join(out, path) + + tgtdir = os.path.dirname(tgt) + if not os.path.exists(tgtdir): + os.makedirs(tgtdir) + fp = open(tgt, 'wb') + fp.write(zf.read(path)) + fp.close() + zf.close() + + elif args[0] == '-c': + if len(args) < 3: + print USAGE + sys.exit(1) + + def addToZip(zf, path, zippath): + if os.path.isfile(path): + zf.write(path, zippath, ZIP_DEFLATED) + elif os.path.isdir(path): + for nm in os.listdir(path): + addToZip(zf, + os.path.join(path, nm), os.path.join(zippath, nm)) + # else: ignore + + zf = ZipFile(args[1], 'w', allowZip64=True) + for src in args[2:]: + addToZip(zf, src, os.path.basename(src)) + + zf.close() + +if __name__ == "__main__": + main() Modified: branches/astwrite/build.xml =================================================================== --- branches/astwrite/build.xml 2008-11-25 03:03:43 UTC (rev 5634) +++ branches/astwrite/build.xml 2008-11-25 04:19:42 UTC (rev 5635) @@ -152,6 +152,7 @@ <property name="gensrc.dir" value="${output.dir}/gensrc" /> <property name="dist.dir" value="${work.dir}/dist" /> <property name="apidoc.dir" value="${dist.dir}/Doc/javadoc" /> + <property name="junit.reports" value="${dist.dir}/testreports" /> <!-- classpaths --> <path id="main.classpath"> @@ -761,14 +762,21 @@ </jar> </target> - <target name="test" depends="javatest,launchertest,regrtest"/> + <target name="test" depends="prepare-test,javatest,launchertest,regrtest"/> + <target name="prepare-test" depends="init"> + <!-- Clean any old test output --> + <delete dir="${junit.reports}"/> + </target> <target name="javatest" depends="compile,expose"> + <mkdir dir="${junit.reports}"/> <junit fork="true" printsummary="true"> + <formatter type="xml"/> <classpath refid="test.classpath"/> - <batchtest todir="${dist.dir}/testreports"> + <batchtest todir="${junit.reports}"> <fileset dir="${test.source.dir}" includes="**/*Test*.java"> <exclude name="javatests/**/*" /> <exclude name="**/InterpTestCase.java" /> + <exclude name="org/python/antlr/**" /> </fileset> </batchtest> </junit> @@ -786,6 +794,8 @@ <arg value="${dist.dir}/Lib/test/regrtest.py"/> <!-- Only run the tests that are expected to work on Jython --> <arg value="--expected"/> + <arg value="-j"/> + <arg value="${junit.reports}"/> </exec> </target> <target name="regrtest-windows" if="os.family.windows"> @@ -794,6 +804,8 @@ <arg value="${dist.dir}/Lib/test/regrtest.py"/> <!-- Only run the tests that are expected to work on Jython --> <arg value="--expected"/> + <arg value="-j"/> + <arg value="${junit.reports}"/> </exec> </target> Modified: branches/astwrite/src/org/python/core/Py.java =================================================================== --- branches/astwrite/src/org/python/core/Py.java 2008-11-25 03:03:43 UTC (rev 5634) +++ branches/astwrite/src/org/python/core/Py.java 2008-11-25 04:19:42 UTC (rev 5635) @@ -82,7 +82,9 @@ /** A Python string containing ' ' **/ public static PyString Space; /** Set if the type object is dynamically allocated */ - public static long TPFLAGS_HEAPTYPE; + public static long TPFLAGS_HEAPTYPE = 1L << 9; + /** Set if the type allows subclassing */ + public static long TPFLAGS_BASETYPE = 1L << 10; /** Builtin types that are used to setup PyObject. */ static final Set<Class> BOOTSTRAP_TYPES = new HashSet<Class>(4); Modified: branches/astwrite/src/org/python/core/PyBoolean.java =================================================================== --- branches/astwrite/src/org/python/core/PyBoolean.java 2008-11-25 03:03:43 UTC (rev 5634) +++ branches/astwrite/src/org/python/core/PyBoolean.java 2008-11-25 04:19:42 UTC (rev 5635) @@ -1,7 +1,5 @@ package org.python.core; -import java.io.Serializable; - import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; import org.python.expose.ExposedType; @@ -10,7 +8,7 @@ /** * A builtin python bool. */ -@ExposedType(name = "bool") +@ExposedType(name = "bool", isBaseType = false) public class PyBoolean extends PyInteger { public static final PyType TYPE = PyType.fromClass(PyBoolean.class); Modified: branches/astwrite/src/org/python/core/PyBuiltinCallable.java =================================================================== --- branches/astwrite/src/org/python/core/PyBuiltinCallable.java 2008-11-25 03:03:43 UTC (rev 5634) +++ branches/astwrite/src/org/python/core/PyBuiltinCallab... [truncated message content] |
From: <fwi...@us...> - 2008-11-25 03:03:54
|
Revision: 5634 http://jython.svn.sourceforge.net/jython/?rev=5634&view=rev Author: fwierzbicki Date: 2008-11-25 03:03:43 +0000 (Tue, 25 Nov 2008) Log Message: ----------- Another small step towards writable AST. Starting on some Adapter classes. The names and design need to change, but this is a start. Modified Paths: -------------- branches/astwrite/ast/asdl_antlr.py branches/astwrite/src/org/python/antlr/ListWrapper.java branches/astwrite/src/org/python/antlr/ast/Assert.java branches/astwrite/src/org/python/antlr/ast/Assign.java branches/astwrite/src/org/python/antlr/ast/Attribute.java branches/astwrite/src/org/python/antlr/ast/AugAssign.java branches/astwrite/src/org/python/antlr/ast/BinOp.java branches/astwrite/src/org/python/antlr/ast/BoolOp.java branches/astwrite/src/org/python/antlr/ast/Break.java branches/astwrite/src/org/python/antlr/ast/Call.java branches/astwrite/src/org/python/antlr/ast/ClassDef.java branches/astwrite/src/org/python/antlr/ast/Compare.java branches/astwrite/src/org/python/antlr/ast/Continue.java branches/astwrite/src/org/python/antlr/ast/Delete.java branches/astwrite/src/org/python/antlr/ast/Dict.java branches/astwrite/src/org/python/antlr/ast/Ellipsis.java branches/astwrite/src/org/python/antlr/ast/Exec.java branches/astwrite/src/org/python/antlr/ast/Expr.java branches/astwrite/src/org/python/antlr/ast/Expression.java branches/astwrite/src/org/python/antlr/ast/ExtSlice.java branches/astwrite/src/org/python/antlr/ast/For.java branches/astwrite/src/org/python/antlr/ast/FunctionDef.java branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java branches/astwrite/src/org/python/antlr/ast/Global.java branches/astwrite/src/org/python/antlr/ast/If.java branches/astwrite/src/org/python/antlr/ast/IfExp.java branches/astwrite/src/org/python/antlr/ast/Import.java branches/astwrite/src/org/python/antlr/ast/ImportFrom.java branches/astwrite/src/org/python/antlr/ast/Index.java branches/astwrite/src/org/python/antlr/ast/Interactive.java branches/astwrite/src/org/python/antlr/ast/Lambda.java branches/astwrite/src/org/python/antlr/ast/List.java branches/astwrite/src/org/python/antlr/ast/ListComp.java branches/astwrite/src/org/python/antlr/ast/Module.java branches/astwrite/src/org/python/antlr/ast/Name.java branches/astwrite/src/org/python/antlr/ast/Num.java branches/astwrite/src/org/python/antlr/ast/Pass.java branches/astwrite/src/org/python/antlr/ast/Print.java branches/astwrite/src/org/python/antlr/ast/Raise.java branches/astwrite/src/org/python/antlr/ast/Repr.java branches/astwrite/src/org/python/antlr/ast/Return.java branches/astwrite/src/org/python/antlr/ast/Slice.java branches/astwrite/src/org/python/antlr/ast/Str.java branches/astwrite/src/org/python/antlr/ast/Subscript.java branches/astwrite/src/org/python/antlr/ast/Suite.java branches/astwrite/src/org/python/antlr/ast/TryExcept.java branches/astwrite/src/org/python/antlr/ast/TryFinally.java branches/astwrite/src/org/python/antlr/ast/Tuple.java branches/astwrite/src/org/python/antlr/ast/UnaryOp.java branches/astwrite/src/org/python/antlr/ast/VisitorBase.java branches/astwrite/src/org/python/antlr/ast/While.java branches/astwrite/src/org/python/antlr/ast/With.java branches/astwrite/src/org/python/antlr/ast/Yield.java branches/astwrite/src/org/python/antlr/ast/aliasType.java branches/astwrite/src/org/python/antlr/ast/argumentsType.java branches/astwrite/src/org/python/antlr/ast/comprehensionType.java branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java branches/astwrite/src/org/python/antlr/ast/exprType.java branches/astwrite/src/org/python/antlr/ast/keywordType.java branches/astwrite/src/org/python/antlr/ast/modType.java branches/astwrite/src/org/python/antlr/ast/sliceType.java branches/astwrite/src/org/python/antlr/ast/stmtType.java Added Paths: ----------- branches/astwrite/src/org/python/antlr/AstAdapters.java branches/astwrite/src/org/python/antlr/AstObjectAdapter.java branches/astwrite/src/org/python/antlr/StmtListAdapter.java Removed Paths: ------------- branches/astwrite/src/org/python/antlr/AstAdapter.java Modified: branches/astwrite/ast/asdl_antlr.py =================================================================== --- branches/astwrite/ast/asdl_antlr.py 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/ast/asdl_antlr.py 2008-11-25 03:03:43 UTC (rev 5634) @@ -57,7 +57,7 @@ print >> self.file, 'package org.python.antlr.ast;' if refersToPythonTree: print >> self.file, 'import java.util.ArrayList;' - print >> self.file, 'import org.python.antlr.AstAdapter;' + print >> self.file, 'import org.python.antlr.AstAdapters;' print >> self.file, 'import org.python.antlr.PythonTree;' print >> self.file, 'import org.python.antlr.ListWrapper;' print >> self.file, 'import org.antlr.runtime.CommonToken;' @@ -430,9 +430,9 @@ field.name), depth) if field.seq: #self.emit("this.%s = new %s(" % (field.name, self.javaType(field)), depth+1) - self.emit("this.%s = AstAdapter.to_%sList(%s);" % (field.name, str(field.type), field.name), depth+1) + self.emit("this.%s = AstAdapters.to_%sList(%s);" % (field.name, str(field.type), field.name), depth+1) else: - self.emit("this.%s = AstAdapter.to_%s(%s);" % (field.name, str(field.type), field.name), depth+1) + self.emit("this.%s = AstAdapters.to_%s(%s);" % (field.name, str(field.type), field.name), depth+1) self.emit("}", depth) self.emit("", 0) Deleted: branches/astwrite/src/org/python/antlr/AstAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstAdapter.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/AstAdapter.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,145 +0,0 @@ -package org.python.antlr; - -import org.python.antlr.ast.*; -import org.python.core.*; - -/** - * AstAdapter turns Python and Java objects into ast nodes. - */ -public class AstAdapter { - - public static java.util.List<aliasType> to_aliasList(Object o) { - return null; - } - - public static java.util.List<cmpopType> to_cmpopList(Object o) { - return null; - } - - public static java.util.List<comprehensionType> to_comprehensionList(Object o) { - return null; - } - - public static java.util.List<excepthandlerType> to_excepthandlerList(Object o) { - return null; - } - - public static java.util.List<exprType> to_exprList(Object o) { - return null; - } - - public static java.util.List<String> to_identifierList(Object o) { - return null; - } - - public static java.util.List<keywordType> to_keywordList(Object o) { - return null; - } - - public static java.util.List<sliceType> to_sliceList(Object o) { - return null; - } - - public static java.util.List<stmtType> to_stmtList(Object o) { - return null; - } - - public static exprType to_expr(Object o) { - if (o == null || o instanceof exprType) { - return (exprType)o; - } else if (o instanceof Integer) { - return new Num(new PyInteger((Integer)o)); - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); - } - - public static int to_int(Object o) { - if (o == null || o instanceof Integer) { - return (Integer)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to int node"); - } - - public static String to_identifier(Object o) { - if (o == null || o instanceof String) { - return (String)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); - } - - public static expr_contextType to_expr_context(Object o) { - if (o == null || o instanceof expr_contextType) { - return (expr_contextType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr_context node"); - } - - public static sliceType to_slice(Object o) { - if (o == null || o instanceof sliceType) { - return (sliceType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); - } - - public static String to_string(Object o) { - if (o == null || o instanceof String) { - return (String)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to string node"); - } - - public static operatorType to_operator(Object o) { - if (o == null || o instanceof operatorType) { - return (operatorType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to operator node"); - } - - public static boolopType to_boolop(Object o) { - if (o == null || o instanceof boolopType) { - return (boolopType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to boolop node"); - } - - public static argumentsType to_arguments(Object o) { - if (o == null || o instanceof argumentsType) { - return (argumentsType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arguments node"); - } - - public static Object to_object(Object o) { - if (o == null || o instanceof Object) { - return (Object)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to object node"); - } - - public static Boolean to_bool(Object o) { - if (o == null || o instanceof Boolean) { - return (Boolean)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to Boolean node"); - } - - public static unaryopType to_unaryop(Object o) { - if (o == null || o instanceof unaryopType) { - return (unaryopType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to unaryop node"); - } - -} Added: branches/astwrite/src/org/python/antlr/AstAdapters.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstAdapters.java (rev 0) +++ branches/astwrite/src/org/python/antlr/AstAdapters.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -0,0 +1,156 @@ +package org.python.antlr; + +import org.python.antlr.ast.*; +import org.python.core.*; + +/** + * AstAdapter turns Python and Java objects into ast nodes. + */ +public class AstAdapters { + + public static java.util.List<aliasType> to_aliasList(Object o) { + return null; + } + + public static java.util.List<cmpopType> to_cmpopList(Object o) { + return null; + } + + public static java.util.List<comprehensionType> to_comprehensionList(Object o) { + return null; + } + + public static java.util.List<excepthandlerType> to_excepthandlerList(Object o) { + return null; + } + + public static java.util.List<exprType> to_exprList(Object o) { + return null; + } + + public static java.util.List<String> to_identifierList(Object o) { + return null; + } + + public static java.util.List<keywordType> to_keywordList(Object o) { + return null; + } + + public static java.util.List<sliceType> to_sliceList(Object o) { + return null; + } + + public static java.util.List<stmtType> to_stmtList(Object o) { + return null; + } + + public static exprType to_expr(Object o) { + if (o == null || o instanceof exprType) { + return (exprType)o; + } else if (o instanceof Integer) { + return new Num(new PyInteger((Integer)o)); + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); + } + + public static int to_int(Object o) { + if (o == null || o instanceof Integer) { + return (Integer)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to int node"); + } + + public static String to_identifier(Object o) { + if (o == null || o instanceof String) { + return (String)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); + } + + public static expr_contextType to_expr_context(Object o) { + if (o == null || o instanceof expr_contextType) { + return (expr_contextType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr_context node"); + } + + public static sliceType to_slice(Object o) { + if (o == null || o instanceof sliceType) { + return (sliceType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); + } + + public static stmtType to_stmt(Object o) { + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(stmtType.class); + } + if (o == null || o instanceof stmtType) { + return (stmtType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to stmt node"); + } + + public static String to_string(Object o) { + if (o == null || o instanceof String) { + return (String)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to string node"); + } + + public static operatorType to_operator(Object o) { + if (o == null || o instanceof operatorType) { + return (operatorType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to operator node"); + } + + public static boolopType to_boolop(Object o) { + if (o == null || o instanceof boolopType) { + return (boolopType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to boolop node"); + } + + public static argumentsType to_arguments(Object o) { + if (o == null || o instanceof argumentsType) { + return (argumentsType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arguments node"); + } + + public static Object to_object(Object o) { + if (o == null || o instanceof Object) { + return (Object)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to object node"); + } + + public static Boolean to_bool(Object o) { + if (o == null || o instanceof Boolean) { + return (Boolean)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to Boolean node"); + } + + public static unaryopType to_unaryop(Object o) { + if (o == null || o instanceof unaryopType) { + return (unaryopType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to unaryop node"); + } + +} Added: branches/astwrite/src/org/python/antlr/AstObjectAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstObjectAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/AstObjectAdapter.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -0,0 +1,5 @@ +package org.python.antlr; + +public interface AstObjectAdapter { + public Object adapt(Object o); +} Modified: branches/astwrite/src/org/python/antlr/ListWrapper.java =================================================================== --- branches/astwrite/src/org/python/antlr/ListWrapper.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ListWrapper.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -7,14 +7,20 @@ import java.util.ListIterator; import org.python.core.PyObject; -public class ListWrapper<E> implements List<E> { +public class ListWrapper implements List { - private List<E> list; + private List list; + private AstObjectAdapter adapter; - public ListWrapper(List<E> list) { + public ListWrapper(List list) { this.list = list; } + public ListWrapper(List list, AstObjectAdapter adapter) { + this.adapter = adapter; + this.list = list; + } + public boolean containsAll(Collection c) { return containsAll(c); } @@ -27,11 +33,11 @@ return list.retainAll(c); } - public boolean add(E e) { + public boolean add(Object e) { return list.add(e); } - public void add(int index, E e) { + public void add(int index, Object e) { list.add(index, e); } @@ -51,7 +57,7 @@ return list.contains(elem); } - public E get(int index) { + public Object get(int index) { return list.get(index); } @@ -67,7 +73,7 @@ return list.lastIndexOf(elem); } - public E remove(int index) { + public Object remove(int index) { return list.remove(index); } @@ -75,7 +81,7 @@ return list.remove(o); } - public E set(int index, E element) { + public Object set(int index, Object element) { return list.set(index, element); } @@ -147,7 +153,7 @@ } public void append(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + list.add(adapter.adapt(o)); } public int count(PyObject o) { Added: branches/astwrite/src/org/python/antlr/StmtListAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/StmtListAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/StmtListAdapter.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -0,0 +1,22 @@ +package org.python.antlr; + +import org.python.antlr.ast.stmtType; + +import java.util.ArrayList; +import java.util.List; + +public class StmtListAdapter implements AstObjectAdapter { + public Object adaptList(Object list) { + List<stmtType> s = new ArrayList<stmtType>(); + if (list instanceof List) { + for (Object o : (List)list) { + s.add(AstAdapters.to_stmt(o)); + } + } + return s; + } + + public Object adapt(Object o) { + return AstAdapters.to_stmt(o); + } +} Modified: branches/astwrite/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assert.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Assert.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return test; } public void setTest(Object test) { - this.test = AstAdapter.to_expr(test); + this.test = AstAdapters.to_expr(test); } private exprType msg; @@ -29,7 +29,7 @@ return msg; } public void setMsg(Object msg) { - this.msg = AstAdapter.to_expr(msg); + this.msg = AstAdapters.to_expr(msg); } Modified: branches/astwrite/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(targets); } public void setTargets(Object targets) { - this.targets = AstAdapter.to_exprList(targets); + this.targets = AstAdapters.to_exprList(targets); } private exprType value; @@ -29,7 +29,7 @@ return value; } public void setValue(Object value) { - this.value = AstAdapter.to_expr(value); + this.value = AstAdapters.to_expr(value); } Modified: branches/astwrite/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Attribute.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Attribute.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return value; } public void setValue(Object value) { - this.value = AstAdapter.to_expr(value); + this.value = AstAdapters.to_expr(value); } private String attr; @@ -29,7 +29,7 @@ return attr; } public void setAttr(Object attr) { - this.attr = AstAdapter.to_identifier(attr); + this.attr = AstAdapters.to_identifier(attr); } private expr_contextType ctx; @@ -40,7 +40,7 @@ return ctx; } public void setCtx(Object ctx) { - this.ctx = AstAdapter.to_expr_context(ctx); + this.ctx = AstAdapters.to_expr_context(ctx); } Modified: branches/astwrite/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/AugAssign.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/AugAssign.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return target; } public void setTarget(Object target) { - this.target = AstAdapter.to_expr(target); + this.target = AstAdapters.to_expr(target); } private operatorType op; @@ -29,7 +29,7 @@ return op; } public void setOp(Object op) { - this.op = AstAdapter.to_operator(op); + this.op = AstAdapters.to_operator(op); } private exprType value; @@ -40,7 +40,7 @@ return value; } public void setValue(Object value) { - this.value = AstAdapter.to_expr(value); + this.value = AstAdapters.to_expr(value); } Modified: branches/astwrite/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BinOp.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/BinOp.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return left; } public void setLeft(Object left) { - this.left = AstAdapter.to_expr(left); + this.left = AstAdapters.to_expr(left); } private operatorType op; @@ -29,7 +29,7 @@ return op; } public void setOp(Object op) { - this.op = AstAdapter.to_operator(op); + this.op = AstAdapters.to_operator(op); } private exprType right; @@ -40,7 +40,7 @@ return right; } public void setRight(Object right) { - this.right = AstAdapter.to_expr(right); + this.right = AstAdapters.to_expr(right); } Modified: branches/astwrite/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return op; } public void setOp(Object op) { - this.op = AstAdapter.to_boolop(op); + this.op = AstAdapters.to_boolop(op); } private java.util.List<exprType> values; @@ -29,7 +29,7 @@ return new ListWrapper(values); } public void setValues(Object values) { - this.values = AstAdapter.to_exprList(values); + this.values = AstAdapters.to_exprList(values); } Modified: branches/astwrite/src/org/python/antlr/ast/Break.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Break.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Break.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; Modified: branches/astwrite/src/org/python/antlr/ast/Call.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return func; } public void setFunc(Object func) { - this.func = AstAdapter.to_expr(func); + this.func = AstAdapters.to_expr(func); } private java.util.List<exprType> args; @@ -29,7 +29,7 @@ return new ListWrapper(args); } public void setArgs(Object args) { - this.args = AstAdapter.to_exprList(args); + this.args = AstAdapters.to_exprList(args); } private java.util.List<keywordType> keywords; @@ -40,7 +40,7 @@ return new ListWrapper(keywords); } public void setKeywords(Object keywords) { - this.keywords = AstAdapter.to_keywordList(keywords); + this.keywords = AstAdapters.to_keywordList(keywords); } private exprType starargs; @@ -51,7 +51,7 @@ return starargs; } public void setStarargs(Object starargs) { - this.starargs = AstAdapter.to_expr(starargs); + this.starargs = AstAdapters.to_expr(starargs); } private exprType kwargs; @@ -62,7 +62,7 @@ return kwargs; } public void setKwargs(Object kwargs) { - this.kwargs = AstAdapter.to_expr(kwargs); + this.kwargs = AstAdapters.to_expr(kwargs); } Modified: branches/astwrite/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return name; } public void setName(Object name) { - this.name = AstAdapter.to_identifier(name); + this.name = AstAdapters.to_identifier(name); } private java.util.List<exprType> bases; @@ -29,7 +29,7 @@ return new ListWrapper(bases); } public void setBases(Object bases) { - this.bases = AstAdapter.to_exprList(bases); + this.bases = AstAdapters.to_exprList(bases); } private java.util.List<stmtType> body; @@ -40,7 +40,7 @@ return new ListWrapper(body); } public void setBody(Object body) { - this.body = AstAdapter.to_stmtList(body); + this.body = AstAdapters.to_stmtList(body); } private java.util.List<exprType> decorators; @@ -51,7 +51,7 @@ return new ListWrapper(decorators); } public void setDecorators(Object decorators) { - this.decorators = AstAdapter.to_exprList(decorators); + this.decorators = AstAdapters.to_exprList(decorators); } Modified: branches/astwrite/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return left; } public void setLeft(Object left) { - this.left = AstAdapter.to_expr(left); + this.left = AstAdapters.to_expr(left); } private java.util.List<cmpopType> ops; @@ -29,7 +29,7 @@ return new ListWrapper(ops); } public void setOps(Object ops) { - this.ops = AstAdapter.to_cmpopList(ops); + this.ops = AstAdapters.to_cmpopList(ops); } private java.util.List<exprType> comparators; @@ -40,7 +40,7 @@ return new ListWrapper(comparators); } public void setComparators(Object comparators) { - this.comparators = AstAdapter.to_exprList(comparators); + this.comparators = AstAdapters.to_exprList(comparators); } Modified: branches/astwrite/src/org/python/antlr/ast/Continue.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Continue.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Continue.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; Modified: branches/astwrite/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(targets); } public void setTargets(Object targets) { - this.targets = AstAdapter.to_exprList(targets); + this.targets = AstAdapters.to_exprList(targets); } Modified: branches/astwrite/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(keys); } public void setKeys(Object keys) { - this.keys = AstAdapter.to_exprList(keys); + this.keys = AstAdapters.to_exprList(keys); } private java.util.List<exprType> values; @@ -29,7 +29,7 @@ return new ListWrapper(values); } public void setValues(Object values) { - this.values = AstAdapter.to_exprList(values); + this.values = AstAdapters.to_exprList(values); } Modified: branches/astwrite/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Ellipsis.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Ellipsis.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; Modified: branches/astwrite/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Exec.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Exec.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return body; } public void setBody(Object body) { - this.body = AstAdapter.to_expr(body); + this.body = AstAdapters.to_expr(body); } private exprType globals; @@ -29,7 +29,7 @@ return globals; } public void setGlobals(Object globals) { - this.globals = AstAdapter.to_expr(globals); + this.globals = AstAdapters.to_expr(globals); } private exprType locals; @@ -40,7 +40,7 @@ return locals; } public void setLocals(Object locals) { - this.locals = AstAdapter.to_expr(locals); + this.locals = AstAdapters.to_expr(locals); } Modified: branches/astwrite/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Expr.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Expr.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return value; } public void setValue(Object value) { - this.value = AstAdapter.to_expr(value); + this.value = AstAdapters.to_expr(value); } Modified: branches/astwrite/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Expression.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Expression.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return body; } public void setBody(Object body) { - this.body = AstAdapter.to_expr(body); + this.body = AstAdapters.to_expr(body); } Modified: branches/astwrite/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(dims); } public void setDims(Object dims) { - this.dims = AstAdapter.to_sliceList(dims); + this.dims = AstAdapters.to_sliceList(dims); } Modified: branches/astwrite/src/org/python/antlr/ast/For.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return target; } public void setTarget(Object target) { - this.target = AstAdapter.to_expr(target); + this.target = AstAdapters.to_expr(target); } private exprType iter; @@ -29,7 +29,7 @@ return iter; } public void setIter(Object iter) { - this.iter = AstAdapter.to_expr(iter); + this.iter = AstAdapters.to_expr(iter); } private java.util.List<stmtType> body; @@ -40,7 +40,7 @@ return new ListWrapper(body); } public void setBody(Object body) { - this.body = AstAdapter.to_stmtList(body); + this.body = AstAdapters.to_stmtList(body); } private java.util.List<stmtType> orelse; @@ -51,7 +51,7 @@ return new ListWrapper(orelse); } public void setOrelse(Object orelse) { - this.orelse = AstAdapter.to_stmtList(orelse); + this.orelse = AstAdapters.to_stmtList(orelse); } Modified: branches/astwrite/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return name; } public void setName(Object name) { - this.name = AstAdapter.to_identifier(name); + this.name = AstAdapters.to_identifier(name); } private argumentsType args; @@ -29,7 +29,7 @@ return args; } public void setArgs(Object args) { - this.args = AstAdapter.to_arguments(args); + this.args = AstAdapters.to_arguments(args); } private java.util.List<stmtType> body; @@ -40,7 +40,7 @@ return new ListWrapper(body); } public void setBody(Object body) { - this.body = AstAdapter.to_stmtList(body); + this.body = AstAdapters.to_stmtList(body); } private java.util.List<exprType> decorators; @@ -51,7 +51,7 @@ return new ListWrapper(decorators); } public void setDecorators(Object decorators) { - this.decorators = AstAdapter.to_exprList(decorators); + this.decorators = AstAdapters.to_exprList(decorators); } Modified: branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return elt; } public void setElt(Object elt) { - this.elt = AstAdapter.to_expr(elt); + this.elt = AstAdapters.to_expr(elt); } private java.util.List<comprehensionType> generators; @@ -29,7 +29,7 @@ return new ListWrapper(generators); } public void setGenerators(Object generators) { - this.generators = AstAdapter.to_comprehensionList(generators); + this.generators = AstAdapters.to_comprehensionList(generators); } Modified: branches/astwrite/src/org/python/antlr/ast/Global.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(names); } public void setNames(Object names) { - this.names = AstAdapter.to_identifierList(names); + this.names = AstAdapters.to_identifierList(names); } Modified: branches/astwrite/src/org/python/antlr/ast/If.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return test; } public void setTest(Object test) { - this.test = AstAdapter.to_expr(test); + this.test = AstAdapters.to_expr(test); } private java.util.List<stmtType> body; @@ -29,7 +29,7 @@ return new ListWrapper(body); } public void setBody(Object body) { - this.body = AstAdapter.to_stmtList(body); + this.body = AstAdapters.to_stmtList(body); } private java.util.List<stmtType> orelse; @@ -40,7 +40,7 @@ return new ListWrapper(orelse); } public void setOrelse(Object orelse) { - this.orelse = AstAdapter.to_stmtList(orelse); + this.orelse = AstAdapters.to_stmtList(orelse); } Modified: branches/astwrite/src/org/python/antlr/ast/IfExp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/IfExp.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/IfExp.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return test; } public void setTest(Object test) { - this.test = AstAdapter.to_expr(test); + this.test = AstAdapters.to_expr(test); } private exprType body; @@ -29,7 +29,7 @@ return body; } public void setBody(Object body) { - this.body = AstAdapter.to_expr(body); + this.body = AstAdapters.to_expr(body); } private exprType orelse; @@ -40,7 +40,7 @@ return orelse; } public void setOrelse(Object orelse) { - this.orelse = AstAdapter.to_expr(orelse); + this.orelse = AstAdapters.to_expr(orelse); } Modified: branches/astwrite/src/org/python/antlr/ast/Import.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Import.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Import.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(names); } public void setNames(Object names) { - this.names = AstAdapter.to_aliasList(names); + this.names = AstAdapters.to_aliasList(names); } Modified: branches/astwrite/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ImportFrom.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/ImportFrom.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return module; } public void setModule(Object module) { - this.module = AstAdapter.to_identifier(module); + this.module = AstAdapters.to_identifier(module); } private java.util.List<aliasType> names; @@ -29,7 +29,7 @@ return new ListWrapper(names); } public void setNames(Object names) { - this.names = AstAdapter.to_aliasList(names); + this.names = AstAdapters.to_aliasList(names); } private Integer level; @@ -40,7 +40,7 @@ return level; } public void setLevel(Object level) { - this.level = AstAdapter.to_int(level); + this.level = AstAdapters.to_int(level); } Modified: branches/astwrite/src/org/python/antlr/ast/Index.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Index.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Index.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return value; } public void setValue(Object value) { - this.value = AstAdapter.to_expr(value); + this.value = AstAdapters.to_expr(value); } Modified: branches/astwrite/src/org/python/antlr/ast/Interactive.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Interactive.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Interactive.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(body); } public void setBody(Object body) { - this.body = AstAdapter.to_stmtList(body); + this.body = AstAdapters.to_stmtList(body); } Modified: branches/astwrite/src/org/python/antlr/ast/Lambda.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Lambda.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Lambda.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return args; } public void setArgs(Object args) { - this.args = AstAdapter.to_arguments(args); + this.args = AstAdapters.to_arguments(args); } private exprType body; @@ -29,7 +29,7 @@ return body; } public void setBody(Object body) { - this.body = AstAdapter.to_expr(body); + this.body = AstAdapters.to_expr(body); } Modified: branches/astwrite/src/org/python/antlr/ast/List.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/List.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/List.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(elts); } public void setElts(Object elts) { - this.elts = AstAdapter.to_exprList(elts); + this.elts = AstAdapters.to_exprList(elts); } private expr_contextType ctx; @@ -29,7 +29,7 @@ return ctx; } public void setCtx(Object ctx) { - this.ctx = AstAdapter.to_expr_context(ctx); + this.ctx = AstAdapters.to_expr_context(ctx); } Modified: branches/astwrite/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ListComp.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/ListComp.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return elt; } public void setElt(Object elt) { - this.elt = AstAdapter.to_expr(elt); + this.elt = AstAdapters.to_expr(elt); } private java.util.List<comprehensionType> generators; @@ -29,7 +29,7 @@ return new ListWrapper(generators); } public void setGenerators(Object generators) { - this.generators = AstAdapter.to_comprehensionList(generators); + this.generators = AstAdapters.to_comprehensionList(generators); } Modified: branches/astwrite/src/org/python/antlr/ast/Module.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Module.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Module.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return new ListWrapper(body); } public void setBody(Object body) { - this.body = AstAdapter.to_stmtList(body); + this.body = AstAdapters.to_stmtList(body); } Modified: branches/astwrite/src/org/python/antlr/ast/Name.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Name.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Name.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return id; } public void setId(Object id) { - this.id = AstAdapter.to_identifier(id); + this.id = AstAdapters.to_identifier(id); } private expr_contextType ctx; @@ -29,7 +29,7 @@ return ctx; } public void setCtx(Object ctx) { - this.ctx = AstAdapter.to_expr_context(ctx); + this.ctx = AstAdapters.to_expr_context(ctx); } Modified: branches/astwrite/src/org/python/antlr/ast/Num.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Num.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Num.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return n; } public void setN(Object n) { - this.n = AstAdapter.to_object(n); + this.n = AstAdapters.to_object(n); } Modified: branches/astwrite/src/org/python/antlr/ast/Pass.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Pass.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Pass.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; Modified: branches/astwrite/src/org/python/antlr/ast/Print.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Print.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Print.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return dest; } public void setDest(Object dest) { - this.dest = AstAdapter.to_expr(dest); + this.dest = AstAdapters.to_expr(dest); } private java.util.List<exprType> values; @@ -29,7 +29,7 @@ return new ListWrapper(values); } public void setValues(Object values) { - this.values = AstAdapter.to_exprList(values); + this.values = AstAdapters.to_exprList(values); } private Boolean nl; @@ -40,7 +40,7 @@ return nl; } public void setNl(Object nl) { - this.nl = AstAdapter.to_bool(nl); + this.nl = AstAdapters.to_bool(nl); } Modified: branches/astwrite/src/org/python/antlr/ast/Raise.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Raise.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Raise.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -18,7 +18,7 @@ return excepttype; } public void setExcepttype(Object excepttype) { - this.excepttype = AstAdapter.to_expr(excepttype); + this.excepttype = AstAdapters.to_expr(excepttype); } private exprType inst; @@ -29,7 +29,7 @@ return inst; } public void setInst(Object inst) { - this.inst = AstAdapter.to_expr(inst); + this.inst = AstAdapters.to_expr(inst); } private exprType tback; @@ -40,7 +40,7 @@ return tback; } public void setTback(Object tback) { - this.tback = AstAdapter.to_expr(tback); + this.tback = AstAdapters.to_expr(tback); } Modified: branches/astwrite/src/org/python/antlr/ast/Repr.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Repr.java 2008-11-24 19:41:50 UTC (rev 5633) +++ branches/astwrite/src/org/python/antlr/ast/Repr.java 2008-11-25 03:03:43 UTC (rev 5634) @@ -1,7 +1,7 @@ // Autogenerated AST node package org.python.antlr.ast; import java.util.ArrayList; -import org.python.antlr.AstAdapter; +import org.python.antlr.AstAdapters; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonTok... [truncated message content] |
From: <fwi...@us...> - 2008-11-24 19:41:56
|
Revision: 5633 http://jython.svn.sourceforge.net/jython/?rev=5633&view=rev Author: fwierzbicki Date: 2008-11-24 19:41:50 +0000 (Mon, 24 Nov 2008) Log Message: ----------- internal compiler operates on the internal lists now ListWrappers. Modified Paths: -------------- branches/astwrite/ast/asdl_antlr.py branches/astwrite/src/org/python/antlr/AstAdapter.java branches/astwrite/src/org/python/antlr/ast/Assert.java branches/astwrite/src/org/python/antlr/ast/Assign.java branches/astwrite/src/org/python/antlr/ast/Attribute.java branches/astwrite/src/org/python/antlr/ast/AugAssign.java branches/astwrite/src/org/python/antlr/ast/BinOp.java branches/astwrite/src/org/python/antlr/ast/BoolOp.java branches/astwrite/src/org/python/antlr/ast/Break.java branches/astwrite/src/org/python/antlr/ast/Call.java branches/astwrite/src/org/python/antlr/ast/ClassDef.java branches/astwrite/src/org/python/antlr/ast/Compare.java branches/astwrite/src/org/python/antlr/ast/Continue.java branches/astwrite/src/org/python/antlr/ast/Delete.java branches/astwrite/src/org/python/antlr/ast/Dict.java branches/astwrite/src/org/python/antlr/ast/Ellipsis.java branches/astwrite/src/org/python/antlr/ast/Exec.java branches/astwrite/src/org/python/antlr/ast/Expr.java branches/astwrite/src/org/python/antlr/ast/Expression.java branches/astwrite/src/org/python/antlr/ast/ExtSlice.java branches/astwrite/src/org/python/antlr/ast/For.java branches/astwrite/src/org/python/antlr/ast/FunctionDef.java branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java branches/astwrite/src/org/python/antlr/ast/Global.java branches/astwrite/src/org/python/antlr/ast/If.java branches/astwrite/src/org/python/antlr/ast/IfExp.java branches/astwrite/src/org/python/antlr/ast/Import.java branches/astwrite/src/org/python/antlr/ast/ImportFrom.java branches/astwrite/src/org/python/antlr/ast/Index.java branches/astwrite/src/org/python/antlr/ast/Interactive.java branches/astwrite/src/org/python/antlr/ast/Lambda.java branches/astwrite/src/org/python/antlr/ast/List.java branches/astwrite/src/org/python/antlr/ast/ListComp.java branches/astwrite/src/org/python/antlr/ast/Module.java branches/astwrite/src/org/python/antlr/ast/Name.java branches/astwrite/src/org/python/antlr/ast/Num.java branches/astwrite/src/org/python/antlr/ast/Pass.java branches/astwrite/src/org/python/antlr/ast/Print.java branches/astwrite/src/org/python/antlr/ast/Raise.java branches/astwrite/src/org/python/antlr/ast/Repr.java branches/astwrite/src/org/python/antlr/ast/Return.java branches/astwrite/src/org/python/antlr/ast/Slice.java branches/astwrite/src/org/python/antlr/ast/Str.java branches/astwrite/src/org/python/antlr/ast/Subscript.java branches/astwrite/src/org/python/antlr/ast/Suite.java branches/astwrite/src/org/python/antlr/ast/TryExcept.java branches/astwrite/src/org/python/antlr/ast/TryFinally.java branches/astwrite/src/org/python/antlr/ast/Tuple.java branches/astwrite/src/org/python/antlr/ast/UnaryOp.java branches/astwrite/src/org/python/antlr/ast/VisitorBase.java branches/astwrite/src/org/python/antlr/ast/While.java branches/astwrite/src/org/python/antlr/ast/With.java branches/astwrite/src/org/python/antlr/ast/Yield.java branches/astwrite/src/org/python/antlr/ast/aliasType.java branches/astwrite/src/org/python/antlr/ast/argumentsType.java branches/astwrite/src/org/python/antlr/ast/comprehensionType.java branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java branches/astwrite/src/org/python/antlr/ast/exprType.java branches/astwrite/src/org/python/antlr/ast/keywordType.java branches/astwrite/src/org/python/antlr/ast/modType.java branches/astwrite/src/org/python/antlr/ast/sliceType.java branches/astwrite/src/org/python/antlr/ast/stmtType.java branches/astwrite/src/org/python/compiler/ArgListCompiler.java Modified: branches/astwrite/ast/asdl_antlr.py =================================================================== --- branches/astwrite/ast/asdl_antlr.py 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/ast/asdl_antlr.py 2008-11-24 19:41:50 UTC (rev 5633) @@ -56,6 +56,7 @@ print >> self.file, "// Autogenerated AST node" print >> self.file, 'package org.python.antlr.ast;' if refersToPythonTree: + print >> self.file, 'import java.util.ArrayList;' print >> self.file, 'import org.python.antlr.AstAdapter;' print >> self.file, 'import org.python.antlr.PythonTree;' print >> self.file, 'import org.python.antlr.ListWrapper;' @@ -294,11 +295,11 @@ def javaConstructorHelper(self, fields, depth): for f in fields: - if f.seq: - self.emit("this.%s = new %s(%s);" % (f.name, - self.javaType(f, True), f.name), depth+1) - else: - self.emit("this.%s = %s;" % (f.name, f.name), depth+1) + #if f.seq: + # self.emit("this.%s = new %s(%s);" % (f.name, + # self.javaType(f), f.name), depth+1) + #else: + self.emit("this.%s = %s;" % (f.name, f.name), depth+1) fparg = self.fieldDef(f) @@ -308,11 +309,12 @@ #For now ignoring String -- will want to revisit if not_simple and fparg.find("String") == -1: if f.seq: - self.emit("if (%s != null) {" % f.name, depth+1); - self.emit("for(PythonTree t : %(name)s) {" % {"name":f.name}, depth+2) - self.emit("addChild(t);", depth+3) - self.emit("}", depth+2) + self.emit("if (%s == null) {" % f.name, depth+1); + self.emit("this.%s = new ArrayList<%s>();" % (f.name, self.javaType(f, False)), depth+2) self.emit("}", depth+1) + self.emit("for(PythonTree t : this.%(name)s) {" % {"name":f.name}, depth+1) + self.emit("addChild(t);", depth+2) + self.emit("}", depth+1) elif str(f.type) == "expr": self.emit("addChild(%s);" % (f.name), depth+1) @@ -413,19 +415,22 @@ def visitField(self, field, depth): - self.emit("private %s;" % self.fieldDef(field, True), depth) - self.emit("public %s getInternal%s() {" % (self.javaType(field, True), + self.emit("private %s;" % self.fieldDef(field), depth) + self.emit("public %s getInternal%s() {" % (self.javaType(field), str(field.name).capitalize()), depth) self.emit("return %s;" % field.name, depth+1) self.emit("}", depth) self.emit("public Object get%s() {" % (str(field.name).capitalize()), depth) - self.emit("return %s;" % field.name, depth+1) + if field.seq: + self.emit("return new ListWrapper(%s);" % field.name, depth+1) + else: + self.emit("return %s;" % field.name, depth+1) self.emit("}", depth) self.emit("public void set%s(Object %s) {" % (str(field.name).capitalize(), field.name), depth) if field.seq: - self.emit("this.%s = new %s(" % (field.name, self.javaType(field, True)), depth+1) - self.emit("(%s)%s);" % (self.javaType(field), field.name), depth+2) + #self.emit("this.%s = new %s(" % (field.name, self.javaType(field)), depth+1) + self.emit("this.%s = AstAdapter.to_%sList(%s);" % (field.name, str(field.type), field.name), depth+1) else: self.emit("this.%s = AstAdapter.to_%s(%s);" % (field.name, str(field.type), field.name), depth+1) self.emit("}", depth) @@ -441,20 +446,16 @@ 'PythonTree' : 'PythonTree', # also for antlr type } - def fieldDef(self, field, wrapper=False): - jtype = self.javaType(field, wrapper) + def fieldDef(self, field): + jtype = self.javaType(field) name = field.name return "%s %s" % (jtype, name) - def javaType(self, field, wrapper=False): + def javaType(self, field, check_seq=True): jtype = str(field.type) jtype = self.bltinnames.get(jtype, jtype + 'Type') - if field.seq: - if wrapper: - return "ListWrapper<%s>" % jtype - else: - return "java.util.List<%s>" % jtype - + if check_seq and field.seq: + return "java.util.List<%s>" % jtype return jtype class VisitorVisitor(EmitVisitor): Modified: branches/astwrite/src/org/python/antlr/AstAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstAdapter.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/AstAdapter.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -8,6 +8,42 @@ */ public class AstAdapter { + public static java.util.List<aliasType> to_aliasList(Object o) { + return null; + } + + public static java.util.List<cmpopType> to_cmpopList(Object o) { + return null; + } + + public static java.util.List<comprehensionType> to_comprehensionList(Object o) { + return null; + } + + public static java.util.List<excepthandlerType> to_excepthandlerList(Object o) { + return null; + } + + public static java.util.List<exprType> to_exprList(Object o) { + return null; + } + + public static java.util.List<String> to_identifierList(Object o) { + return null; + } + + public static java.util.List<keywordType> to_keywordList(Object o) { + return null; + } + + public static java.util.List<sliceType> to_sliceList(Object o) { + return null; + } + + public static java.util.List<stmtType> to_stmtList(Object o) { + return null; + } + public static exprType to_expr(Object o) { if (o == null || o instanceof exprType) { return (exprType)o; Modified: branches/astwrite/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assert.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Assert.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -9,16 +10,15 @@ import java.io.IOException; public class Assign extends stmtType { - private ListWrapper<exprType> targets; - public ListWrapper<exprType> getInternalTargets() { + private java.util.List<exprType> targets; + public java.util.List<exprType> getInternalTargets() { return targets; } public Object getTargets() { - return targets; + return new ListWrapper(targets); } public void setTargets(Object targets) { - this.targets = new ListWrapper<exprType>( - (java.util.List<exprType>)targets); + this.targets = AstAdapter.to_exprList(targets); } private exprType value; @@ -45,12 +45,13 @@ public Assign(Token token, java.util.List<exprType> targets, exprType value) { super(token); - this.targets = new ListWrapper<exprType>(targets); - if (targets != null) { - for(PythonTree t : targets) { - addChild(t); - } + this.targets = targets; + if (targets == null) { + this.targets = new ArrayList<exprType>(); } + for(PythonTree t : this.targets) { + addChild(t); + } this.value = value; addChild(value); } @@ -58,12 +59,13 @@ public Assign(Integer ttype, Token token, java.util.List<exprType> targets, exprType value) { super(ttype, token); - this.targets = new ListWrapper<exprType>(targets); - if (targets != null) { - for(PythonTree t : targets) { - addChild(t); - } + this.targets = targets; + if (targets == null) { + this.targets = new ArrayList<exprType>(); } + for(PythonTree t : this.targets) { + addChild(t); + } this.value = value; addChild(value); } @@ -71,12 +73,13 @@ public Assign(PythonTree tree, java.util.List<exprType> targets, exprType value) { super(tree); - this.targets = new ListWrapper<exprType>(targets); - if (targets != null) { - for(PythonTree t : targets) { - addChild(t); - } + this.targets = targets; + if (targets == null) { + this.targets = new ArrayList<exprType>(); } + for(PythonTree t : this.targets) { + addChild(t); + } this.value = value; addChild(value); } Modified: branches/astwrite/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Attribute.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Attribute.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/AugAssign.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/AugAssign.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BinOp.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/BinOp.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -20,16 +21,15 @@ this.op = AstAdapter.to_boolop(op); } - private ListWrapper<exprType> values; - public ListWrapper<exprType> getInternalValues() { + private java.util.List<exprType> values; + public java.util.List<exprType> getInternalValues() { return values; } public Object getValues() { - return values; + return new ListWrapper(values); } public void setValues(Object values) { - this.values = new ListWrapper<exprType>( - (java.util.List<exprType>)values); + this.values = AstAdapter.to_exprList(values); } @@ -45,36 +45,39 @@ public BoolOp(Token token, boolopType op, java.util.List<exprType> values) { super(token); this.op = op; - this.values = new ListWrapper<exprType>(values); - if (values != null) { - for(PythonTree t : values) { - addChild(t); - } + this.values = values; + if (values == null) { + this.values = new ArrayList<exprType>(); } + for(PythonTree t : this.values) { + addChild(t); + } } public BoolOp(Integer ttype, Token token, boolopType op, java.util.List<exprType> values) { super(ttype, token); this.op = op; - this.values = new ListWrapper<exprType>(values); - if (values != null) { - for(PythonTree t : values) { - addChild(t); - } + this.values = values; + if (values == null) { + this.values = new ArrayList<exprType>(); } + for(PythonTree t : this.values) { + addChild(t); + } } public BoolOp(PythonTree tree, boolopType op, java.util.List<exprType> values) { super(tree); this.op = op; - this.values = new ListWrapper<exprType>(values); - if (values != null) { - for(PythonTree t : values) { - addChild(t); - } + this.values = values; + if (values == null) { + this.values = new ArrayList<exprType>(); } + for(PythonTree t : this.values) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/Break.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Break.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Break.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/Call.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -20,28 +21,26 @@ this.func = AstAdapter.to_expr(func); } - private ListWrapper<exprType> args; - public ListWrapper<exprType> getInternalArgs() { + private java.util.List<exprType> args; + public java.util.List<exprType> getInternalArgs() { return args; } public Object getArgs() { - return args; + return new ListWrapper(args); } public void setArgs(Object args) { - this.args = new ListWrapper<exprType>( - (java.util.List<exprType>)args); + this.args = AstAdapter.to_exprList(args); } - private ListWrapper<keywordType> keywords; - public ListWrapper<keywordType> getInternalKeywords() { + private java.util.List<keywordType> keywords; + public java.util.List<keywordType> getInternalKeywords() { return keywords; } public Object getKeywords() { - return keywords; + return new ListWrapper(keywords); } public void setKeywords(Object keywords) { - this.keywords = new ListWrapper<keywordType>( - (java.util.List<keywordType>)keywords); + this.keywords = AstAdapter.to_keywordList(keywords); } private exprType starargs; @@ -87,18 +86,20 @@ super(token); this.func = func; addChild(func); - this.args = new ListWrapper<exprType>(args); - if (args != null) { - for(PythonTree t : args) { - addChild(t); - } + this.args = args; + if (args == null) { + this.args = new ArrayList<exprType>(); } - this.keywords = new ListWrapper<keywordType>(keywords); - if (keywords != null) { - for(PythonTree t : keywords) { - addChild(t); - } + for(PythonTree t : this.args) { + addChild(t); } + this.keywords = keywords; + if (keywords == null) { + this.keywords = new ArrayList<keywordType>(); + } + for(PythonTree t : this.keywords) { + addChild(t); + } this.starargs = starargs; addChild(starargs); this.kwargs = kwargs; @@ -111,18 +112,20 @@ super(ttype, token); this.func = func; addChild(func); - this.args = new ListWrapper<exprType>(args); - if (args != null) { - for(PythonTree t : args) { - addChild(t); - } + this.args = args; + if (args == null) { + this.args = new ArrayList<exprType>(); } - this.keywords = new ListWrapper<keywordType>(keywords); - if (keywords != null) { - for(PythonTree t : keywords) { - addChild(t); - } + for(PythonTree t : this.args) { + addChild(t); } + this.keywords = keywords; + if (keywords == null) { + this.keywords = new ArrayList<keywordType>(); + } + for(PythonTree t : this.keywords) { + addChild(t); + } this.starargs = starargs; addChild(starargs); this.kwargs = kwargs; @@ -134,18 +137,20 @@ super(tree); this.func = func; addChild(func); - this.args = new ListWrapper<exprType>(args); - if (args != null) { - for(PythonTree t : args) { - addChild(t); - } + this.args = args; + if (args == null) { + this.args = new ArrayList<exprType>(); } - this.keywords = new ListWrapper<keywordType>(keywords); - if (keywords != null) { - for(PythonTree t : keywords) { - addChild(t); - } + for(PythonTree t : this.args) { + addChild(t); } + this.keywords = keywords; + if (keywords == null) { + this.keywords = new ArrayList<keywordType>(); + } + for(PythonTree t : this.keywords) { + addChild(t); + } this.starargs = starargs; addChild(starargs); this.kwargs = kwargs; Modified: branches/astwrite/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -20,40 +21,37 @@ this.name = AstAdapter.to_identifier(name); } - private ListWrapper<exprType> bases; - public ListWrapper<exprType> getInternalBases() { + private java.util.List<exprType> bases; + public java.util.List<exprType> getInternalBases() { return bases; } public Object getBases() { - return bases; + return new ListWrapper(bases); } public void setBases(Object bases) { - this.bases = new ListWrapper<exprType>( - (java.util.List<exprType>)bases); + this.bases = AstAdapter.to_exprList(bases); } - private ListWrapper<stmtType> body; - public ListWrapper<stmtType> getInternalBody() { + private java.util.List<stmtType> body; + public java.util.List<stmtType> getInternalBody() { return body; } public Object getBody() { - return body; + return new ListWrapper(body); } public void setBody(Object body) { - this.body = new ListWrapper<stmtType>( - (java.util.List<stmtType>)body); + this.body = AstAdapter.to_stmtList(body); } - private ListWrapper<exprType> decorators; - public ListWrapper<exprType> getInternalDecorators() { + private java.util.List<exprType> decorators; + public java.util.List<exprType> getInternalDecorators() { return decorators; } public Object getDecorators() { - return decorators; + return new ListWrapper(decorators); } public void setDecorators(Object decorators) { - this.decorators = new ListWrapper<exprType>( - (java.util.List<exprType>)decorators); + this.decorators = AstAdapter.to_exprList(decorators); } @@ -73,24 +71,27 @@ java.util.List<stmtType> body, java.util.List<exprType> decorators) { super(token); this.name = name; - this.bases = new ListWrapper<exprType>(bases); - if (bases != null) { - for(PythonTree t : bases) { - addChild(t); - } + this.bases = bases; + if (bases == null) { + this.bases = new ArrayList<exprType>(); } - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + for(PythonTree t : this.bases) { + addChild(t); } - this.decorators = new ListWrapper<exprType>(decorators); - if (decorators != null) { - for(PythonTree t : decorators) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } + for(PythonTree t : this.body) { + addChild(t); + } + this.decorators = decorators; + if (decorators == null) { + this.decorators = new ArrayList<exprType>(); + } + for(PythonTree t : this.decorators) { + addChild(t); + } } public ClassDef(Integer ttype, Token token, String name, @@ -98,48 +99,54 @@ java.util.List<exprType> decorators) { super(ttype, token); this.name = name; - this.bases = new ListWrapper<exprType>(bases); - if (bases != null) { - for(PythonTree t : bases) { - addChild(t); - } + this.bases = bases; + if (bases == null) { + this.bases = new ArrayList<exprType>(); } - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + for(PythonTree t : this.bases) { + addChild(t); } - this.decorators = new ListWrapper<exprType>(decorators); - if (decorators != null) { - for(PythonTree t : decorators) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } + for(PythonTree t : this.body) { + addChild(t); + } + this.decorators = decorators; + if (decorators == null) { + this.decorators = new ArrayList<exprType>(); + } + for(PythonTree t : this.decorators) { + addChild(t); + } } public ClassDef(PythonTree tree, String name, java.util.List<exprType> bases, java.util.List<stmtType> body, java.util.List<exprType> decorators) { super(tree); this.name = name; - this.bases = new ListWrapper<exprType>(bases); - if (bases != null) { - for(PythonTree t : bases) { - addChild(t); - } + this.bases = bases; + if (bases == null) { + this.bases = new ArrayList<exprType>(); } - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + for(PythonTree t : this.bases) { + addChild(t); } - this.decorators = new ListWrapper<exprType>(decorators); - if (decorators != null) { - for(PythonTree t : decorators) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } + for(PythonTree t : this.body) { + addChild(t); + } + this.decorators = decorators; + if (decorators == null) { + this.decorators = new ArrayList<exprType>(); + } + for(PythonTree t : this.decorators) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -20,28 +21,26 @@ this.left = AstAdapter.to_expr(left); } - private ListWrapper<cmpopType> ops; - public ListWrapper<cmpopType> getInternalOps() { + private java.util.List<cmpopType> ops; + public java.util.List<cmpopType> getInternalOps() { return ops; } public Object getOps() { - return ops; + return new ListWrapper(ops); } public void setOps(Object ops) { - this.ops = new ListWrapper<cmpopType>( - (java.util.List<cmpopType>)ops); + this.ops = AstAdapter.to_cmpopList(ops); } - private ListWrapper<exprType> comparators; - public ListWrapper<exprType> getInternalComparators() { + private java.util.List<exprType> comparators; + public java.util.List<exprType> getInternalComparators() { return comparators; } public Object getComparators() { - return comparators; + return new ListWrapper(comparators); } public void setComparators(Object comparators) { - this.comparators = new ListWrapper<exprType>( - (java.util.List<exprType>)comparators); + this.comparators = AstAdapter.to_exprList(comparators); } @@ -61,13 +60,14 @@ super(token); this.left = left; addChild(left); - this.ops = new ListWrapper<cmpopType>(ops); - this.comparators = new ListWrapper<exprType>(comparators); - if (comparators != null) { - for(PythonTree t : comparators) { - addChild(t); - } + this.ops = ops; + this.comparators = comparators; + if (comparators == null) { + this.comparators = new ArrayList<exprType>(); } + for(PythonTree t : this.comparators) { + addChild(t); + } } public Compare(Integer ttype, Token token, exprType left, @@ -75,13 +75,14 @@ super(ttype, token); this.left = left; addChild(left); - this.ops = new ListWrapper<cmpopType>(ops); - this.comparators = new ListWrapper<exprType>(comparators); - if (comparators != null) { - for(PythonTree t : comparators) { - addChild(t); - } + this.ops = ops; + this.comparators = comparators; + if (comparators == null) { + this.comparators = new ArrayList<exprType>(); } + for(PythonTree t : this.comparators) { + addChild(t); + } } public Compare(PythonTree tree, exprType left, java.util.List<cmpopType> @@ -89,13 +90,14 @@ super(tree); this.left = left; addChild(left); - this.ops = new ListWrapper<cmpopType>(ops); - this.comparators = new ListWrapper<exprType>(comparators); - if (comparators != null) { - for(PythonTree t : comparators) { - addChild(t); - } + this.ops = ops; + this.comparators = comparators; + if (comparators == null) { + this.comparators = new ArrayList<exprType>(); } + for(PythonTree t : this.comparators) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/Continue.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Continue.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Continue.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -9,16 +10,15 @@ import java.io.IOException; public class Delete extends stmtType { - private ListWrapper<exprType> targets; - public ListWrapper<exprType> getInternalTargets() { + private java.util.List<exprType> targets; + public java.util.List<exprType> getInternalTargets() { return targets; } public Object getTargets() { - return targets; + return new ListWrapper(targets); } public void setTargets(Object targets) { - this.targets = new ListWrapper<exprType>( - (java.util.List<exprType>)targets); + this.targets = AstAdapter.to_exprList(targets); } @@ -32,33 +32,36 @@ public Delete(Token token, java.util.List<exprType> targets) { super(token); - this.targets = new ListWrapper<exprType>(targets); - if (targets != null) { - for(PythonTree t : targets) { - addChild(t); - } + this.targets = targets; + if (targets == null) { + this.targets = new ArrayList<exprType>(); } + for(PythonTree t : this.targets) { + addChild(t); + } } public Delete(Integer ttype, Token token, java.util.List<exprType> targets) { super(ttype, token); - this.targets = new ListWrapper<exprType>(targets); - if (targets != null) { - for(PythonTree t : targets) { - addChild(t); - } + this.targets = targets; + if (targets == null) { + this.targets = new ArrayList<exprType>(); } + for(PythonTree t : this.targets) { + addChild(t); + } } public Delete(PythonTree tree, java.util.List<exprType> targets) { super(tree); - this.targets = new ListWrapper<exprType>(targets); - if (targets != null) { - for(PythonTree t : targets) { - addChild(t); - } + this.targets = targets; + if (targets == null) { + this.targets = new ArrayList<exprType>(); } + for(PythonTree t : this.targets) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -9,28 +10,26 @@ import java.io.IOException; public class Dict extends exprType { - private ListWrapper<exprType> keys; - public ListWrapper<exprType> getInternalKeys() { + private java.util.List<exprType> keys; + public java.util.List<exprType> getInternalKeys() { return keys; } public Object getKeys() { - return keys; + return new ListWrapper(keys); } public void setKeys(Object keys) { - this.keys = new ListWrapper<exprType>( - (java.util.List<exprType>)keys); + this.keys = AstAdapter.to_exprList(keys); } - private ListWrapper<exprType> values; - public ListWrapper<exprType> getInternalValues() { + private java.util.List<exprType> values; + public java.util.List<exprType> getInternalValues() { return values; } public Object getValues() { - return values; + return new ListWrapper(values); } public void setValues(Object values) { - this.values = new ListWrapper<exprType>( - (java.util.List<exprType>)values); + this.values = AstAdapter.to_exprList(values); } @@ -46,52 +45,58 @@ public Dict(Token token, java.util.List<exprType> keys, java.util.List<exprType> values) { super(token); - this.keys = new ListWrapper<exprType>(keys); - if (keys != null) { - for(PythonTree t : keys) { - addChild(t); - } + this.keys = keys; + if (keys == null) { + this.keys = new ArrayList<exprType>(); } - this.values = new ListWrapper<exprType>(values); - if (values != null) { - for(PythonTree t : values) { - addChild(t); - } + for(PythonTree t : this.keys) { + addChild(t); } + this.values = values; + if (values == null) { + this.values = new ArrayList<exprType>(); + } + for(PythonTree t : this.values) { + addChild(t); + } } public Dict(Integer ttype, Token token, java.util.List<exprType> keys, java.util.List<exprType> values) { super(ttype, token); - this.keys = new ListWrapper<exprType>(keys); - if (keys != null) { - for(PythonTree t : keys) { - addChild(t); - } + this.keys = keys; + if (keys == null) { + this.keys = new ArrayList<exprType>(); } - this.values = new ListWrapper<exprType>(values); - if (values != null) { - for(PythonTree t : values) { - addChild(t); - } + for(PythonTree t : this.keys) { + addChild(t); } + this.values = values; + if (values == null) { + this.values = new ArrayList<exprType>(); + } + for(PythonTree t : this.values) { + addChild(t); + } } public Dict(PythonTree tree, java.util.List<exprType> keys, java.util.List<exprType> values) { super(tree); - this.keys = new ListWrapper<exprType>(keys); - if (keys != null) { - for(PythonTree t : keys) { - addChild(t); - } + this.keys = keys; + if (keys == null) { + this.keys = new ArrayList<exprType>(); } - this.values = new ListWrapper<exprType>(values); - if (values != null) { - for(PythonTree t : values) { - addChild(t); - } + for(PythonTree t : this.keys) { + addChild(t); } + this.values = values; + if (values == null) { + this.values = new ArrayList<exprType>(); + } + for(PythonTree t : this.values) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Ellipsis.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Ellipsis.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Exec.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Exec.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Expr.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Expr.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Expression.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Expression.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; Modified: branches/astwrite/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -9,16 +10,15 @@ import java.io.IOException; public class ExtSlice extends sliceType { - private ListWrapper<sliceType> dims; - public ListWrapper<sliceType> getInternalDims() { + private java.util.List<sliceType> dims; + public java.util.List<sliceType> getInternalDims() { return dims; } public Object getDims() { - return dims; + return new ListWrapper(dims); } public void setDims(Object dims) { - this.dims = new ListWrapper<sliceType>( - (java.util.List<sliceType>)dims); + this.dims = AstAdapter.to_sliceList(dims); } @@ -32,33 +32,36 @@ public ExtSlice(Token token, java.util.List<sliceType> dims) { super(token); - this.dims = new ListWrapper<sliceType>(dims); - if (dims != null) { - for(PythonTree t : dims) { - addChild(t); - } + this.dims = dims; + if (dims == null) { + this.dims = new ArrayList<sliceType>(); } + for(PythonTree t : this.dims) { + addChild(t); + } } public ExtSlice(Integer ttype, Token token, java.util.List<sliceType> dims) { super(ttype, token); - this.dims = new ListWrapper<sliceType>(dims); - if (dims != null) { - for(PythonTree t : dims) { - addChild(t); - } + this.dims = dims; + if (dims == null) { + this.dims = new ArrayList<sliceType>(); } + for(PythonTree t : this.dims) { + addChild(t); + } } public ExtSlice(PythonTree tree, java.util.List<sliceType> dims) { super(tree); - this.dims = new ListWrapper<sliceType>(dims); - if (dims != null) { - for(PythonTree t : dims) { - addChild(t); - } + this.dims = dims; + if (dims == null) { + this.dims = new ArrayList<sliceType>(); } + for(PythonTree t : this.dims) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/For.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -31,28 +32,26 @@ this.iter = AstAdapter.to_expr(iter); } - private ListWrapper<stmtType> body; - public ListWrapper<stmtType> getInternalBody() { + private java.util.List<stmtType> body; + public java.util.List<stmtType> getInternalBody() { return body; } public Object getBody() { - return body; + return new ListWrapper(body); } public void setBody(Object body) { - this.body = new ListWrapper<stmtType>( - (java.util.List<stmtType>)body); + this.body = AstAdapter.to_stmtList(body); } - private ListWrapper<stmtType> orelse; - public ListWrapper<stmtType> getInternalOrelse() { + private java.util.List<stmtType> orelse; + public java.util.List<stmtType> getInternalOrelse() { return orelse; } public Object getOrelse() { - return orelse; + return new ListWrapper(orelse); } public void setOrelse(Object orelse) { - this.orelse = new ListWrapper<stmtType>( - (java.util.List<stmtType>)orelse); + this.orelse = AstAdapter.to_stmtList(orelse); } @@ -75,18 +74,20 @@ addChild(target); this.iter = iter; addChild(iter); - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } - this.orelse = new ListWrapper<stmtType>(orelse); - if (orelse != null) { - for(PythonTree t : orelse) { - addChild(t); - } + for(PythonTree t : this.body) { + addChild(t); } + this.orelse = orelse; + if (orelse == null) { + this.orelse = new ArrayList<stmtType>(); + } + for(PythonTree t : this.orelse) { + addChild(t); + } } public For(Integer ttype, Token token, exprType target, exprType iter, @@ -96,18 +97,20 @@ addChild(target); this.iter = iter; addChild(iter); - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } - this.orelse = new ListWrapper<stmtType>(orelse); - if (orelse != null) { - for(PythonTree t : orelse) { - addChild(t); - } + for(PythonTree t : this.body) { + addChild(t); } + this.orelse = orelse; + if (orelse == null) { + this.orelse = new ArrayList<stmtType>(); + } + for(PythonTree t : this.orelse) { + addChild(t); + } } public For(PythonTree tree, exprType target, exprType iter, @@ -117,18 +120,20 @@ addChild(target); this.iter = iter; addChild(iter); - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } - this.orelse = new ListWrapper<stmtType>(orelse); - if (orelse != null) { - for(PythonTree t : orelse) { - addChild(t); - } + for(PythonTree t : this.body) { + addChild(t); } + this.orelse = orelse; + if (orelse == null) { + this.orelse = new ArrayList<stmtType>(); + } + for(PythonTree t : this.orelse) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -31,28 +32,26 @@ this.args = AstAdapter.to_arguments(args); } - private ListWrapper<stmtType> body; - public ListWrapper<stmtType> getInternalBody() { + private java.util.List<stmtType> body; + public java.util.List<stmtType> getInternalBody() { return body; } public Object getBody() { - return body; + return new ListWrapper(body); } public void setBody(Object body) { - this.body = new ListWrapper<stmtType>( - (java.util.List<stmtType>)body); + this.body = AstAdapter.to_stmtList(body); } - private ListWrapper<exprType> decorators; - public ListWrapper<exprType> getInternalDecorators() { + private java.util.List<exprType> decorators; + public java.util.List<exprType> getInternalDecorators() { return decorators; } public Object getDecorators() { - return decorators; + return new ListWrapper(decorators); } public void setDecorators(Object decorators) { - this.decorators = new ListWrapper<exprType>( - (java.util.List<exprType>)decorators); + this.decorators = AstAdapter.to_exprList(decorators); } @@ -74,18 +73,20 @@ super(token); this.name = name; this.args = args; - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } - this.decorators = new ListWrapper<exprType>(decorators); - if (decorators != null) { - for(PythonTree t : decorators) { - addChild(t); - } + for(PythonTree t : this.body) { + addChild(t); } + this.decorators = decorators; + if (decorators == null) { + this.decorators = new ArrayList<exprType>(); + } + for(PythonTree t : this.decorators) { + addChild(t); + } } public FunctionDef(Integer ttype, Token token, String name, argumentsType @@ -93,18 +94,20 @@ super(ttype, token); this.name = name; this.args = args; - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } - this.decorators = new ListWrapper<exprType>(decorators); - if (decorators != null) { - for(PythonTree t : decorators) { - addChild(t); - } + for(PythonTree t : this.body) { + addChild(t); } + this.decorators = decorators; + if (decorators == null) { + this.decorators = new ArrayList<exprType>(); + } + for(PythonTree t : this.decorators) { + addChild(t); + } } public FunctionDef(PythonTree tree, String name, argumentsType args, @@ -112,18 +115,20 @@ super(tree); this.name = name; this.args = args; - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); } - this.decorators = new ListWrapper<exprType>(decorators); - if (decorators != null) { - for(PythonTree t : decorators) { - addChild(t); - } + for(PythonTree t : this.body) { + addChild(t); } + this.decorators = decorators; + if (decorators == null) { + this.decorators = new ArrayList<exprType>(); + } + for(PythonTree t : this.decorators) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -20,16 +21,15 @@ this.elt = AstAdapter.to_expr(elt); } - private ListWrapper<comprehensionType> generators; - public ListWrapper<comprehensionType> getInternalGenerators() { + private java.util.List<comprehensionType> generators; + public java.util.List<comprehensionType> getInternalGenerators() { return generators; } public Object getGenerators() { - return generators; + return new ListWrapper(generators); } public void setGenerators(Object generators) { - this.generators = new ListWrapper<comprehensionType>( - (java.util.List<comprehensionType>)generators); + this.generators = AstAdapter.to_comprehensionList(generators); } @@ -47,12 +47,13 @@ super(token); this.elt = elt; addChild(elt); - this.generators = new ListWrapper<comprehensionType>(generators); - if (generators != null) { - for(PythonTree t : generators) { - addChild(t); - } + this.generators = generators; + if (generators == null) { + this.generators = new ArrayList<comprehensionType>(); } + for(PythonTree t : this.generators) { + addChild(t); + } } public GeneratorExp(Integer ttype, Token token, exprType elt, @@ -60,12 +61,13 @@ super(ttype, token); this.elt = elt; addChild(elt); - this.generators = new ListWrapper<comprehensionType>(generators); - if (generators != null) { - for(PythonTree t : generators) { - addChild(t); - } + this.generators = generators; + if (generators == null) { + this.generators = new ArrayList<comprehensionType>(); } + for(PythonTree t : this.generators) { + addChild(t); + } } public GeneratorExp(PythonTree tree, exprType elt, @@ -73,12 +75,13 @@ super(tree); this.elt = elt; addChild(elt); - this.generators = new ListWrapper<comprehensionType>(generators); - if (generators != null) { - for(PythonTree t : generators) { - addChild(t); - } + this.generators = generators; + if (generators == null) { + this.generators = new ArrayList<comprehensionType>(); } + for(PythonTree t : this.generators) { + addChild(t); + } } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/Global.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -9,16 +10,15 @@ import java.io.IOException; public class Global extends stmtType { - private ListWrapper<String> names; - public ListWrapper<String> getInternalNames() { + private java.util.List<String> names; + public java.util.List<String> getInternalNames() { return names; } public Object getNames() { - return names; + return new ListWrapper(names); } public void setNames(Object names) { - this.names = new ListWrapper<String>( - (java.util.List<String>)names); + this.names = AstAdapter.to_identifierList(names); } @@ -32,17 +32,17 @@ public Global(Token token, java.util.List<String> names) { super(token); - this.names = new ListWrapper<String>(names); + this.names = names; } public Global(Integer ttype, Token token, java.util.List<String> names) { super(ttype, token); - this.names = new ListWrapper<String>(names); + this.names = names; } public Global(PythonTree tree, java.util.List<String> names) { super(tree); - this.names = new ListWrapper<String>(names); + this.names = names; } public String toString() { Modified: branches/astwrite/src/org/python/antlr/ast/If.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-24 05:52:36 UTC (rev 5632) +++ branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-24 19:41:50 UTC (rev 5633) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import java.util.ArrayList; import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; @@ -20,28 +21,26 @@ this.test = AstAdapter.to_expr(test); } - private ListWrapper<stmtType> body; - public ListWrapper<stmtType> getInternalBody() { + private java.util.List<stmtType> body; + public java.util.List<stmtType> getInternalBody() { return body; } public Object getBody() { - return body; + return new ListWrapper(body); } public void setBo... [truncated message content] |
From: <cg...@us...> - 2008-11-24 05:52:42
|
Revision: 5632 http://jython.svn.sourceforge.net/jython/?rev=5632&view=rev Author: cgroves Date: 2008-11-24 05:52:36 +0000 (Mon, 24 Nov 2008) Log Message: ----------- Reinstate the code from PyReflectedConstructor that redirectes to the proxy constructor whenever a Python subclass of a Java class attempts to call its Java-superclass constructor. PyJavaType can finally handle it. Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java Modified: branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java 2008-11-24 05:37:21 UTC (rev 5631) +++ branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java 2008-11-24 05:52:36 UTC (rev 5632) @@ -93,6 +93,13 @@ throw Py.TypeError("self invalid - must implement: " + declaringClass.getName()); } + // If the declaring class is a pure Java type but we're instantiating a Python proxy, + // grab the proxy version of the constructor to instantiate the proper type + if (!PyProxy.class.isAssignableFrom(declaringClass) + && !(self.getType() instanceof PyJavaType)) { + return PyType.fromClass(javaClass).lookup("__init__").__call__(self, args, keywords); + } + if (self.javaProxy != null) { Class<?> sup = javaClass; if (PyProxy.class.isAssignableFrom(sup)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-11-24 05:37:25
|
Revision: 5631 http://jython.svn.sourceforge.net/jython/?rev=5631&view=rev Author: cgroves Date: 2008-11-24 05:37:21 +0000 (Mon, 24 Nov 2008) Log Message: ----------- Don't hork when exposing fields on an interface as it won't have a base class Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/PyJavaType.java Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-24 05:02:01 UTC (rev 5630) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-24 05:37:21 UTC (rev 5631) @@ -77,7 +77,7 @@ Field[] fields = underlying_class.getFields(); for (Field field : fields) { Class<?> declaring = field.getDeclaringClass(); - if (declaring != base && base.isAssignableFrom(declaring)) { + if (base == null || (declaring != base && base.isAssignableFrom(declaring))) { String fldname = field.getName(); int fldmods = field.getModifiers(); Class<?> fldtype = field.getType(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-24 05:02:05
|
Revision: 5630 http://jython.svn.sourceforge.net/jython/?rev=5630&view=rev Author: pjenvey Date: 2008-11-24 05:02:01 +0000 (Mon, 24 Nov 2008) Log Message: ----------- fix PyZipFile to compile to $py.class Modified Paths: -------------- trunk/jython/Lib/test/test_zipfile.py trunk/jython/Lib/zipfile.py Modified: trunk/jython/Lib/test/test_zipfile.py =================================================================== --- trunk/jython/Lib/test/test_zipfile.py 2008-11-24 05:01:02 UTC (rev 5629) +++ trunk/jython/Lib/test/test_zipfile.py 2008-11-24 05:02:01 UTC (rev 5630) @@ -9,7 +9,7 @@ from StringIO import StringIO from tempfile import TemporaryFile -from test.test_support import TESTFN, run_unittest +from test.test_support import TESTFN, is_jython, run_unittest TESTFN2 = TESTFN + "2" @@ -245,12 +245,17 @@ fn = __file__ if fn.endswith('.pyc') or fn.endswith('.pyo'): fn = fn[:-1] + elif fn.endswith('$py.class'): + fn = fn[:-9] + '.py' zipfp.writepy(fn) bn = os.path.basename(fn) self.assert_(bn not in zipfp.namelist()) - self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) + if not is_jython: + self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) + else: + self.assert_(bn[:-3] + '$py.class' in zipfp.namelist()) zipfp.close() @@ -258,12 +263,17 @@ fn = __file__ if fn.endswith('.pyc') or fn.endswith('.pyo'): fn = fn[:-1] + elif fn.endswith('$py.class'): + fn = fn[:-9] + '.py' zipfp.writepy(fn, "testpackage") bn = "%s/%s"%("testpackage", os.path.basename(fn)) self.assert_(bn not in zipfp.namelist()) - self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) + if not is_jython: + self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) + else: + self.assert_(bn[:-3] + '$py.class' in zipfp.namelist()) zipfp.close() def testWritePythonPackage(self): @@ -275,8 +285,12 @@ # Check for a couple of modules at different levels of the hieararchy names = zipfp.namelist() - self.assert_('email/__init__.pyo' in names or 'email/__init__.pyc' in names) - self.assert_('email/mime/text.pyo' in names or 'email/mime/text.pyc' in names) + if not is_jython: + self.assert_('email/__init__.pyo' in names or 'email/__init__.pyc' in names) + self.assert_('email/mime/text.pyo' in names or 'email/mime/text.pyc' in names) + else: + self.assert_('email/__init__$py.class' in names) + self.assert_('email/mime/text$py.class' in names) def testWritePythonDirectory(self): os.mkdir(TESTFN2) @@ -297,8 +311,12 @@ zipfp.writepy(TESTFN2) names = zipfp.namelist() - self.assert_('mod1.pyc' in names or 'mod1.pyo' in names) - self.assert_('mod2.pyc' in names or 'mod2.pyo' in names) + if not is_jython: + self.assert_('mod1.pyc' in names or 'mod1.pyo' in names) + self.assert_('mod2.pyc' in names or 'mod2.pyo' in names) + else: + self.assert_('mod1$py.class' in names) + self.assert_('mod2$py.class' in names) self.assert_('mod2.txt' not in names) finally: Modified: trunk/jython/Lib/zipfile.py =================================================================== --- trunk/jython/Lib/zipfile.py 2008-11-24 05:01:02 UTC (rev 5629) +++ trunk/jython/Lib/zipfile.py 2008-11-24 05:02:01 UTC (rev 5630) @@ -12,6 +12,8 @@ __all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] +is_jython = sys.platform.startswith('java') + class BadZipfile(Exception): pass @@ -800,7 +802,7 @@ /python/lib/string, return (/python/lib/string.pyc, string). """ file_py = pathname + ".py" - file_pyc = pathname + ".pyc" + file_pyc = pathname + (".pyc" if not is_jython else "$py.class") file_pyo = pathname + ".pyo" if os.path.isfile(file_pyo) and \ os.stat(file_pyo).st_mtime >= os.stat(file_py).st_mtime: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-24 05:01:07
|
Revision: 5629 http://jython.svn.sourceforge.net/jython/?rev=5629&view=rev Author: pjenvey Date: 2008-11-24 05:01:02 +0000 (Mon, 24 Nov 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/zipfile.py@60117 http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_zipfile.py@46982 Added Paths: ----------- trunk/jython/Lib/test/test_zipfile.py trunk/jython/Lib/zipfile.py Added: trunk/jython/Lib/test/test_zipfile.py =================================================================== --- trunk/jython/Lib/test/test_zipfile.py (rev 0) +++ trunk/jython/Lib/test/test_zipfile.py 2008-11-24 05:01:02 UTC (rev 5629) @@ -0,0 +1,357 @@ +# We can test part of the module without zlib. +try: + import zlib +except ImportError: + zlib = None + +import zipfile, os, unittest, sys, shutil + +from StringIO import StringIO +from tempfile import TemporaryFile + +from test.test_support import TESTFN, run_unittest + +TESTFN2 = TESTFN + "2" + +class TestsWithSourceFile(unittest.TestCase): + def setUp(self): + line_gen = ("Test of zipfile line %d." % i for i in range(0, 1000)) + self.data = '\n'.join(line_gen) + + # Make a source file with some lines + fp = open(TESTFN, "wb") + fp.write(self.data) + fp.close() + + def zipTest(self, f, compression): + # Create the ZIP archive + zipfp = zipfile.ZipFile(f, "w", compression) + zipfp.write(TESTFN, "another"+os.extsep+"name") + zipfp.write(TESTFN, TESTFN) + zipfp.writestr("strfile", self.data) + zipfp.close() + + # Read the ZIP archive + zipfp = zipfile.ZipFile(f, "r", compression) + self.assertEqual(zipfp.read(TESTFN), self.data) + self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data) + self.assertEqual(zipfp.read("strfile"), self.data) + + # Print the ZIP directory + fp = StringIO() + stdout = sys.stdout + try: + sys.stdout = fp + + zipfp.printdir() + finally: + sys.stdout = stdout + + directory = fp.getvalue() + lines = directory.splitlines() + self.assertEquals(len(lines), 4) # Number of files + header + + self.assert_('File Name' in lines[0]) + self.assert_('Modified' in lines[0]) + self.assert_('Size' in lines[0]) + + fn, date, time, size = lines[1].split() + self.assertEquals(fn, 'another.name') + # XXX: timestamp is not tested + self.assertEquals(size, str(len(self.data))) + + # Check the namelist + names = zipfp.namelist() + self.assertEquals(len(names), 3) + self.assert_(TESTFN in names) + self.assert_("another"+os.extsep+"name" in names) + self.assert_("strfile" in names) + + # Check infolist + infos = zipfp.infolist() + names = [ i.filename for i in infos ] + self.assertEquals(len(names), 3) + self.assert_(TESTFN in names) + self.assert_("another"+os.extsep+"name" in names) + self.assert_("strfile" in names) + for i in infos: + self.assertEquals(i.file_size, len(self.data)) + + # check getinfo + for nm in (TESTFN, "another"+os.extsep+"name", "strfile"): + info = zipfp.getinfo(nm) + self.assertEquals(info.filename, nm) + self.assertEquals(info.file_size, len(self.data)) + + # Check that testzip doesn't raise an exception + zipfp.testzip() + + + zipfp.close() + + + + + def testStored(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zipTest(f, zipfile.ZIP_STORED) + + if zlib: + def testDeflated(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zipTest(f, zipfile.ZIP_DEFLATED) + + def testAbsoluteArcnames(self): + zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) + zipfp.write(TESTFN, "/absolute") + zipfp.close() + + zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) + self.assertEqual(zipfp.namelist(), ["absolute"]) + zipfp.close() + + + def tearDown(self): + os.remove(TESTFN) + os.remove(TESTFN2) + +class TestZip64InSmallFiles(unittest.TestCase): + # These tests test the ZIP64 functionality without using large files, + # see test_zipfile64 for proper tests. + + def setUp(self): + self._limit = zipfile.ZIP64_LIMIT + zipfile.ZIP64_LIMIT = 5 + + line_gen = ("Test of zipfile line %d." % i for i in range(0, 1000)) + self.data = '\n'.join(line_gen) + + # Make a source file with some lines + fp = open(TESTFN, "wb") + fp.write(self.data) + fp.close() + + def largeFileExceptionTest(self, f, compression): + zipfp = zipfile.ZipFile(f, "w", compression) + self.assertRaises(zipfile.LargeZipFile, + zipfp.write, TESTFN, "another"+os.extsep+"name") + zipfp.close() + + def largeFileExceptionTest2(self, f, compression): + zipfp = zipfile.ZipFile(f, "w", compression) + self.assertRaises(zipfile.LargeZipFile, + zipfp.writestr, "another"+os.extsep+"name", self.data) + zipfp.close() + + def testLargeFileException(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.largeFileExceptionTest(f, zipfile.ZIP_STORED) + self.largeFileExceptionTest2(f, zipfile.ZIP_STORED) + + def zipTest(self, f, compression): + # Create the ZIP archive + zipfp = zipfile.ZipFile(f, "w", compression, allowZip64=True) + zipfp.write(TESTFN, "another"+os.extsep+"name") + zipfp.write(TESTFN, TESTFN) + zipfp.writestr("strfile", self.data) + zipfp.close() + + # Read the ZIP archive + zipfp = zipfile.ZipFile(f, "r", compression) + self.assertEqual(zipfp.read(TESTFN), self.data) + self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data) + self.assertEqual(zipfp.read("strfile"), self.data) + + # Print the ZIP directory + fp = StringIO() + stdout = sys.stdout + try: + sys.stdout = fp + + zipfp.printdir() + finally: + sys.stdout = stdout + + directory = fp.getvalue() + lines = directory.splitlines() + self.assertEquals(len(lines), 4) # Number of files + header + + self.assert_('File Name' in lines[0]) + self.assert_('Modified' in lines[0]) + self.assert_('Size' in lines[0]) + + fn, date, time, size = lines[1].split() + self.assertEquals(fn, 'another.name') + # XXX: timestamp is not tested + self.assertEquals(size, str(len(self.data))) + + # Check the namelist + names = zipfp.namelist() + self.assertEquals(len(names), 3) + self.assert_(TESTFN in names) + self.assert_("another"+os.extsep+"name" in names) + self.assert_("strfile" in names) + + # Check infolist + infos = zipfp.infolist() + names = [ i.filename for i in infos ] + self.assertEquals(len(names), 3) + self.assert_(TESTFN in names) + self.assert_("another"+os.extsep+"name" in names) + self.assert_("strfile" in names) + for i in infos: + self.assertEquals(i.file_size, len(self.data)) + + # check getinfo + for nm in (TESTFN, "another"+os.extsep+"name", "strfile"): + info = zipfp.getinfo(nm) + self.assertEquals(info.filename, nm) + self.assertEquals(info.file_size, len(self.data)) + + # Check that testzip doesn't raise an exception + zipfp.testzip() + + + zipfp.close() + + def testStored(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zipTest(f, zipfile.ZIP_STORED) + + + if zlib: + def testDeflated(self): + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zipTest(f, zipfile.ZIP_DEFLATED) + + def testAbsoluteArcnames(self): + zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED, allowZip64=True) + zipfp.write(TESTFN, "/absolute") + zipfp.close() + + zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) + self.assertEqual(zipfp.namelist(), ["absolute"]) + zipfp.close() + + + def tearDown(self): + zipfile.ZIP64_LIMIT = self._limit + os.remove(TESTFN) + os.remove(TESTFN2) + +class PyZipFileTests(unittest.TestCase): + def testWritePyfile(self): + zipfp = zipfile.PyZipFile(TemporaryFile(), "w") + fn = __file__ + if fn.endswith('.pyc') or fn.endswith('.pyo'): + fn = fn[:-1] + + zipfp.writepy(fn) + + bn = os.path.basename(fn) + self.assert_(bn not in zipfp.namelist()) + self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) + zipfp.close() + + + zipfp = zipfile.PyZipFile(TemporaryFile(), "w") + fn = __file__ + if fn.endswith('.pyc') or fn.endswith('.pyo'): + fn = fn[:-1] + + zipfp.writepy(fn, "testpackage") + + bn = "%s/%s"%("testpackage", os.path.basename(fn)) + self.assert_(bn not in zipfp.namelist()) + self.assert_(bn + 'o' in zipfp.namelist() or bn + 'c' in zipfp.namelist()) + zipfp.close() + + def testWritePythonPackage(self): + import email + packagedir = os.path.dirname(email.__file__) + + zipfp = zipfile.PyZipFile(TemporaryFile(), "w") + zipfp.writepy(packagedir) + + # Check for a couple of modules at different levels of the hieararchy + names = zipfp.namelist() + self.assert_('email/__init__.pyo' in names or 'email/__init__.pyc' in names) + self.assert_('email/mime/text.pyo' in names or 'email/mime/text.pyc' in names) + + def testWritePythonDirectory(self): + os.mkdir(TESTFN2) + try: + fp = open(os.path.join(TESTFN2, "mod1.py"), "w") + fp.write("print 42\n") + fp.close() + + fp = open(os.path.join(TESTFN2, "mod2.py"), "w") + fp.write("print 42 * 42\n") + fp.close() + + fp = open(os.path.join(TESTFN2, "mod2.txt"), "w") + fp.write("bla bla bla\n") + fp.close() + + zipfp = zipfile.PyZipFile(TemporaryFile(), "w") + zipfp.writepy(TESTFN2) + + names = zipfp.namelist() + self.assert_('mod1.pyc' in names or 'mod1.pyo' in names) + self.assert_('mod2.pyc' in names or 'mod2.pyo' in names) + self.assert_('mod2.txt' not in names) + + finally: + shutil.rmtree(TESTFN2) + + + +class OtherTests(unittest.TestCase): + def testCloseErroneousFile(self): + # This test checks that the ZipFile constructor closes the file object + # it opens if there's an error in the file. If it doesn't, the traceback + # holds a reference to the ZipFile object and, indirectly, the file object. + # On Windows, this causes the os.unlink() call to fail because the + # underlying file is still open. This is SF bug #412214. + # + fp = open(TESTFN, "w") + fp.write("this is not a legal zip file\n") + fp.close() + try: + zf = zipfile.ZipFile(TESTFN) + except zipfile.BadZipfile: + os.unlink(TESTFN) + + def testNonExistentFileRaisesIOError(self): + # make sure we don't raise an AttributeError when a partially-constructed + # ZipFile instance is finalized; this tests for regression on SF tracker + # bug #403871. + + # The bug we're testing for caused an AttributeError to be raised + # when a ZipFile instance was created for a file that did not + # exist; the .fp member was not initialized but was needed by the + # __del__() method. Since the AttributeError is in the __del__(), + # it is ignored, but the user should be sufficiently annoyed by + # the message on the output that regression will be noticed + # quickly. + self.assertRaises(IOError, zipfile.ZipFile, TESTFN) + + def testClosedZipRaisesRuntimeError(self): + # Verify that testzip() doesn't swallow inappropriate exceptions. + data = StringIO() + zipf = zipfile.ZipFile(data, mode="w") + zipf.writestr("foo.txt", "O, for a Muse of Fire!") + zipf.close() + + # This is correct; calling .read on a closed ZipFile should throw + # a RuntimeError, and so should calling .testzip. An earlier + # version of .testzip would swallow this exception (and any other) + # and report that the first file in the archive was corrupt. + self.assertRaises(RuntimeError, zipf.testzip) + +def test_main(): + run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests, PyZipFileTests) + #run_unittest(TestZip64InSmallFiles) + +if __name__ == "__main__": + test_main() Added: trunk/jython/Lib/zipfile.py =================================================================== --- trunk/jython/Lib/zipfile.py (rev 0) +++ trunk/jython/Lib/zipfile.py 2008-11-24 05:01:02 UTC (rev 5629) @@ -0,0 +1,900 @@ +""" +Read and write ZIP files. +""" +import struct, os, time, sys +import binascii, cStringIO + +try: + import zlib # We may need its compression method +except ImportError: + zlib = None + +__all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", + "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] + +class BadZipfile(Exception): + pass + + +class LargeZipFile(Exception): + """ + Raised when writing a zipfile, the zipfile requires ZIP64 extensions + and those extensions are disabled. + """ + +error = BadZipfile # The exception raised by this module + +ZIP64_LIMIT= (1 << 31) - 1 + +# constants for Zip file compression methods +ZIP_STORED = 0 +ZIP_DEFLATED = 8 +# Other ZIP compression methods not supported + +# Here are some struct module formats for reading headers +structEndArchive = "<4s4H2LH" # 9 items, end of archive, 22 bytes +stringEndArchive = "PK\005\006" # magic number for end of archive record +structCentralDir = "<4s4B4HlLL5HLL"# 19 items, central directory, 46 bytes +stringCentralDir = "PK\001\002" # magic number for central directory +structFileHeader = "<4s2B4HlLL2H" # 12 items, file header record, 30 bytes +stringFileHeader = "PK\003\004" # magic number for file header +structEndArchive64Locator = "<4slql" # 4 items, locate Zip64 header, 20 bytes +stringEndArchive64Locator = "PK\x06\x07" # magic token for locator header +structEndArchive64 = "<4sqhhllqqqq" # 10 items, end of archive (Zip64), 56 bytes +stringEndArchive64 = "PK\x06\x06" # magic token for Zip64 header + + +# indexes of entries in the central directory structure +_CD_SIGNATURE = 0 +_CD_CREATE_VERSION = 1 +_CD_CREATE_SYSTEM = 2 +_CD_EXTRACT_VERSION = 3 +_CD_EXTRACT_SYSTEM = 4 # is this meaningful? +_CD_FLAG_BITS = 5 +_CD_COMPRESS_TYPE = 6 +_CD_TIME = 7 +_CD_DATE = 8 +_CD_CRC = 9 +_CD_COMPRESSED_SIZE = 10 +_CD_UNCOMPRESSED_SIZE = 11 +_CD_FILENAME_LENGTH = 12 +_CD_EXTRA_FIELD_LENGTH = 13 +_CD_COMMENT_LENGTH = 14 +_CD_DISK_NUMBER_START = 15 +_CD_INTERNAL_FILE_ATTRIBUTES = 16 +_CD_EXTERNAL_FILE_ATTRIBUTES = 17 +_CD_LOCAL_HEADER_OFFSET = 18 + +# indexes of entries in the local file header structure +_FH_SIGNATURE = 0 +_FH_EXTRACT_VERSION = 1 +_FH_EXTRACT_SYSTEM = 2 # is this meaningful? +_FH_GENERAL_PURPOSE_FLAG_BITS = 3 +_FH_COMPRESSION_METHOD = 4 +_FH_LAST_MOD_TIME = 5 +_FH_LAST_MOD_DATE = 6 +_FH_CRC = 7 +_FH_COMPRESSED_SIZE = 8 +_FH_UNCOMPRESSED_SIZE = 9 +_FH_FILENAME_LENGTH = 10 +_FH_EXTRA_FIELD_LENGTH = 11 + +def is_zipfile(filename): + """Quickly see if file is a ZIP file by checking the magic number.""" + try: + fpin = open(filename, "rb") + endrec = _EndRecData(fpin) + fpin.close() + if endrec: + return True # file has correct magic number + except IOError: + pass + return False + +def _EndRecData64(fpin, offset, endrec): + """ + Read the ZIP64 end-of-archive records and use that to update endrec + """ + locatorSize = struct.calcsize(structEndArchive64Locator) + fpin.seek(offset - locatorSize, 2) + data = fpin.read(locatorSize) + sig, diskno, reloff, disks = struct.unpack(structEndArchive64Locator, data) + if sig != stringEndArchive64Locator: + return endrec + + if diskno != 0 or disks != 1: + raise BadZipfile("zipfiles that span multiple disks are not supported") + + # Assume no 'zip64 extensible data' + endArchiveSize = struct.calcsize(structEndArchive64) + fpin.seek(offset - locatorSize - endArchiveSize, 2) + data = fpin.read(endArchiveSize) + sig, sz, create_version, read_version, disk_num, disk_dir, \ + dircount, dircount2, dirsize, diroffset = \ + struct.unpack(structEndArchive64, data) + if sig != stringEndArchive64: + return endrec + + # Update the original endrec using data from the ZIP64 record + endrec[1] = disk_num + endrec[2] = disk_dir + endrec[3] = dircount + endrec[4] = dircount2 + endrec[5] = dirsize + endrec[6] = diroffset + return endrec + + +def _EndRecData(fpin): + """Return data from the "End of Central Directory" record, or None. + + The data is a list of the nine items in the ZIP "End of central dir" + record followed by a tenth item, the file seek offset of this record.""" + fpin.seek(-22, 2) # Assume no archive comment. + filesize = fpin.tell() + 22 # Get file size + data = fpin.read() + if data[0:4] == stringEndArchive and data[-2:] == "\000\000": + endrec = struct.unpack(structEndArchive, data) + endrec = list(endrec) + endrec.append("") # Append the archive comment + endrec.append(filesize - 22) # Append the record start offset + if endrec[-4] == -1 or endrec[-4] == 0xffffffff: + return _EndRecData64(fpin, -22, endrec) + return endrec + # Search the last END_BLOCK bytes of the file for the record signature. + # The comment is appended to the ZIP file and has a 16 bit length. + # So the comment may be up to 64K long. We limit the search for the + # signature to a few Kbytes at the end of the file for efficiency. + # also, the signature must not appear in the comment. + END_BLOCK = min(filesize, 1024 * 4) + fpin.seek(filesize - END_BLOCK, 0) + data = fpin.read() + start = data.rfind(stringEndArchive) + if start >= 0: # Correct signature string was found + endrec = struct.unpack(structEndArchive, data[start:start+22]) + endrec = list(endrec) + comment = data[start+22:] + if endrec[7] == len(comment): # Comment length checks out + # Append the archive comment and start offset + endrec.append(comment) + endrec.append(filesize - END_BLOCK + start) + if endrec[-4] == -1 or endrec[-4] == 0xffffffff: + return _EndRecData64(fpin, - END_BLOCK + start, endrec) + return endrec + return # Error, return None + + +class ZipInfo (object): + """Class with attributes describing each file in the ZIP archive.""" + + __slots__ = ( + 'orig_filename', + 'filename', + 'date_time', + 'compress_type', + 'comment', + 'extra', + 'create_system', + 'create_version', + 'extract_version', + 'reserved', + 'flag_bits', + 'volume', + 'internal_attr', + 'external_attr', + 'header_offset', + 'CRC', + 'compress_size', + 'file_size', + ) + + def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)): + self.orig_filename = filename # Original file name in archive + + # Terminate the file name at the first null byte. Null bytes in file + # names are used as tricks by viruses in archives. + null_byte = filename.find(chr(0)) + if null_byte >= 0: + filename = filename[0:null_byte] + # This is used to ensure paths in generated ZIP files always use + # forward slashes as the directory separator, as required by the + # ZIP format specification. + if os.sep != "/" and os.sep in filename: + filename = filename.replace(os.sep, "/") + + self.filename = filename # Normalized file name + self.date_time = date_time # year, month, day, hour, min, sec + # Standard values: + self.compress_type = ZIP_STORED # Type of compression for the file + self.comment = "" # Comment for each file + self.extra = "" # ZIP extra data + if sys.platform == 'win32': + self.create_system = 0 # System which created ZIP archive + else: + # Assume everything else is unix-y + self.create_system = 3 # System which created ZIP archive + self.create_version = 20 # Version which created ZIP archive + self.extract_version = 20 # Version needed to extract archive + self.reserved = 0 # Must be zero + self.flag_bits = 0 # ZIP flag bits + self.volume = 0 # Volume number of file header + self.internal_attr = 0 # Internal attributes + self.external_attr = 0 # External file attributes + # Other attributes are set by class ZipFile: + # header_offset Byte offset to the file header + # CRC CRC-32 of the uncompressed file + # compress_size Size of the compressed file + # file_size Size of the uncompressed file + + def FileHeader(self): + """Return the per-file header as a string.""" + dt = self.date_time + dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2] + dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2) + if self.flag_bits & 0x08: + # Set these to zero because we write them after the file data + CRC = compress_size = file_size = 0 + else: + CRC = self.CRC + compress_size = self.compress_size + file_size = self.file_size + + extra = self.extra + + if file_size > ZIP64_LIMIT or compress_size > ZIP64_LIMIT: + # File is larger than what fits into a 4 byte integer, + # fall back to the ZIP64 extension + fmt = '<hhqq' + extra = extra + struct.pack(fmt, + 1, struct.calcsize(fmt)-4, file_size, compress_size) + file_size = 0xffffffff # -1 + compress_size = 0xffffffff # -1 + self.extract_version = max(45, self.extract_version) + self.create_version = max(45, self.extract_version) + + header = struct.pack(structFileHeader, stringFileHeader, + self.extract_version, self.reserved, self.flag_bits, + self.compress_type, dostime, dosdate, CRC, + compress_size, file_size, + len(self.filename), len(extra)) + return header + self.filename + extra + + def _decodeExtra(self): + # Try to decode the extra field. + extra = self.extra + unpack = struct.unpack + while extra: + tp, ln = unpack('<hh', extra[:4]) + if tp == 1: + if ln >= 24: + counts = unpack('<qqq', extra[4:28]) + elif ln == 16: + counts = unpack('<qq', extra[4:20]) + elif ln == 8: + counts = unpack('<q', extra[4:12]) + elif ln == 0: + counts = () + else: + raise RuntimeError, "Corrupt extra field %s"%(ln,) + + idx = 0 + + # ZIP64 extension (large files and/or large archives) + if self.file_size == -1 or self.file_size == 0xFFFFFFFFL: + self.file_size = counts[idx] + idx += 1 + + if self.compress_size == -1 or self.compress_size == 0xFFFFFFFFL: + self.compress_size = counts[idx] + idx += 1 + + if self.header_offset == -1 or self.header_offset == 0xffffffffL: + old = self.header_offset + self.header_offset = counts[idx] + idx+=1 + + extra = extra[ln+4:] + + +class ZipFile: + """ Class with methods to open, read, write, close, list zip files. + + z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) + + file: Either the path to the file, or a file-like object. + If it is a path, the file will be opened and closed by ZipFile. + mode: The mode can be either read "r", write "w" or append "a". + compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). + allowZip64: if True ZipFile will create files with ZIP64 extensions when + needed, otherwise it will raise an exception when this would + be necessary. + + """ + + fp = None # Set here since __del__ checks it + + def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False): + """Open the ZIP file with mode read "r", write "w" or append "a".""" + self._allowZip64 = allowZip64 + self._didModify = False + if compression == ZIP_STORED: + pass + elif compression == ZIP_DEFLATED: + if not zlib: + raise RuntimeError,\ + "Compression requires the (missing) zlib module" + else: + raise RuntimeError, "That compression method is not supported" + self.debug = 0 # Level of printing: 0 through 3 + self.NameToInfo = {} # Find file info given name + self.filelist = [] # List of ZipInfo instances for archive + self.compression = compression # Method of compression + self.mode = key = mode.replace('b', '')[0] + + # Check if we were passed a file-like object + if isinstance(file, basestring): + self._filePassed = 0 + self.filename = file + modeDict = {'r' : 'rb', 'w': 'wb', 'a' : 'r+b'} + self.fp = open(file, modeDict[mode]) + else: + self._filePassed = 1 + self.fp = file + self.filename = getattr(file, 'name', None) + + if key == 'r': + self._GetContents() + elif key == 'w': + pass + elif key == 'a': + try: # See if file is a zip file + self._RealGetContents() + # seek to start of directory and overwrite + self.fp.seek(self.start_dir, 0) + except BadZipfile: # file is not a zip file, just append + self.fp.seek(0, 2) + else: + if not self._filePassed: + self.fp.close() + self.fp = None + raise RuntimeError, 'Mode must be "r", "w" or "a"' + + def _GetContents(self): + """Read the directory, making sure we close the file if the format + is bad.""" + try: + self._RealGetContents() + except BadZipfile: + if not self._filePassed: + self.fp.close() + self.fp = None + raise + + def _RealGetContents(self): + """Read in the table of contents for the ZIP file.""" + fp = self.fp + endrec = _EndRecData(fp) + if not endrec: + raise BadZipfile, "File is not a zip file" + if self.debug > 1: + print endrec + size_cd = endrec[5] # bytes in central directory + offset_cd = endrec[6] # offset of central directory + self.comment = endrec[8] # archive comment + # endrec[9] is the offset of the "End of Central Dir" record + if endrec[9] > ZIP64_LIMIT: + x = endrec[9] - size_cd - 56 - 20 + else: + x = endrec[9] - size_cd + # "concat" is zero, unless zip was concatenated to another file + concat = x - offset_cd + if self.debug > 2: + print "given, inferred, offset", offset_cd, x, concat + # self.start_dir: Position of start of central directory + self.start_dir = offset_cd + concat + fp.seek(self.start_dir, 0) + data = fp.read(size_cd) + fp = cStringIO.StringIO(data) + total = 0 + while total < size_cd: + centdir = fp.read(46) + total = total + 46 + if centdir[0:4] != stringCentralDir: + raise BadZipfile, "Bad magic number for central directory" + centdir = struct.unpack(structCentralDir, centdir) + if self.debug > 2: + print centdir + filename = fp.read(centdir[_CD_FILENAME_LENGTH]) + # Create ZipInfo instance to store file information + x = ZipInfo(filename) + x.extra = fp.read(centdir[_CD_EXTRA_FIELD_LENGTH]) + x.comment = fp.read(centdir[_CD_COMMENT_LENGTH]) + total = (total + centdir[_CD_FILENAME_LENGTH] + + centdir[_CD_EXTRA_FIELD_LENGTH] + + centdir[_CD_COMMENT_LENGTH]) + x.header_offset = centdir[_CD_LOCAL_HEADER_OFFSET] + (x.create_version, x.create_system, x.extract_version, x.reserved, + x.flag_bits, x.compress_type, t, d, + x.CRC, x.compress_size, x.file_size) = centdir[1:12] + x.volume, x.internal_attr, x.external_attr = centdir[15:18] + # Convert date/time code to (year, month, day, hour, min, sec) + x.date_time = ( (d>>9)+1980, (d>>5)&0xF, d&0x1F, + t>>11, (t>>5)&0x3F, (t&0x1F) * 2 ) + + x._decodeExtra() + x.header_offset = x.header_offset + concat + self.filelist.append(x) + self.NameToInfo[x.filename] = x + if self.debug > 2: + print "total", total + + + def namelist(self): + """Return a list of file names in the archive.""" + l = [] + for data in self.filelist: + l.append(data.filename) + return l + + def infolist(self): + """Return a list of class ZipInfo instances for files in the + archive.""" + return self.filelist + + def printdir(self): + """Print a table of contents for the zip file.""" + print "%-46s %19s %12s" % ("File Name", "Modified ", "Size") + for zinfo in self.filelist: + date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time[:6] + print "%-46s %s %12d" % (zinfo.filename, date, zinfo.file_size) + + def testzip(self): + """Read all the files and check the CRC.""" + for zinfo in self.filelist: + try: + self.read(zinfo.filename) # Check CRC-32 + except BadZipfile: + return zinfo.filename + + + def getinfo(self, name): + """Return the instance of ZipInfo given 'name'.""" + return self.NameToInfo[name] + + def read(self, name): + """Return file bytes (as a string) for name.""" + if self.mode not in ("r", "a"): + raise RuntimeError, 'read() requires mode "r" or "a"' + if not self.fp: + raise RuntimeError, \ + "Attempt to read ZIP archive that was already closed" + zinfo = self.getinfo(name) + filepos = self.fp.tell() + + self.fp.seek(zinfo.header_offset, 0) + + # Skip the file header: + fheader = self.fp.read(30) + if fheader[0:4] != stringFileHeader: + raise BadZipfile, "Bad magic number for file header" + + fheader = struct.unpack(structFileHeader, fheader) + fname = self.fp.read(fheader[_FH_FILENAME_LENGTH]) + if fheader[_FH_EXTRA_FIELD_LENGTH]: + self.fp.read(fheader[_FH_EXTRA_FIELD_LENGTH]) + + if fname != zinfo.orig_filename: + raise BadZipfile, \ + 'File name in directory "%s" and header "%s" differ.' % ( + zinfo.orig_filename, fname) + + bytes = self.fp.read(zinfo.compress_size) + self.fp.seek(filepos, 0) + if zinfo.compress_type == ZIP_STORED: + pass + elif zinfo.compress_type == ZIP_DEFLATED: + if not zlib: + raise RuntimeError, \ + "De-compression requires the (missing) zlib module" + # zlib compress/decompress code by Jeremy Hylton of CNRI + dc = zlib.decompressobj(-15) + bytes = dc.decompress(bytes) + # need to feed in unused pad byte so that zlib won't choke + ex = dc.decompress('Z') + dc.flush() + if ex: + bytes = bytes + ex + else: + raise BadZipfile, \ + "Unsupported compression method %d for file %s" % \ + (zinfo.compress_type, name) + crc = binascii.crc32(bytes) + if crc != zinfo.CRC: + raise BadZipfile, "Bad CRC-32 for file %s" % name + return bytes + + def _writecheck(self, zinfo): + """Check for errors before writing a file to the archive.""" + if zinfo.filename in self.NameToInfo: + if self.debug: # Warning for duplicate names + print "Duplicate name:", zinfo.filename + if self.mode not in ("w", "a"): + raise RuntimeError, 'write() requires mode "w" or "a"' + if not self.fp: + raise RuntimeError, \ + "Attempt to write ZIP archive that was already closed" + if zinfo.compress_type == ZIP_DEFLATED and not zlib: + raise RuntimeError, \ + "Compression requires the (missing) zlib module" + if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): + raise RuntimeError, \ + "That compression method is not supported" + if zinfo.file_size > ZIP64_LIMIT: + if not self._allowZip64: + raise LargeZipFile("Filesize would require ZIP64 extensions") + if zinfo.header_offset > ZIP64_LIMIT: + if not self._allowZip64: + raise LargeZipFile("Zipfile size would require ZIP64 extensions") + + def write(self, filename, arcname=None, compress_type=None): + """Put the bytes from filename into the archive under the name + arcname.""" + st = os.stat(filename) + mtime = time.localtime(st.st_mtime) + date_time = mtime[0:6] + # Create ZipInfo instance to store file information + if arcname is None: + arcname = filename + arcname = os.path.normpath(os.path.splitdrive(arcname)[1]) + while arcname[0] in (os.sep, os.altsep): + arcname = arcname[1:] + zinfo = ZipInfo(arcname, date_time) + zinfo.external_attr = (st[0] & 0xFFFF) << 16L # Unix attributes + if compress_type is None: + zinfo.compress_type = self.compression + else: + zinfo.compress_type = compress_type + + zinfo.file_size = st.st_size + zinfo.flag_bits = 0x00 + zinfo.header_offset = self.fp.tell() # Start of header bytes + + self._writecheck(zinfo) + self._didModify = True + fp = open(filename, "rb") + # Must overwrite CRC and sizes with correct data later + zinfo.CRC = CRC = 0 + zinfo.compress_size = compress_size = 0 + zinfo.file_size = file_size = 0 + self.fp.write(zinfo.FileHeader()) + if zinfo.compress_type == ZIP_DEFLATED: + cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, + zlib.DEFLATED, -15) + else: + cmpr = None + while 1: + buf = fp.read(1024 * 8) + if not buf: + break + file_size = file_size + len(buf) + CRC = binascii.crc32(buf, CRC) + if cmpr: + buf = cmpr.compress(buf) + compress_size = compress_size + len(buf) + self.fp.write(buf) + fp.close() + if cmpr: + buf = cmpr.flush() + compress_size = compress_size + len(buf) + self.fp.write(buf) + zinfo.compress_size = compress_size + else: + zinfo.compress_size = file_size + zinfo.CRC = CRC + zinfo.file_size = file_size + # Seek backwards and write CRC and file sizes + position = self.fp.tell() # Preserve current position in file + self.fp.seek(zinfo.header_offset + 14, 0) + self.fp.write(struct.pack("<lLL", zinfo.CRC, zinfo.compress_size, + zinfo.file_size)) + self.fp.seek(position, 0) + self.filelist.append(zinfo) + self.NameToInfo[zinfo.filename] = zinfo + + def writestr(self, zinfo_or_arcname, bytes): + """Write a file into the archive. The contents is the string + 'bytes'. 'zinfo_or_arcname' is either a ZipInfo instance or + the name of the file in the archive.""" + if not isinstance(zinfo_or_arcname, ZipInfo): + zinfo = ZipInfo(filename=zinfo_or_arcname, + date_time=time.localtime(time.time())[:6]) + zinfo.compress_type = self.compression + else: + zinfo = zinfo_or_arcname + zinfo.file_size = len(bytes) # Uncompressed size + zinfo.header_offset = self.fp.tell() # Start of header bytes + self._writecheck(zinfo) + self._didModify = True + zinfo.CRC = binascii.crc32(bytes) # CRC-32 checksum + if zinfo.compress_type == ZIP_DEFLATED: + co = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, + zlib.DEFLATED, -15) + bytes = co.compress(bytes) + co.flush() + zinfo.compress_size = len(bytes) # Compressed size + else: + zinfo.compress_size = zinfo.file_size + zinfo.header_offset = self.fp.tell() # Start of header bytes + self.fp.write(zinfo.FileHeader()) + self.fp.write(bytes) + self.fp.flush() + if zinfo.flag_bits & 0x08: + # Write CRC and file sizes after the file data + self.fp.write(struct.pack("<lLL", zinfo.CRC, zinfo.compress_size, + zinfo.file_size)) + self.filelist.append(zinfo) + self.NameToInfo[zinfo.filename] = zinfo + + def __del__(self): + """Call the "close()" method in case the user forgot.""" + self.close() + + def close(self): + """Close the file, and for mode "w" and "a" write the ending + records.""" + if self.fp is None: + return + + if self.mode in ("w", "a") and self._didModify: # write ending records + count = 0 + pos1 = self.fp.tell() + for zinfo in self.filelist: # write central directory + count = count + 1 + dt = zinfo.date_time + dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2] + dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2) + extra = [] + if zinfo.file_size > ZIP64_LIMIT \ + or zinfo.compress_size > ZIP64_LIMIT: + extra.append(zinfo.file_size) + extra.append(zinfo.compress_size) + file_size = 0xffffffff #-1 + compress_size = 0xffffffff #-1 + else: + file_size = zinfo.file_size + compress_size = zinfo.compress_size + + if zinfo.header_offset > ZIP64_LIMIT: + extra.append(zinfo.header_offset) + header_offset = -1 # struct "l" format: 32 one bits + else: + header_offset = zinfo.header_offset + + extra_data = zinfo.extra + if extra: + # Append a ZIP64 field to the extra's + extra_data = struct.pack( + '<hh' + 'q'*len(extra), + 1, 8*len(extra), *extra) + extra_data + + extract_version = max(45, zinfo.extract_version) + create_version = max(45, zinfo.create_version) + else: + extract_version = zinfo.extract_version + create_version = zinfo.create_version + + centdir = struct.pack(structCentralDir, + stringCentralDir, create_version, + zinfo.create_system, extract_version, zinfo.reserved, + zinfo.flag_bits, zinfo.compress_type, dostime, dosdate, + zinfo.CRC, compress_size, file_size, + len(zinfo.filename), len(extra_data), len(zinfo.comment), + 0, zinfo.internal_attr, zinfo.external_attr, + header_offset) + self.fp.write(centdir) + self.fp.write(zinfo.filename) + self.fp.write(extra_data) + self.fp.write(zinfo.comment) + + pos2 = self.fp.tell() + # Write end-of-zip-archive record + if pos1 > ZIP64_LIMIT: + # Need to write the ZIP64 end-of-archive records + zip64endrec = struct.pack( + structEndArchive64, stringEndArchive64, + 44, 45, 45, 0, 0, count, count, pos2 - pos1, pos1) + self.fp.write(zip64endrec) + + zip64locrec = struct.pack( + structEndArchive64Locator, + stringEndArchive64Locator, 0, pos2, 1) + self.fp.write(zip64locrec) + + # XXX Why is `pos3` computed next? It's never referenced. + pos3 = self.fp.tell() + endrec = struct.pack(structEndArchive, stringEndArchive, + 0, 0, count, count, pos2 - pos1, -1, 0) + self.fp.write(endrec) + + else: + endrec = struct.pack(structEndArchive, stringEndArchive, + 0, 0, count, count, pos2 - pos1, pos1, 0) + self.fp.write(endrec) + self.fp.flush() + if not self._filePassed: + self.fp.close() + self.fp = None + + +class PyZipFile(ZipFile): + """Class to create ZIP archives with Python library files and packages.""" + + def writepy(self, pathname, basename = ""): + """Add all files from "pathname" to the ZIP archive. + + If pathname is a package directory, search the directory and + all package subdirectories recursively for all *.py and enter + the modules into the archive. If pathname is a plain + directory, listdir *.py and enter all modules. Else, pathname + must be a Python *.py file and the module will be put into the + archive. Added modules are always module.pyo or module.pyc. + This method will compile the module.py into module.pyc if + necessary. + """ + dir, name = os.path.split(pathname) + if os.path.isdir(pathname): + initname = os.path.join(pathname, "__init__.py") + if os.path.isfile(initname): + # This is a package directory, add it + if basename: + basename = "%s/%s" % (basename, name) + else: + basename = name + if self.debug: + print "Adding package in", pathname, "as", basename + fname, arcname = self._get_codename(initname[0:-3], basename) + if self.debug: + print "Adding", arcname + self.write(fname, arcname) + dirlist = os.listdir(pathname) + dirlist.remove("__init__.py") + # Add all *.py files and package subdirectories + for filename in dirlist: + path = os.path.join(pathname, filename) + root, ext = os.path.splitext(filename) + if os.path.isdir(path): + if os.path.isfile(os.path.join(path, "__init__.py")): + # This is a package directory, add it + self.writepy(path, basename) # Recursive call + elif ext == ".py": + fname, arcname = self._get_codename(path[0:-3], + basename) + if self.debug: + print "Adding", arcname + self.write(fname, arcname) + else: + # This is NOT a package directory, add its files at top level + if self.debug: + print "Adding files from directory", pathname + for filename in os.listdir(pathname): + path = os.path.join(pathname, filename) + root, ext = os.path.splitext(filename) + if ext == ".py": + fname, arcname = self._get_codename(path[0:-3], + basename) + if self.debug: + print "Adding", arcname + self.write(fname, arcname) + else: + if pathname[-3:] != ".py": + raise RuntimeError, \ + 'Files added with writepy() must end with ".py"' + fname, arcname = self._get_codename(pathname[0:-3], basename) + if self.debug: + print "Adding file", arcname + self.write(fname, arcname) + + def _get_codename(self, pathname, basename): + """Return (filename, archivename) for the path. + + Given a module name path, return the correct file path and + archive name, compiling if necessary. For example, given + /python/lib/string, return (/python/lib/string.pyc, string). + """ + file_py = pathname + ".py" + file_pyc = pathname + ".pyc" + file_pyo = pathname + ".pyo" + if os.path.isfile(file_pyo) and \ + os.stat(file_pyo).st_mtime >= os.stat(file_py).st_mtime: + fname = file_pyo # Use .pyo file + elif not os.path.isfile(file_pyc) or \ + os.stat(file_pyc).st_mtime < os.stat(file_py).st_mtime: + import py_compile + if self.debug: + print "Compiling", file_py + try: + py_compile.compile(file_py, file_pyc, None, True) + except py_compile.PyCompileError,err: + print err.msg + fname = file_pyc + else: + fname = file_pyc + archivename = os.path.split(fname)[1] + if basename: + archivename = "%s/%s" % (basename, archivename) + return (fname, archivename) + + +def main(args = None): + import textwrap + USAGE=textwrap.dedent("""\ + Usage: + zipfile.py -l zipfile.zip # Show listing of a zipfile + zipfile.py -t zipfile.zip # Test if a zipfile is valid + zipfile.py -e zipfile.zip target # Extract zipfile into target dir + zipfile.py -c zipfile.zip src ... # Create zipfile from sources + """) + if args is None: + args = sys.argv[1:] + + if not args or args[0] not in ('-l', '-c', '-e', '-t'): + print USAGE + sys.exit(1) + + if args[0] == '-l': + if len(args) != 2: + print USAGE + sys.exit(1) + zf = ZipFile(args[1], 'r') + zf.printdir() + zf.close() + + elif args[0] == '-t': + if len(args) != 2: + print USAGE + sys.exit(1) + zf = ZipFile(args[1], 'r') + zf.testzip() + print "Done testing" + + elif args[0] == '-e': + if len(args) != 3: + print USAGE + sys.exit(1) + + zf = ZipFile(args[1], 'r') + out = args[2] + for path in zf.namelist(): + if path.startswith('./'): + tgt = os.path.join(out, path[2:]) + else: + tgt = os.path.join(out, path) + + tgtdir = os.path.dirname(tgt) + if not os.path.exists(tgtdir): + os.makedirs(tgtdir) + fp = open(tgt, 'wb') + fp.write(zf.read(path)) + fp.close() + zf.close() + + elif args[0] == '-c': + if len(args) < 3: + print USAGE + sys.exit(1) + + def addToZip(zf, path, zippath): + if os.path.isfile(path): + zf.write(path, zippath, ZIP_DEFLATED) + elif os.path.isdir(path): + for nm in os.listdir(path): + addToZip(zf, + os.path.join(path, nm), os.path.join(zippath, nm)) + # else: ignore + + zf = ZipFile(args[1], 'w', allowZip64=True) + for src in args[2:]: + addToZip(zf, src, os.path.basename(src)) + + zf.close() + +if __name__ == "__main__": + main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-24 04:39:11
|
Revision: 5628 http://jython.svn.sourceforge.net/jython/?rev=5628&view=rev Author: fwierzbicki Date: 2008-11-24 04:39:05 +0000 (Mon, 24 Nov 2008) Log Message: ----------- Just enough to get one of the (modified) 2.6 test_ast tests to pass. Modified Paths: -------------- branches/astwrite/Lib/test/test_ast.py branches/astwrite/ast/asdl_antlr.py branches/astwrite/src/org/python/antlr/ast/Assert.java branches/astwrite/src/org/python/antlr/ast/Assign.java branches/astwrite/src/org/python/antlr/ast/Attribute.java branches/astwrite/src/org/python/antlr/ast/AugAssign.java branches/astwrite/src/org/python/antlr/ast/BinOp.java branches/astwrite/src/org/python/antlr/ast/BoolOp.java branches/astwrite/src/org/python/antlr/ast/Break.java branches/astwrite/src/org/python/antlr/ast/Call.java branches/astwrite/src/org/python/antlr/ast/ClassDef.java branches/astwrite/src/org/python/antlr/ast/Compare.java branches/astwrite/src/org/python/antlr/ast/Continue.java branches/astwrite/src/org/python/antlr/ast/Delete.java branches/astwrite/src/org/python/antlr/ast/Dict.java branches/astwrite/src/org/python/antlr/ast/Ellipsis.java branches/astwrite/src/org/python/antlr/ast/Exec.java branches/astwrite/src/org/python/antlr/ast/Expr.java branches/astwrite/src/org/python/antlr/ast/Expression.java branches/astwrite/src/org/python/antlr/ast/ExtSlice.java branches/astwrite/src/org/python/antlr/ast/For.java branches/astwrite/src/org/python/antlr/ast/FunctionDef.java branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java branches/astwrite/src/org/python/antlr/ast/Global.java branches/astwrite/src/org/python/antlr/ast/If.java branches/astwrite/src/org/python/antlr/ast/IfExp.java branches/astwrite/src/org/python/antlr/ast/Import.java branches/astwrite/src/org/python/antlr/ast/ImportFrom.java branches/astwrite/src/org/python/antlr/ast/Index.java branches/astwrite/src/org/python/antlr/ast/Interactive.java branches/astwrite/src/org/python/antlr/ast/Lambda.java branches/astwrite/src/org/python/antlr/ast/List.java branches/astwrite/src/org/python/antlr/ast/ListComp.java branches/astwrite/src/org/python/antlr/ast/Module.java branches/astwrite/src/org/python/antlr/ast/Name.java branches/astwrite/src/org/python/antlr/ast/Num.java branches/astwrite/src/org/python/antlr/ast/Pass.java branches/astwrite/src/org/python/antlr/ast/Print.java branches/astwrite/src/org/python/antlr/ast/Raise.java branches/astwrite/src/org/python/antlr/ast/Repr.java branches/astwrite/src/org/python/antlr/ast/Return.java branches/astwrite/src/org/python/antlr/ast/Slice.java branches/astwrite/src/org/python/antlr/ast/Str.java branches/astwrite/src/org/python/antlr/ast/Subscript.java branches/astwrite/src/org/python/antlr/ast/Suite.java branches/astwrite/src/org/python/antlr/ast/TryExcept.java branches/astwrite/src/org/python/antlr/ast/TryFinally.java branches/astwrite/src/org/python/antlr/ast/Tuple.java branches/astwrite/src/org/python/antlr/ast/UnaryOp.java branches/astwrite/src/org/python/antlr/ast/VisitorBase.java branches/astwrite/src/org/python/antlr/ast/While.java branches/astwrite/src/org/python/antlr/ast/With.java branches/astwrite/src/org/python/antlr/ast/Yield.java branches/astwrite/src/org/python/antlr/ast/aliasType.java branches/astwrite/src/org/python/antlr/ast/argumentsType.java branches/astwrite/src/org/python/antlr/ast/boolopType.java branches/astwrite/src/org/python/antlr/ast/cmpopType.java branches/astwrite/src/org/python/antlr/ast/comprehensionType.java branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java branches/astwrite/src/org/python/antlr/ast/exprType.java branches/astwrite/src/org/python/antlr/ast/expr_contextType.java branches/astwrite/src/org/python/antlr/ast/keywordType.java branches/astwrite/src/org/python/antlr/ast/modType.java branches/astwrite/src/org/python/antlr/ast/operatorType.java branches/astwrite/src/org/python/antlr/ast/sliceType.java branches/astwrite/src/org/python/antlr/ast/stmtType.java branches/astwrite/src/org/python/antlr/ast/unaryopType.java Added Paths: ----------- branches/astwrite/src/org/python/antlr/AstAdapter.java Modified: branches/astwrite/Lib/test/test_ast.py =================================================================== --- branches/astwrite/Lib/test/test_ast.py 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/Lib/test/test_ast.py 2008-11-24 04:39:05 UTC (rev 5628) @@ -174,20 +174,20 @@ self._assert_order(ast_tree, (0, 0)) def test_nodeclasses(self): - x = ast.BinOp(1, 2, 3, lineno=0) - self.assertEquals(x.left, 1) - self.assertEquals(x.op, 2) - self.assertEquals(x.right, 3) + x = ast.BinOp(1, ast.Add, 3, lineno=0) + self.assertEquals(x.left.n, 1) + self.assertEquals(x.op, ast.Add) + self.assertEquals(x.right.n, 3) self.assertEquals(x.lineno, 0) # node raises exception when not given enough arguments self.assertRaises(TypeError, ast.BinOp, 1, 2) # can set attributes through kwargs too - x = ast.BinOp(left=1, op=2, right=3, lineno=0) - self.assertEquals(x.left, 1) - self.assertEquals(x.op, 2) - self.assertEquals(x.right, 3) + x = ast.BinOp(left=1, op=ast.Add, right=3, lineno=0) + self.assertEquals(x.left.n, 1) + self.assertEquals(x.op, ast.Add) + self.assertEquals(x.right.n, 3) self.assertEquals(x.lineno, 0) # this used to fail because Sub._fields was None Modified: branches/astwrite/ast/asdl_antlr.py =================================================================== --- branches/astwrite/ast/asdl_antlr.py 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/ast/asdl_antlr.py 2008-11-24 04:39:05 UTC (rev 5628) @@ -56,6 +56,7 @@ print >> self.file, "// Autogenerated AST node" print >> self.file, 'package org.python.antlr.ast;' if refersToPythonTree: + print >> self.file, 'import org.python.antlr.AstAdapter;' print >> self.file, 'import org.python.antlr.PythonTree;' print >> self.file, 'import org.python.antlr.ListWrapper;' print >> self.file, 'import org.antlr.runtime.CommonToken;' @@ -150,6 +151,8 @@ self.attributes(sum, depth, True); + self.emit("public %sType __call__() { return this; }" % name, depth + 1) + self.emit("}", depth) self.close() @@ -291,9 +294,6 @@ def javaConstructorHelper(self, fields, depth): for f in fields: - #XXX: old version: - #self.emit("this.%s = %s;" % (f.name, f.name), depth+1) - #XXX: code cut and pasted from visitField if f.seq: self.emit("this.%s = new %s(%s);" % (f.name, self.javaType(f, True), f.name), depth+1) @@ -319,44 +319,9 @@ #XXX: this method used to emit a pickle(DataOutputStream ostream) for cPickle support. # If we want to re-add it, see Jython 2.2's pickle method in its ast nodes. def javaMethods(self, type, clsname, ctorname, fields, depth): - # The java ctors - fpargs = ", ".join([self.fieldDef(f) for f in fields]) - self.emit("public %s(%s) {" % (ctorname, fpargs), depth) - self.javaConstructorHelper(fields, depth) - self.emit("}", depth) - self.emit("", 0) + self.javaConstructors(type, clsname, ctorname, fields, depth) - token = asdl.Field('Token', 'token') - token.typedef = False - fpargs = ", ".join([self.fieldDef(f) for f in [token] + fields]) - self.emit("public %s(%s) {" % (ctorname, fpargs), depth) - self.emit("super(token);", depth+1) - self.javaConstructorHelper(fields, depth) - self.emit("}", depth) - self.emit("", 0) - - ttype = asdl.Field('int', 'ttype') - ttype.typedef = False - fpargs = ", ".join([self.fieldDef(f) for f in [ttype, token] + fields]) - self.emit("public %s(%s) {" % (ctorname, fpargs), depth) - self.emit("super(ttype, token);", depth+1) - self.javaConstructorHelper(fields, depth) - self.emit("}", depth) - self.emit("", 0) - - tree = asdl.Field('PythonTree', 'tree') - tree.typedef = False - fpargs = ", ".join([self.fieldDef(f) for f in [tree] + fields]) - self.emit("public %s(%s) {" % (ctorname, fpargs), depth) - self.emit("super(tree);", depth+1) - self.javaConstructorHelper(fields, depth) - self.emit("}", depth) - self.emit("", 0) - - if fpargs: - fpargs += ", " - # The toString() method self.emit("public String toString() {", depth) self.emit('return "%s";' % clsname, depth+1) @@ -407,6 +372,46 @@ self.emit('}', depth) self.emit("", 0) + def javaConstructors(self, type, clsname, ctorname, fields, depth): + if len(fields) > 0: + self.emit("public %s() {}" % (ctorname), depth) + + fpargs = ", ".join(["Object %s" % f.name for f in fields]) + self.emit("public %s(%s) {" % (ctorname, fpargs), depth) + for f in fields: + self.emit("set%s(%s);" % (str(f.name).capitalize(), + f.name), depth+1) + self.emit("}", depth) + self.emit("", 0) + + token = asdl.Field('Token', 'token') + token.typedef = False + fpargs = ", ".join([self.fieldDef(f) for f in [token] + fields]) + self.emit("public %s(%s) {" % (ctorname, fpargs), depth) + self.emit("super(token);", depth+1) + self.javaConstructorHelper(fields, depth) + self.emit("}", depth) + self.emit("", 0) + + ttype = asdl.Field('int', 'ttype') + ttype.typedef = False + fpargs = ", ".join([self.fieldDef(f) for f in [ttype, token] + fields]) + self.emit("public %s(%s) {" % (ctorname, fpargs), depth) + self.emit("super(ttype, token);", depth+1) + self.javaConstructorHelper(fields, depth) + self.emit("}", depth) + self.emit("", 0) + + tree = asdl.Field('PythonTree', 'tree') + tree.typedef = False + fpargs = ", ".join([self.fieldDef(f) for f in [tree] + fields]) + self.emit("public %s(%s) {" % (ctorname, fpargs), depth) + self.emit("super(tree);", depth+1) + self.javaConstructorHelper(fields, depth) + self.emit("}", depth) + self.emit("", 0) + + def visitField(self, field, depth): self.emit("private %s;" % self.fieldDef(field, True), depth) self.emit("public %s getInternal%s() {" % (self.javaType(field, True), @@ -422,7 +427,7 @@ self.emit("this.%s = new %s(" % (field.name, self.javaType(field, True)), depth+1) self.emit("(%s)%s);" % (self.javaType(field), field.name), depth+2) else: - self.emit("this.%s = (%s)%s;" % (field.name, self.javaType(field), field.name), depth+1) + self.emit("this.%s = AstAdapter.to_%s(%s);" % (field.name, str(field.type), field.name), depth+1) self.emit("}", depth) self.emit("", 0) Added: branches/astwrite/src/org/python/antlr/AstAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/AstAdapter.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -0,0 +1,109 @@ +package org.python.antlr; + +import org.python.antlr.ast.*; +import org.python.core.*; + +/** + * AstAdapter turns Python and Java objects into ast nodes. + */ +public class AstAdapter { + + public static exprType to_expr(Object o) { + if (o == null || o instanceof exprType) { + return (exprType)o; + } else if (o instanceof Integer) { + return new Num(new PyInteger((Integer)o)); + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); + } + + public static int to_int(Object o) { + if (o == null || o instanceof Integer) { + return (Integer)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to int node"); + } + + public static String to_identifier(Object o) { + if (o == null || o instanceof String) { + return (String)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); + } + + public static expr_contextType to_expr_context(Object o) { + if (o == null || o instanceof expr_contextType) { + return (expr_contextType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr_context node"); + } + + public static sliceType to_slice(Object o) { + if (o == null || o instanceof sliceType) { + return (sliceType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); + } + + public static String to_string(Object o) { + if (o == null || o instanceof String) { + return (String)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to string node"); + } + + public static operatorType to_operator(Object o) { + if (o == null || o instanceof operatorType) { + return (operatorType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to operator node"); + } + + public static boolopType to_boolop(Object o) { + if (o == null || o instanceof boolopType) { + return (boolopType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to boolop node"); + } + + public static argumentsType to_arguments(Object o) { + if (o == null || o instanceof argumentsType) { + return (argumentsType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arguments node"); + } + + public static Object to_object(Object o) { + if (o == null || o instanceof Object) { + return (Object)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to object node"); + } + + public static Boolean to_bool(Object o) { + if (o == null || o instanceof Boolean) { + return (Boolean)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to Boolean node"); + } + + public static unaryopType to_unaryop(Object o) { + if (o == null || o instanceof unaryopType) { + return (unaryopType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to unaryop node"); + } + +} Modified: branches/astwrite/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assert.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Assert.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return test; } public void setTest(Object test) { - this.test = (exprType)test; + this.test = AstAdapter.to_expr(test); } private exprType msg; @@ -27,18 +28,17 @@ return msg; } public void setMsg(Object msg) { - this.msg = (exprType)msg; + this.msg = AstAdapter.to_expr(msg); } private final static String[] fields = new String[] {"test", "msg"}; public String[] get_fields() { return fields; } - public Assert(exprType test, exprType msg) { - this.test = test; - addChild(test); - this.msg = msg; - addChild(msg); + public Assert() {} + public Assert(Object test, Object msg) { + setTest(test); + setMsg(msg); } public Assert(Token token, exprType test, exprType msg) { Modified: branches/astwrite/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Assign.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -28,22 +29,17 @@ return value; } public void setValue(Object value) { - this.value = (exprType)value; + this.value = AstAdapter.to_expr(value); } private final static String[] fields = new String[] {"targets", "value"}; public String[] get_fields() { return fields; } - public Assign(java.util.List<exprType> targets, exprType value) { - this.targets = new ListWrapper<exprType>(targets); - if (targets != null) { - for(PythonTree t : targets) { - addChild(t); - } - } - this.value = value; - addChild(value); + public Assign() {} + public Assign(Object targets, Object value) { + setTargets(targets); + setValue(value); } public Assign(Token token, java.util.List<exprType> targets, exprType Modified: branches/astwrite/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Attribute.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Attribute.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return value; } public void setValue(Object value) { - this.value = (exprType)value; + this.value = AstAdapter.to_expr(value); } private String attr; @@ -27,7 +28,7 @@ return attr; } public void setAttr(Object attr) { - this.attr = (String)attr; + this.attr = AstAdapter.to_identifier(attr); } private expr_contextType ctx; @@ -38,7 +39,7 @@ return ctx; } public void setCtx(Object ctx) { - this.ctx = (expr_contextType)ctx; + this.ctx = AstAdapter.to_expr_context(ctx); } @@ -46,11 +47,11 @@ "ctx"}; public String[] get_fields() { return fields; } - public Attribute(exprType value, String attr, expr_contextType ctx) { - this.value = value; - addChild(value); - this.attr = attr; - this.ctx = ctx; + public Attribute() {} + public Attribute(Object value, Object attr, Object ctx) { + setValue(value); + setAttr(attr); + setCtx(ctx); } public Attribute(Token token, exprType value, String attr, expr_contextType Modified: branches/astwrite/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/AugAssign.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/AugAssign.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return target; } public void setTarget(Object target) { - this.target = (exprType)target; + this.target = AstAdapter.to_expr(target); } private operatorType op; @@ -27,7 +28,7 @@ return op; } public void setOp(Object op) { - this.op = (operatorType)op; + this.op = AstAdapter.to_operator(op); } private exprType value; @@ -38,7 +39,7 @@ return value; } public void setValue(Object value) { - this.value = (exprType)value; + this.value = AstAdapter.to_expr(value); } @@ -46,12 +47,11 @@ "value"}; public String[] get_fields() { return fields; } - public AugAssign(exprType target, operatorType op, exprType value) { - this.target = target; - addChild(target); - this.op = op; - this.value = value; - addChild(value); + public AugAssign() {} + public AugAssign(Object target, Object op, Object value) { + setTarget(target); + setOp(op); + setValue(value); } public AugAssign(Token token, exprType target, operatorType op, exprType Modified: branches/astwrite/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BinOp.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/BinOp.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,8 +1,8 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; -import org.python.core.PyInteger; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; import java.io.DataOutputStream; @@ -17,14 +17,9 @@ return left; } public void setLeft(Object left) { - if (left instanceof exprType) { - this.left = (exprType)left; - } else if (left instanceof Integer) { - this.left = new Num(new PyInteger((Integer)left)); - } + this.left = AstAdapter.to_expr(left); } - private operatorType op; public operatorType getInternalOp() { return op; @@ -33,7 +28,7 @@ return op; } public void setOp(Object op) { - this.op = (operatorType)op; + this.op = AstAdapter.to_operator(op); } private exprType right; @@ -44,28 +39,15 @@ return right; } public void setRight(Object right) { - if (right instanceof exprType) { - this.right = (exprType)right; - } else if (right instanceof Integer) { - this.right = new Num(new PyInteger((Integer)right)); - } + this.right = AstAdapter.to_expr(right); } + private final static String[] fields = new String[] {"left", "op", "right"}; public String[] get_fields() { return fields; } - public BinOp(exprType left, operatorType op, exprType right) { - this.left = left; - addChild(left); - this.op = op; - this.right = right; - addChild(right); - } - - public BinOp() { - } - - public BinOp(Object left, operatorType op, Object right) { + public BinOp() {} + public BinOp(Object left, Object op, Object right) { setLeft(left); setOp(op); setRight(right); Modified: branches/astwrite/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/BoolOp.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return op; } public void setOp(Object op) { - this.op = (boolopType)op; + this.op = AstAdapter.to_boolop(op); } private ListWrapper<exprType> values; @@ -35,14 +36,10 @@ private final static String[] fields = new String[] {"op", "values"}; public String[] get_fields() { return fields; } - public BoolOp(boolopType op, java.util.List<exprType> values) { - this.op = op; - this.values = new ListWrapper<exprType>(values); - if (values != null) { - for(PythonTree t : values) { - addChild(t); - } - } + public BoolOp() {} + public BoolOp(Object op, Object values) { + setOp(op); + setValues(values); } public BoolOp(Token token, boolopType op, java.util.List<exprType> values) { Modified: branches/astwrite/src/org/python/antlr/ast/Break.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Break.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Break.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -9,9 +10,6 @@ public class Break extends stmtType { - public Break() { - } - public Break(Token token) { super(token); } Modified: branches/astwrite/src/org/python/antlr/ast/Call.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Call.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return func; } public void setFunc(Object func) { - this.func = (exprType)func; + this.func = AstAdapter.to_expr(func); } private ListWrapper<exprType> args; @@ -51,7 +52,7 @@ return starargs; } public void setStarargs(Object starargs) { - this.starargs = (exprType)starargs; + this.starargs = AstAdapter.to_expr(starargs); } private exprType kwargs; @@ -62,7 +63,7 @@ return kwargs; } public void setKwargs(Object kwargs) { - this.kwargs = (exprType)kwargs; + this.kwargs = AstAdapter.to_expr(kwargs); } @@ -71,26 +72,14 @@ "starargs", "kwargs"}; public String[] get_fields() { return fields; } - public Call(exprType func, java.util.List<exprType> args, - java.util.List<keywordType> keywords, exprType starargs, exprType kwargs) { - this.func = func; - addChild(func); - this.args = new ListWrapper<exprType>(args); - if (args != null) { - for(PythonTree t : args) { - addChild(t); - } - } - this.keywords = new ListWrapper<keywordType>(keywords); - if (keywords != null) { - for(PythonTree t : keywords) { - addChild(t); - } - } - this.starargs = starargs; - addChild(starargs); - this.kwargs = kwargs; - addChild(kwargs); + public Call() {} + public Call(Object func, Object args, Object keywords, Object starargs, + Object kwargs) { + setFunc(func); + setArgs(args); + setKeywords(keywords); + setStarargs(starargs); + setKwargs(kwargs); } public Call(Token token, exprType func, java.util.List<exprType> args, Modified: branches/astwrite/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return name; } public void setName(Object name) { - this.name = (String)name; + this.name = AstAdapter.to_identifier(name); } private ListWrapper<exprType> bases; @@ -60,27 +61,12 @@ "body", "decorators"}; public String[] get_fields() { return fields; } - public ClassDef(String name, java.util.List<exprType> bases, - java.util.List<stmtType> body, java.util.List<exprType> decorators) { - this.name = name; - this.bases = new ListWrapper<exprType>(bases); - if (bases != null) { - for(PythonTree t : bases) { - addChild(t); - } - } - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } - } - this.decorators = new ListWrapper<exprType>(decorators); - if (decorators != null) { - for(PythonTree t : decorators) { - addChild(t); - } - } + public ClassDef() {} + public ClassDef(Object name, Object bases, Object body, Object decorators) { + setName(name); + setBases(bases); + setBody(body); + setDecorators(decorators); } public ClassDef(Token token, String name, java.util.List<exprType> bases, Modified: branches/astwrite/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Compare.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return left; } public void setLeft(Object left) { - this.left = (exprType)left; + this.left = AstAdapter.to_expr(left); } private ListWrapper<cmpopType> ops; @@ -48,17 +49,11 @@ "comparators"}; public String[] get_fields() { return fields; } - public Compare(exprType left, java.util.List<cmpopType> ops, - java.util.List<exprType> comparators) { - this.left = left; - addChild(left); - this.ops = new ListWrapper<cmpopType>(ops); - this.comparators = new ListWrapper<exprType>(comparators); - if (comparators != null) { - for(PythonTree t : comparators) { - addChild(t); - } - } + public Compare() {} + public Compare(Object left, Object ops, Object comparators) { + setLeft(left); + setOps(ops); + setComparators(comparators); } public Compare(Token token, exprType left, java.util.List<cmpopType> ops, Modified: branches/astwrite/src/org/python/antlr/ast/Continue.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Continue.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Continue.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -9,9 +10,6 @@ public class Continue extends stmtType { - public Continue() { - } - public Continue(Token token) { super(token); } Modified: branches/astwrite/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Delete.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -24,13 +25,9 @@ private final static String[] fields = new String[] {"targets"}; public String[] get_fields() { return fields; } - public Delete(java.util.List<exprType> targets) { - this.targets = new ListWrapper<exprType>(targets); - if (targets != null) { - for(PythonTree t : targets) { - addChild(t); - } - } + public Delete() {} + public Delete(Object targets) { + setTargets(targets); } public Delete(Token token, java.util.List<exprType> targets) { Modified: branches/astwrite/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Dict.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -36,20 +37,10 @@ private final static String[] fields = new String[] {"keys", "values"}; public String[] get_fields() { return fields; } - public Dict(java.util.List<exprType> keys, java.util.List<exprType> values) - { - this.keys = new ListWrapper<exprType>(keys); - if (keys != null) { - for(PythonTree t : keys) { - addChild(t); - } - } - this.values = new ListWrapper<exprType>(values); - if (values != null) { - for(PythonTree t : values) { - addChild(t); - } - } + public Dict() {} + public Dict(Object keys, Object values) { + setKeys(keys); + setValues(values); } public Dict(Token token, java.util.List<exprType> keys, Modified: branches/astwrite/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Ellipsis.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Ellipsis.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -9,9 +10,6 @@ public class Ellipsis extends sliceType { - public Ellipsis() { - } - public Ellipsis(Token token) { super(token); } Modified: branches/astwrite/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Exec.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Exec.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return body; } public void setBody(Object body) { - this.body = (exprType)body; + this.body = AstAdapter.to_expr(body); } private exprType globals; @@ -27,7 +28,7 @@ return globals; } public void setGlobals(Object globals) { - this.globals = (exprType)globals; + this.globals = AstAdapter.to_expr(globals); } private exprType locals; @@ -38,7 +39,7 @@ return locals; } public void setLocals(Object locals) { - this.locals = (exprType)locals; + this.locals = AstAdapter.to_expr(locals); } @@ -46,13 +47,11 @@ "locals"}; public String[] get_fields() { return fields; } - public Exec(exprType body, exprType globals, exprType locals) { - this.body = body; - addChild(body); - this.globals = globals; - addChild(globals); - this.locals = locals; - addChild(locals); + public Exec() {} + public Exec(Object body, Object globals, Object locals) { + setBody(body); + setGlobals(globals); + setLocals(locals); } public Exec(Token token, exprType body, exprType globals, exprType locals) { Modified: branches/astwrite/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Expr.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Expr.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,16 +17,16 @@ return value; } public void setValue(Object value) { - this.value = (exprType)value; + this.value = AstAdapter.to_expr(value); } private final static String[] fields = new String[] {"value"}; public String[] get_fields() { return fields; } - public Expr(exprType value) { - this.value = value; - addChild(value); + public Expr() {} + public Expr(Object value) { + setValue(value); } public Expr(Token token, exprType value) { Modified: branches/astwrite/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Expression.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Expression.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,16 +17,16 @@ return body; } public void setBody(Object body) { - this.body = (exprType)body; + this.body = AstAdapter.to_expr(body); } private final static String[] fields = new String[] {"body"}; public String[] get_fields() { return fields; } - public Expression(exprType body) { - this.body = body; - addChild(body); + public Expression() {} + public Expression(Object body) { + setBody(body); } public Expression(Token token, exprType body) { Modified: branches/astwrite/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/ExtSlice.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -24,13 +25,9 @@ private final static String[] fields = new String[] {"dims"}; public String[] get_fields() { return fields; } - public ExtSlice(java.util.List<sliceType> dims) { - this.dims = new ListWrapper<sliceType>(dims); - if (dims != null) { - for(PythonTree t : dims) { - addChild(t); - } - } + public ExtSlice() {} + public ExtSlice(Object dims) { + setDims(dims); } public ExtSlice(Token token, java.util.List<sliceType> dims) { Modified: branches/astwrite/src/org/python/antlr/ast/For.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/For.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return target; } public void setTarget(Object target) { - this.target = (exprType)target; + this.target = AstAdapter.to_expr(target); } private exprType iter; @@ -27,7 +28,7 @@ return iter; } public void setIter(Object iter) { - this.iter = (exprType)iter; + this.iter = AstAdapter.to_expr(iter); } private ListWrapper<stmtType> body; @@ -59,24 +60,12 @@ "body", "orelse"}; public String[] get_fields() { return fields; } - public For(exprType target, exprType iter, java.util.List<stmtType> body, - java.util.List<stmtType> orelse) { - this.target = target; - addChild(target); - this.iter = iter; - addChild(iter); - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } - } - this.orelse = new ListWrapper<stmtType>(orelse); - if (orelse != null) { - for(PythonTree t : orelse) { - addChild(t); - } - } + public For() {} + public For(Object target, Object iter, Object body, Object orelse) { + setTarget(target); + setIter(iter); + setBody(body); + setOrelse(orelse); } public For(Token token, exprType target, exprType iter, Modified: branches/astwrite/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return name; } public void setName(Object name) { - this.name = (String)name; + this.name = AstAdapter.to_identifier(name); } private argumentsType args; @@ -27,7 +28,7 @@ return args; } public void setArgs(Object args) { - this.args = (argumentsType)args; + this.args = AstAdapter.to_arguments(args); } private ListWrapper<stmtType> body; @@ -59,22 +60,13 @@ "body", "decorators"}; public String[] get_fields() { return fields; } - public FunctionDef(String name, argumentsType args, - java.util.List<stmtType> body, java.util.List<exprType> decorators) { - this.name = name; - this.args = args; - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } - } - this.decorators = new ListWrapper<exprType>(decorators); - if (decorators != null) { - for(PythonTree t : decorators) { - addChild(t); - } - } + public FunctionDef() {} + public FunctionDef(Object name, Object args, Object body, Object + decorators) { + setName(name); + setArgs(args); + setBody(body); + setDecorators(decorators); } public FunctionDef(Token token, String name, argumentsType args, Modified: branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/GeneratorExp.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return elt; } public void setElt(Object elt) { - this.elt = (exprType)elt; + this.elt = AstAdapter.to_expr(elt); } private ListWrapper<comprehensionType> generators; @@ -35,16 +36,10 @@ private final static String[] fields = new String[] {"elt", "generators"}; public String[] get_fields() { return fields; } - public GeneratorExp(exprType elt, java.util.List<comprehensionType> - generators) { - this.elt = elt; - addChild(elt); - this.generators = new ListWrapper<comprehensionType>(generators); - if (generators != null) { - for(PythonTree t : generators) { - addChild(t); - } - } + public GeneratorExp() {} + public GeneratorExp(Object elt, Object generators) { + setElt(elt); + setGenerators(generators); } public GeneratorExp(Token token, exprType elt, Modified: branches/astwrite/src/org/python/antlr/ast/Global.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Global.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -24,8 +25,9 @@ private final static String[] fields = new String[] {"names"}; public String[] get_fields() { return fields; } - public Global(java.util.List<String> names) { - this.names = new ListWrapper<String>(names); + public Global() {} + public Global(Object names) { + setNames(names); } public Global(Token token, java.util.List<String> names) { Modified: branches/astwrite/src/org/python/antlr/ast/If.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/If.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return test; } public void setTest(Object test) { - this.test = (exprType)test; + this.test = AstAdapter.to_expr(test); } private ListWrapper<stmtType> body; @@ -48,22 +49,11 @@ "orelse"}; public String[] get_fields() { return fields; } - public If(exprType test, java.util.List<stmtType> body, - java.util.List<stmtType> orelse) { - this.test = test; - addChild(test); - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } - } - this.orelse = new ListWrapper<stmtType>(orelse); - if (orelse != null) { - for(PythonTree t : orelse) { - addChild(t); - } - } + public If() {} + public If(Object test, Object body, Object orelse) { + setTest(test); + setBody(body); + setOrelse(orelse); } public If(Token token, exprType test, java.util.List<stmtType> body, Modified: branches/astwrite/src/org/python/antlr/ast/IfExp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/IfExp.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/IfExp.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return test; } public void setTest(Object test) { - this.test = (exprType)test; + this.test = AstAdapter.to_expr(test); } private exprType body; @@ -27,7 +28,7 @@ return body; } public void setBody(Object body) { - this.body = (exprType)body; + this.body = AstAdapter.to_expr(body); } private exprType orelse; @@ -38,7 +39,7 @@ return orelse; } public void setOrelse(Object orelse) { - this.orelse = (exprType)orelse; + this.orelse = AstAdapter.to_expr(orelse); } @@ -46,13 +47,11 @@ "orelse"}; public String[] get_fields() { return fields; } - public IfExp(exprType test, exprType body, exprType orelse) { - this.test = test; - addChild(test); - this.body = body; - addChild(body); - this.orelse = orelse; - addChild(orelse); + public IfExp() {} + public IfExp(Object test, Object body, Object orelse) { + setTest(test); + setBody(body); + setOrelse(orelse); } public IfExp(Token token, exprType test, exprType body, exprType orelse) { Modified: branches/astwrite/src/org/python/antlr/ast/Import.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Import.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Import.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -24,13 +25,9 @@ private final static String[] fields = new String[] {"names"}; public String[] get_fields() { return fields; } - public Import(java.util.List<aliasType> names) { - this.names = new ListWrapper<aliasType>(names); - if (names != null) { - for(PythonTree t : names) { - addChild(t); - } - } + public Import() {} + public Import(Object names) { + setNames(names); } public Import(Token token, java.util.List<aliasType> names) { Modified: branches/astwrite/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ImportFrom.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/ImportFrom.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return module; } public void setModule(Object module) { - this.module = (String)module; + this.module = AstAdapter.to_identifier(module); } private ListWrapper<aliasType> names; @@ -39,7 +40,7 @@ return level; } public void setLevel(Object level) { - this.level = (Integer)level; + this.level = AstAdapter.to_int(level); } @@ -47,16 +48,11 @@ "level"}; public String[] get_fields() { return fields; } - public ImportFrom(String module, java.util.List<aliasType> names, Integer - level) { - this.module = module; - this.names = new ListWrapper<aliasType>(names); - if (names != null) { - for(PythonTree t : names) { - addChild(t); - } - } - this.level = level; + public ImportFrom() {} + public ImportFrom(Object module, Object names, Object level) { + setModule(module); + setNames(names); + setLevel(level); } public ImportFrom(Token token, String module, java.util.List<aliasType> Modified: branches/astwrite/src/org/python/antlr/ast/Index.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Index.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Index.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,16 +17,16 @@ return value; } public void setValue(Object value) { - this.value = (exprType)value; + this.value = AstAdapter.to_expr(value); } private final static String[] fields = new String[] {"value"}; public String[] get_fields() { return fields; } - public Index(exprType value) { - this.value = value; - addChild(value); + public Index() {} + public Index(Object value) { + setValue(value); } public Index(Token token, exprType value) { Modified: branches/astwrite/src/org/python/antlr/ast/Interactive.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Interactive.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Interactive.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -24,13 +25,9 @@ private final static String[] fields = new String[] {"body"}; public String[] get_fields() { return fields; } - public Interactive(java.util.List<stmtType> body) { - this.body = new ListWrapper<stmtType>(body); - if (body != null) { - for(PythonTree t : body) { - addChild(t); - } - } + public Interactive() {} + public Interactive(Object body) { + setBody(body); } public Interactive(Token token, java.util.List<stmtType> body) { Modified: branches/astwrite/src/org/python/antlr/ast/Lambda.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Lambda.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/Lambda.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return args; } public void setArgs(Object args) { - this.args = (argumentsType)args; + this.args = AstAdapter.to_arguments(args); } private exprType body; @@ -27,17 +28,17 @@ return body; } public void setBody(Object body) { - this.body = (exprType)body; + this.body = AstAdapter.to_expr(body); } private final static String[] fields = new String[] {"args", "body"}; public String[] get_fields() { return fields; } - public Lambda(argumentsType args, exprType body) { - this.args = args; - this.body = body; - addChild(body); + public Lambda() {} + public Lambda(Object args, Object body) { + setArgs(args); + setBody(body); } public Lambda(Token token, argumentsType args, exprType body) { Modified: branches/astwrite/src/org/python/antlr/ast/List.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/List.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/List.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -28,21 +29,17 @@ return ctx; } public void setCtx(Object ctx) { - this.ctx = (expr_contextType)ctx; + this.ctx = AstAdapter.to_expr_context(ctx); } private final static String[] fields = new String[] {"elts", "ctx"}; public String[] get_fields() { return fields; } - public List(java.util.List<exprType> elts, expr_contextType ctx) { - this.elts = new ListWrapper<exprType>(elts); - if (elts != null) { - for(PythonTree t : elts) { - addChild(t); - } - } - this.ctx = ctx; + public List() {} + public List(Object elts, Object ctx) { + setElts(elts); + setCtx(ctx); } public List(Token token, java.util.List<exprType> elts, expr_contextType Modified: branches/astwrite/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ListComp.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrite/src/org/python/antlr/ast/ListComp.java 2008-11-24 04:39:05 UTC (rev 5628) @@ -1,5 +1,6 @@ // Autogenerated AST node package org.python.antlr.ast; +import org.python.antlr.AstAdapter; import org.python.antlr.PythonTree; import org.python.antlr.ListWrapper; import org.antlr.runtime.CommonToken; @@ -16,7 +17,7 @@ return elt; } public void setElt(Object elt) { - this.elt = (exprType)elt; + this.elt = AstAdapter.to_expr(elt); } private ListWrapper<comprehensionType> generators; @@ -35,16 +36,10 @@ private final static String[] fields = new String[] {"elt", "generators"}; public String[] get_fields() { return fields; } - public ListComp(exprType elt, java.util.List<comprehensionType> generators) - { - this.elt = elt; - addChild(elt); - this.generators = new ListWrapper<comprehensionType>(generators); - if (generators != null) { - for(PythonTree t : generators) { - addChild(t); - } - } + public ListComp() {} + public ListComp(Object elt, Object generators) { + setElt(elt); + setGenerators(generators); } public ListComp(Token token, exprType elt, Modified: branches/astwrite/src/org/python/antlr/ast/Module.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Module.java 2008-11-24 02:48:33 UTC (rev 5627) +++ branches/astwrit... [truncated message content] |
From: <pj...@us...> - 2008-11-24 02:48:39
|
Revision: 5627 http://jython.svn.sourceforge.net/jython/?rev=5627&view=rev Author: pjenvey Date: 2008-11-24 02:48:33 +0000 (Mon, 24 Nov 2008) Log Message: ----------- disallow sublcassing a number of types fixes #1758319 Modified Paths: -------------- trunk/jython/Lib/test/test_bool.py trunk/jython/src/org/python/core/PyBoolean.java trunk/jython/src/org/python/core/PyCell.java trunk/jython/src/org/python/core/PyClassMethodDescr.java trunk/jython/src/org/python/core/PyDataDescr.java trunk/jython/src/org/python/core/PyDictProxy.java trunk/jython/src/org/python/core/PyEllipsis.java trunk/jython/src/org/python/core/PyFunction.java trunk/jython/src/org/python/core/PyGenerator.java trunk/jython/src/org/python/core/PyMethod.java trunk/jython/src/org/python/core/PyMethodDescr.java trunk/jython/src/org/python/core/PyNone.java trunk/jython/src/org/python/core/PyNotImplemented.java trunk/jython/src/org/python/core/PySlice.java trunk/jython/src/org/python/core/PySlot.java trunk/jython/src/org/python/core/PyTraceback.java trunk/jython/src/org/python/core/PyXRange.java trunk/jython/src/org/python/modules/PyTeeIterator.java trunk/jython/src/org/python/modules/_codecs.java trunk/jython/src/org/python/modules/_weakref/CallableProxyType.java trunk/jython/src/org/python/modules/_weakref/ProxyType.java trunk/jython/src/org/python/modules/operator.java trunk/jython/src/org/python/modules/time/PyTimeTuple.java Modified: trunk/jython/Lib/test/test_bool.py =================================================================== --- trunk/jython/Lib/test/test_bool.py 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/Lib/test/test_bool.py 2008-11-24 02:48:33 UTC (rev 5627) @@ -343,9 +343,6 @@ # StackOverflow if __nonzero__ returns self # http://jython.org/bugs/1758318 del BoolTest.test_convert_to_bool -# bool should not be subclassable -# http://jython.org/bugs/1758319 -del BoolTest.test_subclass def test_main(): test_support.run_unittest(BoolTest) Modified: trunk/jython/src/org/python/core/PyBoolean.java =================================================================== --- trunk/jython/src/org/python/core/PyBoolean.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyBoolean.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -1,7 +1,5 @@ package org.python.core; -import java.io.Serializable; - import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; import org.python.expose.ExposedType; @@ -10,7 +8,7 @@ /** * A builtin python bool. */ -@ExposedType(name = "bool") +@ExposedType(name = "bool", isBaseType = false) public class PyBoolean extends PyInteger { public static final PyType TYPE = PyType.fromClass(PyBoolean.class); Modified: trunk/jython/src/org/python/core/PyCell.java =================================================================== --- trunk/jython/src/org/python/core/PyCell.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyCell.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -10,7 +10,7 @@ * Cells are used to implement variables referenced by multiple * scopes. */ -@ExposedType(name = "cell") +@ExposedType(name = "cell", isBaseType = false) public class PyCell extends PyObject { /** The underlying content of the cell, or null. */ Modified: trunk/jython/src/org/python/core/PyClassMethodDescr.java =================================================================== --- trunk/jython/src/org/python/core/PyClassMethodDescr.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyClassMethodDescr.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -3,7 +3,7 @@ import org.python.expose.ExposedMethod; import org.python.expose.ExposedType; -@ExposedType(name = "classmethod_descriptor") +@ExposedType(name = "classmethod_descriptor", isBaseType = false) public class PyClassMethodDescr extends PyMethodDescr { public static final PyType TYPE = PyType.fromClass(PyClassMethodDescr.class); Modified: trunk/jython/src/org/python/core/PyDataDescr.java =================================================================== --- trunk/jython/src/org/python/core/PyDataDescr.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyDataDescr.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -12,7 +12,7 @@ * those methods, their respective implementsDescr* methods should be overriden * as well. */ -@ExposedType(name = "getset_descriptor", base = PyObject.class) +@ExposedType(name = "getset_descriptor", base = PyObject.class, isBaseType = false) public abstract class PyDataDescr extends PyDescriptor { protected Class ofType; Modified: trunk/jython/src/org/python/core/PyDictProxy.java =================================================================== --- trunk/jython/src/org/python/core/PyDictProxy.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyDictProxy.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -9,7 +9,7 @@ * Readonly proxy for dictionaries (actually any mapping). * */ -@ExposedType(name = "dictproxy") +@ExposedType(name = "dictproxy", isBaseType = false) public class PyDictProxy extends PyObject { /** The dict proxied to. */ Modified: trunk/jython/src/org/python/core/PyEllipsis.java =================================================================== --- trunk/jython/src/org/python/core/PyEllipsis.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyEllipsis.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -8,8 +8,7 @@ /** * A class representing the singleton Ellipsis <code>...</code> object. */ -// XXX: not subclassable -@ExposedType(name = "ellipsis", base = PyObject.class) +@ExposedType(name = "ellipsis", base = PyObject.class, isBaseType = false) public class PyEllipsis extends PySingleton implements Serializable { public static final PyType TYPE = PyType.fromClass(PyEllipsis.class); Modified: trunk/jython/src/org/python/core/PyFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyFunction.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyFunction.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -11,7 +11,7 @@ /** * A Python function. */ -@ExposedType(name = "function") +@ExposedType(name = "function", isBaseType = false) public class PyFunction extends PyObject { public static final PyType TYPE = PyType.fromClass(PyFunction.class); Modified: trunk/jython/src/org/python/core/PyGenerator.java =================================================================== --- trunk/jython/src/org/python/core/PyGenerator.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyGenerator.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -4,7 +4,7 @@ import org.python.expose.ExposedMethod; import org.python.expose.ExposedType; -@ExposedType(name="generator", base=PyObject.class) +@ExposedType(name = "generator", base = PyObject.class, isBaseType = false) public class PyGenerator extends PyIterator { @ExposedGet Modified: trunk/jython/src/org/python/core/PyMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyMethod.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyMethod.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -10,7 +10,7 @@ /** * A Python method. */ -@ExposedType(name = "instancemethod") +@ExposedType(name = "instancemethod", isBaseType = false) public class PyMethod extends PyObject { public static final PyType TYPE = PyType.fromClass(PyMethod.class); Modified: trunk/jython/src/org/python/core/PyMethodDescr.java =================================================================== --- trunk/jython/src/org/python/core/PyMethodDescr.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyMethodDescr.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -4,7 +4,7 @@ import org.python.expose.ExposedMethod; import org.python.expose.ExposedType; -@ExposedType(name = "method_descriptor", base = PyObject.class) +@ExposedType(name = "method_descriptor", base = PyObject.class, isBaseType = false) public class PyMethodDescr extends PyDescriptor implements PyBuiltinCallable.Info { protected int minargs, maxargs; Modified: trunk/jython/src/org/python/core/PyNone.java =================================================================== --- trunk/jython/src/org/python/core/PyNone.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyNone.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -9,8 +9,7 @@ /** * A class representing the singleton None object, */ -// XXX: not subclassable -@ExposedType(name = "NoneType") +@ExposedType(name = "NoneType", isBaseType = false) public class PyNone extends PyObject implements Serializable { Modified: trunk/jython/src/org/python/core/PyNotImplemented.java =================================================================== --- trunk/jython/src/org/python/core/PyNotImplemented.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyNotImplemented.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -2,6 +2,7 @@ import java.io.Serializable; +// XXX: isBaseType = false public class PyNotImplemented extends PySingleton implements Serializable { PyNotImplemented() { Modified: trunk/jython/src/org/python/core/PySlice.java =================================================================== --- trunk/jython/src/org/python/core/PySlice.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PySlice.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -9,7 +9,7 @@ /** * The Python slice object. */ -@ExposedType(name = "slice") +@ExposedType(name = "slice", isBaseType = false) public class PySlice extends PyObject { public static final PyType TYPE = PyType.fromClass(PySlice.class); Modified: trunk/jython/src/org/python/core/PySlot.java =================================================================== --- trunk/jython/src/org/python/core/PySlot.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PySlot.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -4,7 +4,7 @@ import org.python.expose.ExposedMethod; import org.python.expose.ExposedType; -@ExposedType(name = "member_descriptor", base = PyObject.class) +@ExposedType(name = "member_descriptor", base = PyObject.class, isBaseType = false) public class PySlot extends PyDescriptor { private int index; Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyTraceback.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -6,6 +6,7 @@ /** * A python traceback object. */ +// XXX: isBaseType = false public class PyTraceback extends PyObject { public PyObject tb_next; Modified: trunk/jython/src/org/python/core/PyXRange.java =================================================================== --- trunk/jython/src/org/python/core/PyXRange.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/core/PyXRange.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -8,8 +8,7 @@ /** * The builtin xrange type. */ -// XXX: Not subclassable -@ExposedType(name = "xrange", base = PyObject.class) +@ExposedType(name = "xrange", base = PyObject.class, isBaseType = false) public class PyXRange extends PySequence { public static final PyType TYPE = PyType.fromClass(PyXRange.class); Modified: trunk/jython/src/org/python/modules/PyTeeIterator.java =================================================================== --- trunk/jython/src/org/python/modules/PyTeeIterator.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/modules/PyTeeIterator.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -13,7 +13,7 @@ import org.python.expose.ExposedNew; import org.python.expose.ExposedType; -@ExposedType(name = "itertools.tee", base = PyObject.class) +@ExposedType(name = "itertools.tee", base = PyObject.class, isBaseType = false) public class PyTeeIterator extends PyIterator { private final int position; Modified: trunk/jython/src/org/python/modules/_codecs.java =================================================================== --- trunk/jython/src/org/python/modules/_codecs.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/modules/_codecs.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -650,7 +650,7 @@ * creating integer objects in the process. The trie is created by inverting the * encoding map. */ - @ExposedType(name = "EncodingMap") + @ExposedType(name = "EncodingMap", isBaseType = false) public static class EncodingMap extends PyObject { char[] level1; Modified: trunk/jython/src/org/python/modules/_weakref/CallableProxyType.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/CallableProxyType.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/modules/_weakref/CallableProxyType.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -9,8 +9,7 @@ /** * ProxyType with __call__. */ -// XXX: not subclassable -@ExposedType(name = "weakcallableproxy") +@ExposedType(name = "weakcallableproxy", isBaseType = false) public class CallableProxyType extends ProxyType { public static final PyType TYPE = PyType.fromClass(CallableProxyType.class); Modified: trunk/jython/src/org/python/modules/_weakref/ProxyType.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/ProxyType.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/modules/_weakref/ProxyType.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -1,10 +1,8 @@ /* Copyright (c) Jython Developers */ package org.python.modules._weakref; -import org.python.core.Py; import org.python.core.PyComplex; import org.python.core.PyFloat; -import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyType; @@ -13,8 +11,7 @@ /** * A weak reference proxy object. */ -// XXX: not subclassable -@ExposedType(name = "weakproxy") +@ExposedType(name = "weakproxy", isBaseType = false) public class ProxyType extends AbstractReference { public static final PyType TYPE = PyType.fromClass(ProxyType.class); Modified: trunk/jython/src/org/python/modules/operator.java =================================================================== --- trunk/jython/src/org/python/modules/operator.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/modules/operator.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -286,8 +286,7 @@ /** * The attrgetter type. */ - // XXX: not subclassable - @ExposedType(name = "operator.attrgetter") + @ExposedType(name = "operator.attrgetter", isBaseType = false) static class PyAttrGetter extends PyObject { public static final PyType TYPE = PyType.fromClass(PyAttrGetter.class); @@ -350,8 +349,7 @@ /** * The itemgetter type. */ - // XXX: not subclassable - @ExposedType(name = "operator.itemgetter") + @ExposedType(name = "operator.itemgetter", isBaseType = false) static class PyItemGetter extends PyObject { public static final PyType TYPE = PyType.fromClass(PyItemGetter.class); Modified: trunk/jython/src/org/python/modules/time/PyTimeTuple.java =================================================================== --- trunk/jython/src/org/python/modules/time/PyTimeTuple.java 2008-11-24 02:02:47 UTC (rev 5626) +++ trunk/jython/src/org/python/modules/time/PyTimeTuple.java 2008-11-24 02:48:33 UTC (rev 5627) @@ -3,11 +3,9 @@ import org.python.core.ArgParser; import org.python.core.Py; -import org.python.core.PyInteger; import org.python.core.PyList; import org.python.core.PyNewWrapper; import org.python.core.PyObject; -import org.python.core.PySequence; import org.python.core.PyTuple; import org.python.core.PyType; import org.python.expose.ExposedGet; @@ -20,7 +18,7 @@ * struct_time of the time module. * */ -@ExposedType(name = "time.struct_time") +@ExposedType(name = "time.struct_time", isBaseType = false) public class PyTimeTuple extends PyTuple { @ExposedGet This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Philip J. <pj...@un...> - 2008-11-24 02:05:26
|
Begin forwarded message: > Revision: 5626 > http://jython.svn.sourceforge.net/jython/?rev=5626&view=rev > Author: pjenvey > Date: 2008-11-24 02:02:47 +0000 (Mon, 24 Nov 2008) > > Log Message: > ----------- > add an isBaseType flag to @ExposedType for toggling whether types are > subclassable. disallow subclassing of builtin_function_or_method > (fixes > test_descr.errors). note that this requires an ant clean > refs #1758319 Heads up: You'll need to run an ant clean after updating to this revision. -- Philip Jenvey |
From: <pj...@us...> - 2008-11-24 02:02:51
|
Revision: 5626 http://jython.svn.sourceforge.net/jython/?rev=5626&view=rev Author: pjenvey Date: 2008-11-24 02:02:47 +0000 (Mon, 24 Nov 2008) Log Message: ----------- add an isBaseType flag to @ExposedType for toggling whether types are subclassable. disallow subclassing of builtin_function_or_method (fixes test_descr.errors). note that this requires an ant clean refs #1758319 Modified Paths: -------------- trunk/jython/Lib/test/test_descr.py trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyBuiltinCallable.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/expose/BaseTypeBuilder.java trunk/jython/src/org/python/expose/ExposedType.java trunk/jython/src/org/python/expose/TypeBuilder.java trunk/jython/src/org/python/expose/generate/ExposedTypeProcessor.java trunk/jython/src/org/python/expose/generate/ExposedTypeVisitor.java trunk/jython/src/org/python/expose/generate/TypeExposer.java trunk/jython/tests/java/org/python/expose/generate/ExposedTypeVisitorTest.java trunk/jython/tests/java/org/python/expose/generate/SimpleExposed.java trunk/jython/tests/java/org/python/expose/generate/TypeExposerTest.java Modified: trunk/jython/Lib/test/test_descr.py =================================================================== --- trunk/jython/Lib/test/test_descr.py 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/Lib/test/test_descr.py 2008-11-24 02:02:47 UTC (rev 5626) @@ -4404,11 +4404,6 @@ classmethods_in_c, staticmethods_in_c, - # Jython allows subclassing of classes it shouldn't (like - # builtin_function_or_method): - # http://bugs.jython.org/issue1758319 - errors, - # CPython's unicode.__cmp__ is derived from type (and only # takes 1 arg) specials, Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/core/Py.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -82,7 +82,9 @@ /** A Python string containing ' ' **/ public static PyString Space; /** Set if the type object is dynamically allocated */ - public static long TPFLAGS_HEAPTYPE; + public static long TPFLAGS_HEAPTYPE = 1L << 9; + /** Set if the type allows subclassing */ + public static long TPFLAGS_BASETYPE = 1L << 10; /** Builtin types that are used to setup PyObject. */ static final Set<Class> BOOTSTRAP_TYPES = new HashSet<Class>(4); Modified: trunk/jython/src/org/python/core/PyBuiltinCallable.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinCallable.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/core/PyBuiltinCallable.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -3,8 +3,7 @@ import org.python.expose.ExposedGet; import org.python.expose.ExposedType; -// XXX: not subclassable -@ExposedType(name = "builtin_function_or_method") +@ExposedType(name = "builtin_function_or_method", isBaseType = false) public abstract class PyBuiltinCallable extends PyObject { protected Info info; Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -589,8 +589,6 @@ Py.Newline = new PyString("\n"); Py.Space = new PyString(" "); - Py.TPFLAGS_HEAPTYPE = (1L<<9); - // Setup standard wrappers for stdout and stderr... Py.stderr = new StderrWrapper(); Py.stdout = new StdoutWrapper(); Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/core/PyType.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -58,6 +58,9 @@ boolean has_set; boolean has_delete; + /** Whether this type allows subclassing. */ + private boolean isBaseType = true; + /** Whether finalization is required for this type's instances (implements __del__). */ private boolean needs_finalizer; @@ -134,7 +137,6 @@ bases_list = new PyObject[] {object_type}; } - // XXX can be subclassed ? if (dict.__finditem__("__module__") == null) { PyFrame frame = Py.getFrame(); if (frame != null) { @@ -164,6 +166,11 @@ newtype.numSlots = newtype.base.numSlots; newtype.bases = bases_list; + if (!newtype.base.isBaseType) { + throw Py.TypeError(String.format("type '%.100s' is not an acceptable base type", + newtype.base.name)); + } + PyObject slots = dict.__finditem__("__slots__"); boolean needsDictDescr = false; if (slots == null) { @@ -209,7 +216,7 @@ } } - newtype.tp_flags = Py.TPFLAGS_HEAPTYPE; + newtype.tp_flags = Py.TPFLAGS_HEAPTYPE | Py.TPFLAGS_BASETYPE; // special case __new__, if function => static method PyObject tmp = dict.__finditem__("__new__"); @@ -420,6 +427,11 @@ } + private void setIsBaseType(boolean isBaseType) { + this.isBaseType = isBaseType; + tp_flags = isBaseType ? tp_flags | Py.TPFLAGS_BASETYPE : tp_flags & ~Py.TPFLAGS_BASETYPE; + } + private void mro_internal() { if (getType() == TYPE) { mro = compute_mro(); @@ -891,6 +903,7 @@ PyType objType = fromClass(builder.getTypeClass()); objType.name = builder.getName(); objType.dict = builder.getDict(objType); + objType.setIsBaseType(builder.getIsBaseType()); Class<?> base = builder.getBase(); if (base == Object.class) { base = forClass.getSuperclass(); @@ -907,17 +920,19 @@ return exposedAs; } Class<?> base = null; + boolean isBaseType = true; String name = null; TypeBuilder tb = getBuilder(c); if (tb != null) { name = tb.getName(); + isBaseType = tb.getIsBaseType(); if (!tb.getBase().equals(Object.class)) { base = tb.getBase(); } } PyType type = class_to_type.get(c); if (type == null) { - type = createType(c, base, name); + type = createType(c, base, name, isBaseType); } return type; } @@ -926,7 +941,7 @@ return classToBuilder == null ? null : classToBuilder.get(c); } - private static PyType createType(Class<?> c, Class<?> base, String name) { + private static PyType createType(Class<?> c, Class<?> base, String name, boolean isBaseType) { PyType newtype; if (c == PyType.class) { newtype = new PyType(false); @@ -955,6 +970,7 @@ newtype.name = name; newtype.underlying_class = c; newtype.builtin = true; + newtype.setIsBaseType(isBaseType); fillInMRO(newtype, base); // basic mro, base, bases newtype.fillDict(); return newtype; Modified: trunk/jython/src/org/python/expose/BaseTypeBuilder.java =================================================================== --- trunk/jython/src/org/python/expose/BaseTypeBuilder.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/expose/BaseTypeBuilder.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -22,14 +22,18 @@ private String name; + private boolean isBaseType; + public BaseTypeBuilder(String name, Class typeClass, Class baseClass, + boolean isBaseType, PyBuiltinMethod[] meths, PyDataDescr[] descrs, PyNewWrapper newWrapper) { this.typeClass = typeClass; this.baseClass = baseClass; + this.isBaseType = isBaseType; this.name = name; this.descrs = descrs; this.meths = meths; @@ -64,4 +68,8 @@ public Class getBase() { return baseClass; } -} \ No newline at end of file + + public boolean getIsBaseType() { + return isBaseType; + } +} Modified: trunk/jython/src/org/python/expose/ExposedType.java =================================================================== --- trunk/jython/src/org/python/expose/ExposedType.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/expose/ExposedType.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -26,4 +26,9 @@ * unspecified, the base is set to object, or PyObject.class. */ Class base() default Object.class; + + /** + * @return Whether this type allows subclassing. + */ + boolean isBaseType() default true; } Modified: trunk/jython/src/org/python/expose/TypeBuilder.java =================================================================== --- trunk/jython/src/org/python/expose/TypeBuilder.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/expose/TypeBuilder.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -15,4 +15,6 @@ public Class getTypeClass(); public Class getBase(); + + public boolean getIsBaseType(); } Modified: trunk/jython/src/org/python/expose/generate/ExposedTypeProcessor.java =================================================================== --- trunk/jython/src/org/python/expose/generate/ExposedTypeProcessor.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/expose/generate/ExposedTypeProcessor.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -109,6 +109,8 @@ private Type baseType = OBJECT; + private boolean isBaseType = true; + private boolean generatedStaticBlock; private TypeProcessor(ClassVisitor cv) { @@ -140,6 +142,10 @@ public void handleResult(Type base) { baseType = base; } + + public void handleResult(boolean boolIsBaseType) { + isBaseType = boolIsBaseType; + } }; } return super.visitAnnotation(desc, visible); @@ -158,6 +164,7 @@ } typeExposer = new TypeExposer(onType, baseType, + isBaseType, getName(), methodExposers, descExposers.values(), Modified: trunk/jython/src/org/python/expose/generate/ExposedTypeVisitor.java =================================================================== --- trunk/jython/src/org/python/expose/generate/ExposedTypeVisitor.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/expose/generate/ExposedTypeVisitor.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -13,6 +13,8 @@ private Type base = Type.getType(Object.class); + private boolean isBaseType = true; + public ExposedTypeVisitor(Type onType) { this.onType = onType; } @@ -23,6 +25,8 @@ typeName = (String)value; } else if(name.equals("base")) { base = (Type)value; + } else if(name.equals("isBaseType")) { + isBaseType = (Boolean)value; } else { super.visit(name, value); } @@ -36,10 +40,13 @@ } handleResult(typeName); handleResult(base); + handleResult(isBaseType); } public abstract void handleResult(Type base); + public abstract void handleResult(boolean isBaseType); + /** * @param name - * the name the type should be exposed as from the annotation. Modified: trunk/jython/src/org/python/expose/generate/TypeExposer.java =================================================================== --- trunk/jython/src/org/python/expose/generate/TypeExposer.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/src/org/python/expose/generate/TypeExposer.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -18,6 +18,8 @@ private Type baseType; + private boolean isBaseType; + private Type onType; private String name; @@ -32,12 +34,14 @@ public TypeExposer(Type onType, Type baseType, + boolean isBaseType, String name, Collection<MethodExposer> methods, Collection<DescriptorExposer> descriptors, Exposer ne) { super(BaseTypeBuilder.class, makeGeneratedName(onType)); this.baseType = baseType; + this.isBaseType = isBaseType; this.onType = onType; this.name = name; this.methods = methods; @@ -101,6 +105,7 @@ mv.visitLdcInsn(getName()); mv.visitLdcInsn(onType); mv.visitLdcInsn(baseType); + mv.visitLdcInsn(isBaseType); mv.visitLdcInsn(numNames); mv.visitTypeInsn(ANEWARRAY, BUILTIN_METHOD.getInternalName()); mv.visitVarInsn(ASTORE, 1); @@ -135,7 +140,8 @@ } else { mv.visitInsn(ACONST_NULL); } - superConstructor(STRING, CLASS, CLASS, ABUILTIN_METHOD, ADATA_DESCR, PYNEWWRAPPER); + superConstructor(STRING, CLASS, CLASS, BOOLEAN, ABUILTIN_METHOD, ADATA_DESCR, + PYNEWWRAPPER); endConstructor(); } } Modified: trunk/jython/tests/java/org/python/expose/generate/ExposedTypeVisitorTest.java =================================================================== --- trunk/jython/tests/java/org/python/expose/generate/ExposedTypeVisitorTest.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/tests/java/org/python/expose/generate/ExposedTypeVisitorTest.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -20,6 +20,11 @@ public void handleResult(Type base) { baseResult = base; } + + @Override + public void handleResult(boolean isBaseType) { + isBaseTypeResult = isBaseType; + } }; } @@ -32,9 +37,11 @@ public void testNamedType() { etv.visit("name", "different"); etv.visit("base", Type.getType(PyObject.class)); + etv.visit("isBaseType", false); etv.visitEnd(); assertEquals("different", result); assertEquals(Type.getType(PyObject.class), baseResult); + assertEquals(false, isBaseTypeResult); } ExposedTypeVisitor etv; @@ -42,4 +49,6 @@ private String result; private Type baseResult; + + private boolean isBaseTypeResult; } Modified: trunk/jython/tests/java/org/python/expose/generate/SimpleExposed.java =================================================================== --- trunk/jython/tests/java/org/python/expose/generate/SimpleExposed.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/tests/java/org/python/expose/generate/SimpleExposed.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -15,7 +15,7 @@ import org.python.expose.ExposedType; import org.python.expose.MethodType; -@ExposedType(name = "simpleexposed") +@ExposedType(name = "simpleexposed", isBaseType = false) public class SimpleExposed extends PyObject { public void method() {} @@ -145,4 +145,4 @@ public String toStringVal = TO_STRING_RETURN; public static final String TO_STRING_RETURN = "A simple test class"; -} \ No newline at end of file +} Modified: trunk/jython/tests/java/org/python/expose/generate/TypeExposerTest.java =================================================================== --- trunk/jython/tests/java/org/python/expose/generate/TypeExposerTest.java 2008-11-24 01:57:05 UTC (rev 5625) +++ trunk/jython/tests/java/org/python/expose/generate/TypeExposerTest.java 2008-11-24 02:02:47 UTC (rev 5626) @@ -22,6 +22,7 @@ TypeBuilder t = etp.getTypeExposer().makeBuilder(); assertEquals("simpleexposed", t.getName()); assertEquals(SimpleExposed.class, t.getTypeClass()); + assertEquals(false, t.getIsBaseType()); PyType type = PyType.fromClass(SimpleExposed.class); PyObject dict = t.getDict(type); assertNotNull(dict.__finditem__("simple_method")); @@ -36,6 +37,7 @@ ExposedTypeProcessor etp = new ExposedTypeProcessor(getClass().getClassLoader() .getResourceAsStream("org/python/expose/generate/TypeExposerTest$SimplestNew.class")); TypeBuilder te = etp.getTypeExposer().makeBuilder(); + assertEquals(true, te.getIsBaseType()); PyObject new_ = te.getDict(PyType.fromClass(SimplestNew.class)).__finditem__("__new__"); assertEquals(Py.One, new_.__call__(PyType.fromClass(SimplestNew.class))); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-11-24 01:57:08
|
Revision: 5625 http://jython.svn.sourceforge.net/jython/?rev=5625&view=rev Author: cgroves Date: 2008-11-24 01:57:05 +0000 (Mon, 24 Nov 2008) Log Message: ----------- Don't strip the package out of wrapped Java types Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/PyType.java Modified: branches/newstyle-java-types/src/org/python/core/PyType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyType.java 2008-11-24 00:00:42 UTC (rev 5624) +++ branches/newstyle-java-types/src/org/python/core/PyType.java 2008-11-24 01:57:05 UTC (rev 5625) @@ -962,13 +962,14 @@ if (base == null) { base = c.getSuperclass(); } + newtype.underlying_class = c; if (name == null) { name = c.getName(); // Strip the java fully qualified class name (specifically remove org.python.core.Py or // fallback to stripping to the last dot) if (name.startsWith("org.python.core.Py")) { name = name.substring("org.python.core.Py".length()).toLowerCase(); - } else { + } else if(newtype.getProxyType() == null) { int lastDot = name.lastIndexOf('.'); if (lastDot != -1) { name = name.substring(lastDot + 1); @@ -976,7 +977,6 @@ } } newtype.name = name; - newtype.underlying_class = c; newtype.builtin = true; fillInMRO(newtype, base); // basic mro, base, bases newtype.fillDict(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-24 00:00:44
|
Revision: 5624 http://jython.svn.sourceforge.net/jython/?rev=5624&view=rev Author: fwierzbicki Date: 2008-11-24 00:00:42 +0000 (Mon, 24 Nov 2008) Log Message: ----------- Test for basic eval from a bare PythonInterpreter (was throwing an NPE) see http://bugs.jython.org/issue1174. Added Paths: ----------- trunk/jython/tests/java/org/python/util/ trunk/jython/tests/java/org/python/util/InterpreterTest.java Added: trunk/jython/tests/java/org/python/util/InterpreterTest.java =================================================================== --- trunk/jython/tests/java/org/python/util/InterpreterTest.java (rev 0) +++ trunk/jython/tests/java/org/python/util/InterpreterTest.java 2008-11-24 00:00:42 UTC (rev 5624) @@ -0,0 +1,22 @@ +package org.python.util; + +import junit.framework.TestCase; + +import org.python.core.*; +import org.python.util.*; + +public class InterpreterTest extends TestCase { + + /** + * Motivated by a NPE reported on http://bugs.jython.org/issue1174. + */ + public void testBasicEval() throws Exception { + PyDictionary test = new PyDictionary(); + test.__setitem__(new PyUnicode("one"), new PyUnicode("two")); + PythonInterpreter.initialize(System.getProperties(), null, new +String[] {}); + PythonInterpreter interp = new PythonInterpreter(); + PyObject pyo = interp.eval("{u'one': u'two'}"); + assertEquals(test, pyo); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |