From: <fwi...@us...> - 2009-01-05 13:16:51
|
Revision: 5848 http://jython.svn.sourceforge.net/jython/?rev=5848&view=rev Author: fwierzbicki Date: 2009-01-05 13:16:44 +0000 (Mon, 05 Jan 2009) Log Message: ----------- Initial switchover to 3.0 Python.asdl. Doesn't compiler yet. Modified Paths: -------------- branches/jy3k/ast/Python.asdl branches/jy3k/grammar/Python.g branches/jy3k/grammar/PythonPartial.g branches/jy3k/src/org/python/antlr/ast/ClassDef.java branches/jy3k/src/org/python/antlr/ast/Ellipsis.java branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java branches/jy3k/src/org/python/antlr/ast/FunctionDef.java branches/jy3k/src/org/python/antlr/ast/Raise.java branches/jy3k/src/org/python/antlr/ast/VisitorBase.java branches/jy3k/src/org/python/antlr/ast/VisitorIF.java branches/jy3k/src/org/python/antlr/ast/arguments.java Added Paths: ----------- branches/jy3k/src/org/python/antlr/ast/Bytes.java branches/jy3k/src/org/python/antlr/ast/DictComp.java branches/jy3k/src/org/python/antlr/ast/Nonlocal.java branches/jy3k/src/org/python/antlr/ast/Set.java branches/jy3k/src/org/python/antlr/ast/SetComp.java branches/jy3k/src/org/python/antlr/ast/Starred.java branches/jy3k/src/org/python/antlr/ast/arg.java Removed Paths: ------------- branches/jy3k/src/org/python/antlr/ast/Exec.java branches/jy3k/src/org/python/antlr/ast/Print.java branches/jy3k/src/org/python/antlr/ast/Repr.java Modified: branches/jy3k/ast/Python.asdl =================================================================== --- branches/jy3k/ast/Python.asdl 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/ast/Python.asdl 2009-01-05 13:16:44 UTC (rev 5848) @@ -1,6 +1,6 @@ --- ASDL's five builtin types are identifier, int, string, object, bool +-- ASDL's four builtin types are identifier, int, string, object -module Python version "$Revision: 62047 $" +module Python version "$Revision: 67616 $" { mod = Module(stmt* body) | Interactive(stmt* body) @@ -10,26 +10,27 @@ | Suite(stmt* body) stmt = FunctionDef(identifier name, arguments args, - stmt* body, expr* decorator_list) - | ClassDef(identifier name, expr* bases, stmt* body, expr *decorator_list) + stmt* body, expr* decorator_list, expr? returns) + | ClassDef(identifier name, + expr* bases, + keyword* keywords, + expr? starargs, + expr? kwargs, + stmt* body, + expr *decorator_list) | Return(expr? value) | Delete(expr* targets) | Assign(expr* targets, expr value) | AugAssign(expr target, operator op, expr value) - -- not sure if bool is allowed, can always use int - | Print(expr? dest, expr* values, bool nl) - -- use 'orelse' because else is a keyword in target languages | For(expr target, expr iter, stmt* body, stmt* orelse) | While(expr test, stmt* body, stmt* orelse) | If(expr test, stmt* body, stmt* orelse) | 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) + | Raise(expr? exc, expr? cause) | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse) | TryFinally(stmt* body, stmt* finalbody) | Assert(expr test, expr? msg) @@ -37,12 +38,8 @@ | Import(alias* names) | ImportFrom(identifier module, alias* names, int? level) - -- Doesn't capture requirement that locals must be - -- defined if globals is - -- still supports use as a function! - | Exec(expr body, expr? globals, expr? locals) - | Global(identifier* names) + | Nonlocal(identifier* names) | Expr(expr value) | Pass | Break | Continue @@ -57,7 +54,10 @@ | Lambda(arguments args, expr body) | IfExp(expr test, expr body, expr orelse) | Dict(expr* keys, expr* values) + | Set(expr* elts) | ListComp(expr elt, comprehension* generators) + | SetComp(expr elt, comprehension* generators) + | DictComp(expr key, expr value, comprehension* generators) | GeneratorExp(expr elt, comprehension* generators) -- the grammar constrains where yield expressions can occur | Yield(expr? value) @@ -66,14 +66,16 @@ | Compare(expr left, cmpop* ops, expr* comparators) | Call(expr func, expr* args, keyword* keywords, expr? starargs, expr? kwargs) - | Repr(expr value) | Num(object n) -- a number as a PyObject. | Str(string s) -- need to specify raw, unicode, etc? + | Bytes(string s) + | Ellipsis -- other literals? bools? -- the following expression can appear in assignment context | Attribute(expr value, identifier attr, expr_context ctx) | Subscript(expr value, slice slice, expr_context ctx) + | Starred(expr value, expr_context ctx) | Name(identifier id, expr_context ctx) | List(expr* elts, expr_context ctx) | Tuple(expr* elts, expr_context ctx) @@ -83,7 +85,7 @@ expr_context = Load | Store | Del | AugLoad | AugStore | Param - slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step) + slice = Slice(expr? lower, expr? upper, expr? step) | ExtSlice(slice* dims) | Index(expr value) @@ -100,11 +102,14 @@ -- not sure what to call the first argument for raise and except -- changed to 'type' to excepttype for Jython - excepthandler = ExceptHandler(expr? excepttype, expr? name, stmt* body) + excepthandler = ExceptHandler(expr? excepttype, identifier? name, stmt* body) attributes (int lineno, int col_offset) - arguments = (expr* args, identifier? vararg, - identifier? kwarg, expr* defaults) + arguments = (arg* args, identifier? vararg, expr? varargannotation, + arg* kwonlyargs, identifier? kwarg, + expr? kwargannotation, expr* defaults, + expr* kw_defaults) + arg = (identifier arg, expr? annotation) -- keyword arguments supplied to call keyword = (identifier arg, expr value) @@ -112,3 +117,4 @@ -- import name with optional 'as' alias. alias = (identifier name, identifier? asname) } + Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/grammar/Python.g 2009-01-05 13:16:44 UTC (rev 5848) @@ -105,7 +105,6 @@ import org.python.antlr.ast.Ellipsis; import org.python.antlr.ast.ErrorMod; import org.python.antlr.ast.ExceptHandler; -import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; import org.python.antlr.ast.Expression; import org.python.antlr.ast.expr_contextType; @@ -127,7 +126,6 @@ import org.python.antlr.ast.Num; import org.python.antlr.ast.operatorType; import org.python.antlr.ast.Pass; -import org.python.antlr.ast.Print; import org.python.antlr.ast.Raise; import org.python.antlr.ast.Repr; import org.python.antlr.ast.Return; @@ -393,7 +391,6 @@ | OR | ORELSE | PASS - | PRINT | RAISE | RETURN | TRY @@ -545,13 +542,11 @@ //small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | // import_stmt | global_stmt | exec_stmt | assert_stmt) small_stmt : expr_stmt - | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt - | exec_stmt | assert_stmt ; @@ -615,60 +610,6 @@ | DOUBLESLASHEQUAL {$op = operatorType.FloorDiv;} ; -//print_stmt: 'print' ( [ test (',' test)* [','] ] | -// '>>' test [ (',' test)+ [','] ] ) -print_stmt - : PRINT - (t1=printlist - -> ^(PRINT<Print>[$PRINT, null, actions.castExprs($t1.elts), $t1.newline]) - | RIGHTSHIFT t2=printlist2 - -> ^(PRINT<Print>[$PRINT, actions.castExpr($t2.elts.get(0)), actions.castExprs($t2.elts, 1), $t2.newline]) - | - -> ^(PRINT<Print>[$PRINT, null, new ArrayList<expr>(), false]) - ) - ; - -//not in CPython's Grammar file -printlist returns [boolean newline, List elts] - : (test[null] COMMA) => - t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* - (trailcomma=COMMA)? - { - $elts=$t; - if ($trailcomma == null) { - $newline = true; - } else { - $newline = false; - } - } - | t+=test[expr_contextType.Load] - { - $elts=$t; - $newline = true; - } - ; - -//XXX: would be nice if printlist and printlist2 could be merged. -//not in CPython's Grammar file -printlist2 returns [boolean newline, List elts] - : (test[null] COMMA test[null]) => - t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* - (trailcomma=COMMA)? - { $elts=$t; - if ($trailcomma == null) { - $newline = true; - } else { - $newline = false; - } - } - | t+=test[expr_contextType.Load] - { - $elts=$t; - $newline = true; - } - ; - - //del_stmt: 'del' exprlist del_stmt : DELETE del_list @@ -807,21 +748,6 @@ -> ^(GLOBAL<Global>[$GLOBAL, actions.makeNames($n)]) ; -//exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt -@init { - stmt stype = null; -} -@after { - $exec_stmt.tree = stype; -} - : EXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] - (COMMA t2=test[expr_contextType.Load])?)? - { - stype = new Exec($EXEC, actions.castExpr($expr.tree), actions.castExpr($t1.tree), actions.castExpr($t2.tree)); - } - ; - //assert_stmt: 'assert' test [',' test] assert_stmt : ASSERT t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])? @@ -1619,7 +1545,6 @@ LAMBDA : 'lambda' ; ORELSE : 'else' ; PASS : 'pass' ; -PRINT : 'print' ; RAISE : 'raise' ; RETURN : 'return' ; TRY : 'try' ; Modified: branches/jy3k/grammar/PythonPartial.g =================================================================== --- branches/jy3k/grammar/PythonPartial.g 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/grammar/PythonPartial.g 2009-01-05 13:16:44 UTC (rev 5848) @@ -152,13 +152,11 @@ ; small_stmt : expr_stmt - | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt - | exec_stmt | assert_stmt ; @@ -196,13 +194,6 @@ | DOUBLESLASHEQUAL ; -print_stmt : PRINT (printlist | RIGHTSHIFT printlist)? - ; - -printlist returns [boolean newline] - : test (options {k=2;}: COMMA test)* (COMMA)? - ; - del_stmt : DELETE exprlist ; @@ -262,9 +253,6 @@ global_stmt : GLOBAL NAME (COMMA NAME)* ; -exec_stmt : EXEC expr (IN test (COMMA test)?)? - ; - assert_stmt : ASSERT test (COMMA test)? ; Added: branches/jy3k/src/org/python/antlr/ast/Bytes.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/Bytes.java (rev 0) +++ branches/jy3k/src/org/python/antlr/ast/Bytes.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -0,0 +1,147 @@ +// Autogenerated AST node +package org.python.antlr.ast; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.Token; +import org.python.antlr.AST; +import org.python.antlr.PythonTree; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.base.excepthandler; +import org.python.antlr.base.expr; +import org.python.antlr.base.mod; +import org.python.antlr.base.slice; +import org.python.antlr.base.stmt; +import org.python.core.ArgParser; +import org.python.core.AstList; +import org.python.core.Py; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyType; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; + +@ExposedType(name = "_ast.Bytes", base = AST.class) +public class Bytes extends expr { +public static final PyType TYPE = PyType.fromClass(Bytes.class); + private Object s; + public Object getInternalS() { + return s; + } + @ExposedGet(name = "s") + public PyObject getS() { + return (PyObject)s; + } + @ExposedSet(name = "s") + public void setS(PyObject s) { + this.s = AstAdapters.py2string(s); + } + + + private final static PyString[] fields = + new PyString[] {new PyString("s")}; + @ExposedGet(name = "_fields") + public PyString[] get_fields() { return fields; } + + private final static PyString[] attributes = + new PyString[] {new PyString("lineno"), new PyString("col_offset")}; + @ExposedGet(name = "_attributes") + public PyString[] get_attributes() { return attributes; } + + public Bytes(PyType subType) { + super(subType); + } + public Bytes() { + this(TYPE); + } + @ExposedNew + @ExposedMethod + public void Bytes___init__(PyObject[] args, String[] keywords) { + ArgParser ap = new ArgParser("Bytes", args, keywords, new String[] + {"s", "lineno", "col_offset"}, 1); + setS(ap.getPyObject(0)); + int lin = ap.getInt(1, -1); + if (lin != -1) { + setLineno(lin); + } + + int col = ap.getInt(2, -1); + if (col != -1) { + setLineno(col); + } + + } + + public Bytes(PyObject s) { + setS(s); + } + + public Bytes(Token token, Object s) { + super(token); + this.s = s; + } + + public Bytes(Integer ttype, Token token, Object s) { + super(ttype, token); + this.s = s; + } + + public Bytes(PythonTree tree, Object s) { + super(tree); + this.s = s; + } + + @ExposedGet(name = "repr") + public String toString() { + return "Bytes"; + } + + public String toStringTree() { + StringBuffer sb = new StringBuffer("Bytes("); + sb.append("s="); + sb.append(dumpThis(s)); + sb.append(","); + sb.append(")"); + return sb.toString(); + } + + public <R> R accept(VisitorIF<R> visitor) throws Exception { + return visitor.visitBytes(this); + } + + public void traverse(VisitorIF visitor) throws Exception { + } + + private int lineno = -1; + @ExposedGet(name = "lineno") + public int getLineno() { + if (lineno != -1) { + return lineno; + } + return getLine(); + } + + @ExposedSet(name = "lineno") + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; + @ExposedGet(name = "col_offset") + public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } + return getCharPositionInLine(); + } + + @ExposedSet(name = "col_offset") + public void setCol_offset(int num) { + col_offset = num; + } + +} Modified: branches/jy3k/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/ClassDef.java 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/src/org/python/antlr/ast/ClassDef.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -55,6 +55,45 @@ this.bases = AstAdapters.py2exprList(bases); } + private java.util.List<keyword> keywords; + public java.util.List<keyword> getInternalKeywords() { + return keywords; + } + @ExposedGet(name = "keywords") + public PyObject getKeywords() { + return new AstList(keywords, AstAdapters.keywordAdapter); + } + @ExposedSet(name = "keywords") + public void setKeywords(PyObject keywords) { + this.keywords = AstAdapters.py2keywordList(keywords); + } + + private expr starargs; + public expr getInternalStarargs() { + return starargs; + } + @ExposedGet(name = "starargs") + public PyObject getStarargs() { + return starargs; + } + @ExposedSet(name = "starargs") + public void setStarargs(PyObject starargs) { + this.starargs = AstAdapters.py2expr(starargs); + } + + private expr kwargs; + public expr getInternalKwargs() { + return kwargs; + } + @ExposedGet(name = "kwargs") + public PyObject getKwargs() { + return kwargs; + } + @ExposedSet(name = "kwargs") + public void setKwargs(PyObject kwargs) { + this.kwargs = AstAdapters.py2expr(kwargs); + } + private java.util.List<stmt> body; public java.util.List<stmt> getInternalBody() { return body; @@ -83,7 +122,8 @@ private final static PyString[] fields = - new PyString[] {new PyString("name"), new PyString("bases"), new PyString("body"), new + new PyString[] {new PyString("name"), new PyString("bases"), new PyString("keywords"), new + PyString("starargs"), new PyString("kwargs"), new PyString("body"), new PyString("decorator_list")}; @ExposedGet(name = "_fields") public PyString[] get_fields() { return fields; } @@ -103,32 +143,41 @@ @ExposedMethod public void ClassDef___init__(PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("ClassDef", args, keywords, new String[] - {"name", "bases", "body", "decorator_list", "lineno", "col_offset"}, 4); + {"name", "bases", "keywords", "starargs", "kwargs", "body", "decorator_list", "lineno", + "col_offset"}, 7); setName(ap.getPyObject(0)); setBases(ap.getPyObject(1)); - setBody(ap.getPyObject(2)); - setDecorator_list(ap.getPyObject(3)); - int lin = ap.getInt(4, -1); + setKeywords(ap.getPyObject(2)); + setStarargs(ap.getPyObject(3)); + setKwargs(ap.getPyObject(4)); + setBody(ap.getPyObject(5)); + setDecorator_list(ap.getPyObject(6)); + int lin = ap.getInt(7, -1); if (lin != -1) { setLineno(lin); } - int col = ap.getInt(5, -1); + int col = ap.getInt(8, -1); if (col != -1) { setLineno(col); } } - public ClassDef(PyObject name, PyObject bases, PyObject body, PyObject decorator_list) { + public ClassDef(PyObject name, PyObject bases, PyObject keywords, PyObject starargs, PyObject + kwargs, PyObject body, PyObject decorator_list) { setName(name); setBases(bases); + setKeywords(keywords); + setStarargs(starargs); + setKwargs(kwargs); setBody(body); setDecorator_list(decorator_list); } - public ClassDef(Token token, String name, java.util.List<expr> bases, java.util.List<stmt> - body, java.util.List<expr> decorator_list) { + public ClassDef(Token token, String name, java.util.List<expr> bases, java.util.List<keyword> + keywords, expr starargs, expr kwargs, java.util.List<stmt> body, java.util.List<expr> + decorator_list) { super(token); this.name = name; this.bases = bases; @@ -138,6 +187,17 @@ for(PythonTree t : this.bases) { addChild(t); } + this.keywords = keywords; + if (keywords == null) { + this.keywords = new ArrayList<keyword>(); + } + for(PythonTree t : this.keywords) { + addChild(t); + } + this.starargs = starargs; + addChild(starargs); + this.kwargs = kwargs; + addChild(kwargs); this.body = body; if (body == null) { this.body = new ArrayList<stmt>(); @@ -155,7 +215,8 @@ } public ClassDef(Integer ttype, Token token, String name, java.util.List<expr> bases, - java.util.List<stmt> body, java.util.List<expr> decorator_list) { + java.util.List<keyword> keywords, expr starargs, expr kwargs, java.util.List<stmt> body, + java.util.List<expr> decorator_list) { super(ttype, token); this.name = name; this.bases = bases; @@ -165,6 +226,17 @@ for(PythonTree t : this.bases) { addChild(t); } + this.keywords = keywords; + if (keywords == null) { + this.keywords = new ArrayList<keyword>(); + } + for(PythonTree t : this.keywords) { + addChild(t); + } + this.starargs = starargs; + addChild(starargs); + this.kwargs = kwargs; + addChild(kwargs); this.body = body; if (body == null) { this.body = new ArrayList<stmt>(); @@ -181,8 +253,9 @@ } } - public ClassDef(PythonTree tree, String name, java.util.List<expr> bases, java.util.List<stmt> - body, java.util.List<expr> decorator_list) { + public ClassDef(PythonTree tree, String name, java.util.List<expr> bases, + java.util.List<keyword> keywords, expr starargs, expr kwargs, java.util.List<stmt> body, + java.util.List<expr> decorator_list) { super(tree); this.name = name; this.bases = bases; @@ -192,6 +265,17 @@ for(PythonTree t : this.bases) { addChild(t); } + this.keywords = keywords; + if (keywords == null) { + this.keywords = new ArrayList<keyword>(); + } + for(PythonTree t : this.keywords) { + addChild(t); + } + this.starargs = starargs; + addChild(starargs); + this.kwargs = kwargs; + addChild(kwargs); this.body = body; if (body == null) { this.body = new ArrayList<stmt>(); @@ -221,6 +305,15 @@ sb.append("bases="); sb.append(dumpThis(bases)); sb.append(","); + sb.append("keywords="); + sb.append(dumpThis(keywords)); + sb.append(","); + sb.append("starargs="); + sb.append(dumpThis(starargs)); + sb.append(","); + sb.append("kwargs="); + sb.append(dumpThis(kwargs)); + sb.append(","); sb.append("body="); sb.append(dumpThis(body)); sb.append(","); @@ -242,6 +335,16 @@ t.accept(visitor); } } + if (keywords != null) { + for (PythonTree t : keywords) { + if (t != null) + t.accept(visitor); + } + } + if (starargs != null) + starargs.accept(visitor); + if (kwargs != null) + kwargs.accept(visitor); if (body != null) { for (PythonTree t : body) { if (t != null) Added: branches/jy3k/src/org/python/antlr/ast/DictComp.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/DictComp.java (rev 0) +++ branches/jy3k/src/org/python/antlr/ast/DictComp.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -0,0 +1,225 @@ +// Autogenerated AST node +package org.python.antlr.ast; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.Token; +import org.python.antlr.AST; +import org.python.antlr.PythonTree; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.base.excepthandler; +import org.python.antlr.base.expr; +import org.python.antlr.base.mod; +import org.python.antlr.base.slice; +import org.python.antlr.base.stmt; +import org.python.core.ArgParser; +import org.python.core.AstList; +import org.python.core.Py; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyType; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; + +@ExposedType(name = "_ast.DictComp", base = AST.class) +public class DictComp extends expr { +public static final PyType TYPE = PyType.fromClass(DictComp.class); + private expr key; + public expr getInternalKey() { + return key; + } + @ExposedGet(name = "key") + public PyObject getKey() { + return key; + } + @ExposedSet(name = "key") + public void setKey(PyObject key) { + this.key = AstAdapters.py2expr(key); + } + + private expr value; + public expr getInternalValue() { + return value; + } + @ExposedGet(name = "value") + public PyObject getValue() { + return value; + } + @ExposedSet(name = "value") + public void setValue(PyObject value) { + this.value = AstAdapters.py2expr(value); + } + + private java.util.List<comprehension> generators; + public java.util.List<comprehension> getInternalGenerators() { + return generators; + } + @ExposedGet(name = "generators") + public PyObject getGenerators() { + return new AstList(generators, AstAdapters.comprehensionAdapter); + } + @ExposedSet(name = "generators") + public void setGenerators(PyObject generators) { + this.generators = AstAdapters.py2comprehensionList(generators); + } + + + private final static PyString[] fields = + new PyString[] {new PyString("key"), new PyString("value"), new PyString("generators")}; + @ExposedGet(name = "_fields") + public PyString[] get_fields() { return fields; } + + private final static PyString[] attributes = + new PyString[] {new PyString("lineno"), new PyString("col_offset")}; + @ExposedGet(name = "_attributes") + public PyString[] get_attributes() { return attributes; } + + public DictComp(PyType subType) { + super(subType); + } + public DictComp() { + this(TYPE); + } + @ExposedNew + @ExposedMethod + public void DictComp___init__(PyObject[] args, String[] keywords) { + ArgParser ap = new ArgParser("DictComp", args, keywords, new String[] + {"key", "value", "generators", "lineno", "col_offset"}, 3); + setKey(ap.getPyObject(0)); + setValue(ap.getPyObject(1)); + setGenerators(ap.getPyObject(2)); + int lin = ap.getInt(3, -1); + if (lin != -1) { + setLineno(lin); + } + + int col = ap.getInt(4, -1); + if (col != -1) { + setLineno(col); + } + + } + + public DictComp(PyObject key, PyObject value, PyObject generators) { + setKey(key); + setValue(value); + setGenerators(generators); + } + + public DictComp(Token token, expr key, expr value, java.util.List<comprehension> generators) { + super(token); + this.key = key; + addChild(key); + this.value = value; + addChild(value); + this.generators = generators; + if (generators == null) { + this.generators = new ArrayList<comprehension>(); + } + for(PythonTree t : this.generators) { + addChild(t); + } + } + + public DictComp(Integer ttype, Token token, expr key, expr value, java.util.List<comprehension> + generators) { + super(ttype, token); + this.key = key; + addChild(key); + this.value = value; + addChild(value); + this.generators = generators; + if (generators == null) { + this.generators = new ArrayList<comprehension>(); + } + for(PythonTree t : this.generators) { + addChild(t); + } + } + + public DictComp(PythonTree tree, expr key, expr value, java.util.List<comprehension> + generators) { + super(tree); + this.key = key; + addChild(key); + this.value = value; + addChild(value); + this.generators = generators; + if (generators == null) { + this.generators = new ArrayList<comprehension>(); + } + for(PythonTree t : this.generators) { + addChild(t); + } + } + + @ExposedGet(name = "repr") + public String toString() { + return "DictComp"; + } + + public String toStringTree() { + StringBuffer sb = new StringBuffer("DictComp("); + sb.append("key="); + sb.append(dumpThis(key)); + sb.append(","); + sb.append("value="); + sb.append(dumpThis(value)); + sb.append(","); + sb.append("generators="); + sb.append(dumpThis(generators)); + sb.append(","); + sb.append(")"); + return sb.toString(); + } + + public <R> R accept(VisitorIF<R> visitor) throws Exception { + return visitor.visitDictComp(this); + } + + public void traverse(VisitorIF visitor) throws Exception { + if (key != null) + key.accept(visitor); + if (value != null) + value.accept(visitor); + if (generators != null) { + for (PythonTree t : generators) { + if (t != null) + t.accept(visitor); + } + } + } + + private int lineno = -1; + @ExposedGet(name = "lineno") + public int getLineno() { + if (lineno != -1) { + return lineno; + } + return getLine(); + } + + @ExposedSet(name = "lineno") + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; + @ExposedGet(name = "col_offset") + public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } + return getCharPositionInLine(); + } + + @ExposedSet(name = "col_offset") + public void setCol_offset(int num) { + col_offset = num; + } + +} Modified: branches/jy3k/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/Ellipsis.java 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/src/org/python/antlr/ast/Ellipsis.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -26,14 +26,15 @@ import java.util.ArrayList; @ExposedType(name = "_ast.Ellipsis", base = AST.class) -public class Ellipsis extends slice { +public class Ellipsis extends expr { public static final PyType TYPE = PyType.fromClass(Ellipsis.class); private final static PyString[] fields = new PyString[0]; @ExposedGet(name = "_fields") public PyString[] get_fields() { return fields; } - private final static PyString[] attributes = new PyString[0]; + private final static PyString[] attributes = + new PyString[] {new PyString("lineno"), new PyString("col_offset")}; @ExposedGet(name = "_attributes") public PyString[] get_attributes() { return attributes; } @@ -44,7 +45,17 @@ @ExposedMethod public void Ellipsis___init__(PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("Ellipsis", args, keywords, new String[] - {}, 0); + {"lineno", "col_offset"}, 0); + int lin = ap.getInt(0, -1); + if (lin != -1) { + setLineno(lin); + } + + int col = ap.getInt(1, -1); + if (col != -1) { + setLineno(col); + } + } public Ellipsis() { @@ -80,4 +91,32 @@ public void traverse(VisitorIF visitor) throws Exception { } + private int lineno = -1; + @ExposedGet(name = "lineno") + public int getLineno() { + if (lineno != -1) { + return lineno; + } + return getLine(); + } + + @ExposedSet(name = "lineno") + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; + @ExposedGet(name = "col_offset") + public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } + return getCharPositionInLine(); + } + + @ExposedSet(name = "col_offset") + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -41,17 +41,18 @@ this.excepttype = AstAdapters.py2expr(excepttype); } - private expr name; - public expr getInternalName() { + private String name; + public String getInternalName() { return name; } @ExposedGet(name = "name") public PyObject getName() { - return name; + if (name == null) return Py.None; + return new PyString(name); } @ExposedSet(name = "name") public void setName(PyObject name) { - this.name = AstAdapters.py2expr(name); + this.name = AstAdapters.py2identifier(name); } private java.util.List<stmt> body; @@ -110,12 +111,11 @@ setBody(body); } - public ExceptHandler(Token token, expr excepttype, expr name, java.util.List<stmt> body) { + public ExceptHandler(Token token, expr excepttype, String name, java.util.List<stmt> body) { super(token); this.excepttype = excepttype; addChild(excepttype); this.name = name; - addChild(name); this.body = body; if (body == null) { this.body = new ArrayList<stmt>(); @@ -125,13 +125,12 @@ } } - public ExceptHandler(Integer ttype, Token token, expr excepttype, expr name, + public ExceptHandler(Integer ttype, Token token, expr excepttype, String name, java.util.List<stmt> body) { super(ttype, token); this.excepttype = excepttype; addChild(excepttype); this.name = name; - addChild(name); this.body = body; if (body == null) { this.body = new ArrayList<stmt>(); @@ -141,12 +140,11 @@ } } - public ExceptHandler(PythonTree tree, expr excepttype, expr name, java.util.List<stmt> body) { + public ExceptHandler(PythonTree tree, expr excepttype, String name, java.util.List<stmt> body) { super(tree); this.excepttype = excepttype; addChild(excepttype); this.name = name; - addChild(name); this.body = body; if (body == null) { this.body = new ArrayList<stmt>(); @@ -183,8 +181,6 @@ 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) Deleted: branches/jy3k/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/Exec.java 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/src/org/python/antlr/ast/Exec.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -1,204 +0,0 @@ -// Autogenerated AST node -package org.python.antlr.ast; -import org.antlr.runtime.CommonToken; -import org.antlr.runtime.Token; -import org.python.antlr.AST; -import org.python.antlr.PythonTree; -import org.python.antlr.adapter.AstAdapters; -import org.python.antlr.base.excepthandler; -import org.python.antlr.base.expr; -import org.python.antlr.base.mod; -import org.python.antlr.base.slice; -import org.python.antlr.base.stmt; -import org.python.core.ArgParser; -import org.python.core.AstList; -import org.python.core.Py; -import org.python.core.PyObject; -import org.python.core.PyString; -import org.python.core.PyType; -import org.python.expose.ExposedGet; -import org.python.expose.ExposedMethod; -import org.python.expose.ExposedNew; -import org.python.expose.ExposedSet; -import org.python.expose.ExposedType; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; - -@ExposedType(name = "_ast.Exec", base = AST.class) -public class Exec extends stmt { -public static final PyType TYPE = PyType.fromClass(Exec.class); - private expr body; - public expr getInternalBody() { - return body; - } - @ExposedGet(name = "body") - public PyObject getBody() { - return body; - } - @ExposedSet(name = "body") - public void setBody(PyObject body) { - this.body = AstAdapters.py2expr(body); - } - - private expr globals; - public expr getInternalGlobals() { - return globals; - } - @ExposedGet(name = "globals") - public PyObject getGlobals() { - return globals; - } - @ExposedSet(name = "globals") - public void setGlobals(PyObject globals) { - this.globals = AstAdapters.py2expr(globals); - } - - private expr locals; - public expr getInternalLocals() { - return locals; - } - @ExposedGet(name = "locals") - public PyObject getLocals() { - return locals; - } - @ExposedSet(name = "locals") - public void setLocals(PyObject locals) { - this.locals = AstAdapters.py2expr(locals); - } - - - private final static PyString[] fields = - new PyString[] {new PyString("body"), new PyString("globals"), new PyString("locals")}; - @ExposedGet(name = "_fields") - public PyString[] get_fields() { return fields; } - - private final static PyString[] attributes = - new PyString[] {new PyString("lineno"), new PyString("col_offset")}; - @ExposedGet(name = "_attributes") - public PyString[] get_attributes() { return attributes; } - - public Exec(PyType subType) { - super(subType); - } - public Exec() { - this(TYPE); - } - @ExposedNew - @ExposedMethod - public void Exec___init__(PyObject[] args, String[] keywords) { - ArgParser ap = new ArgParser("Exec", args, keywords, new String[] - {"body", "globals", "locals", "lineno", "col_offset"}, 3); - setBody(ap.getPyObject(0)); - setGlobals(ap.getPyObject(1)); - setLocals(ap.getPyObject(2)); - int lin = ap.getInt(3, -1); - if (lin != -1) { - setLineno(lin); - } - - int col = ap.getInt(4, -1); - if (col != -1) { - setLineno(col); - } - - } - - public Exec(PyObject body, PyObject globals, PyObject locals) { - setBody(body); - setGlobals(globals); - setLocals(locals); - } - - public Exec(Token token, expr body, expr globals, expr locals) { - super(token); - this.body = body; - addChild(body); - this.globals = globals; - addChild(globals); - this.locals = locals; - addChild(locals); - } - - public Exec(Integer ttype, Token token, expr body, expr globals, expr locals) { - super(ttype, token); - this.body = body; - addChild(body); - this.globals = globals; - addChild(globals); - this.locals = locals; - addChild(locals); - } - - public Exec(PythonTree tree, expr body, expr globals, expr locals) { - super(tree); - this.body = body; - addChild(body); - this.globals = globals; - addChild(globals); - this.locals = locals; - addChild(locals); - } - - @ExposedGet(name = "repr") - public String toString() { - return "Exec"; - } - - public String toStringTree() { - StringBuffer sb = new StringBuffer("Exec("); - sb.append("body="); - sb.append(dumpThis(body)); - sb.append(","); - sb.append("globals="); - sb.append(dumpThis(globals)); - sb.append(","); - sb.append("locals="); - sb.append(dumpThis(locals)); - sb.append(","); - sb.append(")"); - return sb.toString(); - } - - public <R> R accept(VisitorIF<R> visitor) throws Exception { - return visitor.visitExec(this); - } - - public void traverse(VisitorIF visitor) throws Exception { - if (body != null) - body.accept(visitor); - if (globals != null) - globals.accept(visitor); - if (locals != null) - locals.accept(visitor); - } - - private int lineno = -1; - @ExposedGet(name = "lineno") - public int getLineno() { - if (lineno != -1) { - return lineno; - } - return getLine(); - } - - @ExposedSet(name = "lineno") - public void setLineno(int num) { - lineno = num; - } - - private int col_offset = -1; - @ExposedGet(name = "col_offset") - public int getCol_offset() { - if (col_offset != -1) { - return col_offset; - } - return getCharPositionInLine(); - } - - @ExposedSet(name = "col_offset") - public void setCol_offset(int num) { - col_offset = num; - } - -} Modified: branches/jy3k/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/FunctionDef.java 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/src/org/python/antlr/ast/FunctionDef.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -81,10 +81,23 @@ this.decorator_list = AstAdapters.py2exprList(decorator_list); } + private expr returns; + public expr getInternalReturns() { + return returns; + } + @ExposedGet(name = "returns") + public PyObject getReturns() { + return returns; + } + @ExposedSet(name = "returns") + public void setReturns(PyObject returns) { + this.returns = AstAdapters.py2expr(returns); + } + private final static PyString[] fields = new PyString[] {new PyString("name"), new PyString("args"), new PyString("body"), new - PyString("decorator_list")}; + PyString("decorator_list"), new PyString("returns")}; @ExposedGet(name = "_fields") public PyString[] get_fields() { return fields; } @@ -103,32 +116,35 @@ @ExposedMethod public void FunctionDef___init__(PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("FunctionDef", args, keywords, new String[] - {"name", "args", "body", "decorator_list", "lineno", "col_offset"}, 4); + {"name", "args", "body", "decorator_list", "returns", "lineno", "col_offset"}, 5); setName(ap.getPyObject(0)); setArgs(ap.getPyObject(1)); setBody(ap.getPyObject(2)); setDecorator_list(ap.getPyObject(3)); - int lin = ap.getInt(4, -1); + setReturns(ap.getPyObject(4)); + int lin = ap.getInt(5, -1); if (lin != -1) { setLineno(lin); } - int col = ap.getInt(5, -1); + int col = ap.getInt(6, -1); if (col != -1) { setLineno(col); } } - public FunctionDef(PyObject name, PyObject args, PyObject body, PyObject decorator_list) { + public FunctionDef(PyObject name, PyObject args, PyObject body, PyObject decorator_list, + PyObject returns) { setName(name); setArgs(args); setBody(body); setDecorator_list(decorator_list); + setReturns(returns); } public FunctionDef(Token token, String name, arguments args, java.util.List<stmt> body, - java.util.List<expr> decorator_list) { + java.util.List<expr> decorator_list, expr returns) { super(token); this.name = name; this.args = args; @@ -146,10 +162,12 @@ for(PythonTree t : this.decorator_list) { addChild(t); } + this.returns = returns; + addChild(returns); } public FunctionDef(Integer ttype, Token token, String name, arguments args, - java.util.List<stmt> body, java.util.List<expr> decorator_list) { + java.util.List<stmt> body, java.util.List<expr> decorator_list, expr returns) { super(ttype, token); this.name = name; this.args = args; @@ -167,10 +185,12 @@ for(PythonTree t : this.decorator_list) { addChild(t); } + this.returns = returns; + addChild(returns); } public FunctionDef(PythonTree tree, String name, arguments args, java.util.List<stmt> body, - java.util.List<expr> decorator_list) { + java.util.List<expr> decorator_list, expr returns) { super(tree); this.name = name; this.args = args; @@ -188,6 +208,8 @@ for(PythonTree t : this.decorator_list) { addChild(t); } + this.returns = returns; + addChild(returns); } @ExposedGet(name = "repr") @@ -209,6 +231,9 @@ sb.append("decorator_list="); sb.append(dumpThis(decorator_list)); sb.append(","); + sb.append("returns="); + sb.append(dumpThis(returns)); + sb.append(","); sb.append(")"); return sb.toString(); } @@ -232,6 +257,8 @@ t.accept(visitor); } } + if (returns != null) + returns.accept(visitor); } private int lineno = -1; Added: branches/jy3k/src/org/python/antlr/ast/Nonlocal.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/Nonlocal.java (rev 0) +++ branches/jy3k/src/org/python/antlr/ast/Nonlocal.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -0,0 +1,147 @@ +// Autogenerated AST node +package org.python.antlr.ast; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.Token; +import org.python.antlr.AST; +import org.python.antlr.PythonTree; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.base.excepthandler; +import org.python.antlr.base.expr; +import org.python.antlr.base.mod; +import org.python.antlr.base.slice; +import org.python.antlr.base.stmt; +import org.python.core.ArgParser; +import org.python.core.AstList; +import org.python.core.Py; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyType; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; + +@ExposedType(name = "_ast.Nonlocal", base = AST.class) +public class Nonlocal extends stmt { +public static final PyType TYPE = PyType.fromClass(Nonlocal.class); + private java.util.List<String> names; + public java.util.List<String> getInternalNames() { + return names; + } + @ExposedGet(name = "names") + public PyObject getNames() { + return new AstList(names, AstAdapters.identifierAdapter); + } + @ExposedSet(name = "names") + public void setNames(PyObject names) { + this.names = AstAdapters.py2identifierList(names); + } + + + private final static PyString[] fields = + new PyString[] {new PyString("names")}; + @ExposedGet(name = "_fields") + public PyString[] get_fields() { return fields; } + + private final static PyString[] attributes = + new PyString[] {new PyString("lineno"), new PyString("col_offset")}; + @ExposedGet(name = "_attributes") + public PyString[] get_attributes() { return attributes; } + + public Nonlocal(PyType subType) { + super(subType); + } + public Nonlocal() { + this(TYPE); + } + @ExposedNew + @ExposedMethod + public void Nonlocal___init__(PyObject[] args, String[] keywords) { + ArgParser ap = new ArgParser("Nonlocal", args, keywords, new String[] + {"names", "lineno", "col_offset"}, 1); + setNames(ap.getPyObject(0)); + int lin = ap.getInt(1, -1); + if (lin != -1) { + setLineno(lin); + } + + int col = ap.getInt(2, -1); + if (col != -1) { + setLineno(col); + } + + } + + public Nonlocal(PyObject names) { + setNames(names); + } + + public Nonlocal(Token token, java.util.List<String> names) { + super(token); + this.names = names; + } + + public Nonlocal(Integer ttype, Token token, java.util.List<String> names) { + super(ttype, token); + this.names = names; + } + + public Nonlocal(PythonTree tree, java.util.List<String> names) { + super(tree); + this.names = names; + } + + @ExposedGet(name = "repr") + public String toString() { + return "Nonlocal"; + } + + public String toStringTree() { + StringBuffer sb = new StringBuffer("Nonlocal("); + sb.append("names="); + sb.append(dumpThis(names)); + sb.append(","); + sb.append(")"); + return sb.toString(); + } + + public <R> R accept(VisitorIF<R> visitor) throws Exception { + return visitor.visitNonlocal(this); + } + + public void traverse(VisitorIF visitor) throws Exception { + } + + private int lineno = -1; + @ExposedGet(name = "lineno") + public int getLineno() { + if (lineno != -1) { + return lineno; + } + return getLine(); + } + + @ExposedSet(name = "lineno") + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; + @ExposedGet(name = "col_offset") + public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } + return getCharPositionInLine(); + } + + @ExposedSet(name = "col_offset") + public void setCol_offset(int num) { + col_offset = num; + } + +} Deleted: branches/jy3k/src/org/python/antlr/ast/Print.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/Print.java 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/src/org/python/antlr/ast/Print.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -1,219 +0,0 @@ -// Autogenerated AST node -package org.python.antlr.ast; -import org.antlr.runtime.CommonToken; -import org.antlr.runtime.Token; -import org.python.antlr.AST; -import org.python.antlr.PythonTree; -import org.python.antlr.adapter.AstAdapters; -import org.python.antlr.base.excepthandler; -import org.python.antlr.base.expr; -import org.python.antlr.base.mod; -import org.python.antlr.base.slice; -import org.python.antlr.base.stmt; -import org.python.core.ArgParser; -import org.python.core.AstList; -import org.python.core.Py; -import org.python.core.PyObject; -import org.python.core.PyString; -import org.python.core.PyType; -import org.python.expose.ExposedGet; -import org.python.expose.ExposedMethod; -import org.python.expose.ExposedNew; -import org.python.expose.ExposedSet; -import org.python.expose.ExposedType; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; - -@ExposedType(name = "_ast.Print", base = AST.class) -public class Print extends stmt { -public static final PyType TYPE = PyType.fromClass(Print.class); - private expr dest; - public expr getInternalDest() { - return dest; - } - @ExposedGet(name = "dest") - public PyObject getDest() { - return dest; - } - @ExposedSet(name = "dest") - public void setDest(PyObject dest) { - this.dest = AstAdapters.py2expr(dest); - } - - private java.util.List<expr> values; - public java.util.List<expr> getInternalValues() { - return values; - } - @ExposedGet(name = "values") - public PyObject getValues() { - return new AstList(values, AstAdapters.exprAdapter); - } - @ExposedSet(name = "values") - public void setValues(PyObject values) { - this.values = AstAdapters.py2exprList(values); - } - - private Boolean nl; - public Boolean getInternalNl() { - return nl; - } - @ExposedGet(name = "nl") - public PyObject getNl() { - if (nl) return Py.True; - return Py.False; - } - @ExposedSet(name = "nl") - public void setNl(PyObject nl) { - this.nl = AstAdapters.py2bool(nl); - } - - - private final static PyString[] fields = - new PyString[] {new PyString("dest"), new PyString("values"), new PyString("nl")}; - @ExposedGet(name = "_fields") - public PyString[] get_fields() { return fields; } - - private final static PyString[] attributes = - new PyString[] {new PyString("lineno"), new PyString("col_offset")}; - @ExposedGet(name = "_attributes") - public PyString[] get_attributes() { return attributes; } - - public Print(PyType subType) { - super(subType); - } - public Print() { - this(TYPE); - } - @ExposedNew - @ExposedMethod - public void Print___init__(PyObject[] args, String[] keywords) { - ArgParser ap = new ArgParser("Print", args, keywords, new String[] - {"dest", "values", "nl", "lineno", "col_offset"}, 3); - setDest(ap.getPyObject(0)); - setValues(ap.getPyObject(1)); - setNl(ap.getPyObject(2)); - int lin = ap.getInt(3, -1); - if (lin != -1) { - setLineno(lin); - } - - int col = ap.getInt(4, -1); - if (col != -1) { - setLineno(col); - } - - } - - public Print(PyObject dest, PyObject values, PyObject nl) { - setDest(dest); - setValues(values); - setNl(nl); - } - - public Print(Token token, expr dest, java.util.List<expr> values, Boolean nl) { - super(token); - this.dest = dest; - addChild(dest); - this.values = values; - if (values == null) { - this.values = new ArrayList<expr>(); - } - for(PythonTree t : this.values) { - addChild(t); - } - this.nl = nl; - } - - public Print(Integer ttype, Token token, expr dest, java.util.List<expr> values, Boolean nl) { - super(ttype, token); - this.dest = dest; - addChild(dest); - this.values = values; - if (values == null) { - this.values = new ArrayList<expr>(); - } - for(PythonTree t : this.values) { - addChild(t); - } - this.nl = nl; - } - - public Print(PythonTree tree, expr dest, java.util.List<expr> values, Boolean nl) { - super(tree); - this.dest = dest; - addChild(dest); - this.values = values; - if (values == null) { - this.values = new ArrayList<expr>(); - } - for(PythonTree t : this.values) { - addChild(t); - } - this.nl = nl; - } - - @ExposedGet(name = "repr") - public String toString() { - return "Print"; - } - - public String toStringTree() { - StringBuffer sb = new StringBuffer("Print("); - sb.append("dest="); - sb.append(dumpThis(dest)); - sb.append(","); - sb.append("values="); - sb.append(dumpThis(values)); - sb.append(","); - sb.append("nl="); - sb.append(dumpThis(nl)); - sb.append(","); - sb.append(")"); - return sb.toString(); - } - - public <R> R accept(VisitorIF<R> visitor) throws Exception { - return visitor.visitPrint(this); - } - - public void traverse(VisitorIF visitor) throws Exception { - if (dest != null) - dest.accept(visitor); - if (values != null) { - for (PythonTree t : values) { - if (t != null) - t.accept(visitor); - } - } - } - - private int lineno = -1; - @ExposedGet(name = "lineno") - public int getLineno() { - if (lineno != -1) { - return lineno; - } - return getLine(); - } - - @ExposedSet(name = "lineno") - public void setLineno(int num) { - lineno = num; - } - - private int col_offset = -1; - @ExposedGet(name = "col_offset") - public int getCol_offset() { - if (col_offset != -1) { - return col_offset; - } - return getCharPositionInLine(); - } - - @ExposedSet(name = "col_offset") - public void setCol_offset(int num) { - col_offset = num; - } - -} Modified: branches/jy3k/src/org/python/antlr/ast/Raise.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/Raise.java 2009-01-05 07:12:43 UTC (rev 5847) +++ branches/jy3k/src/org/python/antlr/ast/Raise.java 2009-01-05 13:16:44 UTC (rev 5848) @@ -28,48 +28,35 @@ @ExposedType(name = "_ast.Raise", base = AST.class) public class Raise extends stmt { public static final PyType TYPE = PyType.fromClass(Raise.class); - private expr excepttype; - public expr getInternalExcepttype() { - return excepttype; + private expr exc; + public expr getInternalExc() { + return exc; } - @ExposedGet(name = "excepttype") - public PyObject getExcepttype() { - return excepttype; + @ExposedGet(name = "exc") + public PyObject getExc() { + return exc; } - @ExposedSet(name = "excepttype") - public void setExcepttype(PyObject excepttype) { - this.excepttype = AstAdapters.py2expr(excepttype); + @ExposedSet(name = "exc") + public void setExc(PyObject exc) { + this.exc = AstAdapters.py2expr(exc); } - private expr inst; - public expr getInternalInst() { - return inst; + private expr cause; + public expr getInternalCause() { + return cause; } - @ExposedGet(name = "inst") - public PyObject getInst() { - return inst; + @ExposedGet(name = "cause") + public PyObject getCause() { + return cause; } - @ExposedSet(name = "inst") - public void setInst(PyObject inst) { - this.inst = AstAdapters.py2expr(inst); + @ExposedSet(name = "cause") + public void setCause(PyObject cause) { + this.cause = AstAdapters.py2expr(cause); } - private expr tback; - public expr getInternalTback() { - return tback; - } - @ExposedGet(name = "tback") - public PyObject getTback() { - return tback; - } - @ExposedSet(name = "tback") - public void setTback(PyObject tback) { - this.tback = AstAdapters.py2expr(tback); - } - private final static PyString[] fields = - new PyString[] {new PyString("excepttype"), new PyString("inst"), new PyString("tback")}; + new PyString[] {new PyString("exc"), new PyString("cause")}; @ExposedGet(name = "_fields") public PyString[] get_fields() { return fields; } @@ -88,56 +75,48 @@ @ExposedMethod public void Raise___init__(PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("Raise", args, keywords, new String[] - {"excepttype", "inst", "tback", "lineno", "col_offset"}, 3); - setExcepttype(ap.getPyObject(0)); - setInst(ap.getPyObject(1)); - setTback(ap.getPyObject(2)); - int lin = ap.getInt(3, -1); + {"exc", "cause", "lineno", "col_offset"}, 2); + setExc(ap.getPyObject(0)); + setCause(ap.getPyObject(1)); + int lin = ap.getInt(2, -1); if (lin != -1) { setLineno(lin); } - int col = ap.getInt(4, -1); + int col = ap.getInt(3, -1); if (col != -1) { setLineno(col); } } - public Raise(PyObject excepttype, PyObject inst, PyObject tback) { - setExcepttype(excepttype); - setInst(inst); - setTback(tback); + public Raise(PyObject exc, PyObject cause) { + setExc(exc); + setCause(cause); } - public Raise(Token token, expr excepttype, expr inst, expr tback) { + public Raise(Token token, expr exc, expr cause) { super(token); - this.excepttype = excepttype; - addChild(excepttype); - this.inst = inst; - addChild(inst); - this.tback = tback; - addChild(tback); + this.exc = exc; + addChild(exc); + this.cause = cause; + addChild(cause); } - public Rais... [truncated message content] |
From: <fwi...@us...> - 2009-01-05 13:39:43
|
Revision: 5849 http://jython.svn.sourceforge.net/jython/?rev=5849&view=rev Author: fwierzbicki Date: 2009-01-05 13:39:31 +0000 (Mon, 05 Jan 2009) Log Message: ----------- print, exec, repr no longer exist. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java branches/jy3k/src/org/python/antlr/ast/AstModule.java branches/jy3k/src/org/python/compiler/CodeCompiler.java branches/jy3k/src/org/python/compiler/ScopesCompiler.java Removed Paths: ------------- branches/jy3k/src/org/python/antlr/ast/ExecDerived.java branches/jy3k/src/org/python/antlr/ast/PrintDerived.java branches/jy3k/src/org/python/antlr/ast/ReprDerived.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-05 13:16:44 UTC (rev 5848) +++ branches/jy3k/grammar/Python.g 2009-01-05 13:39:31 UTC (rev 5849) @@ -127,7 +127,6 @@ import org.python.antlr.ast.operatorType; import org.python.antlr.ast.Pass; import org.python.antlr.ast.Raise; -import org.python.antlr.ast.Repr; import org.python.antlr.ast.Return; import org.python.antlr.ast.Slice; import org.python.antlr.ast.Str; @@ -455,69 +454,107 @@ ; //not in CPython's Grammar file -defparameter[List defaults] returns [expr etype] +tdefparameter[List defaults] returns [expr etype] @after { - $defparameter.tree = $etype; + $tdefparameter.tree = $etype; } - : fpdef[expr_contextType.Param] (ASSIGN test[expr_contextType.Load])? + : vfpdef[expr_contextType.Param] (ASSIGN test[expr_contextType.Load])? { - $etype = actions.castExpr($fpdef.tree); + $etype = actions.castExpr($vfpdef.tree); if ($ASSIGN != null) { defaults.add($test.tree); } else if (!defaults.isEmpty()) { - throw new ParseException("non-default argument follows default argument", $fpdef.tree); + throw new ParseException("non-default argument follows default argument", $vfpdef.tree); } } ; - -//varargslist: ((fpdef ['=' test] ',')* -// ('*' NAME [',' '**' NAME] | '**' NAME) | -// fpdef ['=' test] (',' fpdef ['=' test])* [',']) -varargslist returns [arguments args] +//typedargslist: ((tfpdef ['=' test] ',')* +// ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef) +// | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) +typedargslist returns [arguments args] @init { List defaults = new ArrayList(); } - : d+=defparameter[defaults] (options {greedy=true;}:COMMA d+=defparameter[defaults])* + : d+=tdefparameter[defaults] (options {greedy=true;}:COMMA d+=tdefparameter[defaults])* (COMMA - (STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)? - | DOUBLESTAR kwargs=NAME + (STAR (starargs=tfpdef[expr_contextType.Param])? (COMMA tdefparameter[defaults])* (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? + | DOUBLESTAR kwargs=tfpdef[expr_contextType.Param] )? )? { - $args = actions.makeArgumentsType($varargslist.start, $d, $starargs, $kwargs, defaults); + $args = actions.makeArgumentsType($typedargslist.start, $d, $starargs.tree, $kwargs.tree, defaults); } - | STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)? + | STAR starargs=tfpdef[expr_contextType.Param] (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? { - $args = actions.makeArgumentsType($varargslist.start, $d, $starargs, $kwargs, defaults); + $args = actions.makeArgumentsType($typedargslist.start, $d, $starargs.tree.tree, $kwargs.tree, defaults); } - | DOUBLESTAR kwargs=NAME + | DOUBLESTAR kwargs=tfpdef[expr_contextType.Param] { - $args = actions.makeArgumentsType($varargslist.start, $d, null, $kwargs, defaults); + $args = actions.makeArgumentsType($typedargslist.start, $d, null, $kwargs.tree, defaults); } ; -//fpdef: NAME | '(' fplist ')' -fpdef[expr_contextType ctype] +//tfpdef: NAME [':' test] +tfpdef[expr_contextType ctype] @after { - actions.checkAssign(actions.castExpr($fpdef.tree)); + actions.checkAssign(actions.castExpr($vfpdef.tree)); } - : NAME + : NAME (':' test[ctype])? -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) - | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN - -> ^(LPAREN<Tuple>[$fplist.start, actions.castExprs($fplist.etypes), expr_contextType.Store]) - | LPAREN fplist RPAREN - -> fplist ; -//fplist: fpdef (',' fpdef)* [','] -fplist returns [List etypes] - : f+=fpdef[expr_contextType.Store] - (options {greedy=true;}:COMMA f+=fpdef[expr_contextType.Store])* (COMMA)? +//not in CPython's Grammar file +vdefparameter[List defaults] returns [expr etype] +@after { + $vdefparameter.tree = $etype; +} + : vfpdef[expr_contextType.Param] (ASSIGN test[expr_contextType.Load])? { - $etypes = $f; + $etype = actions.castExpr($vfpdef.tree); + if ($ASSIGN != null) { + defaults.add($test.tree); + } else if (!defaults.isEmpty()) { + throw new ParseException("non-default argument follows default argument", $vfpdef.tree); + } } ; +//varargslist: ((vfpdef ['=' test] ',')* +// ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef) +// vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) +varargslist returns [arguments args] +@init { + List defaults = new ArrayList(); +} + : d+=vdefparameter[defaults] (options {greedy=true;}:COMMA d+=vdefparameter[defaults])* + (COMMA + (STAR (starargs=vfpdef[expr_contextType.Param])? (COMMA DOUBLESTAR kwargs=vfpdef[expr_contextType.Param])? + | DOUBLESTAR kwargs=vfpdef[expr_contextType.Param] + )? + )? + { + $args = actions.makeArgumentsType($varargslist.start, $d, $starargs.tree, $kwargs.tree, defaults); + } + | STAR starargs=vfpdef[expr_contextType.Param] (COMMA DOUBLESTAR kwargs=vfpdef[expr_contextType.Param])? + { + $args = actions.makeArgumentsType($varargslist.start, $d, $starargs.tree, $kwargs.tree, defaults); + } + | DOUBLESTAR kwargs=vfpdef[expr_contextType.Param] + { + $args = actions.makeArgumentsType($varargslist.start, $d, null, $kwargs.tree, defaults); + } + ; + +//vfpdef: NAME +vfpdef[expr_contextType ctype] +@after { + actions.checkAssign(actions.castExpr($vfpdef.tree)); +} + : NAME + -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) + ; + + //stmt: simple_stmt | compound_stmt stmt returns [List stypes] : simple_stmt @@ -1194,8 +1231,6 @@ -> ^(LCURLY<Dict>[$LCURLY, new ArrayList<expr>(), new ArrayList<expr>()]) ) RCURLY - | lb=BACKQUOTE testlist[expr_contextType.Load] rb=BACKQUOTE - -> ^(BACKQUOTE<Repr>[$lb, actions.castExpr($testlist.tree)]) | NAME -> ^(NAME<Name>[$NAME, $NAME.text, $expr::ctype]) | INT Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-05 13:16:44 UTC (rev 5848) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-05 13:39:31 UTC (rev 5849) @@ -41,7 +41,6 @@ import org.python.antlr.ast.TryExcept; import org.python.antlr.ast.TryFinally; import org.python.antlr.ast.Tuple; -import org.python.antlr.ast.Repr; import org.python.antlr.ast.Str; import org.python.antlr.ast.UnaryOp; import org.python.antlr.ast.While; @@ -615,8 +614,6 @@ errorHandler.error("can't assign to lambda", e); } else if (e instanceof Call) { errorHandler.error("can't assign to function call", e); - } else if (e instanceof Repr) { - errorHandler.error("can't assign to repr", e); } else if (e instanceof IfExp) { errorHandler.error("can't assign to conditional expression", e); } else if (e instanceof ListComp) { Modified: branches/jy3k/src/org/python/antlr/ast/AstModule.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/AstModule.java 2009-01-05 13:16:44 UTC (rev 5848) +++ branches/jy3k/src/org/python/antlr/ast/AstModule.java 2009-01-05 13:39:31 UTC (rev 5849) @@ -52,7 +52,6 @@ // dict.__setitem__("ErrorSlice", ErrorSlice.TYPE); // dict.__setitem__("ErrorStmt", ErrorStmt.TYPE); dict.__setitem__("ExceptHandler", ExceptHandler.TYPE); - dict.__setitem__("Exec", Exec.TYPE); dict.__setitem__("Expr", Expr.TYPE); dict.__setitem__("Expression", Expression.TYPE); dict.__setitem__("ExtSlice", ExtSlice.TYPE); @@ -73,9 +72,7 @@ dict.__setitem__("Name", Name.TYPE); dict.__setitem__("Num", Num.TYPE); dict.__setitem__("Pass", Pass.TYPE); - dict.__setitem__("Print", Print.TYPE); dict.__setitem__("Raise", Raise.TYPE); - dict.__setitem__("Repr", Repr.TYPE); dict.__setitem__("Return", Return.TYPE); dict.__setitem__("Slice", Slice.TYPE); dict.__setitem__("Str", Str.TYPE); Deleted: branches/jy3k/src/org/python/antlr/ast/ExecDerived.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/ExecDerived.java 2009-01-05 13:16:44 UTC (rev 5848) +++ branches/jy3k/src/org/python/antlr/ast/ExecDerived.java 2009-01-05 13:39:31 UTC (rev 5849) @@ -1,1163 +0,0 @@ -/* Generated file, do not modify. See jython/src/templates/gderived.py. */ -package org.python.antlr.ast; - -import java.io.Serializable; -import org.python.core.*; - -public class ExecDerived extends Exec implements Slotted { - - public PyObject getSlot(int index) { - return slots[index]; - } - - public void setSlot(int index,PyObject value) { - slots[index]=value; - } - - private PyObject[]slots; - - private PyObject dict; - - public PyObject fastGetDict() { - return dict; - } - - public PyObject getDict() { - return dict; - } - - public void setDict(PyObject newDict) { - if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { - dict=newDict; - } else { - throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); - } - } - - public void delDict() { - // deleting an object's instance dict makes it grow a new one - dict=new PyStringMap(); - } - - public ExecDerived(PyType subtype) { - super(subtype); - slots=new PyObject[subtype.getNumSlots()]; - dict=subtype.instDict(); - } - - public PyString __str__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__str__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__str__(); - } - - public PyString __repr__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__repr__(); - } - - public PyString __hex__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__hex__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__hex__(); - } - - public PyString __oct__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__oct__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__oct__(); - } - - public PyFloat __float__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__float__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyFloat) - return(PyFloat)res; - throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); - } - return super.__float__(); - } - - public PyComplex __complex__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__complex__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyComplex) - return(PyComplex)res; - throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); - } - return super.__complex__(); - } - - public PyObject __pos__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__pos__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__pos__(); - } - - public PyObject __neg__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__neg__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__neg__(); - } - - public PyObject __abs__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__abs__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__abs__(); - } - - public PyObject __invert__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__invert__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__invert__(); - } - - public PyObject __reduce__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__reduce__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__reduce__(); - } - - public PyObject __add__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__add__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__add__(other); - } - - public PyObject __radd__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__radd__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__radd__(other); - } - - public PyObject __sub__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__sub__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__sub__(other); - } - - public PyObject __rsub__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rsub__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rsub__(other); - } - - public PyObject __mul__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__mul__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__mul__(other); - } - - public PyObject __rmul__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rmul__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rmul__(other); - } - - public PyObject __div__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__div__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__div__(other); - } - - public PyObject __rdiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rdiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rdiv__(other); - } - - public PyObject __floordiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__floordiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__floordiv__(other); - } - - public PyObject __rfloordiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rfloordiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rfloordiv__(other); - } - - public PyObject __truediv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__truediv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__truediv__(other); - } - - public PyObject __rtruediv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rtruediv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rtruediv__(other); - } - - public PyObject __mod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__mod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__mod__(other); - } - - public PyObject __rmod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rmod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rmod__(other); - } - - public PyObject __divmod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__divmod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__divmod__(other); - } - - public PyObject __rdivmod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rdivmod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rdivmod__(other); - } - - public PyObject __rpow__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rpow__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rpow__(other); - } - - public PyObject __lshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__lshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__lshift__(other); - } - - public PyObject __rlshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rlshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rlshift__(other); - } - - public PyObject __rshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rshift__(other); - } - - public PyObject __rrshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rrshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rrshift__(other); - } - - public PyObject __and__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__and__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__and__(other); - } - - public PyObject __rand__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rand__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rand__(other); - } - - public PyObject __or__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__or__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__or__(other); - } - - public PyObject __ror__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ror__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ror__(other); - } - - public PyObject __xor__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__xor__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__xor__(other); - } - - public PyObject __rxor__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rxor__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rxor__(other); - } - - public PyObject __lt__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__lt__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__lt__(other); - } - - public PyObject __le__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__le__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__le__(other); - } - - public PyObject __gt__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__gt__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__gt__(other); - } - - public PyObject __ge__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ge__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ge__(other); - } - - public PyObject __eq__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__eq__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__eq__(other); - } - - public PyObject __ne__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ne__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ne__(other); - } - - public PyObject __iadd__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__iadd__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__iadd__(other); - } - - public PyObject __isub__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__isub__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__isub__(other); - } - - public PyObject __imul__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__imul__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__imul__(other); - } - - public PyObject __idiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__idiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__idiv__(other); - } - - public PyObject __ifloordiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ifloordiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ifloordiv__(other); - } - - public PyObject __itruediv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__itruediv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__itruediv__(other); - } - - public PyObject __imod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__imod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__imod__(other); - } - - public PyObject __ipow__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ipow__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ipow__(other); - } - - public PyObject __ilshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ilshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ilshift__(other); - } - - public PyObject __irshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__irshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__irshift__(other); - } - - public PyObject __iand__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__iand__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__iand__(other); - } - - public PyObject __ior__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ior__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ior__(other); - } - - public PyObject __ixor__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ixor__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ixor__(other); - } - - public PyObject __int__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__int__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyInteger||res instanceof PyLong) - return(PyObject)res; - throw Py.TypeError("__int__"+" should return an integer"); - } - return super.__int__(); - } - - public PyObject __long__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__long__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyLong||res instanceof PyInteger) - return res; - throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); - } - return super.__long__(); - } - - public int hashCode() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__hash__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyInteger) { - return((PyInteger)res).getValue(); - } else - if (res instanceof PyLong) { - return((PyLong)res).getValue().intValue(); - } - throw Py.TypeError("__hash__ should return a int"); - } - if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) { - throw Py.TypeError(String.format("unhashable type: '%.200s'",getType().fastGetName())); - } - return super.hashCode(); - } - - public PyUnicode __unicode__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__unicode__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyUnicode) - return(PyUnicode)res; - if (res instanceof PyString) - return new PyUnicode((PyString)res); - throw Py.TypeError("__unicode__"+" should return a "+"unicode"); - } - return super.__unicode__(); - } - - public int __cmp__(PyObject other) { - PyType self_type=getType(); - PyType[]where_type=new PyType[1]; - PyObject impl=self_type.lookup_where("__cmp__",where_type); - // Full Compatibility with CPython __cmp__: - // If the derived type don't override __cmp__, the - // *internal* super().__cmp__ should be called, not the - // exposed one. The difference is that the exposed __cmp__ - // throws a TypeError if the argument is an instance of the same type. - if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) { - return super.__cmp__(other); - } - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) { - return-2; - } - int c=res.asInt(); - return c<0?-1:c>0?1:0; - } - - public boolean __nonzero__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__nonzero__"); - if (impl==null) { - impl=self_type.lookup("__len__"); - if (impl==null) - return super.__nonzero__(); - } - PyObject o=impl.__get__(this,self_type).__call__(); - Class c=o.getClass(); - if (c!=PyInteger.class&&c!=PyBoolean.class) { - throw Py.TypeError(String.format("__nonzero__ should return bool or int, returned %s",self_type.getName())); - } - return o.__nonzero__(); - } - - public boolean __contains__(PyObject o) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__contains__"); - if (impl==null) - return super.__contains__(o); - return impl.__get__(this,self_type).__call__(o).__nonzero__(); - } - - public int __len__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__len__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyInteger) - return((PyInteger)res).getValue(); - throw Py.TypeError("__len__ should return a int"); - } - return super.__len__(); - } - - public PyObject __iter__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__iter__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - impl=self_type.lookup("__getitem__"); - if (impl==null) - return super.__iter__(); - return new PySequenceIter(this); - } - - public PyObject __iternext__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("next"); - if (impl!=null) { - try { - return impl.__get__(this,self_type).__call__(); - } catch (PyException exc) { - if (Py.matchException(exc,Py.StopIteration)) - return null; - throw exc; - } - } - return super.__iternext__(); // ??? - } - - public PyObject __finditem__(PyObject key) { // ??? - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getitem__"); - if (impl!=null) - try { - return impl.__get__(this,self_type).__call__(key); - } catch (PyException exc) { - if (Py.matchException(exc,Py.LookupError)) - return null; - throw exc; - } - return super.__finditem__(key); - } - - public PyObject __finditem__(int key) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getitem__"); - if (impl!=null) - try { - return impl.__get__(this,self_type).__call__(new PyInteger(key)); - } catch (PyException exc) { - if (Py.matchException(exc,Py.LookupError)) - return null; - throw exc; - } - return super.__finditem__(key); - } - - public PyObject __getitem__(PyObject key) { - // Same as __finditem__, without swallowing LookupErrors. This allows - // __getitem__ implementations written in Python to raise custom - // exceptions (such as subclasses of KeyError). - // - // We are forced to duplicate the code, instead of defining __finditem__ - // in terms of __getitem__. That's because PyObject defines __getitem__ - // in terms of __finditem__. Therefore, we would end with an infinite - // loop when self_type.lookup("__getitem__") returns null: - // - // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__ - // - // By duplicating the (short) lookup and call code, we are safe, because - // the call chains will be: - // - // __finditem__ -> super.__finditem__ - // - // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__ - - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getitem__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(key); - return super.__getitem__(key); - } - - public void __setitem__(PyObject key,PyObject value) { // ??? - PyType self_type=getType(); - PyObject impl=self_type.lookup("__setitem__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(key,value); - return; - } - super.__setitem__(key,value); - } - - public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? - if (step!=null) { - return __getitem__(new PySlice(start,stop,step)); - } - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getslice__"); - if (impl!=null) { - PyObject[]indices=PySlice.indices2(this,start,stop); - return impl.__get__(this,self_type).__call__(indices[0],indices[1]); - } - return super.__getslice__(start,stop,step); - } - - public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { - if (step!=null) { - __setitem__(new PySlice(start,stop,step),value); - return; - } - PyType self_type=getType(); - PyObject impl=self_type.lookup("__setslice__"); - if (impl!=null) { - PyObject[]indices=PySlice.indices2(this,start,stop); - impl.__get__(this,self_type).__call__(indices[0],indices[1],value); - return; - } - super.__setslice__(start,stop,step,value); - } - - public void __delslice__(PyObject start,PyObject stop,PyObject step) { - if (step!=null) { - __delitem__(new PySlice(start,stop,step)); - return; - } - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delslice__"); - if (impl!=null) { - PyObject[]indices=PySlice.indices2(this,start,stop); - impl.__get__(this,self_type).__call__(indices[0],indices[1]); - return; - } - super.__delslice__(start,stop,step); - } - - public void __delitem__(PyObject key) { // ??? - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delitem__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(key); - return; - } - super.__delitem__(key); - } - - public PyObject __call__(PyObject args[],String keywords[]) { - ThreadState ts=Py.getThreadState(); - if (ts.recursion_depth++>ts.systemState.getrecursionlimit()) - throw Py.RuntimeError("maximum __call__ recursion depth exceeded"); - try { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__call__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(args,keywords); - return super.__call__(args,keywords); - } finally { - --ts.recursion_depth; - } - } - - public PyObject __findattr_ex__(String name) { - PyType self_type=getType(); - // TODO: We should speed this up. As the __getattribute__ slot almost never - // changes, it is a good candidate for caching, as PyClass does with - // __getattr__. See #1102. - PyObject getattribute=self_type.lookup("__getattribute__"); - PyString py_name=null; - PyException firstAttributeError=null; - try { - if (getattribute!=null) { - py_name=PyString.fromInterned(name); - return getattribute.__get__(this,self_type).__call__(py_name); - } else { - Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); - PyObject ret=super.__findattr_ex__(name); - if (ret!=null) { - return ret; - } // else: pass through to __getitem__ invocation - } - } catch (PyException e) { - if (!Py.matchException(e,Py.AttributeError)) { - throw e; - } else { - firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors - // and pass through to __getattr__ invocation. - } - } - PyObject getattr=self_type.lookup("__getattr__"); - if (getattr!=null) { - if (py_name==null) { - py_name=PyString.fromInterned(name); - } - return getattr.__get__(this,self_type).__call__(py_name); - } - if (firstAttributeError!=null) { - throw firstAttributeError; - } - return null; - } - - public void __setattr__(String name,PyObject value) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__setattr__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); - return; - } - super.__setattr__(name,value); - } - - public void __delattr__(String name) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delattr__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); - return; - } - super.__delattr__(name); - } - - public PyObject __get__(PyObject obj,PyObject type) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__get__"); - if (impl!=null) { - if (obj==null) - obj=Py.None; - if (type==null) - type=Py.None; - return impl.__get__(this,self_type).__call__(obj,type); - } - return super.__get__(obj,type); - } - - public void __set__(PyObject obj,PyObject value) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__set__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(obj,value); - return; - } - super.__set__(obj,value); - } - - public void __delete__(PyObject obj) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delete__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(obj); - return; - } - super.__delete__(obj); - } - - public PyObject __pow__(PyObject other,PyObject modulo) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__pow__"); - if (impl!=null) { - PyObject res; - if (modulo==null) { - res=impl.__get__(this,self_type).__call__(other); - } else { - res=impl.__get__(this,self_type).__call__(other,modulo); - } - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__pow__(other,modulo); - } - - public void dispatch__init__(PyType type,PyObject[]args,String[]keywords) { - PyType self_type=getType(); - if (self_type.isSubType(type)) { - PyObject impl=self_type.lookup("__init__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(args,keywords); - if (res!=Py.None) { - throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); - } - proxyInit(); - } - } - } - - public PyObject __index__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__index__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyInteger||res instanceof PyLong) { - return res; - } - throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); - } - return super.__index__(); - } - - public Object __tojava__(Class c) { - // If we are not being asked by the "default" conversion to java, then - // we can provide this as the result, as long as it is a instance of the - // specified class. Without this, derived.__tojava__(PyObject.class) - // would broke. (And that's not pure speculation: PyReflectedFunction's - // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c!=Serializable.class)&&(c.isInstance(this))) { - return this; - } - // Otherwise, we call the derived __tojava__, if it exists: - PyType self_type=getType(); - PyObject impl=self_type.lookup("__tojava__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava__(Object.class); - return super.__tojava__(c); - } - - public Object __coerce_ex__(PyObject o) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__coerce__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(o); - if (res==Py.NotImplemented) - return Py.None; - if (!(res instanceof PyTuple)) - throw Py.TypeError("__coerce__ didn't return a 2-tuple"); - return((PyTuple)res).getArray(); - } - return super.__coerce_ex__(o); - } - - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); - return((PyString)res).toString(); - } - return super.toString(); - } - -} Deleted: branches/jy3k/src/org/python/antlr/ast/PrintDerived.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/PrintDerived.java 2009-01-05 13:16:44 UTC (rev 5848) +++ branches/jy3k/src/org/python/antlr/ast/PrintDerived.java 2009-01-05 13:39:31 UTC (rev 5849) @@ -1,1163 +0,0 @@ -/* Generated file, do not modify. See jython/src/templates/gderived.py. */ -package org.python.antlr.ast; - -import java.io.Serializable; -import org.python.core.*; - -public class PrintDerived extends Print implements Slotted { - - public PyObject getSlot(int index) { - return slots[index]; - } - - public void setSlot(int index,PyObject value) { - slots[index]=value; - } - - private PyObject[]slots; - - private PyObject dict; - - public PyObject fastGetDict() { - return dict; - } - - public PyObject getDict() { - return dict; - } - - public void setDict(PyObject newDict) { - if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { - dict=newDict; - } else { - throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); - } - } - - public void delDict() { - // deleting an object's instance dict makes it grow a new one - dict=new PyStringMap(); - } - - public PrintDerived(PyType subtype) { - super(subtype); - slots=new PyObject[subtype.getNumSlots()]; - dict=subtype.instDict(); - } - - public PyString __str__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__str__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__str__(); - } - - public PyString __repr__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__repr__(); - } - - public PyString __hex__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__hex__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__hex__(); - } - - public PyString __oct__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__oct__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__oct__(); - } - - public PyFloat __float__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__float__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyFloat) - return(PyFloat)res; - throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); - } - return super.__float__(); - } - - public PyComplex __complex__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__complex__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyComplex) - return(PyComplex)res; - throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); - } - return super.__complex__(); - } - - public PyObject __pos__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__pos__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__pos__(); - } - - public PyObject __neg__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__neg__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__neg__(); - } - - public PyObject __abs__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__abs__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__abs__(); - } - - public PyObject __invert__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__invert__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__invert__(); - } - - public PyObject __reduce__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__reduce__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__reduce__(); - } - - public PyObject __add__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__add__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__add__(other); - } - - public PyObject __radd__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__radd__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__radd__(other); - } - - public PyObject __sub__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__sub__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__sub__(other); - } - - public PyObject __rsub__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rsub__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rsub__(other); - } - - public PyObject __mul__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__mul__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__mul__(other); - } - - public PyObject __rmul__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rmul__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rmul__(other); - } - - public PyObject __div__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__div__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__div__(other); - } - - public PyObject __rdiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rdiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rdiv__(other); - } - - public PyObject __floordiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__floordiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__floordiv__(other); - } - - public PyObject __rfloordiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rfloordiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rfloordiv__(other); - } - - public PyObject __truediv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__truediv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__truediv__(other); - } - - public PyObject __rtruediv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rtruediv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rtruediv__(other); - } - - public PyObject __mod__(PyObject other) { ... [truncated message content] |
From: <fwi...@us...> - 2009-01-05 13:51:17
|
Revision: 5850 http://jython.svn.sourceforge.net/jython/?rev=5850&view=rev Author: fwierzbicki Date: 2009-01-05 13:51:12 +0000 (Mon, 05 Jan 2009) Log Message: ----------- Raise now takes only 2 args. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/compiler/CodeCompiler.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-05 13:39:31 UTC (rev 5849) +++ branches/jy3k/grammar/Python.g 2009-01-05 13:51:12 UTC (rev 5850) @@ -699,11 +699,10 @@ : yield_expr -> ^(YIELD<Expr>[$yield_expr.start, actions.castExpr($yield_expr.tree)]) ; -//raise_stmt: 'raise' [test [',' test [',' test]]] +//raise_stmt: 'raise' [test ['from' test]] raise_stmt - : RAISE (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load] - (COMMA t3=test[expr_contextType.Load])?)?)? - -> ^(RAISE<Raise>[$RAISE, actions.castExpr($t1.tree), actions.castExpr($t2.tree), actions.castExpr($t3.tree)]) + : RAISE (t1=test[expr_contextType.Load] (FROM t2=test[expr_contextType.Load])?)? + -> ^(RAISE<Raise>[$RAISE, actions.castExpr($t1.tree), actions.castExpr($t2.tree)]) ; //import_stmt: import_name | import_from Modified: branches/jy3k/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-05 13:39:31 UTC (rev 5849) +++ branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-05 13:51:12 UTC (rev 5850) @@ -705,20 +705,16 @@ @Override public Object visitRaise(Raise node) throws Exception { setline(node); - if (node.getInternalExcepttype() != null) { visit(node.getInternalExcepttype()); stackProduce(); } - if (node.getInternalInst() != null) { visit(node.getInternalInst()); stackProduce(); } - if (node.getInternalTback() != null) { visit(node.getInternalTback()); stackProduce(); } - if (node.getInternalExcepttype() == null) { + if (node.getInternalExc() != null) { visit(node.getInternalExc()); stackProduce(); } + if (node.getInternalCause() != null) { visit(node.getInternalCause()); stackProduce(); } + if (node.getInternalExc() == null) { code.invokestatic("org/python/core/Py", "makeException", "()" + $pyExc); - } else if (node.getInternalInst() == null) { + } else if (node.getInternalCause() == null) { stackConsume(); code.invokestatic("org/python/core/Py", "makeException", "(" + $pyObj + ")" + $pyExc); - } else if (node.getInternalTback() == null) { + } else { stackConsume(2); code.invokestatic("org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); - } else { - stackConsume(3); - code.invokestatic("org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyExc); } code.athrow(); return Exit; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-05 17:59:09
|
Revision: 5851 http://jython.svn.sourceforge.net/jython/?rev=5851&view=rev Author: fwierzbicki Date: 2009-01-05 17:59:06 +0000 (Mon, 05 Jan 2009) Log Message: ----------- Just enough to get ast.arguments constructor calls passing. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-05 13:51:12 UTC (rev 5850) +++ branches/jy3k/grammar/Python.g 2009-01-05 17:59:06 UTC (rev 5851) @@ -84,6 +84,7 @@ import org.python.antlr.ParseException; import org.python.antlr.PythonTree; import org.python.antlr.ast.alias; +import org.python.antlr.ast.arg; import org.python.antlr.ast.arguments; import org.python.antlr.ast.Assert; import org.python.antlr.ast.Assign; @@ -447,7 +448,7 @@ parameters returns [arguments args] : LPAREN (varargslist {$args = $varargslist.args;} - | { $args = new arguments($parameters.start, new ArrayList<expr>(), null, null, new ArrayList<expr>()); + | { $args = new arguments($parameters.start, new ArrayList<arg>(), null, null, new ArrayList<arg>(), null, null, new ArrayList<expr>(), new ArrayList<expr>()); } ) RPAREN @@ -486,7 +487,7 @@ } | STAR starargs=tfpdef[expr_contextType.Param] (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? { - $args = actions.makeArgumentsType($typedargslist.start, $d, $starargs.tree.tree, $kwargs.tree, defaults); + $args = actions.makeArgumentsType($typedargslist.start, $d, $starargs.tree, $kwargs.tree, defaults); } | DOUBLESTAR kwargs=tfpdef[expr_contextType.Param] { @@ -1310,7 +1311,7 @@ { arguments a = $varargslist.args; if (a == null) { - a = new arguments($LAMBDA, new ArrayList<expr>(), null, null, new ArrayList<expr>()); + a = new arguments($LAMBDA, new ArrayList<arg>(), null, null, new ArrayList<arg>(), null, null, new ArrayList<expr>(), new ArrayList<expr>()); } etype = new Lambda($LAMBDA, a, actions.castExpr($test.tree)); } Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-05 13:51:12 UTC (rev 5850) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-05 17:59:06 UTC (rev 5851) @@ -10,6 +10,7 @@ import org.python.core.PyString; import org.python.core.PyUnicode; import org.python.antlr.ast.alias; +import org.python.antlr.ast.arg; import org.python.antlr.ast.arguments; import org.python.antlr.ast.boolopType; import org.python.antlr.ast.cmpopType; @@ -150,7 +151,20 @@ } return result; } - + + List<arg> castArgs(List args) { + List<arg> result = new ArrayList<arg>(); + if (args != null) { + for (int i=start; i<args.size(); i++) { + Object o = args.get(i); + if (o instanceof arg) { + result.add((arg)o); + } + } + } + return result; + } + List<stmt> makeElse(List elseSuite, PythonTree elif) { if (elseSuite != null) { return castStmts(elseSuite); @@ -250,7 +264,7 @@ if (args != null) { a = args; } else { - a = new arguments(t, new ArrayList<expr>(), null, null, new ArrayList<expr>()); + a = new arguments(t, new ArrayList<arg>(), null, null, new ArrayList<arg>(), null, null, new ArrayList<expr>(), new ArrayList<expr>()); } List<stmt> s = castStmts(funcStatements); List<expr> d = castExprs(decorators); @@ -292,10 +306,10 @@ } } - arguments makeArgumentsType(Token t, List params, Token snameToken, - Token knameToken, List defaults) { + arguments makeArgumentsType(Token t, List params, PythonTree snameToken, + PythonTree knameToken, List defaults) { - List<expr> p = castExprs(params); + List<arg> p = castArgs(params); List<expr> d = castExprs(defaults); String s; String k; @@ -309,7 +323,7 @@ } else { k = cantBeNone(knameToken); } - return new arguments(t, p, s, k, d); + return new arguments(t, p, s, null, new ArrayList<arg>(), k, null, d, new ArrayList<expr>()); } List<expr> extractArgs(List args) { @@ -591,10 +605,11 @@ return t.getText(); } - void cantBeNone(PythonTree e) { + String cantBeNone(PythonTree e) { if (e.getText().equals("None")) { errorHandler.error("can't be None", e); } + return e.getText(); } void checkAssign(expr e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-05 18:48:59
|
Revision: 5852 http://jython.svn.sourceforge.net/jython/?rev=5852&view=rev Author: fwierzbicki Date: 2009-01-05 18:48:54 +0000 (Mon, 05 Jan 2009) Log Message: ----------- Just enough patchwork to get this thing compiling. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java branches/jy3k/src/org/python/antlr/adapter/AstAdapters.java branches/jy3k/src/org/python/compiler/ArgListCompiler.java branches/jy3k/src/org/python/compiler/CodeCompiler.java branches/jy3k/src/org/python/compiler/ScopesCompiler.java Added Paths: ----------- branches/jy3k/src/org/python/antlr/adapter/ArgAdapter.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-05 17:59:06 UTC (rev 5851) +++ branches/jy3k/grammar/Python.g 2009-01-05 18:48:54 UTC (rev 5852) @@ -498,7 +498,7 @@ //tfpdef: NAME [':' test] tfpdef[expr_contextType ctype] @after { - actions.checkAssign(actions.castExpr($vfpdef.tree)); + actions.checkAssign(actions.castExpr($tfpdef.tree)); } : NAME (':' test[ctype])? -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) @@ -905,10 +905,10 @@ } ; -//except_clause: 'except' [test [',' test]] +//except_clause: 'except' [test ['as' NAME]] except_clause - : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite[!$suite.isEmpty() && $suite::continueIllegal] - -> ^(EXCEPT<ExceptHandler>[$EXCEPT, actions.castExpr($t1.tree), actions.castExpr($t2.tree), + : EXCEPT (test[expr_contextType.Load] (AS NAME)?)? COLON suite[!$suite.isEmpty() && $suite::continueIllegal] + -> ^(EXCEPT<ExceptHandler>[$EXCEPT, actions.castExpr($test.tree), $NAME.getText(), actions.castStmts($suite.stypes)]) ; @@ -1434,6 +1434,9 @@ } stype = new ClassDef(t, actions.cantBeNone($NAME), actions.makeBases(actions.castExpr($testlist.tree)), + new ArrayList<keyword>(), + null, + null, actions.castStmts($suite.stypes), actions.castExprs($decorators.etypes)); } Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-05 17:59:06 UTC (rev 5851) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-05 18:48:54 UTC (rev 5852) @@ -155,8 +155,7 @@ List<arg> castArgs(List args) { List<arg> result = new ArrayList<arg>(); if (args != null) { - for (int i=start; i<args.size(); i++) { - Object o = args.get(i); + for (Object o : args) { if (o instanceof arg) { result.add((arg)o); } @@ -268,7 +267,7 @@ } List<stmt> s = castStmts(funcStatements); List<expr> d = castExprs(decorators); - return new FunctionDef(t, nameToken.getText(), a, s, d); + return new FunctionDef(t, nameToken.getText(), a, s, d, null); } List<expr> makeAssignTargets(expr lhs, List rhs) { @@ -496,8 +495,8 @@ cantBeNone(nameToken); List<expr> b = castExprs(bases); List<stmt> s = castStmts(body); - List<expr> d = castExprs(decorators); - return new ClassDef(t, nameToken.getText(), b, s, d); + List<expr> d = castExprs(decorators); + return new ClassDef(t, nameToken.getText(), b, new ArrayList<keyword>(), null, null, s, d); } stmt makeTryExcept(PythonTree t, List body, List handlers, List orelse, List finBody) { Added: branches/jy3k/src/org/python/antlr/adapter/ArgAdapter.java =================================================================== --- branches/jy3k/src/org/python/antlr/adapter/ArgAdapter.java (rev 0) +++ branches/jy3k/src/org/python/antlr/adapter/ArgAdapter.java 2009-01-05 18:48:54 UTC (rev 5852) @@ -0,0 +1,35 @@ +package org.python.antlr.adapter; + +import java.util.ArrayList; +import java.util.List; + +import org.python.antlr.ast.arg; +import org.python.core.Py; +import org.python.core.PyObject; + +public class ArgAdapter implements AstAdapter { + + public Object py2ast(PyObject o) { + if (o == null || o instanceof arg) { + return o; + } else if (o == Py.None) { + return null; + } + + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arg node"); + } + + public PyObject ast2py(Object o) { + return (PyObject)o; + } + + public List iter2ast(PyObject iter) { + List<arg> args = new ArrayList<arg>(); + for(Object o : (Iterable)iter) { + args.add((arg)py2ast((PyObject)o)); + } + return args; + } + +} Modified: branches/jy3k/src/org/python/antlr/adapter/AstAdapters.java =================================================================== --- branches/jy3k/src/org/python/antlr/adapter/AstAdapters.java 2009-01-05 17:59:06 UTC (rev 5851) +++ branches/jy3k/src/org/python/antlr/adapter/AstAdapters.java 2009-01-05 18:48:54 UTC (rev 5852) @@ -11,6 +11,7 @@ */ public class AstAdapters { public static AliasAdapter aliasAdapter = new AliasAdapter(); + public static ArgAdapter argAdapter = new ArgAdapter(); public static CmpopAdapter cmpopAdapter = new CmpopAdapter(); public static ComprehensionAdapter comprehensionAdapter = new ComprehensionAdapter(); public static ExcepthandlerAdapter excepthandlerAdapter = new ExcepthandlerAdapter(); @@ -24,6 +25,10 @@ return (java.util.List<alias>)aliasAdapter.iter2ast(o); } + public static java.util.List<arg> py2argList(PyObject o) { + return (java.util.List<arg>)argAdapter.iter2ast(o); + } + public static java.util.List<cmpopType> py2cmpopList(PyObject o) { return (java.util.List<cmpopType>)cmpopAdapter.iter2ast(o); } Modified: branches/jy3k/src/org/python/compiler/ArgListCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/ArgListCompiler.java 2009-01-05 17:59:06 UTC (rev 5851) +++ branches/jy3k/src/org/python/compiler/ArgListCompiler.java 2009-01-05 18:48:54 UTC (rev 5852) @@ -51,14 +51,6 @@ for (int i = 0; i < args.getInternalArgs().size(); i++) { String name = (String) visit(args.getInternalArgs().get(i)); names.add(name); - if (args.getInternalArgs().get(i) instanceof Tuple) { - List<expr> targets = new ArrayList<expr>(); - targets.add(args.getInternalArgs().get(i)); - Assign ass = new Assign(args.getInternalArgs().get(i), - targets, - new Name(args.getInternalArgs().get(i), name, expr_contextType.Load)); - init_code.add(ass); - } } if (args.getInternalVararg() != null) { arglist = true; Modified: branches/jy3k/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-05 17:59:06 UTC (rev 5851) +++ branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-05 18:48:54 UTC (rev 5852) @@ -1057,7 +1057,12 @@ if (handler.getInternalName() != null) { code.aload(exc); code.getfield("org/python/core/PyException", "value", "Lorg/python/core/PyObject;"); - set(handler.getInternalName()); + + //XXX: in 3.0 name is now a string, not a node. + //set(handler.getInternalName()); + String name = getName(handler.getInternalName()); + code.ldc(name); + } //do exception body Modified: branches/jy3k/src/org/python/compiler/ScopesCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/ScopesCompiler.java 2009-01-05 17:59:06 UTC (rev 5851) +++ branches/jy3k/src/org/python/compiler/ScopesCompiler.java 2009-01-05 18:48:54 UTC (rev 5852) @@ -4,6 +4,7 @@ import org.python.antlr.Visitor; import org.python.antlr.PythonTree; +import org.python.antlr.ast.arg; import org.python.antlr.ast.ClassDef; import org.python.antlr.ast.Expression; import org.python.antlr.ast.FunctionDef; @@ -301,9 +302,9 @@ + ")"; def(tmp); ArgListCompiler ac = new ArgListCompiler(); - List<expr> args = new ArrayList<expr>(); - args.add(new Name(node.getToken(), bound_exp, expr_contextType.Param)); - ac.visitArgs(new arguments(node, args, null, null, new ArrayList<expr>())); + List<arg> args = new ArrayList<arg>(); + args.add(new arg(node, bound_exp, null)); + ac.visitArgs(new arguments(node, args, null, null, new ArrayList<arg>(), null, null, new ArrayList<expr>(), new ArrayList<expr>())); beginScope(tmp, FUNCSCOPE, node, ac); cur.addParam(bound_exp); cur.markFromParam(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-07 01:21:12
|
Revision: 5860 http://jython.svn.sourceforge.net/jython/?rev=5860&view=rev Author: fwierzbicki Date: 2009-01-07 01:21:04 +0000 (Wed, 07 Jan 2009) Log Message: ----------- with is a keyword now. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/compiler/CodeCompiler.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-06 21:58:40 UTC (rev 5859) +++ branches/jy3k/grammar/Python.g 2009-01-07 01:21:04 UTC (rev 5860) @@ -444,10 +444,10 @@ } ; -//parameters: '(' [varargslist] ')' +//parameters: '(' [typedargslist] ')' parameters returns [arguments args] : LPAREN - (varargslist {$args = $varargslist.args;} + (typedargslist {$args = $typedargslist.args;} | { $args = new arguments($parameters.start, new ArrayList<arg>(), null, null, new ArrayList<arg>(), null, null, new ArrayList<expr>(), new ArrayList<expr>()); } ) @@ -578,7 +578,7 @@ ; //small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | -// import_stmt | global_stmt | exec_stmt | assert_stmt) +// import_stmt | global_stmt | assert_stmt) small_stmt : expr_stmt | del_stmt | pass_stmt @@ -1571,7 +1571,6 @@ DELETE : 'del' ; ELIF : 'elif' ; EXCEPT : 'except' ; -EXEC : 'exec' ; FINALLY : 'finally' ; FROM : 'from' ; FOR : 'for' ; Modified: branches/jy3k/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-06 21:58:40 UTC (rev 5859) +++ branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-07 01:21:04 UTC (rev 5860) @@ -2151,10 +2151,6 @@ @Override public Object visitWith(With node) throws Exception { - if (!module.getFutures().withStatementSupported()) { - throw new ParseException("'with' will become a reserved keyword in Python 2.6", node); - } - final Label label_body_start = new Label(); final Label label_body_end = new Label(); final Label label_catch = new Label(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-07 18:04:28
|
Revision: 5868 http://jython.svn.sourceforge.net/jython/?rev=5868&view=rev Author: fwierzbicki Date: 2009-01-07 18:04:18 +0000 (Wed, 07 Jan 2009) Log Message: ----------- Added ARROW. Created simple (and wrong) print() builtin for sanity checks. Added support for new octal representation. passed os.py through 2to3 converter. Modified Paths: -------------- branches/jy3k/Lib/os.py branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java branches/jy3k/src/org/python/core/__builtin__.java Modified: branches/jy3k/Lib/os.py =================================================================== --- branches/jy3k/Lib/os.py 2009-01-07 17:42:04 UTC (rev 5867) +++ branches/jy3k/Lib/os.py 2009-01-07 18:04:18 UTC (rev 5868) @@ -83,7 +83,7 @@ os_name = str(java.lang.System.getProperty('os.name')) os_type = None - for type, (patterns, shell_commands) in _os_map.iteritems(): + for type, (patterns, shell_commands) in _os_map.items(): for pattern in patterns: if os_name.startswith(pattern): # determine the shell_command later, when it's needed: @@ -113,7 +113,7 @@ def getCurrentWorkingDirectory(self): return File(getcwd()) def getEnv(self): - return ['%s=%s' % (key, val) for key, val in environ.iteritems()] + return ['%s=%s' % (key, val) for key, val in environ.items()] def getInputStream(self): return getattr(java.lang.System, 'in') # XXX handle resetting def getOutputStream(self): @@ -412,7 +412,7 @@ Translate an error code to a message string. """ - if not isinstance(code, (int, long)): + if not isinstance(code, int): raise TypeError('an integer is required') constant = Errno.valueOf(code) if constant is Errno.__UNKNOWN_CONSTANT__: @@ -435,7 +435,7 @@ specified access to the path. The mode argument can be F_OK to test existence, or the inclusive-OR of R_OK, W_OK, and X_OK. """ - if not isinstance(mode, (int, long)): + if not isinstance(mode, int): raise TypeError('an integer is required') f = File(sys.getPath(path)) @@ -562,14 +562,14 @@ _time_t = Integer if Platform.IS_32_BIT else Long try: - floor = long(seconds) + floor = int(seconds) except TypeError: raise TypeError('an integer is required') if not _time_t.MIN_VALUE <= floor <= _time_t.MAX_VALUE: raise OverflowError('long int too large to convert to int') # usec can't exceed 1000000 - usec = long((seconds - floor) * 1e6) + usec = int((seconds - floor) * 1e6) if usec < 0: # If rounding gave us a negative number, truncate usec = 0 @@ -608,7 +608,7 @@ rawio = FileDescriptors.get(fd) try: rawio.truncate(length) - except Exception, e: + except Exception as e: raise IOError(errno.EBADF, strerror(errno.EBADF)) def lseek(fd, pos, how): @@ -619,7 +619,8 @@ rawio = FileDescriptors.get(fd) return _handle_oserror(rawio.seek, pos, how) -def open(filename, flag, mode=0777): +#FIXME: needs to change to mode=0o777 for 3.0 +def open(filename, flag, mode=0o777): """open(filename, flag [, mode=0777]) -> fd Open a file (for low level IO). @@ -655,7 +656,7 @@ if not File(sys.getPath(filename)).createNewFile(): raise OSError(errno.EEXIST, strerror(errno.EEXIST), filename) - except java.io.IOException, ioe: + except java.io.IOException as ioe: raise OSError(ioe) mode = '%s%s%s%s' % (reading and 'r' or '', @@ -667,7 +668,7 @@ from java.io import FileNotFoundException, RandomAccessFile try: fchannel = RandomAccessFile(sys.getPath(filename), 'rws').getChannel() - except FileNotFoundException, fnfe: + except FileNotFoundException as fnfe: if path.isdir(filename): raise OSError(errno.EISDIR, strerror(errno.EISDIR)) raise OSError(errno.ENOENT, strerror(errno.ENOENT), filename) @@ -841,7 +842,7 @@ # Note that listdir and error are globals in this module due # to earlier import-*. names = listdir(top) - except error, err: + except error as err: if onerror is not None: onerror(err) return @@ -875,7 +876,7 @@ def __init__(self, environ): UserDict.UserDict.__init__(self) data = self.data - for k, v in environ.items(): + for k, v in list(environ.items()): data[k.upper()] = v def __setitem__(self, key, item): self.data[key.upper()] = item @@ -890,7 +891,7 @@ def get(self, key, failobj=None): return self.data.get(key.upper(), failobj) def update(self, dict): - for k, v in dict.items(): + for k, v in list(dict.items()): self[k] = v def copy(self): return dict(self) @@ -1063,7 +1064,7 @@ return _posix.isatty(fileno) if not isinstance(fileno, IOBase): - print fileno + print(fileno) raise TypeError('a file descriptor is required') return fileno.isatty() Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-07 17:42:04 UTC (rev 5867) +++ branches/jy3k/grammar/Python.g 2009-01-07 18:04:18 UTC (rev 5868) @@ -434,7 +434,7 @@ funcdef @init { stmt stype = null; } @after { $funcdef.tree = stype; } - : decorators? DEF NAME parameters COLON suite[false] + : decorators? DEF NAME parameters (ARROW test[expr_contextType.Load])? COLON suite[false] { Token t = $DEF; if ($decorators.start != null) { @@ -754,8 +754,7 @@ } ; -//XXX: when does CPython Grammar match "dotted_name NAME NAME"? -//dotted_as_name: dotted_name [('as' | NAME) NAME] +//dotted_as_name: dotted_name ['as' NAME] dotted_as_name returns [alias atype] @after { $dotted_as_name.tree = $atype; @@ -1569,6 +1568,8 @@ -> ^(YIELD<Yield>[$YIELD, actions.castExpr($testlist.tree)]) ; +ARROW : '->' ; + AS : 'as' ; ASSERT : 'assert' ; BREAK : 'break' ; @@ -1710,8 +1711,8 @@ INT : // Hex '0' ('x' | 'X') ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+ | // Octal - '0' ( '0' .. '7' )* - | '1'..'9' DIGITS* + '0' ('o' | 'O') ( '0' .. '7' )* + | '0'..'9' DIGITS* ; COMPLEX Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-07 17:42:04 UTC (rev 5867) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-07 18:04:18 UTC (rev 5868) @@ -362,8 +362,9 @@ if (s.startsWith("0x") || s.startsWith("0X")) { radix = 16; s = s.substring(2, s.length()); - } else if (s.startsWith("0")) { + } else if (s.startsWith("0o") || s.startsWith("0O")) { radix = 8; + s = s.substring(2, s.length()); } if (s.endsWith("L") || s.endsWith("l")) { s = s.substring(0, s.length()-1); Modified: branches/jy3k/src/org/python/core/__builtin__.java =================================================================== --- branches/jy3k/src/org/python/core/__builtin__.java 2009-01-07 17:42:04 UTC (rev 5867) +++ branches/jy3k/src/org/python/core/__builtin__.java 2009-01-07 18:04:18 UTC (rev 5868) @@ -370,6 +370,7 @@ dict.__setitem__("sorted", new SortedFunction()); dict.__setitem__("all", new AllFunction()); dict.__setitem__("any", new AnyFunction()); + dict.__setitem__("print", new PrintFunction()); } public static PyObject abs(PyObject o) { @@ -1591,3 +1592,22 @@ return PyFile.TYPE.__call__(args, kwds); } } + +class PrintFunction extends PyBuiltinFunctionNarrow { + PrintFunction() { + super("print", 1, 1, + "Prints the values to a stream, or to sys.stdout by default.\n" + + "Optional keyword arguments:\n" + + "file: a file-like object (stream); defaults to the current sys.stdout.\n" + + "sep: string inserted between values, default a space." + + "end: string appended after the last value, default a newline."); + } + + @Override + public PyObject __call__(PyObject arg) { + Py.println(arg); + return Py.None; + } +} + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-07 21:21:54
|
Revision: 5870 http://jython.svn.sourceforge.net/jython/?rev=5870&view=rev Author: fwierzbicki Date: 2009-01-07 21:21:48 +0000 (Wed, 07 Jan 2009) Log Message: ----------- Use new arg node in function defs. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/ErrorHandler.java branches/jy3k/src/org/python/antlr/FailFastHandler.java branches/jy3k/src/org/python/antlr/GrammarActions.java branches/jy3k/src/org/python/antlr/ListErrorHandler.java branches/jy3k/src/org/python/compiler/ArgListCompiler.java Added Paths: ----------- branches/jy3k/src/org/python/antlr/ast/ErrorArg.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-07 18:12:46 UTC (rev 5869) +++ branches/jy3k/grammar/Python.g 2009-01-07 21:21:48 UTC (rev 5870) @@ -455,20 +455,21 @@ ; //not in CPython's Grammar file -tdefparameter[List defaults] returns [expr etype] +tdefparameter[List defaults] returns [arg etype] @after { $tdefparameter.tree = $etype; } - : vfpdef[expr_contextType.Param] (ASSIGN test[expr_contextType.Load])? + : tfpdef[expr_contextType.Param] (ASSIGN test[expr_contextType.Load])? { - $etype = actions.castExpr($vfpdef.tree); + $etype = actions.castArg($tfpdef.tree); if ($ASSIGN != null) { defaults.add($test.tree); } else if (!defaults.isEmpty()) { - throw new ParseException("non-default argument follows default argument", $vfpdef.tree); + throw new ParseException("non-default argument follows default argument", $tfpdef.tree); } } ; + //typedargslist: ((tfpdef ['=' test] ',')* // ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef) // | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) @@ -497,11 +498,8 @@ //tfpdef: NAME [':' test] tfpdef[expr_contextType ctype] -@after { - actions.checkAssign(actions.castExpr($tfpdef.tree)); -} - : NAME (':' test[ctype])? - -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) + : NAME (COLON test[ctype])? + -> ^(NAME<arg>[$NAME, $NAME.text, null]) ; //not in CPython's Grammar file Modified: branches/jy3k/src/org/python/antlr/ErrorHandler.java =================================================================== --- branches/jy3k/src/org/python/antlr/ErrorHandler.java 2009-01-07 18:12:46 UTC (rev 5869) +++ branches/jy3k/src/org/python/antlr/ErrorHandler.java 2009-01-07 21:21:48 UTC (rev 5870) @@ -5,6 +5,7 @@ import org.antlr.runtime.IntStream; import org.antlr.runtime.Lexer; import org.antlr.runtime.RecognitionException; +import org.python.antlr.ast.arg; import org.python.antlr.base.expr; import org.python.antlr.base.mod; import org.python.antlr.base.slice; @@ -27,11 +28,12 @@ Object recoverFromMismatchedToken(BaseRecognizer br, IntStream input, int ttype, BitSet follow) throws RecognitionException; - //expr, mod, slice, stmt + //expr, mod, slice, stmt, arg expr errorExpr(PythonTree t); mod errorMod(PythonTree t); slice errorSlice(PythonTree t); stmt errorStmt(PythonTree t); + arg errorArg(PythonTree t); //exceptions void error(String message, PythonTree t); Modified: branches/jy3k/src/org/python/antlr/FailFastHandler.java =================================================================== --- branches/jy3k/src/org/python/antlr/FailFastHandler.java 2009-01-07 18:12:46 UTC (rev 5869) +++ branches/jy3k/src/org/python/antlr/FailFastHandler.java 2009-01-07 21:21:48 UTC (rev 5870) @@ -6,6 +6,7 @@ import org.antlr.runtime.Lexer; import org.antlr.runtime.MismatchedTokenException; import org.antlr.runtime.RecognitionException; +import org.python.antlr.ast.arg; import org.python.antlr.base.expr; import org.python.antlr.base.mod; import org.python.antlr.base.slice; @@ -52,6 +53,10 @@ throw new ParseException("Bad Stmt Node", t); } + public arg errorArg(PythonTree t) { + throw new ParseException("Bad Arg Node", t); + } + public void error(String message, PythonTree t) { throw new ParseException(message, t); } Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-07 18:12:46 UTC (rev 5869) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-07 21:21:48 UTC (rev 5870) @@ -156,13 +156,22 @@ List<arg> result = new ArrayList<arg>(); if (args != null) { for (Object o : args) { - if (o instanceof arg) { - result.add((arg)o); - } + result.add(castArg(o)); } } return result; } + + arg castArg(Object o) { + if (o instanceof arg) { + return (arg)o; + } + if (o instanceof PythonTree) { + return errorHandler.errorArg((PythonTree)o); + } + errorHandler.error("Bad Arg node", null); + return null; + } List<stmt> makeElse(List elseSuite, PythonTree elif) { if (elseSuite != null) { @@ -660,7 +669,6 @@ } void checkDelete(expr e) { - //System.out.println("trying to del " + e); if (e instanceof Call) { errorHandler.error("can't delete function call", e); } else if (e instanceof Num) { Modified: branches/jy3k/src/org/python/antlr/ListErrorHandler.java =================================================================== --- branches/jy3k/src/org/python/antlr/ListErrorHandler.java 2009-01-07 18:12:46 UTC (rev 5869) +++ branches/jy3k/src/org/python/antlr/ListErrorHandler.java 2009-01-07 21:21:48 UTC (rev 5870) @@ -5,6 +5,8 @@ import org.antlr.runtime.IntStream; import org.antlr.runtime.Lexer; import org.antlr.runtime.RecognitionException; +import org.python.antlr.ast.arg; +import org.python.antlr.ast.ErrorArg; import org.python.antlr.ast.ErrorMod; import org.python.antlr.ast.ErrorExpr; import org.python.antlr.ast.ErrorSlice; @@ -52,6 +54,10 @@ return new ErrorStmt(t); } + public arg errorArg(PythonTree t) { + return new ErrorArg(t); + } + public void error(String message, PythonTree t) { System.err.println(message); } Added: branches/jy3k/src/org/python/antlr/ast/ErrorArg.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/ErrorArg.java (rev 0) +++ branches/jy3k/src/org/python/antlr/ast/ErrorArg.java 2009-01-07 21:21:48 UTC (rev 5870) @@ -0,0 +1,38 @@ +package org.python.antlr.ast; +import org.python.antlr.PythonTree; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.Token; +import java.io.DataOutputStream; +import java.io.IOException; + +public class ErrorArg extends arg { + + public ErrorArg(PythonTree tree) { + super(tree, null, null); + } + + public String toString() { + return "ErrorArg"; + } + + public String toStringTree() { + return "ErrorArg"; + } + + public int getLineno() { + return getLine(); + } + + public int getCol_offset() { + return getCharPositionInLine(); + } + + public <R> R accept(VisitorIF<R> visitor) { + return null; + } + + public void traverse(VisitorIF visitor) throws Exception { + //no op. + } + +} Modified: branches/jy3k/src/org/python/compiler/ArgListCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/ArgListCompiler.java 2009-01-07 18:12:46 UTC (rev 5869) +++ branches/jy3k/src/org/python/compiler/ArgListCompiler.java 2009-01-07 21:21:48 UTC (rev 5870) @@ -11,6 +11,7 @@ import org.python.antlr.ast.Name; import org.python.antlr.ast.Suite; import org.python.antlr.ast.Tuple; +import org.python.antlr.ast.arg; import org.python.antlr.ast.arguments; import org.python.antlr.ast.expr_contextType; import org.python.antlr.base.expr; @@ -47,9 +48,19 @@ return defaults; } + public Object visitArg(arg node) throws Exception { + if (fpnames.contains(node.getInternalArg())) { + throw new ParseException("duplicate argument name found: " + + node.getInternalArg(), node); + } + fpnames.add(node.getInternalArg()); + return node.getInternalArg(); + } + + public void visitArgs(arguments args) throws Exception { for (int i = 0; i < args.getInternalArgs().size(); i++) { - String name = (String) visit(args.getInternalArgs().get(i)); + String name = (String) visitArg(args.getInternalArgs().get(i)); names.add(name); } if (args.getInternalVararg() != null) { @@ -85,6 +96,7 @@ return node.getInternalId(); } + /* @Override public Object visitTuple(Tuple node) throws Exception { StringBuffer name = new StringBuffer("("); @@ -97,4 +109,5 @@ name.append(")"); return name.toString(); } + */ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-08 00:32:26
|
Revision: 5873 http://jython.svn.sourceforge.net/jython/?rev=5873&view=rev Author: fwierzbicki Date: 2009-01-08 00:32:17 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Merged revisions 5842-5847,5854,5857-5859,5863-5865,5869 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5842 | cgroves | 2009-01-04 17:15:09 -0500 (Sun, 04 Jan 2009) | 5 lines Split java subclassing tests out of test_java_integration into test_java_subclasses, move unduplicated bits of test_jsubclass into test_java_subclasses. ........ r5843 | cgroves | 2009-01-04 18:06:27 -0500 (Sun, 04 Jan 2009) | 1 line Add tests that have been failing or skipping for the past few months to the expected lists ........ r5844 | cgroves | 2009-01-04 18:20:34 -0500 (Sun, 04 Jan 2009) | 1 line One more longstanding skip ........ r5845 | cgroves | 2009-01-04 22:56:25 -0500 (Sun, 04 Jan 2009) | 17 lines test292 - Moved to test_java_integration test293 - Importing no longer auto-imports submodules; deleted test294 - Moved to test_java_subclasses test295 - Moved to test_traceback test296 - Moved to test_import_jy test297,301,310,313,314,315,317 - Testing jythonc; deleted test298 - Moved to test_import_jy test299,300 - Tested by test_file test303 - Moved to test_java_visibility test307,308 - Moved to test_zipimport_jy test309 - Tested by test_scope test311 - Already disabled; deleted test312 - Moved to test_sax_jy test316 - Moved to test_java_integration test318 - Tested by test_syntax test319 - Moved to test_java_visibility ........ r5846 | cgroves | 2009-01-05 02:08:51 -0500 (Mon, 05 Jan 2009) | 1 line From http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_doctest.py@59127 ........ r5847 | cgroves | 2009-01-05 02:12:43 -0500 (Mon, 05 Jan 2009) | 10 lines test302 - Move to test_pep263_jy This adds a check for the encoding declared by the source file actually matching up with what we were getting out of it, and switches the default encoding to ascii to follow CPython. CPython assumes utf-8 in some single compilation contexts, and this uses the same parser algorithm everywhere, so I made a small change to test_doctest since Jython is throwing a SyntaxError on utf-8 strings to a single compilation. ........ r5854 | amak | 2009-01-05 14:47:25 -0500 (Mon, 05 Jan 2009) | 2 lines Fixed a bug where connect timeouts were not being honoured when set through socket.setdefaulttimeout() http://bugs.jython.org/issue1218 ........ r5857 | fwierzbicki | 2009-01-05 21:11:04 -0500 (Mon, 05 Jan 2009) | 2 lines Remove some unused methods. ........ r5858 | fwierzbicki | 2009-01-06 15:57:41 -0500 (Tue, 06 Jan 2009) | 4 lines Making the package names point to the raw original package names in source and making the jarjar step process everything in one step so the package mangling happens on our source as well as the included jars for jython-complete.jar. ........ r5859 | otmarhumbel | 2009-01-06 16:58:40 -0500 (Tue, 06 Jan 2009) | 2 lines - using ${dist.dir} for both jython.jar and jython-complete.jar - no unjar of jarjar.jar (since it does not exist any more) ........ r5863 | otmarhumbel | 2009-01-07 02:35:05 -0500 (Wed, 07 Jan 2009) | 2 lines - added asm and constantine .jar files to the eclipse build path - jarjar directory is not needed any more ........ r5864 | otmarhumbel | 2009-01-07 03:08:00 -0500 (Wed, 07 Jan 2009) | 5 lines 1) exlude jython.jar from the installation this makes the installer autotests pass again 2) do not include the /Lib files into jython-complete.jar once issue #1214 is fixed, 'java -jar jython-complete.jar' will run for all installation types (for now, set the -Dpython.home variable if not in standalone mode) ........ r5865 | otmarhumbel | 2009-01-07 03:28:57 -0500 (Wed, 07 Jan 2009) | 1 line preparation for an easy rename of the jython .jar files ........ r5869 | cgroves | 2009-01-07 13:12:46 -0500 (Wed, 07 Jan 2009) | 1 line Use the path to the imported item as __file__, not the package path ........ Modified Paths: -------------- branches/jy3k/.classpath branches/jy3k/Lib/os.py branches/jy3k/Lib/socket.py branches/jy3k/Lib/test/regrtest.py branches/jy3k/Lib/test/test_classpathimporter.py branches/jy3k/Lib/test/test_import_jy.py branches/jy3k/Lib/test/test_java_integration.py branches/jy3k/Lib/test/test_java_visibility.py branches/jy3k/Lib/test/test_socket.py branches/jy3k/Lib/test/test_traceback.py branches/jy3k/Lib/test/test_traceback_jy.py branches/jy3k/build.xml branches/jy3k/src/org/python/antlr/GrammarActions.java branches/jy3k/src/org/python/compiler/AdapterMaker.java branches/jy3k/src/org/python/compiler/ClassFile.java branches/jy3k/src/org/python/compiler/Code.java branches/jy3k/src/org/python/compiler/CodeCompiler.java branches/jy3k/src/org/python/compiler/Constant.java branches/jy3k/src/org/python/compiler/Module.java branches/jy3k/src/org/python/compiler/ProxyMaker.java branches/jy3k/src/org/python/core/APIReader.java branches/jy3k/src/org/python/core/BytecodeLoader.java branches/jy3k/src/org/python/core/ClasspathPyImporter.java branches/jy3k/src/org/python/core/ParserFacade.java branches/jy3k/src/org/python/core/Py.java branches/jy3k/src/org/python/core/PyReflectedConstructor.java branches/jy3k/src/org/python/core/imp.java branches/jy3k/src/org/python/core/io/FileIO.java branches/jy3k/src/org/python/core/io/IOBase.java branches/jy3k/src/org/python/core/io/ServerSocketIO.java branches/jy3k/src/org/python/core/util/importer.java branches/jy3k/src/org/python/expose/generate/ClassMethodExposer.java branches/jy3k/src/org/python/expose/generate/DescriptorExposer.java branches/jy3k/src/org/python/expose/generate/ExposeTask.java branches/jy3k/src/org/python/expose/generate/ExposedFieldFinder.java branches/jy3k/src/org/python/expose/generate/ExposedMethodFinder.java branches/jy3k/src/org/python/expose/generate/ExposedTypeProcessor.java branches/jy3k/src/org/python/expose/generate/ExposedTypeVisitor.java branches/jy3k/src/org/python/expose/generate/Exposer.java branches/jy3k/src/org/python/expose/generate/InstanceMethodExposer.java branches/jy3k/src/org/python/expose/generate/MethodExposer.java branches/jy3k/src/org/python/expose/generate/NewExposer.java branches/jy3k/src/org/python/expose/generate/OverridableNewExposer.java branches/jy3k/src/org/python/expose/generate/PyTypes.java branches/jy3k/src/org/python/expose/generate/RestrictiveAnnotationVisitor.java branches/jy3k/src/org/python/expose/generate/TypeExposer.java branches/jy3k/src/org/python/modules/_py_compile.java branches/jy3k/src/org/python/modules/errno.java branches/jy3k/src/org/python/modules/zipimport/zipimporter.java branches/jy3k/tests/java/org/python/expose/generate/DescriptorExposerTest.java branches/jy3k/tests/java/org/python/expose/generate/ExposeMethodFinderTest.java branches/jy3k/tests/java/org/python/expose/generate/ExposedTypeVisitorTest.java branches/jy3k/tests/java/org/python/expose/generate/MethodExposerTest.java branches/jy3k/tests/java/org/python/expose/generate/NewExposerTest.java branches/jy3k/tests/java/org/python/expose/generate/OverridableNewExposerTest.java branches/jy3k/tests/java/org/python/expose/generate/TypeExposerTest.java branches/jy3k/tests/java/org/python/tests/BeanInterface.java branches/jy3k/tests/java/org/python/tests/Coercions.java Added Paths: ----------- branches/jy3k/Lib/test/anygui.py branches/jy3k/Lib/test/import_nonexistent.py branches/jy3k/Lib/test/invalid_utf_8_declared_encoding.py branches/jy3k/Lib/test/latin1_no_encoding.py branches/jy3k/Lib/test/python_home.policy branches/jy3k/Lib/test/syspath_import.jar branches/jy3k/Lib/test/test_doctest.py branches/jy3k/Lib/test/test_java_subclasses.py branches/jy3k/Lib/test/test_pep263_jy.py branches/jy3k/Lib/test/test_sax_jy.py branches/jy3k/Lib/test/test_zipimport_jy.py branches/jy3k/tests/java/org/python/tests/Matryoshka.java Removed Paths: ------------- branches/jy3k/Lib/test/test_jsubclass.py branches/jy3k/bugtests/classes/test288i.java branches/jy3k/bugtests/classes/test288j.java branches/jy3k/bugtests/test290.py branches/jy3k/bugtests/test291.py branches/jy3k/bugtests/test292.policy branches/jy3k/bugtests/test292.py branches/jy3k/bugtests/test293.py branches/jy3k/bugtests/test293p/ branches/jy3k/bugtests/test294.py branches/jy3k/bugtests/test294j.java branches/jy3k/bugtests/test295.py branches/jy3k/bugtests/test296.py branches/jy3k/bugtests/test296p/ branches/jy3k/bugtests/test297.py branches/jy3k/bugtests/test297c.py branches/jy3k/bugtests/test298.py branches/jy3k/bugtests/test298m1.py branches/jy3k/bugtests/test299.py branches/jy3k/bugtests/test300.py branches/jy3k/bugtests/test301.py branches/jy3k/bugtests/test301c.py branches/jy3k/bugtests/test302.py branches/jy3k/bugtests/test303.py branches/jy3k/bugtests/test303j.java branches/jy3k/bugtests/test307.py branches/jy3k/bugtests/test307foobar.template branches/jy3k/bugtests/test307m.template branches/jy3k/bugtests/test307p.template branches/jy3k/bugtests/test308.py branches/jy3k/bugtests/test308d/ branches/jy3k/bugtests/test309.py branches/jy3k/bugtests/test310.py branches/jy3k/bugtests/test310c.py branches/jy3k/bugtests/test311.py branches/jy3k/bugtests/test312.py branches/jy3k/bugtests/test313.py branches/jy3k/bugtests/test313c.py branches/jy3k/bugtests/test314.py branches/jy3k/bugtests/test314c.py branches/jy3k/bugtests/test315.py branches/jy3k/bugtests/test315c.py branches/jy3k/bugtests/test316.py branches/jy3k/bugtests/test317.py branches/jy3k/bugtests/test317c.py branches/jy3k/bugtests/test318.py branches/jy3k/bugtests/test319.py branches/jy3k/bugtests/test319j.java branches/jy3k/tests/java/javatests/MethodInvokationTest.java Property Changed: ---------------- branches/jy3k/ Property changes on: branches/jy3k ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5840 + /trunk/jython:1-5872 Modified: branches/jy3k/.classpath =================================================================== --- branches/jy3k/.classpath 2009-01-07 23:59:24 UTC (rev 5872) +++ branches/jy3k/.classpath 2009-01-08 00:32:17 UTC (rev 5873) @@ -12,8 +12,10 @@ <classpathentry kind="lib" path="extlibs/mysql-connector-java-5.1.6.jar"/> <classpathentry kind="lib" path="extlibs/postgresql-8.3-603.jdbc4.jar"/> <classpathentry kind="lib" path="extlibs/servlet-api-2.5.jar"/> - <classpathentry kind="lib" path="build/jarjar"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> <classpathentry kind="lib" path="extlibs/antlr-3.1.1-runtime.jar"/> + <classpathentry kind="lib" path="extlibs/asm-3.1.jar"/> + <classpathentry kind="lib" path="extlibs/asm-commons-3.1.jar"/> + <classpathentry kind="lib" path="extlibs/constantine-0.4.jar"/> <classpathentry kind="output" path="bugtests/classes"/> </classpath> Modified: branches/jy3k/Lib/os.py =================================================================== --- branches/jy3k/Lib/os.py 2009-01-07 23:59:24 UTC (rev 5872) +++ branches/jy3k/Lib/os.py 2009-01-08 00:32:17 UTC (rev 5873) @@ -47,10 +47,14 @@ import stat as _stat import sys from java.io import File -from org.python.constantine.platform import Errno from org.python.core.io import FileDescriptors, FileIO, IOBase from org.python.core.Py import newString as asPyString +try: + from org.python.constantine.platform import Errno +except ImportError: + from com.kenai.constantine.platform import Errno + # Mapping of: os._name: [name list, shell command list] _os_map = dict(nt=[ ['Windows 95', 'Windows 98', 'Windows ME', 'Windows NT', @@ -96,7 +100,10 @@ # should *NOT* use it _name = get_os_type() -from org.python.posix import JavaPOSIX, POSIXHandler, POSIXFactory +try: + from org.python.posix import JavaPOSIX, POSIXHandler, POSIXFactory +except ImportError: + from org.jruby.ext.posix import JavaPOSIX, POSIXHandler, POSIXFactory class PythonPOSIXHandler(POSIXHandler): def error(self, error, msg): @@ -420,7 +427,10 @@ if constant.name() == constant.description(): # XXX: have constantine handle this fallback # Fake constant or just lacks a description, fallback to Linux's - from org.python.constantine.platform.linux import Errno as LinuxErrno + try: + from org.python.constantine.platform.linux import Errno as LinuxErrno + except ImportError: + from com.kenai.constantine.platform.linux import Errno as LinuxErrno constant = getattr(LinuxErrno, constant.name(), None) if not constant: return 'Unknown error: %d' % code @@ -558,7 +568,10 @@ global _time_t if _time_t is None: from java.lang import Integer, Long - from org.python.posix.util import Platform + try: + from org.python.posix import Platform + except ImportError: + from org.jruby.ext.posix.util import Platform _time_t = Integer if Platform.IS_32_BIT else Long try: Modified: branches/jy3k/Lib/socket.py =================================================================== --- branches/jy3k/Lib/socket.py 2009-01-07 23:59:24 UTC (rev 5872) +++ branches/jy3k/Lib/socket.py 2009-01-08 00:32:17 UTC (rev 5873) @@ -632,12 +632,14 @@ class _nonblocking_api_mixin: - timeout = _defaulttimeout mode = MODE_BLOCKING reference_count = 0 close_lock = threading.Lock() def __init__(self): + self.timeout = _defaulttimeout + if self.timeout is not None: + self.mode = MODE_TIMEOUT self.pending_options = { SO_REUSEADDR: 0, } @@ -791,7 +793,7 @@ self.sock_impl.bind(bind_host, bind_port, self.pending_options[SO_REUSEADDR]) self._config() # Configure timeouts, etc, now that the socket exists self.sock_impl.connect(host, port) - except java.lang.Exception, jlx: + except java.lang.Exception, jlx: raise _map_exception(jlx) def connect(self, addr): Copied: branches/jy3k/Lib/test/anygui.py (from rev 5869, trunk/jython/Lib/test/anygui.py) =================================================================== --- branches/jy3k/Lib/test/anygui.py (rev 0) +++ branches/jy3k/Lib/test/anygui.py 2009-01-08 00:32:17 UTC (rev 5873) @@ -0,0 +1,40 @@ +'''Used by test_import_jy/test_getattr_module''' +import sys + +class anygui: + __all__ = ['Window'] # Etc... + + def __init__(self): + self.__backend = None + self.__backends = ['msw', 'x', 'mac', 'wx', 'tk', 'java'] + + def __try_to_get(self, modulename): + import imp + try: + module = imp.find_module(modulename) + except (IOError, ImportError, AttributeError, AssertionError): + return None + else: + return module + + def __import_backend(self, wishlist): + candidates = self.__backends[:] + for wish in wishlist: + if wish in candidates: + candidates.remove(wish) + else: + wishlist.remove(wish) + candidates = wishlist + candidates + + for name in candidates: + backend = self.__try_to_get('%sgui' % name) + if not backend: + raise Exception, 'not able to import any GUI backends' + self.__backend = backend + + def __getattr__(self, name): + if not self.__backend: + self.__import_backend(self.__dict__.get('wishlist', [])) + return self.__backend.__dict__[name] + +sys.modules[__name__] = anygui() Copied: branches/jy3k/Lib/test/import_nonexistent.py (from rev 5869, trunk/jython/Lib/test/import_nonexistent.py) =================================================================== --- branches/jy3k/Lib/test/import_nonexistent.py (rev 0) +++ branches/jy3k/Lib/test/import_nonexistent.py 2009-01-08 00:32:17 UTC (rev 5873) @@ -0,0 +1,7 @@ +try: + import nonexistent_module +except ImportError: + pass # This should cause an import error, but as there's a security manager in place it hasn't + # always done so +else: + raise Error("Should've caused an import error!") Copied: branches/jy3k/Lib/test/invalid_utf_8_declared_encoding.py (from rev 5869, trunk/jython/Lib/test/invalid_utf_8_declared_encoding.py) =================================================================== (Binary files differ) Copied: branches/jy3k/Lib/test/latin1_no_encoding.py (from rev 5869, trunk/jython/Lib/test/latin1_no_encoding.py) =================================================================== (Binary files differ) Copied: branches/jy3k/Lib/test/python_home.policy (from rev 5869, trunk/jython/Lib/test/python_home.policy) =================================================================== --- branches/jy3k/Lib/test/python_home.policy (rev 0) +++ branches/jy3k/Lib/test/python_home.policy 2009-01-08 00:32:17 UTC (rev 5873) @@ -0,0 +1,5 @@ +grant codeBase "file:${python.home}/-" { + permission java.util.PropertyPermission "*", "read,write"; + permission java.io.FilePermission "<<ALL FILES>>", "read,write"; +}; + Modified: branches/jy3k/Lib/test/regrtest.py =================================================================== --- branches/jy3k/Lib/test/regrtest.py 2009-01-07 23:59:24 UTC (rev 5872) +++ branches/jy3k/Lib/test/regrtest.py 2009-01-08 00:32:17 UTC (rev 5873) @@ -1380,6 +1380,7 @@ 'java': """ test__locale + test__rawffi test_aepack test_al test_applesingle @@ -1449,6 +1450,7 @@ test_winreg test_winsound test_xml_etree_c + test_zipfile64 """ } _expectations['freebsd5'] = _expectations['freebsd4'] @@ -1475,11 +1477,16 @@ test_gc test_iterlen test_marshal + test_multibytecodec + test_multibytecodec_support test_peepholer test_profile test_pyclbr + test_stringprep test_transformer test_ucn + test_unicode + test_unicodedata test_xml_etree test_zipimport """, Copied: branches/jy3k/Lib/test/syspath_import.jar (from rev 5869, trunk/jython/Lib/test/syspath_import.jar) =================================================================== (Binary files differ) Modified: branches/jy3k/Lib/test/test_classpathimporter.py =================================================================== --- branches/jy3k/Lib/test/test_classpathimporter.py 2009-01-07 23:59:24 UTC (rev 5872) +++ branches/jy3k/Lib/test/test_classpathimporter.py 2009-01-08 00:32:17 UTC (rev 5873) @@ -18,22 +18,24 @@ except KeyError: pass - def setClassLoaderAndCheck(self, jar): + def setClassLoaderAndCheck(self, jar, prefix): Thread.currentThread().contextClassLoader = test_support.make_jar_classloader(jar) import flat_in_jar self.assertEquals(flat_in_jar.value, 7) import jar_pkg + self.assertEquals(prefix + '/jar_pkg/__init__$py.class', jar_pkg.__file__) from jar_pkg import prefer_compiled + self.assertEquals(prefix + '/jar_pkg/prefer_compiled$py.class', prefer_compiled.__file__) self.assert_(prefer_compiled.compiled) self.assertRaises(NameError, __import__, 'flat_bad') self.assertRaises(NameError, __import__, 'jar_pkg.bad') def test_default_pyclasspath(self): - self.setClassLoaderAndCheck("classimport.jar") + self.setClassLoaderAndCheck("classimport.jar", "__pyclasspath__") def test_path_in_pyclasspath(self): sys.path = ['__pyclasspath__/Lib'] - self.setClassLoaderAndCheck("classimport_Lib.jar") + self.setClassLoaderAndCheck("classimport_Lib.jar", "__pyclasspath__/Lib") def test_main(): test_support.run_unittest(ClasspathImporterTestCase) Copied: branches/jy3k/Lib/test/test_doctest.py (from rev 5869, trunk/jython/Lib/test/test_doctest.py) =================================================================== --- branches/jy3k/Lib/test/test_doctest.py (rev 0) +++ branches/jy3k/Lib/test/test_doctest.py 2009-01-08 00:32:17 UTC (rev 5873) @@ -0,0 +1,2438 @@ +""" +Test script for doctest. +""" + +from test import test_support +import doctest +import warnings + +###################################################################### +## Sample Objects (used by test cases) +###################################################################### + +def sample_func(v): + """ + Blah blah + + >>> print sample_func(22) + 44 + + Yee ha! + """ + return v+v + +class SampleClass: + """ + >>> print 1 + 1 + + >>> # comments get ignored. so are empty PS1 and PS2 prompts: + >>> + ... + + Multiline example: + >>> sc = SampleClass(3) + >>> for i in range(10): + ... sc = sc.double() + ... print sc.get(), + 6 12 24 48 96 192 384 768 1536 3072 + """ + def __init__(self, val): + """ + >>> print SampleClass(12).get() + 12 + """ + self.val = val + + def double(self): + """ + >>> print SampleClass(12).double().get() + 24 + """ + return SampleClass(self.val + self.val) + + def get(self): + """ + >>> print SampleClass(-5).get() + -5 + """ + return self.val + + def a_staticmethod(v): + """ + >>> print SampleClass.a_staticmethod(10) + 11 + """ + return v+1 + a_staticmethod = staticmethod(a_staticmethod) + + def a_classmethod(cls, v): + """ + >>> print SampleClass.a_classmethod(10) + 12 + >>> print SampleClass(0).a_classmethod(10) + 12 + """ + return v+2 + a_classmethod = classmethod(a_classmethod) + + a_property = property(get, doc=""" + >>> print SampleClass(22).a_property + 22 + """) + + class NestedClass: + """ + >>> x = SampleClass.NestedClass(5) + >>> y = x.square() + >>> print y.get() + 25 + """ + def __init__(self, val=0): + """ + >>> print SampleClass.NestedClass().get() + 0 + """ + self.val = val + def square(self): + return SampleClass.NestedClass(self.val*self.val) + def get(self): + return self.val + +class SampleNewStyleClass(object): + r""" + >>> print '1\n2\n3' + 1 + 2 + 3 + """ + def __init__(self, val): + """ + >>> print SampleNewStyleClass(12).get() + 12 + """ + self.val = val + + def double(self): + """ + >>> print SampleNewStyleClass(12).double().get() + 24 + """ + return SampleNewStyleClass(self.val + self.val) + + def get(self): + """ + >>> print SampleNewStyleClass(-5).get() + -5 + """ + return self.val + +###################################################################### +## Fake stdin (for testing interactive debugging) +###################################################################### + +class _FakeInput: + """ + A fake input stream for pdb's interactive debugger. Whenever a + line is read, print it (to simulate the user typing it), and then + return it. The set of lines to return is specified in the + constructor; they should not have trailing newlines. + """ + def __init__(self, lines): + self.lines = lines + + def readline(self): + line = self.lines.pop(0) + print line + return line+'\n' + +###################################################################### +## Test Cases +###################################################################### + +def test_Example(): r""" +Unit tests for the `Example` class. + +Example is a simple container class that holds: + - `source`: A source string. + - `want`: An expected output string. + - `exc_msg`: An expected exception message string (or None if no + exception is expected). + - `lineno`: A line number (within the docstring). + - `indent`: The example's indentation in the input string. + - `options`: An option dictionary, mapping option flags to True or + False. + +These attributes are set by the constructor. `source` and `want` are +required; the other attributes all have default values: + + >>> example = doctest.Example('print 1', '1\n') + >>> (example.source, example.want, example.exc_msg, + ... example.lineno, example.indent, example.options) + ('print 1\n', '1\n', None, 0, 0, {}) + +The first three attributes (`source`, `want`, and `exc_msg`) may be +specified positionally; the remaining arguments should be specified as +keyword arguments: + + >>> exc_msg = 'IndexError: pop from an empty list' + >>> example = doctest.Example('[].pop()', '', exc_msg, + ... lineno=5, indent=4, + ... options={doctest.ELLIPSIS: True}) + >>> (example.source, example.want, example.exc_msg, + ... example.lineno, example.indent, example.options) + ('[].pop()\n', '', 'IndexError: pop from an empty list\n', 5, 4, {8: True}) + +The constructor normalizes the `source` string to end in a newline: + + Source spans a single line: no terminating newline. + >>> e = doctest.Example('print 1', '1\n') + >>> e.source, e.want + ('print 1\n', '1\n') + + >>> e = doctest.Example('print 1\n', '1\n') + >>> e.source, e.want + ('print 1\n', '1\n') + + Source spans multiple lines: require terminating newline. + >>> e = doctest.Example('print 1;\nprint 2\n', '1\n2\n') + >>> e.source, e.want + ('print 1;\nprint 2\n', '1\n2\n') + + >>> e = doctest.Example('print 1;\nprint 2', '1\n2\n') + >>> e.source, e.want + ('print 1;\nprint 2\n', '1\n2\n') + + Empty source string (which should never appear in real examples) + >>> e = doctest.Example('', '') + >>> e.source, e.want + ('\n', '') + +The constructor normalizes the `want` string to end in a newline, +unless it's the empty string: + + >>> e = doctest.Example('print 1', '1\n') + >>> e.source, e.want + ('print 1\n', '1\n') + + >>> e = doctest.Example('print 1', '1') + >>> e.source, e.want + ('print 1\n', '1\n') + + >>> e = doctest.Example('print', '') + >>> e.source, e.want + ('print\n', '') + +The constructor normalizes the `exc_msg` string to end in a newline, +unless it's `None`: + + Message spans one line + >>> exc_msg = 'IndexError: pop from an empty list' + >>> e = doctest.Example('[].pop()', '', exc_msg) + >>> e.exc_msg + 'IndexError: pop from an empty list\n' + + >>> exc_msg = 'IndexError: pop from an empty list\n' + >>> e = doctest.Example('[].pop()', '', exc_msg) + >>> e.exc_msg + 'IndexError: pop from an empty list\n' + + Message spans multiple lines + >>> exc_msg = 'ValueError: 1\n 2' + >>> e = doctest.Example('raise ValueError("1\n 2")', '', exc_msg) + >>> e.exc_msg + 'ValueError: 1\n 2\n' + + >>> exc_msg = 'ValueError: 1\n 2\n' + >>> e = doctest.Example('raise ValueError("1\n 2")', '', exc_msg) + >>> e.exc_msg + 'ValueError: 1\n 2\n' + + Empty (but non-None) exception message (which should never appear + in real examples) + >>> exc_msg = '' + >>> e = doctest.Example('raise X()', '', exc_msg) + >>> e.exc_msg + '\n' +""" + +def test_DocTest(): r""" +Unit tests for the `DocTest` class. + +DocTest is a collection of examples, extracted from a docstring, along +with information about where the docstring comes from (a name, +filename, and line number). The docstring is parsed by the `DocTest` +constructor: + + >>> docstring = ''' + ... >>> print 12 + ... 12 + ... + ... Non-example text. + ... + ... >>> print 'another\example' + ... another + ... example + ... ''' + >>> globs = {} # globals to run the test in. + >>> parser = doctest.DocTestParser() + >>> test = parser.get_doctest(docstring, globs, 'some_test', + ... 'some_file', 20) + >>> print test + <DocTest some_test from some_file:20 (2 examples)> + >>> len(test.examples) + 2 + >>> e1, e2 = test.examples + >>> (e1.source, e1.want, e1.lineno) + ('print 12\n', '12\n', 1) + >>> (e2.source, e2.want, e2.lineno) + ("print 'another\\example'\n", 'another\nexample\n', 6) + +Source information (name, filename, and line number) is available as +attributes on the doctest object: + + >>> (test.name, test.filename, test.lineno) + ('some_test', 'some_file', 20) + +The line number of an example within its containing file is found by +adding the line number of the example and the line number of its +containing test: + + >>> test.lineno + e1.lineno + 21 + >>> test.lineno + e2.lineno + 26 + +If the docstring contains inconsistant leading whitespace in the +expected output of an example, then `DocTest` will raise a ValueError: + + >>> docstring = r''' + ... >>> print 'bad\nindentation' + ... bad + ... indentation + ... ''' + >>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0) + Traceback (most recent call last): + ValueError: line 4 of the docstring for some_test has inconsistent leading whitespace: 'indentation' + +If the docstring contains inconsistent leading whitespace on +continuation lines, then `DocTest` will raise a ValueError: + + >>> docstring = r''' + ... >>> print ('bad indentation', + ... ... 2) + ... ('bad', 'indentation') + ... ''' + >>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0) + Traceback (most recent call last): + ValueError: line 2 of the docstring for some_test has inconsistent leading whitespace: '... 2)' + +If there's no blank space after a PS1 prompt ('>>>'), then `DocTest` +will raise a ValueError: + + >>> docstring = '>>>print 1\n1' + >>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0) + Traceback (most recent call last): + ValueError: line 1 of the docstring for some_test lacks blank after >>>: '>>>print 1' + +If there's no blank space after a PS2 prompt ('...'), then `DocTest` +will raise a ValueError: + + >>> docstring = '>>> if 1:\n...print 1\n1' + >>> parser.get_doctest(docstring, globs, 'some_test', 'filename', 0) + Traceback (most recent call last): + ValueError: line 2 of the docstring for some_test lacks blank after ...: '...print 1' + +""" + +def test_DocTestFinder(): r""" +Unit tests for the `DocTestFinder` class. + +DocTestFinder is used to extract DocTests from an object's docstring +and the docstrings of its contained objects. It can be used with +modules, functions, classes, methods, staticmethods, classmethods, and +properties. + +Finding Tests in Functions +~~~~~~~~~~~~~~~~~~~~~~~~~~ +For a function whose docstring contains examples, DocTestFinder.find() +will return a single test (for that function's docstring): + + >>> finder = doctest.DocTestFinder() + +We'll simulate a __file__ attr that ends in pyc: + + >>> import test.test_doctest + >>> old = test.test_doctest.__file__ + >>> test.test_doctest.__file__ = 'test_doctest.pyc' + + >>> tests = finder.find(sample_func) + + >>> print tests # doctest: +ELLIPSIS + [<DocTest sample_func from ...:13 (1 example)>] + +The exact name depends on how test_doctest was invoked, so allow for +leading path components. + + >>> tests[0].filename # doctest: +ELLIPSIS + '...test_doctest.py' + + >>> test.test_doctest.__file__ = old + + + >>> e = tests[0].examples[0] + >>> (e.source, e.want, e.lineno) + ('print sample_func(22)\n', '44\n', 3) + +By default, tests are created for objects with no docstring: + + >>> def no_docstring(v): + ... pass + >>> finder.find(no_docstring) + [] + +However, the optional argument `exclude_empty` to the DocTestFinder +constructor can be used to exclude tests for objects with empty +docstrings: + + >>> def no_docstring(v): + ... pass + >>> excl_empty_finder = doctest.DocTestFinder(exclude_empty=True) + >>> excl_empty_finder.find(no_docstring) + [] + +If the function has a docstring with no examples, then a test with no +examples is returned. (This lets `DocTestRunner` collect statistics +about which functions have no tests -- but is that useful? And should +an empty test also be created when there's no docstring?) + + >>> def no_examples(v): + ... ''' no doctest examples ''' + >>> finder.find(no_examples) # doctest: +ELLIPSIS + [<DocTest no_examples from ...:1 (no examples)>] + +Finding Tests in Classes +~~~~~~~~~~~~~~~~~~~~~~~~ +For a class, DocTestFinder will create a test for the class's +docstring, and will recursively explore its contents, including +methods, classmethods, staticmethods, properties, and nested classes. + + >>> finder = doctest.DocTestFinder() + >>> tests = finder.find(SampleClass) + >>> for t in tests: + ... print '%2s %s' % (len(t.examples), t.name) + 3 SampleClass + 3 SampleClass.NestedClass + 1 SampleClass.NestedClass.__init__ + 1 SampleClass.__init__ + 2 SampleClass.a_classmethod + 1 SampleClass.a_property + 1 SampleClass.a_staticmethod + 1 SampleClass.double + 1 SampleClass.get + +New-style classes are also supported: + + >>> tests = finder.find(SampleNewStyleClass) + >>> for t in tests: + ... print '%2s %s' % (len(t.examples), t.name) + 1 SampleNewStyleClass + 1 SampleNewStyleClass.__init__ + 1 SampleNewStyleClass.double + 1 SampleNewStyleClass.get + +Finding Tests in Modules +~~~~~~~~~~~~~~~~~~~~~~~~ +For a module, DocTestFinder will create a test for the class's +docstring, and will recursively explore its contents, including +functions, classes, and the `__test__` dictionary, if it exists: + + >>> # A module + >>> import new + >>> m = new.module('some_module') + >>> def triple(val): + ... ''' + ... >>> print triple(11) + ... 33 + ... ''' + ... return val*3 + >>> m.__dict__.update({ + ... 'sample_func': sample_func, + ... 'SampleClass': SampleClass, + ... '__doc__': ''' + ... Module docstring. + ... >>> print 'module' + ... module + ... ''', + ... '__test__': { + ... 'd': '>>> print 6\n6\n>>> print 7\n7\n', + ... 'c': triple}}) + + >>> finder = doctest.DocTestFinder() + >>> # Use module=test.test_doctest, to prevent doctest from + >>> # ignoring the objects since they weren't defined in m. + >>> import test.test_doctest + >>> tests = finder.find(m, module=test.test_doctest) + >>> for t in tests: + ... print '%2s %s' % (len(t.examples), t.name) + 1 some_module + 3 some_module.SampleClass + 3 some_module.SampleClass.NestedClass + 1 some_module.SampleClass.NestedClass.__init__ + 1 some_module.SampleClass.__init__ + 2 some_module.SampleClass.a_classmethod + 1 some_module.SampleClass.a_property + 1 some_module.SampleClass.a_staticmethod + 1 some_module.SampleClass.double + 1 some_module.SampleClass.get + 1 some_module.__test__.c + 2 some_module.__test__.d + 1 some_module.sample_func + +Duplicate Removal +~~~~~~~~~~~~~~~~~ +If a single object is listed twice (under different names), then tests +will only be generated for it once: + + >>> from test import doctest_aliases + >>> tests = excl_empty_finder.find(doctest_aliases) + >>> print len(tests) + 2 + >>> print tests[0].name + test.doctest_aliases.TwoNames + + TwoNames.f and TwoNames.g are bound to the same object. + We can't guess which will be found in doctest's traversal of + TwoNames.__dict__ first, so we have to allow for either. + + >>> tests[1].name.split('.')[-1] in ['f', 'g'] + True + +Empty Tests +~~~~~~~~~~~ +By default, an object with no doctests doesn't create any tests: + + >>> tests = doctest.DocTestFinder().find(SampleClass) + >>> for t in tests: + ... print '%2s %s' % (len(t.examples), t.name) + 3 SampleClass + 3 SampleClass.NestedClass + 1 SampleClass.NestedClass.__init__ + 1 SampleClass.__init__ + 2 SampleClass.a_classmethod + 1 SampleClass.a_property + 1 SampleClass.a_staticmethod + 1 SampleClass.double + 1 SampleClass.get + +By default, that excluded objects with no doctests. exclude_empty=False +tells it to include (empty) tests for objects with no doctests. This feature +is really to support backward compatibility in what doctest.master.summarize() +displays. + + >>> tests = doctest.DocTestFinder(exclude_empty=False).find(SampleClass) + >>> for t in tests: + ... print '%2s %s' % (len(t.examples), t.name) + 3 SampleClass + 3 SampleClass.NestedClass + 1 SampleClass.NestedClass.__init__ + 0 SampleClass.NestedClass.get + 0 SampleClass.NestedClass.square + 1 SampleClass.__init__ + 2 SampleClass.a_classmethod + 1 SampleClass.a_property + 1 SampleClass.a_staticmethod + 1 SampleClass.double + 1 SampleClass.get + +Turning off Recursion +~~~~~~~~~~~~~~~~~~~~~ +DocTestFinder can be told not to look for tests in contained objects +using the `recurse` flag: + + >>> tests = doctest.DocTestFinder(recurse=False).find(SampleClass) + >>> for t in tests: + ... print '%2s %s' % (len(t.examples), t.name) + 3 SampleClass + +Line numbers +~~~~~~~~~~~~ +DocTestFinder finds the line number of each example: + + >>> def f(x): + ... ''' + ... >>> x = 12 + ... + ... some text + ... + ... >>> # examples are not created for comments & bare prompts. + ... >>> + ... ... + ... + ... >>> for x in range(10): + ... ... print x, + ... 0 1 2 3 4 5 6 7 8 9 + ... >>> x//2 + ... 6 + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> [e.lineno for e in test.examples] + [1, 9, 12] +""" + +def test_DocTestParser(): r""" +Unit tests for the `DocTestParser` class. + +DocTestParser is used to parse docstrings containing doctest examples. + +The `parse` method divides a docstring into examples and intervening +text: + + >>> s = ''' + ... >>> x, y = 2, 3 # no output expected + ... >>> if 1: + ... ... print x + ... ... print y + ... 2 + ... 3 + ... + ... Some text. + ... >>> x+y + ... 5 + ... ''' + >>> parser = doctest.DocTestParser() + >>> for piece in parser.parse(s): + ... if isinstance(piece, doctest.Example): + ... print 'Example:', (piece.source, piece.want, piece.lineno) + ... else: + ... print ' Text:', `piece` + Text: '\n' + Example: ('x, y = 2, 3 # no output expected\n', '', 1) + Text: '' + Example: ('if 1:\n print x\n print y\n', '2\n3\n', 2) + Text: '\nSome text.\n' + Example: ('x+y\n', '5\n', 9) + Text: '' + +The `get_examples` method returns just the examples: + + >>> for piece in parser.get_examples(s): + ... print (piece.source, piece.want, piece.lineno) + ('x, y = 2, 3 # no output expected\n', '', 1) + ('if 1:\n print x\n print y\n', '2\n3\n', 2) + ('x+y\n', '5\n', 9) + +The `get_doctest` method creates a Test from the examples, along with the +given arguments: + + >>> test = parser.get_doctest(s, {}, 'name', 'filename', lineno=5) + >>> (test.name, test.filename, test.lineno) + ('name', 'filename', 5) + >>> for piece in test.examples: + ... print (piece.source, piece.want, piece.lineno) + ('x, y = 2, 3 # no output expected\n', '', 1) + ('if 1:\n print x\n print y\n', '2\n3\n', 2) + ('x+y\n', '5\n', 9) +""" + +class test_DocTestRunner: + def basics(): r""" +Unit tests for the `DocTestRunner` class. + +DocTestRunner is used to run DocTest test cases, and to accumulate +statistics. Here's a simple DocTest case we can use: + + >>> def f(x): + ... ''' + ... >>> x = 12 + ... >>> print x + ... 12 + ... >>> x//2 + ... 6 + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + +The main DocTestRunner interface is the `run` method, which runs a +given DocTest case in a given namespace (globs). It returns a tuple +`(f,t)`, where `f` is the number of failed tests and `t` is the number +of tried tests. + + >>> doctest.DocTestRunner(verbose=False).run(test) + (0, 3) + +If any example produces incorrect output, then the test runner reports +the failure and proceeds to the next example: + + >>> def f(x): + ... ''' + ... >>> x = 12 + ... >>> print x + ... 14 + ... >>> x//2 + ... 6 + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=True).run(test) + ... # doctest: +ELLIPSIS + Trying: + x = 12 + Expecting nothing + ok + Trying: + print x + Expecting: + 14 + ********************************************************************** + File ..., line 4, in f + Failed example: + print x + Expected: + 14 + Got: + 12 + Trying: + x//2 + Expecting: + 6 + ok + (1, 3) +""" + def verbose_flag(): r""" +The `verbose` flag makes the test runner generate more detailed +output: + + >>> def f(x): + ... ''' + ... >>> x = 12 + ... >>> print x + ... 12 + ... >>> x//2 + ... 6 + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + + >>> doctest.DocTestRunner(verbose=True).run(test) + Trying: + x = 12 + Expecting nothing + ok + Trying: + print x + Expecting: + 12 + ok + Trying: + x//2 + Expecting: + 6 + ok + (0, 3) + +If the `verbose` flag is unspecified, then the output will be verbose +iff `-v` appears in sys.argv: + + >>> # Save the real sys.argv list. + >>> old_argv = sys.argv + + >>> # If -v does not appear in sys.argv, then output isn't verbose. + >>> sys.argv = ['test'] + >>> doctest.DocTestRunner().run(test) + (0, 3) + + >>> # If -v does appear in sys.argv, then output is verbose. + >>> sys.argv = ['test', '-v'] + >>> doctest.DocTestRunner().run(test) + Trying: + x = 12 + Expecting nothing + ok + Trying: + print x + Expecting: + 12 + ok + Trying: + x//2 + Expecting: + 6 + ok + (0, 3) + + >>> # Restore sys.argv + >>> sys.argv = old_argv + +In the remaining examples, the test runner's verbosity will be +explicitly set, to ensure that the test behavior is consistent. + """ + def exceptions(): r""" +Tests of `DocTestRunner`'s exception handling. + +An expected exception is specified with a traceback message. The +lines between the first line and the type/value may be omitted or +replaced with any other string: + + >>> def f(x): + ... ''' + ... >>> x = 12 + ... >>> print x//0 + ... Traceback (most recent call last): + ... ZeroDivisionError: integer division or modulo by zero + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + (0, 2) + +An example may not generate output before it raises an exception; if +it does, then the traceback message will not be recognized as +signaling an expected exception, so the example will be reported as an +unexpected exception: + + >>> def f(x): + ... ''' + ... >>> x = 12 + ... >>> print 'pre-exception output', x//0 + ... pre-exception output + ... Traceback (most recent call last): + ... ZeroDivisionError: integer division or modulo by zero + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 4, in f + Failed example: + print 'pre-exception output', x//0 + Exception raised: + ... + ZeroDivisionError: integer division or modulo by zero + (1, 2) + +Exception messages may contain newlines: + + >>> def f(x): + ... r''' + ... >>> raise ValueError, 'multi\nline\nmessage' + ... Traceback (most recent call last): + ... ValueError: multi + ... line + ... message + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + (0, 1) + +If an exception is expected, but an exception with the wrong type or +message is raised, then it is reported as a failure: + + >>> def f(x): + ... r''' + ... >>> raise ValueError, 'message' + ... Traceback (most recent call last): + ... ValueError: wrong message + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 3, in f + Failed example: + raise ValueError, 'message' + Expected: + Traceback (most recent call last): + ValueError: wrong message + Got: + Traceback (most recent call last): + ... + ValueError: message + (1, 1) + +However, IGNORE_EXCEPTION_DETAIL can be used to allow a mismatch in the +detail: + + >>> def f(x): + ... r''' + ... >>> raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + ... Traceback (most recent call last): + ... ValueError: wrong message + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + (0, 1) + +But IGNORE_EXCEPTION_DETAIL does not allow a mismatch in the exception type: + + >>> def f(x): + ... r''' + ... >>> raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + ... Traceback (most recent call last): + ... TypeError: wrong type + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 3, in f + Failed example: + raise ValueError, 'message' #doctest: +IGNORE_EXCEPTION_DETAIL + Expected: + Traceback (most recent call last): + TypeError: wrong type + Got: + Traceback (most recent call last): + ... + ValueError: message + (1, 1) + +If an exception is raised but not expected, then it is reported as an +unexpected exception: + + >>> def f(x): + ... r''' + ... >>> 1//0 + ... 0 + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 3, in f + Failed example: + 1//0 + Exception raised: + Traceback (most recent call last): + ... + ZeroDivisionError: integer division or modulo by zero + (1, 1) +""" + def optionflags(): r""" +Tests of `DocTestRunner`'s option flag handling. + +Several option flags can be used to customize the behavior of the test +runner. These are defined as module constants in doctest, and passed +to the DocTestRunner constructor (multiple constants should be or-ed +together). + +The DONT_ACCEPT_TRUE_FOR_1 flag disables matches between True/False +and 1/0: + + >>> def f(x): + ... '>>> True\n1\n' + + >>> # Without the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + (0, 1) + + >>> # With the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.DONT_ACCEPT_TRUE_FOR_1 + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 2, in f + Failed example: + True + Expected: + 1 + Got: + True + (1, 1) + +The DONT_ACCEPT_BLANKLINE flag disables the match between blank lines +and the '<BLANKLINE>' marker: + + >>> def f(x): + ... '>>> print "a\\n\\nb"\na\n<BLANKLINE>\nb\n' + + >>> # Without the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + (0, 1) + + >>> # With the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.DONT_ACCEPT_BLANKLINE + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 2, in f + Failed example: + print "a\n\nb" + Expected: + a + <BLANKLINE> + b + Got: + a + <BLANKLINE> + b + (1, 1) + +The NORMALIZE_WHITESPACE flag causes all sequences of whitespace to be +treated as equal: + + >>> def f(x): + ... '>>> print 1, 2, 3\n 1 2\n 3' + + >>> # Without the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 2, in f + Failed example: + print 1, 2, 3 + Expected: + 1 2 + 3 + Got: + 1 2 3 + (1, 1) + + >>> # With the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.NORMALIZE_WHITESPACE + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + (0, 1) + + An example from the docs: + >>> print range(20) #doctest: +NORMALIZE_WHITESPACE + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] + +The ELLIPSIS flag causes ellipsis marker ("...") in the expected +output to match any substring in the actual output: + + >>> def f(x): + ... '>>> print range(15)\n[0, 1, 2, ..., 14]\n' + + >>> # Without the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 2, in f + Failed example: + print range(15) + Expected: + [0, 1, 2, ..., 14] + Got: + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] + (1, 1) + + >>> # With the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.ELLIPSIS + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + (0, 1) + + ... also matches nothing: + + >>> for i in range(100): + ... print i**2, #doctest: +ELLIPSIS + 0 1...4...9 16 ... 36 49 64 ... 9801 + + ... can be surprising; e.g., this test passes: + + >>> for i in range(21): #doctest: +ELLIPSIS + ... print i, + 0 1 2 ...1...2...0 + + Examples from the docs: + + >>> print range(20) # doctest:+ELLIPSIS + [0, 1, ..., 18, 19] + + >>> print range(20) # doctest: +ELLIPSIS + ... # doctest: +NORMALIZE_WHITESPACE + [0, 1, ..., 18, 19] + +The SKIP flag causes an example to be skipped entirely. I.e., the +example is not run. It can be useful in contexts where doctest +examples serve as both documentation and test cases, and an example +should be included for documentation purposes, but should not be +checked (e.g., because its output is random, or depends on resources +which would be unavailable.) The SKIP flag can also be used for +'commenting out' broken examples. + + >>> import unavailable_resource # doctest: +SKIP + >>> unavailable_resource.do_something() # doctest: +SKIP + >>> unavailable_resource.blow_up() # doctest: +SKIP + Traceback (most recent call last): + ... + UncheckedBlowUpError: Nobody checks me. + + >>> import random + >>> print random.random() # doctest: +SKIP + 0.721216923889 + +The REPORT_UDIFF flag causes failures that involve multi-line expected +and actual outputs to be displayed using a unified diff: + + >>> def f(x): + ... r''' + ... >>> print '\n'.join('abcdefg') + ... a + ... B + ... c + ... d + ... f + ... g + ... h + ... ''' + + >>> # Without the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 3, in f + Failed example: + print '\n'.join('abcdefg') + Expected: + a + B + c + d + f + g + h + Got: + a + b + c + d + e + f + g + (1, 1) + + >>> # With the flag: + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.REPORT_UDIFF + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 3, in f + Failed example: + print '\n'.join('abcdefg') + Differences (unified diff with -expected +actual): + @@ -1,7 +1,7 @@ + a + -B + +b + c + d + +e + f + g + -h + (1, 1) + +The REPORT_CDIFF flag causes failures that involve multi-line expected +and actual outputs to be displayed using a context diff: + + >>> # Reuse f() from the REPORT_UDIFF example, above. + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.REPORT_CDIFF + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 3, in f + Failed example: + print '\n'.join('abcdefg') + Differences (context diff with expected followed by actual): + *************** + *** 1,7 **** + a + ! B + c + d + f + g + - h + --- 1,7 ---- + a + ! b + c + d + + e + f + g + (1, 1) + + +The REPORT_NDIFF flag causes failures to use the difflib.Differ algorithm +used by the popular ndiff.py utility. This does intraline difference +marking, as well as interline differences. + + >>> def f(x): + ... r''' + ... >>> print "a b c d e f g h i j k l m" + ... a b c d e f g h i j k 1 m + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.REPORT_NDIFF + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 3, in f + Failed example: + print "a b c d e f g h i j k l m" + Differences (ndiff with -expected +actual): + - a b c d e f g h i j k 1 m + ? ^ + + a b c d e f g h i j k l m + ? + ++ ^ + (1, 1) + +The REPORT_ONLY_FIRST_FAILURE supresses result output after the first +failing example: + + >>> def f(x): + ... r''' + ... >>> print 1 # first success + ... 1 + ... >>> print 2 # first failure + ... 200 + ... >>> print 3 # second failure + ... 300 + ... >>> print 4 # second success + ... 4 + ... >>> print 5 # third failure + ... 500 + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.REPORT_ONLY_FIRST_FAILURE + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 5, in f + Failed example: + print 2 # first failure + Expected: + 200 + Got: + 2 + (3, 5) + +However, output from `report_start` is not supressed: + + >>> doctest.DocTestRunner(verbose=True, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + Trying: + print 1 # first success + Expecting: + 1 + ok + Trying: + print 2 # first failure + Expecting: + 200 + ********************************************************************** + File ..., line 5, in f + Failed example: + print 2 # first failure + Expected: + 200 + Got: + 2 + (3, 5) + +For the purposes of REPORT_ONLY_FIRST_FAILURE, unexpected exceptions +count as failures: + + >>> def f(x): + ... r''' + ... >>> print 1 # first success + ... 1 + ... >>> raise ValueError(2) # first failure + ... 200 + ... >>> print 3 # second failure + ... 300 + ... >>> print 4 # second success + ... 4 + ... >>> print 5 # third failure + ... 500 + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.REPORT_ONLY_FIRST_FAILURE + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 5, in f + Failed example: + raise ValueError(2) # first failure + Exception raised: + ... + ValueError: 2 + (3, 5) + +New option flags can also be registered, via register_optionflag(). Here +we reach into doctest's internals a bit. + + >>> unlikely = "UNLIKELY_OPTION_NAME" + >>> unlikely in doctest.OPTIONFLAGS_BY_NAME + False + >>> new_flag_value = doctest.register_optionflag(unlikely) + >>> unlikely in doctest.OPTIONFLAGS_BY_NAME + True + +Before 2.4.4/2.5, registering a name more than once erroneously created +more than one flag value. Here we verify that's fixed: + + >>> redundant_flag_value = doctest.register_optionflag(unlikely) + >>> redundant_flag_value == new_flag_value + True + +Clean up. + >>> del doctest.OPTIONFLAGS_BY_NAME[unlikely] + + """ + + def option_directives(): r""" +Tests of `DocTestRunner`'s option directive mechanism. + +Option directives can be used to turn option flags on or off for a +single example. To turn an option on for an example, follow that +example with a comment of the form ``# doctest: +OPTION``: + + >>> def f(x): r''' + ... >>> print range(10) # should fail: no ellipsis + ... [0, 1, ..., 9] + ... + ... >>> print range(10) # doctest: +ELLIPSIS + ... [0, 1, ..., 9] + ... ''' + >>> test = doctest.DocTestFinder().find(f)[0] + >>> doctest.DocTestRunner(verbose=False).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 2, in f + Failed example: + print range(10) # should fail: no ellipsis + Expected: + [0, 1, ..., 9] + Got: + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + (1, 2) + +To turn an option off for an example, follow that example with a +comment of the form ``# doctest: -OPTION``: + + >>> def f(x): r''' + ... >>> print range(10) + ... [0, 1, ..., 9] + ... + ... >>> # should fail: ... [truncated message content] |
From: <fwi...@us...> - 2009-01-08 02:21:22
|
Revision: 5876 http://jython.svn.sourceforge.net/jython/?rev=5876&view=rev Author: fwierzbicki Date: 2009-01-08 02:21:17 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Merged revisions 5875 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5875 | fwierzbicki | 2009-01-07 21:08:58 -0500 (Wed, 07 Jan 2009) | 4 lines Change to Raise and ExceptHandler so that Python sees the properly named "type" field, but the getters and setters are mangled to getExceptType so PyObject's getType method is not in conflict. ........ Modified Paths: -------------- branches/jy3k/ast/Python.asdl branches/jy3k/ast/asdl_antlr.py branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java branches/jy3k/src/org/python/compiler/CodeCompiler.java Property Changed: ---------------- branches/jy3k/ Property changes on: branches/jy3k ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5872 + /trunk/jython:1-5875 Modified: branches/jy3k/ast/Python.asdl =================================================================== --- branches/jy3k/ast/Python.asdl 2009-01-08 02:08:58 UTC (rev 5875) +++ branches/jy3k/ast/Python.asdl 2009-01-08 02:21:17 UTC (rev 5876) @@ -101,8 +101,7 @@ comprehension = (expr target, expr iter, expr* ifs) -- not sure what to call the first argument for raise and except - -- changed to 'type' to excepttype for Jython - excepthandler = ExceptHandler(expr? excepttype, identifier? name, stmt* body) + excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) attributes (int lineno, int col_offset) arguments = (arg* args, identifier? vararg, expr? varargannotation, Modified: branches/jy3k/ast/asdl_antlr.py =================================================================== --- branches/jy3k/ast/asdl_antlr.py 2009-01-08 02:08:58 UTC (rev 5875) +++ branches/jy3k/ast/asdl_antlr.py 2009-01-08 02:21:17 UTC (rev 5876) @@ -484,7 +484,7 @@ self.emit('{%s}, %s);' % (fpargs, len(fields)), depth + 2) i = 0 for f in fields: - self.emit("set%s(ap.getPyObject(%s));" % (str(f.name).capitalize(), + self.emit("set%s(ap.getPyObject(%s));" % (self.processFieldName(f.name), str(i)), depth+1) i += 1 if str(name) in ('stmt', 'expr', 'excepthandler'): @@ -506,8 +506,7 @@ fpargs = ", ".join(["PyObject %s" % f.name for f in fields]) self.emit("public %s(%s) {" % (clsname, fpargs), depth) for f in fields: - self.emit("set%s(%s);" % (str(f.name).capitalize(), - f.name), depth+1) + self.emit("set%s(%s);" % (self.processFieldName(f.name), f.name), depth+1) self.emit("}", depth) self.emit("", 0) @@ -539,6 +538,14 @@ self.emit("", 0) + #This is mainly a kludge to turn get/setType -> get/setExceptType because + #getType conflicts with a method on PyObject. + def processFieldName(self, name): + name = str(name).capitalize() + if name == "Type": + name = "ExceptType" + return name + def visitField(self, field, depth): self.emit("private %s;" % self.fieldDef(field), depth) self.emit("public %s getInternal%s() {" % (self.javaType(field), @@ -546,7 +553,7 @@ self.emit("return %s;" % field.name, depth+1) self.emit("}", depth) self.emit('@ExposedGet(name = "%s")' % field.name, depth) - self.emit("public PyObject get%s() {" % (str(field.name).capitalize()), depth) + self.emit("public PyObject get%s() {" % self.processFieldName(field.name), depth) if field.seq: self.emit("return new AstList(%s, AstAdapters.%sAdapter);" % (field.name, field.type), depth+1) else: @@ -567,8 +574,7 @@ #self.emit("return Py.None;", depth+1) self.emit("}", depth) self.emit('@ExposedSet(name = "%s")' % field.name, depth) - self.emit("public void set%s(PyObject %s) {" % (str(field.name).capitalize(), - field.name), depth) + self.emit("public void set%s(PyObject %s) {" % (self.processFieldName(field.name), field.name), depth) if field.seq: #self.emit("this.%s = new %s(" % (field.name, self.javaType(field)), depth+1) self.emit("this.%s = AstAdapters.py2%sList(%s);" % (field.name, str(field.type), field.name), depth+1) Modified: branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java 2009-01-08 02:08:58 UTC (rev 5875) +++ branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java 2009-01-08 02:21:17 UTC (rev 5876) @@ -28,17 +28,17 @@ @ExposedType(name = "_ast.ExceptHandler", base = AST.class) public class ExceptHandler extends excepthandler { public static final PyType TYPE = PyType.fromClass(ExceptHandler.class); - private expr excepttype; - public expr getInternalExcepttype() { - return excepttype; + private expr type; + public expr getInternalType() { + return type; } - @ExposedGet(name = "excepttype") - public PyObject getExcepttype() { - return excepttype; + @ExposedGet(name = "type") + public PyObject getExceptType() { + return type; } - @ExposedSet(name = "excepttype") - public void setExcepttype(PyObject excepttype) { - this.excepttype = AstAdapters.py2expr(excepttype); + @ExposedSet(name = "type") + public void setExceptType(PyObject type) { + this.type = AstAdapters.py2expr(type); } private String name; @@ -70,7 +70,7 @@ private final static PyString[] fields = - new PyString[] {new PyString("excepttype"), new PyString("name"), new PyString("body")}; + new PyString[] {new PyString("type"), new PyString("name"), new PyString("body")}; @ExposedGet(name = "_fields") public PyString[] get_fields() { return fields; } @@ -89,8 +89,8 @@ @ExposedMethod public void ExceptHandler___init__(PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("ExceptHandler", args, keywords, new String[] - {"excepttype", "name", "body", "lineno", "col_offset"}, 3); - setExcepttype(ap.getPyObject(0)); + {"type", "name", "body", "lineno", "col_offset"}, 3); + setExceptType(ap.getPyObject(0)); setName(ap.getPyObject(1)); setBody(ap.getPyObject(2)); int lin = ap.getInt(3, -1); @@ -105,16 +105,16 @@ } - public ExceptHandler(PyObject excepttype, PyObject name, PyObject body) { - setExcepttype(excepttype); + public ExceptHandler(PyObject type, PyObject name, PyObject body) { + setExceptType(type); setName(name); setBody(body); } - public ExceptHandler(Token token, expr excepttype, String name, java.util.List<stmt> body) { + public ExceptHandler(Token token, expr type, String name, java.util.List<stmt> body) { super(token); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; this.body = body; if (body == null) { @@ -125,11 +125,11 @@ } } - public ExceptHandler(Integer ttype, Token token, expr excepttype, String name, - java.util.List<stmt> body) { + public ExceptHandler(Integer ttype, Token token, expr type, String name, java.util.List<stmt> + body) { super(ttype, token); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; this.body = body; if (body == null) { @@ -140,10 +140,10 @@ } } - public ExceptHandler(PythonTree tree, expr excepttype, String name, java.util.List<stmt> body) { + public ExceptHandler(PythonTree tree, expr type, String name, java.util.List<stmt> body) { super(tree); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; this.body = body; if (body == null) { @@ -161,8 +161,8 @@ public String toStringTree() { StringBuffer sb = new StringBuffer("ExceptHandler("); - sb.append("excepttype="); - sb.append(dumpThis(excepttype)); + sb.append("type="); + sb.append(dumpThis(type)); sb.append(","); sb.append("name="); sb.append(dumpThis(name)); @@ -179,8 +179,8 @@ } public void traverse(VisitorIF visitor) throws Exception { - if (excepttype != null) - excepttype.accept(visitor); + if (type != null) + type.accept(visitor); if (body != null) { for (PythonTree t : body) { if (t != null) Modified: branches/jy3k/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-08 02:08:58 UTC (rev 5875) +++ branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-08 02:21:17 UTC (rev 5876) @@ -1041,10 +1041,10 @@ //setline(name); Label end_of_self = new Label(); - if (handler.getInternalExcepttype() != null) { + if (handler.getInternalType() != null) { code.aload(exc); //get specific exception - visit(handler.getInternalExcepttype()); + visit(handler.getInternalType()); code.invokestatic("org/python/core/Py", "matchException", "(" + $pyExc + $pyObj + ")Z"); code.ifeq(end_of_self); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-08 16:12:57
|
Revision: 5880 http://jython.svn.sourceforge.net/jython/?rev=5880&view=rev Author: fwierzbicki Date: 2009-01-08 16:12:44 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Added nonlocal, and support for the -> annotation. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-08 15:52:56 UTC (rev 5879) +++ branches/jy3k/grammar/Python.g 2009-01-08 16:12:44 UTC (rev 5880) @@ -377,7 +377,6 @@ | DELETE | ELIF | EXCEPT - | EXEC | FINALLY | FROM | FOR @@ -443,7 +442,7 @@ if ($decorators.start != null) { t = $decorators.start; } - stype = actions.makeFuncdef(t, $NAME, $parameters.args, $suite.stypes, $decorators.etypes); + stype = actions.makeFuncdef(t, $NAME, $parameters.args, $suite.stypes, $decorators.etypes, actions.castExpr($test.tree)); } ; @@ -1584,6 +1583,7 @@ IN : 'in' ; IS : 'is' ; LAMBDA : 'lambda' ; +NONLOCAL : 'nonlocal' ; ORELSE : 'else' ; PASS : 'pass' ; RAISE : 'raise' ; Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-08 15:52:56 UTC (rev 5879) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-08 16:12:44 UTC (rev 5880) @@ -263,7 +263,7 @@ return new TryFinally(t, b, f); } - stmt makeFuncdef(Token t, Token nameToken, arguments args, List funcStatements, List decorators) { + stmt makeFuncdef(Token t, Token nameToken, arguments args, List funcStatements, List decorators, expr returnType) { if (nameToken == null) { return errorHandler.errorStmt(new PythonTree(t)); } @@ -276,7 +276,7 @@ } List<stmt> s = castStmts(funcStatements); List<expr> d = castExprs(decorators); - return new FunctionDef(t, nameToken.getText(), a, s, d, null); + return new FunctionDef(t, nameToken.getText(), a, s, d, returnType); } List<expr> makeAssignTargets(expr lhs, List rhs) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-08 16:48:10
|
Revision: 5882 http://jython.svn.sourceforge.net/jython/?rev=5882&view=rev Author: fwierzbicki Date: 2009-01-08 16:48:06 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Add binary literal. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-08 16:38:16 UTC (rev 5881) +++ branches/jy3k/grammar/Python.g 2009-01-08 16:48:06 UTC (rev 5882) @@ -1699,7 +1699,10 @@ '0' ('x' | 'X') ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+ | // Octal '0' ('o' | 'O') ( '0' .. '7' )* - | '0'..'9' DIGITS* + | // Binary + '0' ('b' | 'B') ( '0' .. '1' )* + | // Decimal + '0'..'9' DIGITS* ; COMPLEX Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-08 16:38:16 UTC (rev 5881) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-08 16:48:06 UTC (rev 5882) @@ -374,6 +374,9 @@ } else if (s.startsWith("0o") || s.startsWith("0O")) { radix = 8; s = s.substring(2, s.length()); + } else if (s.startsWith("0b") || s.startsWith("0B")) { + radix = 2; + s = s.substring(2, s.length()); } if (s.endsWith("L") || s.endsWith("l")) { s = s.substring(0, s.length()-1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-08 19:22:54
|
Revision: 5883 http://jython.svn.sourceforge.net/jython/?rev=5883&view=rev Author: fwierzbicki Date: 2009-01-08 19:22:49 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Very initial attempt to support Bytes type in parser. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java branches/jy3k/src/org/python/core/PyUnicode.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-08 16:48:06 UTC (rev 5882) +++ branches/jy3k/grammar/Python.g 2009-01-08 19:22:49 UTC (rev 5883) @@ -94,6 +94,7 @@ import org.python.antlr.ast.BoolOp; import org.python.antlr.ast.boolopType; import org.python.antlr.ast.Break; +import org.python.antlr.ast.Bytes; import org.python.antlr.ast.Call; import org.python.antlr.ast.ClassDef; import org.python.antlr.ast.cmpopType; @@ -1243,6 +1244,8 @@ -> ^(COMPLEX<Num>[$COMPLEX, actions.makeComplex($COMPLEX)]) | (S+=STRING)+ -> ^(STRING<Str>[actions.extractStringToken($S), actions.extractStrings($S, encoding)]) + | (B+=BYTES)+ + -> ^(BYTES<Bytes>[actions.extractStringToken($B), actions.extractBytes($B, encoding)]) ; //listmaker: test ( list_for | (',' test)* [','] ) @@ -1720,6 +1723,24 @@ /** Match various string types. Note that greedy=false implies ''' * should make us exit loop not continue. */ +BYTES + : ('b'|'B') + ( '\'\'\'' (options {greedy=false;}:TRIAPOS)* '\'\'\'' + | '"""' (options {greedy=false;}:TRIQUOTE)* '"""' + | '"' (ESC|~('\\'|'\n'|'"'))* '"' + | '\'' (ESC|~('\\'|'\n'|'\''))* '\'' + ) { + if (state.tokenStartLine != input.getLine()) { + state.tokenStartLine = input.getLine(); + state.tokenStartCharPositionInLine = -2; + } + } + ; + + +/** Match various string types. Note that greedy=false implies ''' + * should make us exit loop not continue. + */ STRING : ('r'|'R')? ( '\'\'\'' (options {greedy=false;}:TRIAPOS)* '\'\'\'' @@ -1735,7 +1756,7 @@ ; STRINGPART - : {partial}?=> ('r'|'R')? + : {partial}?=> ('r'|'b'|'R'|'B')? ( '\'\'\'' ~('\'\'\'')* | '"""' ~('"""')* ) Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-08 16:48:06 UTC (rev 5882) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-08 19:22:49 UTC (rev 5883) @@ -17,6 +17,7 @@ import org.python.antlr.ast.expr_contextType; import org.python.antlr.ast.operatorType; import org.python.antlr.ast.unaryopType; +import org.python.antlr.ast.Bytes; import org.python.antlr.ast.Context; import org.python.antlr.ast.keyword; import org.python.antlr.ast.Attribute; @@ -397,53 +398,67 @@ return Py.newInteger((int) l); } - class StringPair { - private String s; - private boolean unicode; + //FIXME: this is just a guess ATM + PyString extractBytes(List s, String encoding) { + Token last = null; + StringBuffer sb = new StringBuffer(); + Iterator iter = s.iterator(); + while (iter.hasNext()) { + last = (Token)iter.next(); + String sp = extractBytesPart(last, encoding); + sb.append(sp); + } + return new PyString(sb.toString()); + } - StringPair(String s, boolean unicode) { - this.s = s; - this.unicode = unicode; + //FIXME: this is just a guess ATM + String extractBytesPart(Token t, String encoding) { + String string = t.getText(); + char quoteChar = string.charAt(0); + int start = 0; + int end; + quoteChar = string.charAt(start); + boolean raw = false; + if (quoteChar == 'b' || quoteChar == 'B') { + raw = true; + start++; } - String getString() { - return s; + int quotes = 3; + if (string.length() - start == 2) { + quotes = 1; } - - boolean isUnicode() { - return unicode; + if (string.charAt(start) != string.charAt(start+1)) { + quotes = 1; } + + start = quotes + start; + end = string.length() - quotes; + if (encoding != null) { + string = new PyUnicode(string.substring(start, end)).encode(encoding); + } else { + string = string.substring(start, end); + } + return string; } + PyString extractStrings(List s, String encoding) { - boolean ustring = false; Token last = null; StringBuffer sb = new StringBuffer(); Iterator iter = s.iterator(); while (iter.hasNext()) { last = (Token)iter.next(); - StringPair sp = extractString(last, encoding); - if (sp.isUnicode()) { - ustring = true; - } - sb.append(sp.getString()); + String sp = extractString(last, encoding); + sb.append(sp); } - if (ustring) { - return new PyUnicode(sb.toString()); - } - return new PyString(sb.toString()); + return new PyUnicode(sb.toString()); } - StringPair extractString(Token t, String encoding) { + String extractString(Token t, String encoding) { String string = t.getText(); char quoteChar = string.charAt(0); int start = 0; int end; - boolean ustring = false; - - if (quoteChar == 'u' || quoteChar == 'U') { - ustring = true; - start++; - } quoteChar = string.charAt(start); boolean raw = false; if (quoteChar == 'r' || quoteChar == 'R') { @@ -463,22 +478,22 @@ // string is properly decoded according to the source encoding // XXX: No need to re-encode when the encoding is iso-8859-1, but ParserFacade // needs to normalize the encoding name - if (!ustring && encoding != null) { + if (encoding != null) { // str with a specified encoding: first re-encode back out string = new PyUnicode(string.substring(start, end)).encode(encoding); if (!raw) { // Handle escapes in non-raw strs string = PyString.decode_UnicodeEscape(string, 0, string.length(), "strict", - ustring); + false); } } else if (raw) { // Raw str without an encoding or raw unicode: simply passthru string = string.substring(start, end); } else { // Plain unicode: already decoded, just handle escapes - string = PyString.decode_UnicodeEscape(string, start, end, "strict", ustring); + string = PyString.decode_UnicodeEscape(string, start, end, "strict", true); } - return new StringPair(string, ustring); + return string; } Token extractStringToken(List s) { Modified: branches/jy3k/src/org/python/core/PyUnicode.java =================================================================== --- branches/jy3k/src/org/python/core/PyUnicode.java 2009-01-08 16:48:06 UTC (rev 5882) +++ branches/jy3k/src/org/python/core/PyUnicode.java 2009-01-08 19:22:49 UTC (rev 5883) @@ -246,7 +246,7 @@ @ExposedMethod(doc = BuiltinDocs.unicode___repr___doc) final PyString unicode___repr__() { - return new PyString("u" + encode_UnicodeEscape(string, true)); + return new PyString(encode_UnicodeEscape(string, true)); } @ExposedMethod(doc = BuiltinDocs.unicode___getitem___doc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-08 19:48:49
|
Revision: 5886 http://jython.svn.sourceforge.net/jython/?rev=5886&view=rev Author: fwierzbicki Date: 2009-01-08 19:48:42 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Merged revisions 5877,5884-5885 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5877 | pjenvey | 2009-01-08 02:40:01 -0500 (Thu, 08 Jan 2009) | 4 lines from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_xml_etree.py@50943 http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_xml_etree_c.py@51322 ........ r5884 | fwierzbicki | 2009-01-08 14:34:31 -0500 (Thu, 08 Jan 2009) | 2 lines improvement to astview.py in light of better ast.py in Jython. ........ r5885 | fwierzbicki | 2009-01-08 14:36:33 -0500 (Thu, 08 Jan 2009) | 2 lines _ast -> ast ........ Modified Paths: -------------- branches/jy3k/ast/astview.py branches/jy3k/src/org/python/compiler/CodeCompiler.java Added Paths: ----------- branches/jy3k/Lib/test/test_xml_etree.py branches/jy3k/Lib/test/test_xml_etree_c.py Property Changed: ---------------- branches/jy3k/ Property changes on: branches/jy3k ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5875 + /trunk/jython:1-5885 Copied: branches/jy3k/Lib/test/test_xml_etree.py (from rev 5885, trunk/jython/Lib/test/test_xml_etree.py) =================================================================== --- branches/jy3k/Lib/test/test_xml_etree.py (rev 0) +++ branches/jy3k/Lib/test/test_xml_etree.py 2009-01-08 19:48:42 UTC (rev 5886) @@ -0,0 +1,354 @@ +# xml.etree test. This file contains enough tests to make sure that +# all included components work as they should. For a more extensive +# test suite, see the selftest script in the ElementTree distribution. + +import doctest, sys + +from test import test_support + +SAMPLE_XML = """ +<body> + <tag>text</tag> + <tag /> + <section> + <tag>subtext</tag> + </section> +</body> +""" + +SAMPLE_XML_NS = """ +<body xmlns="http://effbot.org/ns"> + <tag>text</tag> + <tag /> + <section> + <tag>subtext</tag> + </section> +</body> +""" + +def sanity(): + """ + Import sanity. + + >>> from xml.etree import ElementTree + >>> from xml.etree import ElementInclude + >>> from xml.etree import ElementPath + """ + +def check_method(method): + if not callable(method): + print method, "not callable" + +def serialize(ET, elem, encoding=None): + import StringIO + file = StringIO.StringIO() + tree = ET.ElementTree(elem) + if encoding: + tree.write(file, encoding) + else: + tree.write(file) + return file.getvalue() + +def summarize(elem): + return elem.tag + +def summarize_list(seq): + return map(summarize, seq) + +def interface(): + """ + Test element tree interface. + + >>> from xml.etree import ElementTree as ET + + >>> element = ET.Element("tag", key="value") + >>> tree = ET.ElementTree(element) + + Make sure all standard element methods exist. + + >>> check_method(element.append) + >>> check_method(element.insert) + >>> check_method(element.remove) + >>> check_method(element.getchildren) + >>> check_method(element.find) + >>> check_method(element.findall) + >>> check_method(element.findtext) + >>> check_method(element.clear) + >>> check_method(element.get) + >>> check_method(element.set) + >>> check_method(element.keys) + >>> check_method(element.items) + >>> check_method(element.getiterator) + + Basic method sanity checks. + + >>> serialize(ET, element) # 1 + '<tag key="value" />' + >>> subelement = ET.Element("subtag") + >>> element.append(subelement) + >>> serialize(ET, element) # 2 + '<tag key="value"><subtag /></tag>' + >>> element.insert(0, subelement) + >>> serialize(ET, element) # 3 + '<tag key="value"><subtag /><subtag /></tag>' + >>> element.remove(subelement) + >>> serialize(ET, element) # 4 + '<tag key="value"><subtag /></tag>' + >>> element.remove(subelement) + >>> serialize(ET, element) # 5 + '<tag key="value" />' + >>> element.remove(subelement) + Traceback (most recent call last): + ValueError: list.remove(x): x not in list + >>> serialize(ET, element) # 6 + '<tag key="value" />' + """ + +def find(): + """ + Test find methods (including xpath syntax). + + >>> from xml.etree import ElementTree as ET + + >>> elem = ET.XML(SAMPLE_XML) + >>> elem.find("tag").tag + 'tag' + >>> ET.ElementTree(elem).find("tag").tag + 'tag' + >>> elem.find("section/tag").tag + 'tag' + >>> ET.ElementTree(elem).find("section/tag").tag + 'tag' + >>> elem.findtext("tag") + 'text' + >>> elem.findtext("tog") + >>> elem.findtext("tog", "default") + 'default' + >>> ET.ElementTree(elem).findtext("tag") + 'text' + >>> elem.findtext("section/tag") + 'subtext' + >>> ET.ElementTree(elem).findtext("section/tag") + 'subtext' + >>> summarize_list(elem.findall("tag")) + ['tag', 'tag'] + >>> summarize_list(elem.findall("*")) + ['tag', 'tag', 'section'] + >>> summarize_list(elem.findall(".//tag")) + ['tag', 'tag', 'tag'] + >>> summarize_list(elem.findall("section/tag")) + ['tag'] + >>> summarize_list(elem.findall("section//tag")) + ['tag'] + >>> summarize_list(elem.findall("section/*")) + ['tag'] + >>> summarize_list(elem.findall("section//*")) + ['tag'] + >>> summarize_list(elem.findall("section/.//*")) + ['tag'] + >>> summarize_list(elem.findall("*/*")) + ['tag'] + >>> summarize_list(elem.findall("*//*")) + ['tag'] + >>> summarize_list(elem.findall("*/tag")) + ['tag'] + >>> summarize_list(elem.findall("*/./tag")) + ['tag'] + >>> summarize_list(elem.findall("./tag")) + ['tag', 'tag'] + >>> summarize_list(elem.findall(".//tag")) + ['tag', 'tag', 'tag'] + >>> summarize_list(elem.findall("././tag")) + ['tag', 'tag'] + >>> summarize_list(ET.ElementTree(elem).findall("/tag")) + ['tag', 'tag'] + >>> summarize_list(ET.ElementTree(elem).findall("./tag")) + ['tag', 'tag'] + >>> elem = ET.XML(SAMPLE_XML_NS) + >>> summarize_list(elem.findall("tag")) + [] + >>> summarize_list(elem.findall("{http://effbot.org/ns}tag")) + ['{http://effbot.org/ns}tag', '{http://effbot.org/ns}tag'] + >>> summarize_list(elem.findall(".//{http://effbot.org/ns}tag")) + ['{http://effbot.org/ns}tag', '{http://effbot.org/ns}tag', '{http://effbot.org/ns}tag'] + """ + +def parseliteral(): + r""" + + >>> from xml.etree import ElementTree as ET + + >>> element = ET.XML("<html><body>text</body></html>") + >>> ET.ElementTree(element).write(sys.stdout) + <html><body>text</body></html> + >>> element = ET.fromstring("<html><body>text</body></html>") + >>> ET.ElementTree(element).write(sys.stdout) + <html><body>text</body></html> + >>> print ET.tostring(element) + <html><body>text</body></html> + >>> print ET.tostring(element, "ascii") + <?xml version='1.0' encoding='ascii'?> + <html><body>text</body></html> + >>> _, ids = ET.XMLID("<html><body>text</body></html>") + >>> len(ids) + 0 + >>> _, ids = ET.XMLID("<html><body id='body'>text</body></html>") + >>> len(ids) + 1 + >>> ids["body"].tag + 'body' + """ + + +def check_encoding(ET, encoding): + """ + >>> from xml.etree import ElementTree as ET + + >>> check_encoding(ET, "ascii") + >>> check_encoding(ET, "us-ascii") + >>> check_encoding(ET, "iso-8859-1") + >>> check_encoding(ET, "iso-8859-15") + >>> check_encoding(ET, "cp437") + >>> check_encoding(ET, "mac-roman") + """ + ET.XML("<?xml version='1.0' encoding='%s'?><xml />" % encoding) + + +# +# xinclude tests (samples from appendix C of the xinclude specification) + +XINCLUDE = {} + +XINCLUDE["C1.xml"] = """\ +<?xml version='1.0'?> +<document xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>120 Mz is adequate for an average home user.</p> + <xi:include href="disclaimer.xml"/> +</document> +""" + +XINCLUDE["disclaimer.xml"] = """\ +<?xml version='1.0'?> +<disclaimer> + <p>The opinions represented herein represent those of the individual + and should not be interpreted as official policy endorsed by this + organization.</p> +</disclaimer> +""" + +XINCLUDE["C2.xml"] = """\ +<?xml version='1.0'?> +<document xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>This document has been accessed + <xi:include href="count.txt" parse="text"/> times.</p> +</document> +""" + +XINCLUDE["count.txt"] = "324387" + +XINCLUDE["C3.xml"] = """\ +<?xml version='1.0'?> +<document xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>The following is the source of the "data.xml" resource:</p> + <example><xi:include href="data.xml" parse="text"/></example> +</document> +""" + +XINCLUDE["data.xml"] = """\ +<?xml version='1.0'?> +<data> + <item><![CDATA[Brooks & Shields]]></item> +</data> +""" + +XINCLUDE["C5.xml"] = """\ +<?xml version='1.0'?> +<div xmlns:xi="http://www.w3.org/2001/XInclude"> + <xi:include href="example.txt" parse="text"> + <xi:fallback> + <xi:include href="fallback-example.txt" parse="text"> + <xi:fallback><a href="mailto:bo...@ex...">Report error</a></xi:fallback> + </xi:include> + </xi:fallback> + </xi:include> +</div> +""" + +XINCLUDE["default.xml"] = """\ +<?xml version='1.0'?> +<document xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>Example.</p> + <xi:include href="samples/simple.xml"/> +</document> +""" + +def xinclude_loader(href, parse="xml", encoding=None): + try: + data = XINCLUDE[href] + except KeyError: + raise IOError("resource not found") + if parse == "xml": + from xml.etree.ElementTree import XML + return XML(data) + return data + +def xinclude(): + r""" + Basic inclusion example (XInclude C.1) + + >>> from xml.etree import ElementTree as ET + >>> from xml.etree import ElementInclude + + >>> document = xinclude_loader("C1.xml") + >>> ElementInclude.include(document, xinclude_loader) + >>> print serialize(ET, document) # C1 + <document> + <p>120 Mz is adequate for an average home user.</p> + <disclaimer> + <p>The opinions represented herein represent those of the individual + and should not be interpreted as official policy endorsed by this + organization.</p> + </disclaimer> + </document> + + Textual inclusion example (XInclude C.2) + + >>> document = xinclude_loader("C2.xml") + >>> ElementInclude.include(document, xinclude_loader) + >>> print serialize(ET, document) # C2 + <document> + <p>This document has been accessed + 324387 times.</p> + </document> + + Textual inclusion of XML example (XInclude C.3) + + >>> document = xinclude_loader("C3.xml") + >>> ElementInclude.include(document, xinclude_loader) + >>> print serialize(ET, document) # C3 + <document> + <p>The following is the source of the "data.xml" resource:</p> + <example><?xml version='1.0'?> + <data> + <item><![CDATA[Brooks & Shields]]></item> + </data> + </example> + </document> + + Fallback example (XInclude C.5) + Note! Fallback support is not yet implemented + + >>> document = xinclude_loader("C5.xml") + >>> ElementInclude.include(document, xinclude_loader) + Traceback (most recent call last): + IOError: resource not found + >>> # print serialize(ET, document) # C5 + + """ + +def test_main(): + from test import test_xml_etree + test_support.run_doctest(test_xml_etree, verbosity=True) + +if __name__ == '__main__': + test_main() Copied: branches/jy3k/Lib/test/test_xml_etree_c.py (from rev 5885, trunk/jython/Lib/test/test_xml_etree_c.py) =================================================================== --- branches/jy3k/Lib/test/test_xml_etree_c.py (rev 0) +++ branches/jy3k/Lib/test/test_xml_etree_c.py 2009-01-08 19:48:42 UTC (rev 5886) @@ -0,0 +1,223 @@ +# xml.etree test for cElementTree + +import doctest, sys + +from test import test_support + +from xml.etree import cElementTree as ET + +SAMPLE_XML = """ +<body> + <tag>text</tag> + <tag /> + <section> + <tag>subtext</tag> + </section> +</body> +""" + +SAMPLE_XML_NS = """ +<body xmlns="http://effbot.org/ns"> + <tag>text</tag> + <tag /> + <section> + <tag>subtext</tag> + </section> +</body> +""" + +def sanity(): + """ + Import sanity. + + >>> from xml.etree import cElementTree + """ + +def check_method(method): + if not callable(method): + print method, "not callable" + +def serialize(ET, elem, encoding=None): + import StringIO + file = StringIO.StringIO() + tree = ET.ElementTree(elem) + if encoding: + tree.write(file, encoding) + else: + tree.write(file) + return file.getvalue() + +def summarize(elem): + return elem.tag + +def summarize_list(seq): + return map(summarize, seq) + +def interface(): + """ + Test element tree interface. + + >>> element = ET.Element("tag", key="value") + >>> tree = ET.ElementTree(element) + + Make sure all standard element methods exist. + + >>> check_method(element.append) + >>> check_method(element.insert) + >>> check_method(element.remove) + >>> check_method(element.getchildren) + >>> check_method(element.find) + >>> check_method(element.findall) + >>> check_method(element.findtext) + >>> check_method(element.clear) + >>> check_method(element.get) + >>> check_method(element.set) + >>> check_method(element.keys) + >>> check_method(element.items) + >>> check_method(element.getiterator) + + Basic method sanity checks. + + >>> serialize(ET, element) # 1 + '<tag key="value" />' + >>> subelement = ET.Element("subtag") + >>> element.append(subelement) + >>> serialize(ET, element) # 2 + '<tag key="value"><subtag /></tag>' + >>> element.insert(0, subelement) + >>> serialize(ET, element) # 3 + '<tag key="value"><subtag /><subtag /></tag>' + >>> element.remove(subelement) + >>> serialize(ET, element) # 4 + '<tag key="value"><subtag /></tag>' + >>> element.remove(subelement) + >>> serialize(ET, element) # 5 + '<tag key="value" />' + >>> element.remove(subelement) + Traceback (most recent call last): + ValueError: list.remove(x): x not in list + >>> serialize(ET, element) # 6 + '<tag key="value" />' + """ + +def find(): + """ + Test find methods (including xpath syntax). + + >>> elem = ET.XML(SAMPLE_XML) + >>> elem.find("tag").tag + 'tag' + >>> ET.ElementTree(elem).find("tag").tag + 'tag' + >>> elem.find("section/tag").tag + 'tag' + >>> ET.ElementTree(elem).find("section/tag").tag + 'tag' + >>> elem.findtext("tag") + 'text' + >>> elem.findtext("tog") + >>> elem.findtext("tog", "default") + 'default' + >>> ET.ElementTree(elem).findtext("tag") + 'text' + >>> elem.findtext("section/tag") + 'subtext' + >>> ET.ElementTree(elem).findtext("section/tag") + 'subtext' + >>> summarize_list(elem.findall("tag")) + ['tag', 'tag'] + >>> summarize_list(elem.findall("*")) + ['tag', 'tag', 'section'] + >>> summarize_list(elem.findall(".//tag")) + ['tag', 'tag', 'tag'] + >>> summarize_list(elem.findall("section/tag")) + ['tag'] + >>> summarize_list(elem.findall("section//tag")) + ['tag'] + >>> summarize_list(elem.findall("section/*")) + ['tag'] + >>> summarize_list(elem.findall("section//*")) + ['tag'] + >>> summarize_list(elem.findall("section/.//*")) + ['tag'] + >>> summarize_list(elem.findall("*/*")) + ['tag'] + >>> summarize_list(elem.findall("*//*")) + ['tag'] + >>> summarize_list(elem.findall("*/tag")) + ['tag'] + >>> summarize_list(elem.findall("*/./tag")) + ['tag'] + >>> summarize_list(elem.findall("./tag")) + ['tag', 'tag'] + >>> summarize_list(elem.findall(".//tag")) + ['tag', 'tag', 'tag'] + >>> summarize_list(elem.findall("././tag")) + ['tag', 'tag'] + >>> summarize_list(ET.ElementTree(elem).findall("/tag")) + ['tag', 'tag'] + >>> summarize_list(ET.ElementTree(elem).findall("./tag")) + ['tag', 'tag'] + >>> elem = ET.XML(SAMPLE_XML_NS) + >>> summarize_list(elem.findall("tag")) + [] + >>> summarize_list(elem.findall("{http://effbot.org/ns}tag")) + ['{http://effbot.org/ns}tag', '{http://effbot.org/ns}tag'] + >>> summarize_list(elem.findall(".//{http://effbot.org/ns}tag")) + ['{http://effbot.org/ns}tag', '{http://effbot.org/ns}tag', '{http://effbot.org/ns}tag'] + """ + +def parseliteral(): + r""" + + >>> element = ET.XML("<html><body>text</body></html>") + >>> ET.ElementTree(element).write(sys.stdout) + <html><body>text</body></html> + >>> element = ET.fromstring("<html><body>text</body></html>") + >>> ET.ElementTree(element).write(sys.stdout) + <html><body>text</body></html> + >>> print ET.tostring(element) + <html><body>text</body></html> + >>> print ET.tostring(element, "ascii") + <?xml version='1.0' encoding='ascii'?> + <html><body>text</body></html> + >>> _, ids = ET.XMLID("<html><body>text</body></html>") + >>> len(ids) + 0 + >>> _, ids = ET.XMLID("<html><body id='body'>text</body></html>") + >>> len(ids) + 1 + >>> ids["body"].tag + 'body' + """ + +def check_encoding(encoding): + """ + >>> check_encoding("ascii") + >>> check_encoding("us-ascii") + >>> check_encoding("iso-8859-1") + >>> check_encoding("iso-8859-15") + >>> check_encoding("cp437") + >>> check_encoding("mac-roman") + """ + ET.XML( + "<?xml version='1.0' encoding='%s'?><xml />" % encoding + ) + +def bug_1534630(): + """ + >>> bob = ET.TreeBuilder() + >>> e = bob.data("data") + >>> e = bob.start("tag", {}) + >>> e = bob.end("tag") + >>> e = bob.close() + >>> serialize(ET, e) + '<tag />' + """ + +def test_main(): + from test import test_xml_etree_c + test_support.run_doctest(test_xml_etree_c, verbosity=True) + +if __name__ == '__main__': + test_main() Modified: branches/jy3k/ast/astview.py =================================================================== --- branches/jy3k/ast/astview.py 2009-01-08 19:36:33 UTC (rev 5885) +++ branches/jy3k/ast/astview.py 2009-01-08 19:48:42 UTC (rev 5886) @@ -10,33 +10,19 @@ """ -import _ast +import ast import sys if sys.platform.startswith('java'): - - get_symbol_key = lambda op: op - def get_class_name(t): result = t.__class__.__name__ - if result in ("expr_contextType", - "boolopType", - "unaryopType", - "cmpopType", - "operatorType"): - result = str(t) - if result == "AugLoad": - result = "Load" - elif result == "AugStore": - result = "Store" - else: - result = result.split(".")[-1] - if result.endswith("Type"): - result = result[:-4] + if result == "AugLoad": + result = "Load" + elif result == "AugStore": + result = "Store" return result else: - get_symbol_key = type get_class_name = lambda node: node.__class__.__name__ get_lines_and_cols = True @@ -48,7 +34,7 @@ result = get_class_name(node) if get_lines_and_cols and hasattr(node, 'lineno') and hasattr(node, 'col_offset'): result = "%s (%s,%s)" % (result, node.lineno, node.col_offset) - yield result#get_class_name(node)#result + yield result try: for field in node._fields: yield tuple(lispify_field(field, getattr(node, field))) @@ -57,13 +43,13 @@ def lispify_field(field, child): yield field - if not hasattr(child, '__iter__'): - children = [child] - else: + if isinstance(child, list): children = child + else: + children = [child] for node in children: - if isinstance(node, _ast.AST): + if isinstance(node, ast.AST): yield lispify_ast(node) else: if isinstance(node, float): @@ -78,10 +64,10 @@ def tree(pyfile): try: - ast = compile(open(pyfile).read(), pyfile, "exec", _ast.PyCF_ONLY_AST) + node = compile(open(pyfile).read(), pyfile, "exec", ast.PyCF_ONLY_AST) except SyntaxError: return "SyntaxError", - return lispify_ast(ast) + return lispify_ast(node) if __name__ == '__main__': import pprint Modified: branches/jy3k/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-08 19:36:33 UTC (rev 5885) +++ branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-08 19:48:42 UTC (rev 5886) @@ -19,6 +19,7 @@ import org.python.antlr.ast.BinOp; import org.python.antlr.ast.BoolOp; import org.python.antlr.ast.Break; +import org.python.antlr.ast.Bytes; import org.python.antlr.ast.Call; import org.python.antlr.ast.ClassDef; import org.python.antlr.ast.Compare; @@ -2076,12 +2077,15 @@ @Override public Object visitStr(Str node) throws Exception { + PyUnicode s = (PyUnicode)node.getInternalS(); + module.PyUnicode(s.asString()).get(code); + return null; + } + + @Override + public Object visitBytes(Bytes node) throws Exception { PyString s = (PyString)node.getInternalS(); - if (s instanceof PyUnicode) { - module.PyUnicode(s.asString()).get(code); - } else { - module.PyString(s.asString()).get(code); - } + module.PyString(s.asString()).get(code); return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-09 04:50:29
|
Revision: 5899 http://jython.svn.sourceforge.net/jython/?rev=5899&view=rev Author: fwierzbicki Date: 2009-01-09 04:50:22 +0000 (Fri, 09 Jan 2009) Log Message: ----------- Merged revisions 5889-5893 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5889 | pjenvey | 2009-01-08 16:23:29 -0500 (Thu, 08 Jan 2009) | 5 lines jython-elementtree from: http://jython-elementtree.googlecode.com/svn/trunk@69 provides a partial emulation of pyexpat via xerces 2.9.1 and extra tests in test_xml_etree_jy from Sebastien Boisgerault ........ r5890 | pjenvey | 2009-01-08 16:26:19 -0500 (Thu, 08 Jan 2009) | 2 lines xerces 2.9.1 for elementtree ........ r5891 | pjenvey | 2009-01-08 16:49:36 -0500 (Thu, 08 Jan 2009) | 2 lines jarjar xerces into jython-complete and check for the mangled name ........ r5892 | pjenvey | 2009-01-08 17:05:28 -0500 (Thu, 08 Jan 2009) | 2 lines unused import, coding standards ........ r5893 | otmarhumbel | 2009-01-08 17:54:04 -0500 (Thu, 08 Jan 2009) | 10 lines rename the jython*.jar files: jython.jar is now called jython-dev.jar jython-complete.jar is now called jython.jar the one we distribute is jython.jar, containing the necessary external libraries, mangled jython-dev.jar is intended for local developer usage, containing no external libraries, referencing the real external package names ........ Modified Paths: -------------- branches/jy3k/CPythonLib.includes branches/jy3k/Lib/test/regrtest.py branches/jy3k/Lib/test/test_xml_etree.py branches/jy3k/Lib/test/test_xml_etree_c.py branches/jy3k/bugtests/README.txt branches/jy3k/bugtests/test386.py branches/jy3k/bugtests/test394.py branches/jy3k/bugtests/test394jar/MANIFEST.MF branches/jy3k/build.xml branches/jy3k/src/org/python/core/PySystemState.java branches/jy3k/src/org/python/util/JythoncAntTask.java branches/jy3k/src/shell/jython branches/jy3k/src/shell/jython.bat Added Paths: ----------- branches/jy3k/Lib/pyexpat.py branches/jy3k/Lib/test/test_xml_etree_jy.py branches/jy3k/Lib/xml/parsers/ branches/jy3k/Lib/xml/parsers/__init__.py branches/jy3k/Lib/xml/parsers/expat.py branches/jy3k/extlibs/xercesImpl.jar Removed Paths: ------------- branches/jy3k/Lib/xml/parsers/__init__.py branches/jy3k/Lib/xml/parsers/expat.py Property Changed: ---------------- branches/jy3k/ Property changes on: branches/jy3k ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5885 + /trunk/jython:1-5898 Modified: branches/jy3k/CPythonLib.includes =================================================================== --- branches/jy3k/CPythonLib.includes 2009-01-09 04:32:35 UTC (rev 5898) +++ branches/jy3k/CPythonLib.includes 2009-01-09 04:50:22 UTC (rev 5899) @@ -8,6 +8,7 @@ encodings/** logging/* test/** +xml/etree/** # Lib files, in alphabetical order: __future__.py Copied: branches/jy3k/Lib/pyexpat.py (from rev 5893, trunk/jython/Lib/pyexpat.py) =================================================================== --- branches/jy3k/Lib/pyexpat.py (rev 0) +++ branches/jy3k/Lib/pyexpat.py 2009-01-09 04:50:22 UTC (rev 5899) @@ -0,0 +1 @@ +from xml.parsers.expat import * Modified: branches/jy3k/Lib/test/regrtest.py =================================================================== --- branches/jy3k/Lib/test/regrtest.py 2009-01-09 04:32:35 UTC (rev 5898) +++ branches/jy3k/Lib/test/regrtest.py 2009-01-09 04:50:22 UTC (rev 5899) @@ -1449,7 +1449,6 @@ test_wave test_winreg test_winsound - test_xml_etree_c test_zipfile64 """ } @@ -1487,7 +1486,6 @@ test_ucn test_unicode test_unicodedata - test_xml_etree test_zipimport """, } Modified: branches/jy3k/Lib/test/test_xml_etree.py =================================================================== --- branches/jy3k/Lib/test/test_xml_etree.py 2009-01-09 04:32:35 UTC (rev 5898) +++ branches/jy3k/Lib/test/test_xml_etree.py 2009-01-09 04:50:22 UTC (rev 5899) @@ -209,7 +209,7 @@ >>> check_encoding(ET, "iso-8859-1") >>> check_encoding(ET, "iso-8859-15") >>> check_encoding(ET, "cp437") - >>> check_encoding(ET, "mac-roman") + >>> #check_encoding(ET, "mac-roman") """ ET.XML("<?xml version='1.0' encoding='%s'?><xml />" % encoding) Modified: branches/jy3k/Lib/test/test_xml_etree_c.py =================================================================== --- branches/jy3k/Lib/test/test_xml_etree_c.py 2009-01-09 04:32:35 UTC (rev 5898) +++ branches/jy3k/Lib/test/test_xml_etree_c.py 2009-01-09 04:50:22 UTC (rev 5899) @@ -198,7 +198,7 @@ >>> check_encoding("iso-8859-1") >>> check_encoding("iso-8859-15") >>> check_encoding("cp437") - >>> check_encoding("mac-roman") + >>> #check_encoding("mac-roman") """ ET.XML( "<?xml version='1.0' encoding='%s'?><xml />" % encoding Copied: branches/jy3k/Lib/test/test_xml_etree_jy.py (from rev 5893, trunk/jython/Lib/test/test_xml_etree_jy.py) =================================================================== --- branches/jy3k/Lib/test/test_xml_etree_jy.py (rev 0) +++ branches/jy3k/Lib/test/test_xml_etree_jy.py 2009-01-09 04:50:22 UTC (rev 5899) @@ -0,0 +1,754 @@ +# encoding: utf-8 + +import sys +JYTHON = sys.platform.startswith("java") + +import doctest + +import xml.parsers.expat as expat +from xml.etree.ElementTree import * + +def jython(function): + if JYTHON: + return function + else: + return None + +class sortdict(dict): + def __repr__(self): + items = self.items() + items.sort() + pairs = ["%r: %r" % pair for pair in items] + return "{%s}" % ", ".join(pairs) + __str__ = __repr__ + + +class Outputter: + def StartElementHandler(self, name, attrs): + print 'Start element:\n ', repr(name), sortdict(attrs) + + def EndElementHandler(self, name): + print 'End element:\n ', repr(name) + + def CharacterDataHandler(self, data): + data = data.strip() + if data: + print 'Character data:' + print ' ', repr(data) + + def ProcessingInstructionHandler(self, target, data): + print 'PI:\n ', repr(target), repr(data) + + def StartNamespaceDeclHandler(self, prefix, uri): + print 'NS decl:\n ', repr(prefix), repr(uri) + + def EndNamespaceDeclHandler(self, prefix): + print 'End of NS decl:\n ', repr(prefix) + + def StartCdataSectionHandler(self): + print 'Start of CDATA section' + + def EndCdataSectionHandler(self): + print 'End of CDATA section' + + def CommentHandler(self, text): + print 'Comment:\n ', repr(text) + + def NotationDeclHandler(self, *args): + name, base, sysid, pubid = args + print 'Notation declared:', args + + def UnparsedEntityDeclHandler(self, *args): + entityName, base, systemId, publicId, notationName = args + print 'Unparsed entity decl:\n ', args + + def NotStandaloneHandler(self, userData): + print 'Not standalone' + return 1 + + def ExternalEntityRefHandler(self, *args): + context, base, sysId, pubId = args + print 'External entity ref:', args[1:] + return 1 + + def DefaultHandler(self, userData): + pass + + def DefaultHandlerExpand(self, userData): + pass + +_= """ + >>> data = '''\ + ... <?xml version="1.0" encoding="iso-8859-1" standalone="no"?> + ... <?xml-stylesheet href="stylesheet.css"?> + ... <!-- comment data --> + ... <!DOCTYPE quotations SYSTEM "quotations.dtd" [ + ... <!ELEMENT root ANY> + ... <!NOTATION notation SYSTEM "notation.jpeg"> + ... <!ENTITY acirc "â"> + ... <!ENTITY external_entity SYSTEM "entity.file"> + ... <!ENTITY unparsed_entity SYSTEM "entity.file" NDATA notation> + ... %unparsed_entity; + ... ]> + ... + ... <root attr1="value1" attr2="value2ὀ"> + ... <myns:subelement xmlns:myns="http://www.python.org/namespace"> + ... Contents of subelements + ... </myns:subelement> + ... <sub2><![CDATA[contents of CDATA section]]></sub2> + ... &external_entity; + ... </root> + ... ''' + """ + +def test_utf8(): + """ + Source: test_pyexpat.py + Changes: replaced tabs with spaces in Outputter to ease doctest integration + + >>> out = Outputter() + >>> parser = expat.ParserCreate(namespace_separator='!') + >>> HANDLER_NAMES = [ + ... 'StartElementHandler', 'EndElementHandler', + ... 'CharacterDataHandler', + ... 'ProcessingInstructionHandler', + ... 'UnparsedEntityDeclHandler', 'NotationDeclHandler', + ... 'StartNamespaceDeclHandler', 'EndNamespaceDeclHandler', + ... 'CommentHandler', 'StartCdataSectionHandler', + ... 'EndCdataSectionHandler', + ... 'DefaultHandler', 'DefaultHandlerExpand', + ... #'NotStandaloneHandler', + ... 'ExternalEntityRefHandler' + ... ] + >>> for name in HANDLER_NAMES: + ... setattr(parser, name, getattr(out, name)) + + >>> data = '''\\ + ... <?xml version="1.0" encoding="iso-8859-1" standalone="no"?> + ... <?xml-stylesheet href="stylesheet.css"?> + ... <!-- comment data --> + ... <!DOCTYPE quotations SYSTEM "quotations.dtd" [ + ... <!ELEMENT root ANY> + ... <!NOTATION notation SYSTEM "notation.jpeg"> + ... <!ENTITY acirc "â"> + ... <!ENTITY external_entity SYSTEM "entity.file"> + ... <!ENTITY unparsed_entity SYSTEM "entity.file" NDATA notation> + ... %unparsed_entity; + ... ]> + ... + ... <root attr1="value1" attr2="value2ὀ"> + ... <myns:subelement xmlns:myns="http://www.python.org/namespace"> + ... Contents of subelements + ... </myns:subelement> + ... <sub2><![CDATA[contents of CDATA section]]></sub2> + ... &external_entity; + ... </root> + ... ''' + + #Produce UTF-8 output + #>>> parser.returns_unicode = 0 + #>>> try: + #... parser.Parse(data, 1) + #... except expat.error: + #... print '** Error', parser.ErrorCode, expat.ErrorString(parser.ErrorCode) + #... print '** Line', parser.ErrorLineNumber + #... print '** Column', parser.ErrorColumnNumber + #... print '** Byte', parser.ErrorByteIndex + #PI: + #'xml-stylesheet' 'href="stylesheet.css"' + #Comment: + #' comment data ' + #Notation declared: ('notation', None, 'notation.jpeg', None) + #Unparsed entity decl: + #('unparsed_entity', None, 'entity.file', None, 'notation') + #Start element: + #'root' {'attr1': 'value1', 'attr2': 'value2\\xe1\\xbd\\x80'} + #NS decl: + #'myns' 'http://www.python.org/namespace' + #Start element: + #'http://www.python.org/namespace!subelement' {} + #Character data: + #'Contents of subelements' + #End element: + #'http://www.python.org/namespace!subelement' + #End of NS decl: + #'myns' + #Start element: + #'sub2' {} + #Start of CDATA section + #Character data: + #'contents of CDATA section' + #End of CDATA section + #End element: + #'sub2' + #External entity ref: (None, 'entity.file', None) + #End element: + #'root' + #1 + + >>> parser = expat.ParserCreate(namespace_separator='!') + >>> parser.returns_unicode = 1 + >>> for name in HANDLER_NAMES: + ... setattr(parser, name, getattr(out, name)) + >>> try: + ... parser.Parse(data, 1) + ... except expat.error: + ... print '** Line', parser.ErrorLineNumber + ... print '** Column', parser.ErrorColumnNumber + ... print '** Byte', parser.ErrorByteIndex #doctest: +REPORT_UDIFF + PI: + u'xml-stylesheet' u'href="stylesheet.css"' + Comment: + u' comment data ' + Notation declared: (u'notation', None, u'notation.jpeg', None) + Unparsed entity decl: + (u'unparsed_entity', None, u'entity.file', None, u'notation') + Start element: + u'root' {u'attr1': u'value1', u'attr2': u'value2\u1f40'} + NS decl: + u'myns' u'http://www.python.org/namespace' + Start element: + u'http://www.python.org/namespace!subelement' {} + Character data: + u'Contents of subelements' + End element: + u'http://www.python.org/namespace!subelement' + End of NS decl: + u'myns' + Start element: + u'sub2' {} + Start of CDATA section + Character data: + u'contents of CDATA section' + End of CDATA section + End element: + u'sub2' + External entity ref: (None, u'entity.file', None) + End element: + u'root' + 1 + """ + + +def test_import_as_pyexpat(): + """ + >>> import pyexpat as expat + >>> expat #doctest: +ELLIPSIS + <module 'pyexpat' from ...> + """ + + +def test_errors_submodule(): + """ + >>> import xml.parsers.expat as expat + >>> expat.errors + <module 'pyexpat.errors' (built-in)> + >>> dir(expat.errors) #doctest: +ELLIPSIS + ['XML_ERROR_ABORTED', ..., 'XML_ERROR_XML_DECL', '__doc__', '__name__'] + >>> expat.errors.XML_ERROR_ABORTED + 'parsing aborted' + >>> expat.errors.XML_ERROR_XML_DECL + 'XML declaration not well-formed' + """ + +def test_model_submodule(): + """ + >>> import xml.parsers.expat as expat + >>> expat.model + <module 'pyexpat.model' (built-in)> + >>> print sortdict(expat.model.__dict__) + {'XML_CQUANT_NONE': 0, 'XML_CQUANT_OPT': 1, 'XML_CQUANT_PLUS': 3, 'XML_CQUANT_REP': 2, 'XML_CTYPE_ANY': 2, 'XML_CTYPE_CHOICE': 5, 'XML_CTYPE_EMPTY': 1, 'XML_CTYPE_MIXED': 3, 'XML_CTYPE_NAME': 4, 'XML_CTYPE_SEQ': 6, '__doc__': 'Constants used to interpret content model information.', '__name__': 'pyexpat.model'} + """ + +def test_parse_only_xml_data(): + """ + Source: test_pyexpat.py, see also: http://python.org/sf/1296433 + Changes: + - replaced 'iso8859' encoding with 'ISO-8859-1', + - added isfinal=True keyword argument to Parse call (as in this port, + the data is not processed until it is fully available). + With these changes, the test still crashes CPython 2.5. + + >>> import xml.parsers.expat as expat + >>> # xml = "<?xml version='1.0' encoding='iso8859'?><s>%s</s>" % ('a' * 1025) + + This one doesn't crash: + >>> xml = "<?xml version='1.0'?><s>%s</s>" % ('a' * 10000) + + >>> def handler(text): + ... raise Exception + >>> parser = expat.ParserCreate() + >>> parser.CharacterDataHandler = handler + >>> try: + ... parser.Parse(xml, True) + ... except: + ... pass + """ + + +def test_namespace_separator(): + """ + Source: test_pyexpat.py + + Tests that make sure we get errors when the namespace_separator value + is illegal, and that we don't for good values: + + >>> from xml.parsers.expat import ParserCreate + + >>> p = ParserCreate() + >>> p = ParserCreate(namespace_separator=None) + >>> p = ParserCreate(namespace_separator=' ') + >>> p = ParserCreate(namespace_separator=42) #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + TypeError: ... + >>> p = ParserCreate(namespace_separator='too long') #doctest: +ELLIPSIS + Traceback (most recent call last): + ... + ValueError: ... + + ParserCreate() needs to accept a namespace_separator of zero length + to satisfy the requirements of RDF applications that are required + to simply glue together the namespace URI and the localname. Though + considered a wart of the RDF specifications, it needs to be supported. + + See XML-SIG mailing list thread starting with + http://mail.python.org/pipermail/xml-sig/2001-April/005202.html + + >>> p = ParserCreate(namespace_separator='') # too short +""" + + +def test_interning_machinery(): + """ + Source: test_pyexpat.py + + >>> from xml.parsers.expat import ParserCreate + + >>> p = ParserCreate() + >>> L = [] + >>> def collector(name, *args): + ... L.append(name) + >>> p.StartElementHandler = collector + >>> p.EndElementHandler = collector + >>> p.Parse("<e> <e/> <e></e> </e>", 1) + 1 + >>> tag = L[0] + >>> len(L) + 6 + >>> all(tag is entry for entry in L) + True + """ + + +def test_exception_from_callback(): + """ + Source: test_pyexpat.py + + >>> from xml.parsers.expat import ParserCreate + + >>> def StartElementHandler(name, attrs): + ... raise RuntimeError(name) + + >>> parser = ParserCreate() + >>> parser.StartElementHandler = StartElementHandler + >>> try: + ... parser.Parse("<a><b><c/></b></a>", 1) + ... except RuntimeError, e: + ... pass + >>> e.args[0] == "a" + True + """ + + +def test_with_and_without_namespace(): + """ + >>> from xml.parsers.expat import ParserCreate + + >>> xml = '''<root + ... xmlns="http://www.python.org" + ... xmlns:python="http://www.python.org" + ... python:a="1" b="2"> + ... <python:sub1/> + ... <sub2 xmlns=""/> + ... </root>''' + >>> def handler(name, attributes): + ... attributes = sorted(attributes.items()) + ... print name + ... for attr in attributes: + ... print " %s = %r" % attr + + >>> parser = ParserCreate() + >>> parser.StartElementHandler = handler + >>> _ = parser.Parse(xml, True) + root + b = u'2' + python:a = u'1' + xmlns = u'http://www.python.org' + xmlns:python = u'http://www.python.org' + python:sub1 + sub2 + xmlns = u'' + + >>> parser = ParserCreate(namespace_separator="|") + >>> parser.StartElementHandler = handler + >>> _ = parser.Parse(xml, True) + http://www.python.org|root + b = u'2' + http://www.python.org|a = u'1' + http://www.python.org|sub1 + sub2 + """ + +def test_unicode_bug(): + """ + Regression introduced by revision 28 + + >>> doc = XML("<doc>舰</doc>") + >>> doc.text + u'\u8230' + """ + +def test_DTD(): + """ + >>> xml = '''<!DOCTYPE doc [ + ... <!ELEMENT doc (any|empty|text|mixed|opt|many|plus)> + ... <!ELEMENT any ANY> + ... <!ELEMENT empty EMPTY> + ... <!ELEMENT text (#PCDATA)> + ... <!ELEMENT sequence (_sequence)> + ... <!ELEMENT _sequence (any,any)> + ... <!ELEMENT mixed (#PCDATA|any)*> + ... <!ELEMENT opt (empty)?> + ... <!ELEMENT many (empty)*> + ... <!ELEMENT plus (empty)+> + ... ]> + ... <doc><text>content</text></doc> + ... ''' + >>> parser = expat.ParserCreate() + >>> def handler(header, *args): + ... def _handler(*args): + ... print header + ":", args + ... return _handler + >>> parser.ElementDeclHandler = handler("ELEMENT") + >>> parser.AttlistDeclHandler = handler("ATTRIBUTE") + >>> parser.EntityDeclHandler = handler("ENTITY") + >>> parser.NotationDeclHandler = handler("NOTATION") + >>> parser.UnparsedEntityDeclHandler = handler("UNPARSED") + >>> parser.Parse(xml, True) + ELEMENT: (u'doc', (5, 0, None, ((4, 0, u'any', ()), (4, 0, u'empty', ()), (4, 0, u'text', ()), (4, 0, u'mixed', ()), (4, 0, u'opt', ()), (4, 0, u'many', ()), (4, 0, u'plus', ())))) + ELEMENT: (u'any', (2, 0, None, ())) + ELEMENT: (u'empty', (1, 0, None, ())) + ELEMENT: (u'text', (3, 0, None, ())) + ELEMENT: (u'sequence', (6, 0, None, ((4, 0, u'_sequence', ()),))) + ELEMENT: (u'_sequence', (6, 0, None, ((4, 0, u'any', ()), (4, 0, u'any', ())))) + ELEMENT: (u'mixed', (3, 2, None, ((4, 0, u'any', ()),))) + ELEMENT: (u'opt', (6, 1, None, ((4, 0, u'empty', ()),))) + ELEMENT: (u'many', (6, 2, None, ((4, 0, u'empty', ()),))) + ELEMENT: (u'plus', (6, 3, None, ((4, 0, u'empty', ()),))) + 1 + """ + +def test_entity(): + """ + + TODO: need a fallback for entity-resolver so that empty source is returned. + + >>> xml = ''' <!DOCTYPE doc SYSTEM "external.dtd" [ + ... <!ENTITY ext-entity SYSTEM "external-entity"> + ... ]> + ... <doc>&ext-entity;&in-ext-dtd-entity;</doc>''' + >>> parser = expat.ParserCreate() + >>> parser.Parse(xml, True) + 1 + + EXPAT OH MY ! When applicable (internal entities), the CharacterDataHandler + callback will override DefaultHandlerExpand, but it WON'T override + DefaultHandler. On the other hand, the DefaultHandlerExpand callback WILL + override DefaultHandler ... More tests todo here ... + + >>> xml = '''<!DOCTYPE doc SYSTEM "external.dtd" [ + ... <!ENTITY ext-entity SYSTEM "external-entity"> + ... <!ENTITY int-entity "internal"> + ... ]> + ... <doc>&int-entity;&ext-entity;&in-ext-dtd-entity;</doc>''' + >>> parser = expat.ParserCreate() + >>> def handler(header): + ... def _handler(*args): + ... print header + ":", args + ... return 1 + ... return _handler + >>> parser.CharacterDataHandler = handler("text") + >>> parser.DefaultHandler = handler("default") + >>> parser.Parse(xml, True) #doctest: +ELLIPSIS + default: ... + default: (u'&int-entity;',) + default: (u'&ext-entity;',) + default: (u'&in-ext-dtd-entity;',) + ... + 1 + + EXPAT OH MY ! When applicable (internal entities), the CharacterDataHandler + callback will override DefaultHandlerExpand, but it WON'T override + DefaultHandler. On the other hand, the DefaultHandlerExpand callback WILL + override DefaultHandler ... More tests todo here ... + """ + +def test_resolve_entity_handlers(): + """ + >>> xml = '''<!DOCTYPE doc [ + ... <!ENTITY entity SYSTEM "entity"> + ... ]> + ... <doc>&entity;</doc>''' + >>> def handler(header): + ... def _handler(*args): + ... print header + ":", args + ... return 1 + ... return _handler + + >>> parser = expat.ParserCreate() + >>> parser.ExternalEntityRefHandler = handler("ExternalEntityRefHandler") + >>> parser.Parse(xml, True) + ExternalEntityRefHandler: (u'entity', None, u'entity', None) + 1 + """ + +def handler(name, header="XML>", returns=None): + def _handler(*args): + if len(args) == 1: + args = "(%r)" % args[0] + else: + args = str(args) + print header, name + "%s" % args + return returns + return _handler + +def parse(xml, *handlers): + parser = expat.ParserCreate() + for name in handlers: + if name == "ExternalEntityRefHandler": + returns = 1 + else: + returns = None + setattr(parser, name, handler(name, returns=returns)) + parser.Parse(xml, True) + +def test_internal_entities(): + """ + >>> xml = '''<!DOCTYPE doc [ + ... <!ENTITY entity "entity-content"> + ... ]> + ... <doc>&entity;</doc>''' + + >>> parse(xml) + + >>> parse(xml, "CharacterDataHandler") + XML> CharacterDataHandler(u'entity-content') + + >>> parse(xml, "DefaultHandler") #doctest: +ELLIPSIS + XML> ...DefaultHandler(u'&entity;')... + + >>> parse(xml, "DefaultHandlerExpand") #doctest: +ELLIPSIS + XML> ...DefaultHandlerExpand(u'entity-content')... + + # Uhu ? + >>> parse(xml, "CharacterDataHandler", + ... "DefaultHandler") #doctest: +ELLIPSIS + XML> ...DefaultHandler(u'&entity;')... + + >>> parse(xml, "CharacterDataHandler", + ... "DefaultHandlerExpand") #doctest: +ELLIPSIS + XML> ...CharacterDataHandler(u'entity-content')... + + >>> parse(xml, "DefaultHandler", + ... "DefaultHandlerExpand") #doctest: +ELLIPSIS + XML> ...DefaultHandlerExpand(u'entity-content')... + + >>> parse(xml, "CharacterDataHandler", + ... "DefaultHandler", + ... "DefaultHandlerExpand") #doctest: +ELLIPSIS + XML> ...CharacterDataHandler(u'entity-content')... + """ + +def test_external_entities(): + """ + >>> xml = '''<!DOCTYPE doc [ + ... <!ENTITY entity PUBLIC "http://entity-web" "entity-file"> + ... ]> + ... <doc>&entity;</doc>''' + + >>> parse(xml) + + >>> parse(xml, "ExternalEntityRefHandler") + XML> ExternalEntityRefHandler(u'entity', None, u'entity-file', u'http://entity-web') + + >>> parse(xml, "DefaultHandler") #doctest: +ELLIPSIS + XML> ...DefaultHandler(u'&entity;')... + + >>> parse(xml, "DefaultHandlerExpand") #doctest: +ELLIPSIS + XML> ...DefaultHandlerExpand(u'&entity;')... + + >>> parse(xml, "ExternalEntityRefHandler", + ... "DefaultHandler") #doctest: +ELLIPSIS + XML> ...ExternalEntityRefHandler(u'entity', None, u'entity-file', u'http://entity-web')... + + >>> parse(xml, "ExternalEntityRefHandler", + ... "DefaultHandlerExpand") #doctest: +ELLIPSIS + XML> ...ExternalEntityRefHandler(u'entity', None, u'entity-file', u'http://entity-web')... + + >>> parse(xml, "DefaultHandler", + ... "DefaultHandlerExpand") #doctest: +ELLIPSIS + XML> ...DefaultHandlerExpand(u'&entity;')... + + >>> parse(xml, "ExternalEntityRefHandler", + ... "DefaultHandler", + ... "DefaultHandlerExpand") #doctest: +ELLIPSIS + XML> ...ExternalEntityRefHandler(u'entity', None, u'entity-file', u'http://entity-web')... + """ + +def test_undefined_entities(): + """ + >>> xml = "<doc>&entity;</doc>" + >>> parse(xml) + Traceback (most recent call last): + ... + ExpatError: undefined entity: line 1, column 5 + """ + +def locate(parser, name): + def _handler(*args): + print name, parser.CurrentLineNumber, parser.CurrentColumnNumber + return _handler + +def test_current_location(): + """ + >>> xml = '''<doc>text<tag/>text<tag></tag> + ... <tag></tag> + ... text<tag/> + ... </doc>''' + >>> parser = expat.ParserCreate() + >>> parser.CharacterDataHandler = locate(parser, "TEXT:") + >>> parser.StartElementHandler = locate(parser, "START:") + >>> parser.EndElementHandler = locate(parser, "END:") + >>> _ = parser.Parse(xml, True) #doctest: +ELLIPSIS + START: 1 0 + TEXT: 1 5... + START: 1 9 + END: 1 15 + TEXT: 1 15... + START: 1 19 + END: 1 24 + TEXT: 1 30... + START: 2 0 + END: 2 5 + TEXT: 2 11... + START: 3 4 + END: 3 10 + TEXT: 3 10... + END: 4 0 + + >>> xml = '''<doc> + ... start tag after some text<tag/> + ... <elt></elt><tag/> + ... <elt/><tag/> + ... </doc>''' + >>> parser = expat.ParserCreate() + >>> parser.CharacterDataHandler = locate(parser, "TEXT:") + >>> parser.StartElementHandler = locate(parser, "START:") + >>> parser.EndElementHandler = locate(parser, "END:") + >>> _ = parser.Parse(xml, True) #doctest: +ELLIPSIS + START: 1 0 + TEXT: 1 5... + START: 2 25 + END: 2 31 + TEXT: 2 31... + START: 3 0 + END: 3 5 + START: 3 11 + END: 3 17 + TEXT: 3 17... + START: 4 0 + END: 4 6 + START: 4 6 + END: 4 12 + TEXT: 4 12... + END: 5 0 + """ + + +def test_error_location(): + """ + Source: selftest.py, ElementTree 1.3a3 + Changes: removed dependencies in ElementTree, added one extra test + + >>> def error(xml): + ... p = expat.ParserCreate() + ... try: + ... p.Parse(xml, True) + ... except expat.ExpatError, e: + ... return e.lineno, e.offset + + >>> error("foo") + (1, 0) + >>> error("<tag>&foo;</tag>") + (1, 5) + >>> error("foobar<") + (1, 6) + >>> error("<doc>text<doc") + (1, 9) + """ + +@jython +def test_resolveEntity(): + """ + # TODO: test that 'skipEntity' works. + + >>> # Jython + >>> from org.python.core.util import StringUtil + >>> from jarray import array + + >>> # Java Standard Edition + >>> from org.xml.sax import * + >>> from org.xml.sax.ext import * + >>> from org.xml.sax.helpers import * + >>> from java.io import ByteArrayInputStream + + >>> xml = '''<!DOCTYPE doc + ... [<!ENTITY entity SYSTEM "entity-file"> + ... ]> + ... <doc>&entity;</doc> + ... ''' + + >>> def empty_source(): + ... _source = InputSource() + ... byte_stream = ByteArrayInputStream(array([], "b")) + ... _source.setByteStream(byte_stream) + ... return _source + + >>> class Handler(EntityResolver2): + ... def getExternalSubset(self, name, baseURI): + ... return None + ... def resolveEntity(self, name, publicId, baseURI, systemId): + ... print "Entity name:", name + ... return empty_source() + + >>> def main(): + ... sax_parser = "org.apache.xerces.parsers.SAXParser" + ... reader = XMLReaderFactory.createXMLReader(sax_parser) + ... entity_resolver2 = "http://xml.org/sax/features/use-entity-resolver2" + ... enabled = reader.getFeature(entity_resolver2) + ... print "Entity-Resolver2 enabled:", enabled + ... handler = Handler() + ... reader.setEntityResolver(handler) + ... bytes = StringUtil.toBytes(xml) + ... byte_stream = ByteArrayInputStream(bytes) + ... source = InputSource(byte_stream) + ... reader.parse(source) + + >>> main() + Entity-Resolver2 enabled: True + Entity name: entity + """ + +if __name__ == "__main__": + doctest.testmod() Deleted: branches/jy3k/Lib/xml/parsers/expat.py =================================================================== --- trunk/jython/Lib/xml/parsers/expat.py 2009-01-08 22:54:04 UTC (rev 5893) +++ branches/jy3k/Lib/xml/parsers/expat.py 2009-01-09 04:50:22 UTC (rev 5899) @@ -1,617 +0,0 @@ -# coding: utf-8 - -#------------------------------------------------------------------------------ -# Copyright (c) 2008 Sébastien Boisgérault -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# ----------------------------------------------------------------------------- - -__all__ = ["ExpatError", "ParserCreate", "XMLParserType", "error", "errors"] - -# Jython check -import sys -if not sys.platform.startswith('java'): - raise ImportError("this version of expat requires the jython interpreter") - -# Standard Python Library -import re -import types - -# Jython -from org.python.core import Py -from org.python.core.util import StringUtil -from jarray import array - -# Java Standard Edition -from java.io import ByteArrayInputStream -from java.lang import String, StringBuilder -from org.xml.sax import InputSource -from org.xml.sax import SAXNotRecognizedException, SAXParseException -from org.xml.sax.helpers import XMLReaderFactory -from org.xml.sax.ext import DefaultHandler2 - -# Xerces -try: - # Name mangled by jarjar? - import org.python.apache.xerces.parsers.SAXParser - _xerces_parser = "org.python.apache.xerces.parsers.SAXParser" -except ImportError: - _xerces_parser = "org.apache.xerces.parsers.SAXParser" - - -def ParserCreate(encoding=None, namespace_separator=None): - return XMLParser(encoding, namespace_separator) - - -class XMLParser(object): - - def __init__(self, encoding, namespace_separator): - self.encoding = encoding - self.CurrentLineNumber = 1 - self.CurrentColumnNumber = 0 - self._NextLineNumber = 1 - self._NextColumnNumber = 0 - self.ErrorLineNumber = -1 - self.ErrorColumnNumber = -1 - self.ErrorCode = None - - if namespace_separator is None: - self.namespace_separator = namespace_separator - elif isinstance(namespace_separator, basestring): - self.namespace_separator = str(namespace_separator) - if len(self.namespace_separator) > 1: - error = ("namespace_separator must be at most one character, " - "omitted, or None") - raise ValueError(error) - else: - error = ("ParserCreate() argument 2 must be string or None, " - "not %s" % type(namespace_separator).__name__) - raise TypeError(error) - - self._reader = XMLReaderFactory.createXMLReader(_xerces_parser) - - if self.namespace_separator is None: - try: - feature = "http://xml.org/sax/features/namespaces" - self._reader.setFeature(feature, False) - except SAXNotRecognizedException: - error = ("namespace support cannot be disabled; " - "set namespace_separator to a string of length 1.") - raise ValueError(error) - - self._base = None - self._buffer_text = True - self._returns_unicode = True - - self._data = StringBuilder() - - self._handler = XMLEventHandler(self) - self._reader.setContentHandler(self._handler) - self._reader.setErrorHandler(self._handler) - self._reader.setDTDHandler(self._handler) - self._reader.setEntityResolver(self._handler) - - sax_properties = ("lexical-handler", "declaration-handler") - for name in sax_properties: - try: - name = "http://xml.org/sax/properties/" + name - self._reader.setProperty(name, self._handler) - except SAXNotRecognizedException: - error = "can't set property %r" % name - raise NotImplementedError(error) - - apache_features = (("nonvalidating/load-external-dtd", False),) - for name, value in apache_features: - try: - name = "http://apache.org/xml/features/" + name - self._reader.setFeature(name, value) - except SAXNotRecognizedException: - error = "can't set feature %r" % name - raise NotImplementedError(error) - - # experimental - #f = "http://xml.org/sax/features/external-general-entities" - f = "http://xml.org/sax/features/external-parameter-entities" - #self._reader.setFeature(f, False) - - # check - f = "http://xml.org/sax/features/use-entity-resolver2" - assert self._reader.getFeature(f) - - def GetBase(self): - return self._base - - def SetBase(self, base): - self._base = base - - def _error(self, value=None): - raise AttributeError("'XMLParser' has no such attribute") - - def _get_buffer_text(self): - return self._buffer_text - - def _set_buffer_text(self, value): - self._buffer_text = bool(value) - - def _get_returns_unicode(self): - return bool(self._returns_unicode) - - def _set_returns_unicode(self, value): - self._returns_unicode = value - - # 'ordered' and 'specified' attributes are not supported - ordered_attributes = property(_error, _error) - specified_attributes = property(_error, _error) - # any setting is allowed, but it won't make a difference - buffer_text = property(_get_buffer_text, _set_buffer_text) - # non-significant read-only values - buffer_used = property(lambda self: None) - buffer_size = property(lambda self: None) - # 'returns_unicode' attribute is properly supported - returns_unicode = property(_get_returns_unicode, _set_returns_unicode) - - def _expat_error(self, sax_error): - sax_message = sax_error.getMessage() - pattern = 'The entity ".*" was referenced, but not declared\.' - if re.match(pattern, sax_message): - expat_message = "undefined entity: line %s, column %s" % \ - (self.ErrorLineNumber, self.ErrorColumnNumber) - else: - expat_message = sax_message - error = ExpatError(expat_message) - error.lineno = self.ErrorLineNumber - error.offset = self.ErrorColumnNumber - error.code = self.ErrorCode - return error - - def Parse(self, data, isfinal=False): - # The 'data' argument should be an encoded text: a str instance that - # represents an array of bytes. If instead it is a unicode string, - # only the us-ascii range is considered safe enough to be silently - # converted. - if isinstance(data, unicode): - data = data.encode(sys.getdefaultencoding()) - - self._data.append(data) - - if isfinal: - bytes = StringUtil.toBytes(self._data.toString()) - byte_stream = ByteArrayInputStream(bytes) - source = InputSource(byte_stream) - if self.encoding is not None: - source.setEncoding(self.encoding) - try: - self._reader.parse(source) - except SAXParseException, sax_error: - # Experiments tend to show that the '_Next*' parser locations - # match more closely expat behavior than the 'Current*' or sax - # error locations. - self.ErrorLineNumber = self._NextLineNumber - self.ErrorColumnNumber = self._NextColumnNumber - self.ErrorCode = None - raise self._expat_error(sax_error) - return 1 - - def ParseFile(self, file): - # TODO: pseudo-buffering if a read without argument is not supported. - # document parse / parsefile usage. - return self.Parse(file.read(), isfinal=True) - - -XMLParserType = XMLParser - - -def _encode(arg, encoding): - if isinstance(arg, unicode): - return arg.encode(encoding) - else: - if isinstance(arg, dict): - iterator = arg.iteritems() - else: - iterator = iter(arg) - return type(arg)(_encode(_arg, encoding) for _arg in iterator) - - -def expat(callback=None, guard="True", force=False, returns="None"): - global _register - try: - _ = _register - except NameError: - _register = {} - - def _expat(method): - name = method.__name__ - context = id(sys._getframe(1)) - key = name, context - append = _register.setdefault(key, []).append - append((method, callback, guard, force, returns)) - - def new_method(*args): - self = args[0] - parser = self.parser - self._update_location(event=name) # bug if multiple method def - for (method, callback, guard, force, returns) in _register[key]: - _callback = callback and eval(guard) and \ - getattr(parser, callback, None) - if _callback or force: - results = method(*args) - if _callback: - if not isinstance(results, tuple): - results = (results,) - if not parser.returns_unicode: - results = _encode(results, "utf-8") - _callback(*results) - return_ = eval(returns) - if callable(return_): - return return_(*args[1:]) - else: - return return_ - break - new_method.__name__ = name - #new_method.__doc__ = method.__doc__ # what to do with multiple docs ? - return new_method - return _expat - - -class XMLEventHandler(DefaultHandler2): - - def __init__(self, parser): - self.parser = parser - self._tags = {} - self.dtd = False - self._entity = {} - self._previous_event = None - - # --- Helpers ------------------------------------------------------------- - - def _intern(self, tag): - return self._tags.setdefault(tag, tag) - - def _qualify(self, local_name, qname, namespace=None): - namespace_separator = self.parser.namespace_separator - if namespace_separator is None: - return qname - if not namespace: - return local_name - else: - return namespace + namespace_separator + local_name - - def _char_slice_to_unicode(self, characters, start, length): - """Convert a char[] slice to a PyUnicode instance""" - text = Py.newUnicode(String(characters[start:start + length])) - return text - - def _expat_content_model(self, name, model_): - # TODO : implement a model parser - return (name, model_) # does not fit expat conventions - - def _update_location(self, event=None): - parser = self.parser - locator = self._locator - - # ugly hack that takes care of a xerces-specific (?) locator issue: - # locate start and end elements at the '<' instead of the first tag - # type character. - if event == "startElement" and self._previous_event == "characters": - parser._NextColumnNumber = max(parser._NextColumnNumber - 1, 0) - if event == "endElement" and self._previous_event == "characters": - parser._NextColumnNumber = max(parser._NextColumnNumber - 2, 0) - # TODO: use the same trick to report accurate error locations ? - - parser.CurrentLineNumber = parser._NextLineNumber - parser.CurrentColumnNumber = parser._NextColumnNumber - parser._NextLineNumber = locator.getLineNumber() - parser._NextColumnNumber = locator.getColumnNumber() - 1 - - self._previous_event = event - - # --- ContentHandler Interface -------------------------------------------- - - @expat("ProcessingInstructionHandler") - def processingInstruction(self, target, data): - return target, data - - @expat("StartElementHandler") - def startElement(self, namespace, local_name, qname, attributes): - tag = self._qualify(local_name, qname, namespace) - attribs = {} - length = attributes.getLength() - for index in range(length): - local_name = attributes.getLocalName(index) - qname = attributes.getQName(index) - namespace = attributes.getURI(index) - name = self._qualify(local_name, qname, namespace) - value = attributes.getValue(index) - attribs[name] = value - return self._intern(tag), attribs - - @expat("EndElementHandler") - def endElement(self, namespace, local_name, qname): - return self._intern(self._qualify(local_name, qname, namespace)) - - @expat("CharacterDataHandler") - def characters(self, characters, start, length): - return self._char_slice_to_unicode(characters, start, length) - - @expat("DefaultHandlerExpand") - def characters(self, characters, start, length): - return self._char_slice_to_unicode(characters, start, length) - - @expat("DefaultHandler") - def characters(self, characters, start, length): - # TODO: make a helper function here - if self._entity["location"] == (self.parser.CurrentLineNumber, - self.parser.CurrentColumnNumber): - return "&%s;" % self._entity["name"] - else: - return self._char_slice_to_unicode(characters, start, length) - - @expat("StartNamespaceDeclHandler") - def startPrefixMapping(self, prefix, uri): - return prefix, uri - - @expat("EndNamespaceDeclHandler") - def endPrefixMapping(self, prefix): - return prefix - - def _empty_source(self, *args): - name, publicId, baseURI, systemId = args - source = InputSource() - byte_stream = ByteArrayInputStream(array([], "b")) - source.setByteStream(byte_stream) - source.setPublicId(publicId) - source.setSystemId(systemId) - return source - - @expat("ExternalEntityRefHandler", guard="not self.dtd", - returns="self._empty_source") - def resolveEntity(self, name, publicId, baseURI, systemId): - context = name # wrong. see expat headers documentation. - base = self.parser.GetBase() - return context, base, systemId, publicId - - @expat("DefaultHandlerExpand", guard="not self.dtd", - returns="self._empty_source") - def resolveEntity(self, name, publicId, baseURI, systemId): - return "&%s;" % name - - @expat("DefaultHandler", guard="not self.dtd", - returns="self._empty_source") - def resolveEntity(self, name, publicId, baseURI, systemId): - return "&%s;" % name - - @expat(force=True, returns="self._empty_source") - def resolveEntity(self, name, publicId, baseURI, systemId): - pass - - def setDocumentLocator(self, locator): - self._locator = locator - - def skippedEntity(self, name): - error = ExpatError() - error.lineno = self.ErrorLineNumber = self.parser._NextLineNumber - error.offset = self.ErrorColumnNumber = self.parser._NextColumnNumber - error.code = self.ErrorCode = None - message = "undefined entity &%s;: line %s, column %s" - message = message % (name, error.lineno, error.offset) - error.__init__(message) - raise error - - # --- LexicalHandler Interface -------------------------------------------- - - @expat("CommentHandler") - def comment(self, characters, start, length): - return self._char_slice_to_unicode(characters, start, length) - - @expat("StartCdataSectionHandler") - def startCDATA(self): - return () - - @expat("EndCdataSectionHandler") - def endCDATA(self): - return () - - @expat("StartDoctypeDeclHandler", force=True) - def startDTD(self, name, publicId, systemId): - self.dtd = True - has_internal_subset = 0 # don't know this ... - return name, systemId, publicId, has_internal_subset - - @expat("EndDoctypeDeclHandler", force=True) - def endDTD(self): - self.dtd = False - - def startEntity(self, name): - self._entity = {} - self._entity["location"] = (self.parser._NextLineNumber, - self.parser._NextColumnNumber) - self._entity["name"] = name - - def endEntity(self, name): - pass - - # --- DTDHandler Interface ------------------------------------------------ - - @expat("NotationDeclHandler") - def notationDecl(self, name, publicId, systemId): - base = self.parser.GetBase() - return name, base, systemId, publicId - - @expat("UnparsedEntityDeclHandler") # deprecated - def unparsedEntityDecl(self, name, publicId, systemId, notationName): - base = self.parser.GetBase() - return name, base, systemId, publicId, notationName - - # --- DeclHandler Interface ----------------------------------------------- - - @expat("AttlistDeclHandler") - def attributeDecl(self, eName, aName, type, mode, value): - # TODO: adapt mode, required, etc. - required = False - return eName, aName, type, value, required - - @expat("ElementDeclHandler") - def elementDecl(self, name, model): - return self._expat_content_model(name, model) - - @expat("EntityDeclHandler") - def externalEntityDecl(self, name, publicId, systemId): - base = self.parser.GetBase() - value = None - is_parameter_entity = None - notation_name = None - return (name, is_parameter_entity, value, base, systemId, publicId, - notation_name) - - @expat("EntityDeclHandler") - def internalEntityDecl(self, name, value): - base = self.parser.GetBase() - is_parameter_entity = None - notation_name = None - systemId, publicId = None, None - return (name, is_parameter_entity, value, base, systemId, publicId, - notation_name) - - -def _init_model(): - global model - model = types.ModuleType("pyexpat.model") - model.__doc__ = "Constants used to interpret content model information." - quantifiers = "NONE, OPT, REP, PLUS" - for i, quantifier in enumerate(quantifiers.split(", ")): - setattr(model, "XML_CQUANT_" + quantifier, i) - types_ = "EMPTY, ANY, MIXED, NAME, CHOICE, SEQ" - for i, type_ in enumerate(types_.split(", ")): - setattr(model, "XML_CTYPE_" + type_, i+1) - -_init_model() -del _init_model - - -class ExpatError(Exception): - pass - - -error = ExpatError - - -def _init_error_strings(): - global ErrorString - error_strings = ( - None, - "out of memory", - "syntax error", - "no element found", - "not well-formed (invalid token)", - "unclosed token", - "partial character", - "mismatched tag", - "duplicate attribute", - "junk after document element", - "illegal parameter entity reference", - "undefined entity", - "recursive entity reference", - "asynchronous entity", - "reference to invalid character number", - "reference to binary entity", - "reference to external entity in attribute", - "XML or text declaration not at start of entity", - "unknown encoding", - "encoding specified in XML declaration is incorrect", - "unclosed CDATA section", - "error in processing external entity reference", - "document is not standalone", - "unexpected parser state - please send a bug report", - "entity declared in parameter entity", - "requested feature requires XML_DTD support in Expat", - "cannot change setting once parsing has begun", - "unbound prefix", - "must not undeclare prefix", - "incomplete markup in parameter entity", - "XML declaration not well-formed", - "text declaration not well-formed", - "illegal character(s) in public id", - "parser suspended", - "parser not suspended", - "parsing aborted", - "parsing finished", - "cannot suspend in external parameter entity") - def ErrorString(code): - try: - return error_strings[code] - except IndexError: - return None - -_init_error_strings() -del _init_error_strings - - -def _init_errors(): - global errors - - errors = types.ModuleType("pyexpat.errors") - errors.__doc__ = "Constants used to describe error conditions." - - error_names = """ - XML_ERROR_NONE - XML_ERROR_NONE, - XML_ERROR_NO_MEMORY, - XML_ERROR_SYNTAX, - XML_ERROR_NO_ELEMENTS, - XML_ERROR_INVALID_TOKEN, - XML_ERROR_UNCLOSED_TOKEN, - XML_ERROR_PARTIAL_CHAR, - XML_ERROR_TAG_MISMATCH, - XML_ERROR_DUPLICATE_ATTRIBUTE, - XML_ERROR_JUNK_AFTER_DOC_ELEMENT, - XML_ERROR_PARAM_ENTITY_REF, - XML_ERROR_UNDEFINED_ENTITY, - XML_ERROR_RECURSIVE_ENTITY_REF, - XML_ERROR_ASYNC_ENTITY, - XML_ERROR_BAD_CHAR_REF, - XML_ERROR_BINARY_ENTITY_REF, - XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, - XML_ERROR_MISPLACED_XML_PI, - XML_ERROR_UNKNOWN_ENCODING, - XML_ERROR_INCORRECT_ENCODING, - XML_ERROR_UNCLOSED_CDATA_SECTION, - XML_ERROR_EXTERNAL_ENTITY_HANDLING, - XML_ERROR_NOT_STANDALONE, - XML_ERROR_UNEXPECTED_STATE, - XML_ERROR_ENTITY_DECLARED_IN_PE, - XML_ERROR_FEATURE_REQUIRES_XML_DTD, - XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, - XML_ERROR_UNBOUND_PREFIX, - XML_ERROR_UNDECLARING_PREFIX, - XML_ERROR_INCOMPLETE_PE, - XML_ERROR_XML_DECL, - XML_ERROR_TEXT_DECL, - XML_ERROR_PUBLICID, - XML_ERROR_SUSPENDED, - XML_ERROR_NOT_SUSPENDED, - XML_ERROR_ABORTED, - XML_ERROR_FINISHED, - XML_ERROR_SUSPEND_PE - """ - error_names = [name.strip() for name in error_names.split(',')] - for i, name in enumerate(error_names[1:]): - setattr(errors, name, ErrorString(i+1)) - -_init_errors() -del _init_errors Copied: branches/jy3k/Lib/xml/parsers/expat.py (from rev 5893, trunk/jython/Lib/xml/parsers/expat.py) =================================================================== --- branches/jy3k/Lib/xml/parsers/expat.py (rev 0) +++ branches/jy3k/Lib/xml/parsers/expat.py 2009-01-09 04:50:22 UTC (rev 5899) @@ -0,0 +1,617 @@ +# coding: utf-8 + +#------------------------------------------------------------------------------ +# Copyright (c) 2008 Sébastien Boisgérault +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# ----------------------------------------------------------------------------- + +__all__ = ["ExpatError", "ParserCreate", "XMLParserType", "error", "errors"] + +# Jython check +import sys +if not sys.platform.startswith('java'): + raise ImportError("this version of expat requires the jython interpreter") + +# Standard Python Library +import re +import types + +# Jython +from org.python.core import Py +from org.python.core.util import StringUtil +from jarray import array + +# Java Standard Edition +from java.io import ByteArrayInputStream +from java.lang import String, StringBuilder +from org.xml.sax import InputSource +from org.xml.sax import SAXNotRecognizedException, SAXParseException +from org.xml.sax.helpers import XMLReaderFactory +from org.xml.sax.ext import DefaultHandler2 + +# Xerces +try: + # Name mangled by jarjar? + import org.python.apache.xerces.parsers.SAXParser + _xerces_parser = "org.python.apache.xerces.parsers.SAXParser" +except ImportError: + _xerces_parser = "org.apache.xerces.parsers.SAXParser" + + +def ParserCreate(encoding=None, namespace_separator=None): + return XMLParser(encoding, namespace_separator) + + +class XMLParser(object): + + def __init__(self, encoding, namespace_separator): + self.encoding = encoding + self.CurrentLineNumber = 1 + self.CurrentColumnNumber = 0 + self._NextLineNumber = 1 + self._NextColumnNumber = 0 + self.ErrorLineNumber = -1 + self.ErrorColumnNumber = -1 + self.ErrorCode = None + + if namespace_separator is None: + self.namespace_separator = namespace_separator + elif isinstance(namespace_separator, basestring): + self.namespace_separator = str(namespace_separator) + if len(self.namespace_separator) > 1: + error = ("namespace_separator must be at most one character, " + "omitted, or None") + raise ValueError(error) + else: + error = ("ParserCreate() argument 2 must be string or None, " + "not %s" % type(namespace_separator).__name__) + raise TypeError(error) + + self._reader = XMLReaderFactory.createXMLReader(_xerces_parser) + + if self.namespace_separator is None: + try: + feature = "http://xml.org/sax/features/namespaces" + self._reader.setFeature(feature, False) + except SAXNotRecognizedException: + error = ("namespace support cannot be disabled; " + "set namespace_separator to a string of length 1.") + raise ValueError(error) + + self._base = None + self._buffer_text = True + self._returns_unicode = True + + self._data = StringBuilder() + + self._handler = XMLEventHandler(self) + self._reader.setContentHandler(self._handler) + self._reader.setErrorHandler(self._handler) + self._reader.setDTDHandler(self._handler) + self._reader.setEntityResolver(self._handler) + + sax_properties = ("lexical-handler", "declaration-handler") + for name in sax_properties: + try: + name = "http://xml.org/sax/properties/" + name + self._reader.setProperty(name, self._handler) + except SAXNotRecognizedException: + error = "can't set property %r" % name + raise NotImplementedError(error) + + apache_features = (("nonvalidating/load-external-dtd", False),) + for name, value in apache_features: + try: + name = "http://apache.org/xml/features/" + name + self._reader.setFeature(name, value) + except SAXNotRecognizedException: + error = "can't set feature %r" % name + raise NotImplementedError(error) + + # experimental + #f = "http://xml.org/sax/features/external-general-entities" + f = "http://xml.org/sax/features/external-parameter-entities" + #self._reader.setFeature(f, False) + + # check + f = "http://xml.org/sax/features/use-entity-resolver2" + assert self._reader.getFeature(f) + + def GetBase(self): + return self._base + + def SetBase(self, base): + self._base = base + + def _error(self, value=None): + raise AttributeError("'XMLParser' has no such attribute") + + def _get_buffer_text(self): + return self._buffer_text + + def _set_buffer_text(self, value): + self._buffer_text = bool(value) + + def _get_returns_unicode(self): + return bool(self._returns_unicode) + + def _set_returns_unicode(self, value): + self._returns_unicode = value + + # 'ordered' and 'specified' attributes are not supported + ordered_attributes = property(_error, _error) + specified_attributes = property(_error, _error) + # any setting is allowed, but it won't make a difference + buffer_text = property(_get_buffer_text, _set_buffer_text) + # non-significant read-only values + buffer_used = property(lambda self: None) + buffer_size = property(lambda self: None) + # 'returns_unicode' attribute is properly supported + returns_unicode = property(_get_returns_unicode, _set_returns_unicode) + + def _expat_error(self, sax_error): + sax_message = sax_error.getMessage() + pattern = 'The entity ".*" was referenced, but not declared\.' + if re.match(pattern, sax_message): + expat_message = "undefined entity: line %s, column %s" % \ + (self.ErrorLineNumber, self.ErrorColumnNumber) + else: + expat_message = sax_message + error = ExpatError(expat_message) + error.lineno = self.ErrorLineNumber + error.offset = self.ErrorColumnNumber + error.code = self.ErrorCode + return error + + def Parse(self, data, isfinal=False): + # The 'data' argument should be an encoded text: a str instance that + # represents an a... [truncated message content] |
From: <fwi...@us...> - 2009-01-10 03:53:42
|
Revision: 5907 http://jython.svn.sourceforge.net/jython/?rev=5907&view=rev Author: fwierzbicki Date: 2009-01-10 03:53:36 +0000 (Sat, 10 Jan 2009) Log Message: ----------- Improved parsing of expanded 3.0 argument lists. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-10 00:49:02 UTC (rev 5906) +++ branches/jy3k/grammar/Python.g 2009-01-10 03:53:36 UTC (rev 5907) @@ -482,23 +482,46 @@ typedargslist returns [arguments args] @init { List defaults = new ArrayList(); + List kw_defaults = new ArrayList(); } : d+=tdefparameter[defaults] (options {greedy=true;}:COMMA d+=tdefparameter[defaults])* (COMMA - (STAR (starargs=tfpdef[expr_contextType.Param])? (COMMA tdefparameter[defaults])* (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? + (STAR (starargs=tfpdef[expr_contextType.Param])? (COMMA k+=tdefparameter[kw_defaults])* + (COMMA tdefparameter[defaults])* (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? | DOUBLESTAR kwargs=tfpdef[expr_contextType.Param] )? )? { - $args = actions.makeArgumentsType($typedargslist.start, $d, $starargs.tree, $kwargs.tree, defaults); + $args = actions.makeArgumentsType( + $typedargslist.start, + $d, + actions.castArg($starargs.tree), + $k, + actions.castArg($kwargs.tree), + defaults, + kw_defaults); } | STAR starargs=tfpdef[expr_contextType.Param] (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? { - $args = actions.makeArgumentsType($typedargslist.start, $d, $starargs.tree, $kwargs.tree, defaults); + $args = actions.makeArgumentsType( + $typedargslist.start, + $d, + actions.castArg($starargs.tree), + $k, + actions.castArg($kwargs.tree), + defaults, + kw_defaults); } | DOUBLESTAR kwargs=tfpdef[expr_contextType.Param] { - $args = actions.makeArgumentsType($typedargslist.start, $d, null, $kwargs.tree, defaults); + $args = actions.makeArgumentsType( + $typedargslist.start, + $d, + null, + $k, + actions.castArg($kwargs.tree), + defaults, + kw_defaults); } ; @@ -530,23 +553,47 @@ varargslist returns [arguments args] @init { List defaults = new ArrayList(); + List kw_defaults = new ArrayList(); } : d+=vdefparameter[defaults] (options {greedy=true;}:COMMA d+=vdefparameter[defaults])* (COMMA - (STAR (starargs=vfpdef[expr_contextType.Param])? (COMMA DOUBLESTAR kwargs=vfpdef[expr_contextType.Param])? + (STAR (starargs=vfpdef[expr_contextType.Param])? (COMMA k+=vdefparameter[kw_defaults])* + (COMMA DOUBLESTAR kwargs=vfpdef[expr_contextType.Param])? | DOUBLESTAR kwargs=vfpdef[expr_contextType.Param] )? )? { - $args = actions.makeArgumentsType($varargslist.start, $d, $starargs.tree, $kwargs.tree, defaults); + $args = actions.makeArgumentsType( + $varargslist.start, + $d, + actions.castArg($starargs.tree), + $k, + actions.castArg($kwargs.tree), + defaults, + kw_defaults); } | STAR starargs=vfpdef[expr_contextType.Param] (COMMA DOUBLESTAR kwargs=vfpdef[expr_contextType.Param])? { - $args = actions.makeArgumentsType($varargslist.start, $d, $starargs.tree, $kwargs.tree, defaults); + $args = actions.makeArgumentsType( + $varargslist.start, + $d, + actions.castArg($starargs.tree), + $k, + actions.castArg($kwargs.tree), + defaults, + kw_defaults); + } | DOUBLESTAR kwargs=vfpdef[expr_contextType.Param] { - $args = actions.makeArgumentsType($varargslist.start, $d, null, $kwargs.tree, defaults); + $args = actions.makeArgumentsType( + $varargslist.start, + $d, + null, + $k, + actions.castArg($kwargs.tree), + defaults, + kw_defaults); } ; @@ -1482,10 +1529,14 @@ List arguments = new ArrayList(); List kws = new ArrayList(); List gens = new ArrayList(); + + List arguments2 = new ArrayList(); + List kws2 = new ArrayList(); + List gens2 = new ArrayList(); } : argument[arguments, kws, gens, true] (COMMA argument[arguments, kws, gens, false])* (COMMA - ( STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? + ( STAR s=test[expr_contextType.Load] (COMMA argument[arguments2, kws2, gens2, false])* (COMMA DOUBLESTAR k=test[expr_contextType.Load])? | DOUBLESTAR k=test[expr_contextType.Load] )? )? Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-10 00:49:02 UTC (rev 5906) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-10 03:53:36 UTC (rev 5907) @@ -170,7 +170,6 @@ if (o instanceof PythonTree) { return errorHandler.errorArg((PythonTree)o); } - errorHandler.error("Bad Arg node", null); return null; } @@ -315,24 +314,39 @@ } } - arguments makeArgumentsType(Token t, List params, PythonTree snameToken, - PythonTree knameToken, List defaults) { + arguments makeArgumentsType( + Token t, + List args, + arg vararg, + List kwonlyargs, //* + arg kwarg, + List defaults, + List kw_defaults //* + ) { - List<arg> p = castArgs(params); + List<arg> p = castArgs(args); List<expr> d = castExprs(defaults); + List<arg> kw = castArgs(kwonlyargs); + List<expr> kw_d = castExprs(kw_defaults); String s; String k; - if (snameToken == null) { + expr sAnnotation; + expr kAnnotation; + if (vararg == null) { s = null; + sAnnotation = null; } else { - s = cantBeNone(snameToken); + s = cantBeNone(vararg); + sAnnotation = vararg.getInternalAnnotation(); } - if (knameToken == null) { + if (kwarg == null) { k = null; + kAnnotation = null; } else { - k = cantBeNone(knameToken); + k = cantBeNone(kwarg); + kAnnotation = kwarg.getInternalAnnotation(); } - return new arguments(t, p, s, null, new ArrayList<arg>(), k, null, d, new ArrayList<expr>()); + return new arguments(t, p, s, sAnnotation, kw, k, kAnnotation, d, kw_d); } List<expr> extractArgs(List args) { @@ -550,6 +564,13 @@ return new UnaryOp(t, unaryopType.USub, o); } + String cantBeNone(arg a) { + if (a == null || a.getInternalArg().equals("None")) { + errorHandler.error("can't be None", a); + } + return a.getInternalArg(); + } + String cantBeNone(Token t) { if (t == null || t.getText().equals("None")) { errorHandler.error("can't be None", new PythonTree(t)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-10 20:50:40
|
Revision: 5911 http://jython.svn.sourceforge.net/jython/?rev=5911&view=rev Author: fwierzbicki Date: 2009-01-10 20:50:36 +0000 (Sat, 10 Jan 2009) Log Message: ----------- ClassDef now takes arglist for bases. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-10 13:45:43 UTC (rev 5910) +++ branches/jy3k/grammar/Python.g 2009-01-10 20:50:36 UTC (rev 5911) @@ -1505,17 +1505,18 @@ @after { $classdef.tree = stype; } - : decorators? CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite[false] + : decorators? CLASS NAME (LPAREN arglist? RPAREN)? COLON suite[false] { Token t = $CLASS; if ($decorators.start != null) { t = $decorators.start; } - stype = new ClassDef(t, actions.cantBeNone($NAME), - actions.makeBases(actions.castExpr($testlist.tree)), - new ArrayList<keyword>(), - null, - null, + stype = new ClassDef(t, + actions.cantBeNone($NAME), + actions.castExprs($arglist.args), + actions.makeKeywords($arglist.keywords), + $arglist.starargs, + $arglist.kwargs, actions.castStmts($suite.stypes), actions.castExprs($decorators.etypes)); } @@ -1531,12 +1532,11 @@ List gens = new ArrayList(); List arguments2 = new ArrayList(); - List kws2 = new ArrayList(); List gens2 = new ArrayList(); } : argument[arguments, kws, gens, true] (COMMA argument[arguments, kws, gens, false])* (COMMA - ( STAR s=test[expr_contextType.Load] (COMMA argument[arguments2, kws2, gens2, false])* (COMMA DOUBLESTAR k=test[expr_contextType.Load])? + ( STAR s=test[expr_contextType.Load] (COMMA argument[arguments2, kws, gens2, false])* (COMMA DOUBLESTAR k=test[expr_contextType.Load])? | DOUBLESTAR k=test[expr_contextType.Load] )? )? Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-10 13:45:43 UTC (rev 5910) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-10 20:50:36 UTC (rev 5911) @@ -100,17 +100,6 @@ return atypes; } - List<expr> makeBases(expr etype) { - List<expr> result = new ArrayList<expr>(); - if (etype != null) { - if (etype instanceof Tuple) { - return ((Tuple)etype).getInternalElts(); - } - result.add(etype); - } - return result; - } - List<String> makeNames(List names) { List<String> s = new ArrayList<String>(); for(int i=0;i<names.size();i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-11 14:49:47
|
Revision: 5919 http://jython.svn.sourceforge.net/jython/?rev=5919&view=rev Author: fwierzbicki Date: 2009-01-11 14:49:43 +0000 (Sun, 11 Jan 2009) Log Message: ----------- refinements to funcdef args. Modified Paths: -------------- branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-11 10:35:10 UTC (rev 5918) +++ branches/jy3k/grammar/Python.g 2009-01-11 14:49:43 UTC (rev 5919) @@ -461,7 +461,7 @@ ; //not in CPython's Grammar file -tdefparameter[List defaults] returns [arg atype] +tdefparameter[List defaults, boolean defaultToNone] returns [arg atype] @after { $tdefparameter.tree = $atype; } @@ -470,6 +470,9 @@ $atype = actions.castArg($tfpdef.tree); if ($ASSIGN != null) { defaults.add($test.tree); + } else if (defaultToNone) { + //XXX: is this the right way to add None? + defaults.add(null); } else if (!defaults.isEmpty()) { throw new ParseException("non-default argument follows default argument", $tfpdef.tree); } @@ -484,10 +487,10 @@ List defaults = new ArrayList(); List kw_defaults = new ArrayList(); } - : d+=tdefparameter[defaults] (options {greedy=true;}:COMMA d+=tdefparameter[defaults])* + : d+=tdefparameter[defaults, false] (options {greedy=true;}:COMMA d+=tdefparameter[defaults, false])* (COMMA - (STAR (starargs=tfpdef[expr_contextType.Param])? (COMMA k+=tdefparameter[kw_defaults])* - (COMMA tdefparameter[defaults])* (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? + (STAR (starargs=tfpdef[expr_contextType.Param])? (COMMA k+=tdefparameter[kw_defaults, true])* + (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? | DOUBLESTAR kwargs=tfpdef[expr_contextType.Param] )? )? @@ -501,7 +504,7 @@ defaults, kw_defaults); } - | STAR starargs=tfpdef[expr_contextType.Param] (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? + | STAR (starargs=tfpdef[expr_contextType.Param])? (COMMA DOUBLESTAR kwargs=tfpdef[expr_contextType.Param])? { $args = actions.makeArgumentsType( $typedargslist.start, Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-11 10:35:10 UTC (rev 5918) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-11 14:49:43 UTC (rev 5919) @@ -136,7 +136,11 @@ result.add((expr)o); } else if (o instanceof PythonParser.test_return) { result.add((expr)((PythonParser.test_return)o).tree); + } else if (o == null) { + //Should we really add null? This is mainly here for kw_defaults + result.add(null); } + //XXX: throw exception if we get here? } } return result; @@ -307,10 +311,10 @@ Token t, List args, arg vararg, - List kwonlyargs, //* + List kwonlyargs, arg kwarg, List defaults, - List kw_defaults //* + List kw_defaults ) { List<arg> p = castArgs(args); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-14 03:59:03
|
Revision: 5928 http://jython.svn.sourceforge.net/jython/?rev=5928&view=rev Author: fwierzbicki Date: 2009-01-14 03:58:51 +0000 (Wed, 14 Jan 2009) Log Message: ----------- Merged revisions 5900-5901,5903-5906,5908,5912-5918,5920,5923,5925,5927 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5900 | fwierzbicki | 2009-01-09 10:16:08 -0500 (Fri, 09 Jan 2009) | 2 lines Fix for wrong error line number when file ends with open paren. ........ r5901 | otmarhumbel | 2009-01-09 12:31:07 -0500 (Fri, 09 Jan 2009) | 1 line reduce the size of the installer .jar by excluding external libraries we do not want to distribute ........ r5903 | fwierzbicki | 2009-01-09 15:40:11 -0500 (Fri, 09 Jan 2009) | 2 lines Change release numbers in build. ........ r5904 | fwierzbicki | 2009-01-09 15:43:55 -0500 (Fri, 09 Jan 2009) | 2 lines locked CPython to revision 68460. ........ r5905 | fwierzbicki | 2009-01-09 15:53:52 -0500 (Fri, 09 Jan 2009) | 2 lines Update README ........ r5906 | pjenvey | 2009-01-09 19:49:02 -0500 (Fri, 09 Jan 2009) | 2 lines fix broken import ........ r5908 | pedronis | 2009-01-10 07:39:15 -0500 (Sat, 10 Jan 2009) | 5 lines yet another try at binop rule, with more exhaustive tests (verified against cpython) that now pass see also PyPy issue 412 ........ r5912 | cgroves | 2009-01-10 19:53:55 -0500 (Sat, 10 Jan 2009) | 6 lines * Add xerces' version number to its file name for future explorers. * Add a skip-brand property to build.xml that allows version branding to be skipped, which keeps jython-dev.jar from being built even if no other files change and shaves a couple seconds off a dev build. ........ r5913 | cgroves | 2009-01-10 20:03:33 -0500 (Sat, 10 Jan 2009) | 1 line Compile Syspath.java for 1.5 instead of 1.6 ........ r5914 | cgroves | 2009-01-10 20:12:16 -0500 (Sat, 10 Jan 2009) | 5 lines Creating the empty.py file after the bytecode just meant that it had a more recent modtime and would be preferred for importing, so it wasn't testing anything. ........ r5915 | cgroves | 2009-01-10 22:21:25 -0500 (Sat, 10 Jan 2009) | 1 line Cleanup ........ r5916 | cgroves | 2009-01-11 01:04:11 -0500 (Sun, 11 Jan 2009) | 6 lines Convert to PyObject going into and Object coming out of java.util.Set methods on PySet like PyDictionary does for Map methods and PyList does for List methods. Without this, Java code can add non-PyObjects to the underlying set causing the Python access to it to throw ClassCastExceptions. ........ r5917 | cgroves | 2009-01-11 01:24:45 -0500 (Sun, 11 Jan 2009) | 3 lines Huh, I guess ECJ can handle inferring these generics, but javac sure can't. ........ r5918 | cgroves | 2009-01-11 05:35:10 -0500 (Sun, 11 Jan 2009) | 6 lines In String compilation contexts, we can assume the bytes have already been decoded and just pass them through when parsing instead of using ascii. This gets test_doctest back to passing as it was before and keeps the pep 263 checks. ........ r5920 | cgroves | 2009-01-11 17:26:38 -0500 (Sun, 11 Jan 2009) | 6 lines test320 - Moved to test_traceback_jy test366,373 - Moved to test_java_integration test391 - Moved to test_java_visibility test395 - Tested by test_java_visibility test396 - Tested by test_java_subclasses ........ r5923 | pjenvey | 2009-01-11 20:31:59 -0500 (Sun, 11 Jan 2009) | 1 line bump copyright year ........ r5925 | cgroves | 2009-01-13 17:10:24 -0500 (Tue, 13 Jan 2009) | 1 line Allow importation from bytecode in a zip file even if the source isn't present ........ r5927 | fwierzbicki | 2009-01-13 22:42:42 -0500 (Tue, 13 Jan 2009) | 4 lines Small fix to grammar -- a "print" by itself should have it's NL attribute set to true as CPython does. Because "false" doesn't make sense in this context (it would be a no-op), the compiler doesn't check, so it passed unnoticed. ........ Revision Links: -------------- http://jython.svn.sourceforge.net/jython/?rev=68460&view=rev Modified Paths: -------------- branches/jy3k/LICENSE.txt branches/jy3k/Lib/os.py branches/jy3k/Lib/test/syspath_import.jar branches/jy3k/Lib/test/test_descr_jy.py branches/jy3k/Lib/test/test_doctest.py branches/jy3k/Lib/test/test_eof_jy.py branches/jy3k/Lib/test/test_import_jy.py branches/jy3k/Lib/test/test_java_integration.py branches/jy3k/Lib/test/test_java_visibility.py branches/jy3k/Lib/test/test_traceback_jy.py branches/jy3k/README.txt branches/jy3k/build.xml branches/jy3k/src/org/python/antlr/PythonTokenSource.java branches/jy3k/src/org/python/compiler/ProxyMaker.java branches/jy3k/src/org/python/core/BaseSet.java branches/jy3k/src/org/python/core/CompilerFlags.java branches/jy3k/src/org/python/core/ParserFacade.java branches/jy3k/src/org/python/core/PyDictionary.java branches/jy3k/src/org/python/core/PyFrozenSet.java branches/jy3k/src/org/python/core/PyIterator.java branches/jy3k/src/org/python/core/PyLong.java branches/jy3k/src/org/python/core/PyObject.java branches/jy3k/src/org/python/core/PyObjectList.java branches/jy3k/src/org/python/core/PySequenceList.java branches/jy3k/src/org/python/core/PySet.java branches/jy3k/src/org/python/core/PySystemState.java branches/jy3k/src/org/python/core/PyType.java branches/jy3k/src/org/python/modules/zipimport/zipimporter.java branches/jy3k/src/org/python/util/Generic.java branches/jy3k/src/org/python/util/NameUnionAntType.java branches/jy3k/tests/java/javatests/ListTest.java branches/jy3k/tests/java/javatests/TestSupport.java Added Paths: ----------- branches/jy3k/Lib/test/eof_fodder7.py branches/jy3k/Lib/test/except_in_raising_code.py branches/jy3k/Lib/test/test_set_jy.py branches/jy3k/extlibs/xercesImpl-2.9.1.jar branches/jy3k/tests/java/javatests/PySetInJavaTest.java Removed Paths: ------------- branches/jy3k/bugtests/classes/test395j1.java branches/jy3k/bugtests/classes/test395j2.java branches/jy3k/bugtests/classes/test396j.java branches/jy3k/bugtests/test320.py branches/jy3k/bugtests/test366.py branches/jy3k/bugtests/test373.py branches/jy3k/bugtests/test391.py branches/jy3k/bugtests/test395.py branches/jy3k/bugtests/test396.py branches/jy3k/extlibs/xercesImpl.jar branches/jy3k/src/org/python/core/PySetIterator.java Modified: branches/jy3k/LICENSE.txt =================================================================== --- branches/jy3k/LICENSE.txt 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/LICENSE.txt 2009-01-14 03:58:51 UTC (rev 5928) @@ -53,7 +53,7 @@ Jython 2.0, 2.1 License ================================ -Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Jython Developers +Copyright (c) 2000-2009 Jython Developers. All rights reserved. Redistribution and use in source and binary forms, with or without Modified: branches/jy3k/Lib/os.py =================================================================== --- branches/jy3k/Lib/os.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/os.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -569,7 +569,7 @@ if _time_t is None: from java.lang import Integer, Long try: - from org.python.posix import Platform + from org.python.posix.util import Platform except ImportError: from org.jruby.ext.posix.util import Platform _time_t = Integer if Platform.IS_32_BIT else Long Copied: branches/jy3k/Lib/test/eof_fodder7.py (from rev 5927, trunk/jython/Lib/test/eof_fodder7.py) =================================================================== --- branches/jy3k/Lib/test/eof_fodder7.py (rev 0) +++ branches/jy3k/Lib/test/eof_fodder7.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,5 @@ +def hi(): + pass + +def bye(): + hi( Copied: branches/jy3k/Lib/test/except_in_raising_code.py (from rev 5927, trunk/jython/Lib/test/except_in_raising_code.py) =================================================================== --- branches/jy3k/Lib/test/except_in_raising_code.py (rev 0) +++ branches/jy3k/Lib/test/except_in_raising_code.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,8 @@ +def test(): + print noname + +def foo(): + try: + test() + except ValueError: + raise RuntimeError("Accessing a undefined name should raise a NameError") Modified: branches/jy3k/Lib/test/syspath_import.jar =================================================================== (Binary files differ) Modified: branches/jy3k/Lib/test/test_descr_jy.py =================================================================== --- branches/jy3k/Lib/test/test_descr_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_descr_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -368,13 +368,148 @@ except AttributeError, e: self.assertEquals("Custom message", str(e)) +# try to test more exhaustively binop overriding combination cases +class Base(object): + def __init__(self, name): + self.name = name + +def lookup_where(obj, name): + mro = type(obj).__mro__ + for t in mro: + if name in t.__dict__: + return t.__dict__[name], t + return None, None + +def refop(x, y, opname, ropname): + # this has been validated by running the tests on top of cpython + # so for the space of possibilities that the tests touch it is known + # to behave like cpython as long as the latter doesn't change its own + # algorithm + t1 = type(x) + t2 = type(y) + op, where1 = lookup_where(x, opname) + rop, where2 = lookup_where(y, ropname) + if op is None and rop is not None: + return rop(y, x) + if rop and where1 is not where2: + if (issubclass(t2, t1) and not issubclass(where1, where2) + and not issubclass(t1, where2) + ): + return rop(y, x) + if op is None: + return "TypeError" + return op(x,y) + +def do_test(X, Y, name, impl): + x = X('x') + y = Y('y') + opname = '__%s__' % name + ropname = '__r%s__' % name + + count = [0] + fail = [] + + def check(z1, z2): + ref = refop(z1, z2, opname, ropname) + try: + v = impl(z1, z2) + except TypeError: + v = "TypeError" + if v != ref: + fail.append(count[0]) + + def override_in_hier(n=6): + if n == 0: + count[0] += 1 + check(x, y) + check(y, x) + return + + f = lambda self, other: (n, self.name, other.name) + if n%2 == 0: + name = opname + else: + name = ropname + + for C in Y.__mro__: + if name in C.__dict__: + continue + if C is not object: + setattr(C, name, f) + override_in_hier(n-1) + if C is not object: + delattr(C, name) + + override_in_hier() + #print count[0] + return fail + +class BinopCombinationsTestCase(unittest.TestCase): + + def test_binop_combinations_mul(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'mul', lambda x,y: x*y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_sub(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'sub', lambda x,y: x-y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_pow(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'pow', lambda x,y: x**y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_more_exhaustive(self): + class X(Base): + pass + + class B1(object): + pass + + class B2(object): + pass + + class X1(B1, X, B2): + pass + + class C1(object): + pass + + class C2(object): + pass + + class Y(C1, X1, C2): + pass + + fail = do_test(X, Y, 'sub', lambda x,y: x-y) + #print len(fail) + self.assert_(not fail) + def test_main(): test_support.run_unittest(TestDescrTestCase, SubclassDescrTestCase, InPlaceTestCase, DescrExceptionsTestCase, - GetAttrTestCase) + GetAttrTestCase, + BinopCombinationsTestCase) if __name__ == '__main__': test_main() Modified: branches/jy3k/Lib/test/test_doctest.py =================================================================== --- branches/jy3k/Lib/test/test_doctest.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_doctest.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -2265,18 +2265,17 @@ File "...", line 7, in test_doctest4.txt Failed example: u'...' - ... + Expected: + u'f\xf6\xf6' + Got: + u'f\xc3\xb6\xc3\xb6' ********************************************************************** ... ********************************************************************** - ... - ********************************************************************** - ... - ********************************************************************** 1 items had failures: - 4 of 4 in test_doctest4.txt - ***Test Failed*** 4 failures. - (4, 4) + 2 of 4 in test_doctest4.txt + ***Test Failed*** 2 failures. + (2, 4) >>> doctest.master = None # Reset master. >>> doctest.testfile('test_doctest4.txt', encoding='utf-8') Modified: branches/jy3k/Lib/test/test_eof_jy.py =================================================================== --- branches/jy3k/Lib/test/test_eof_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_eof_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -45,6 +45,12 @@ except ImportError, cause: self.fail(cause) + def test_trailing_paren(self): + try: + import eof_fodder7 + except SyntaxError, cause: + self.assertEquals(cause.lineno, 5) + #============================================================================== def test_main(verbose=None): Modified: branches/jy3k/Lib/test/test_import_jy.py =================================================================== --- branches/jy3k/Lib/test/test_import_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_import_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -89,13 +89,11 @@ # Again ensure we didn't recompile self.assertEquals(bytecode, read(init_compiled), 'bytecode was recompiled') + def test_corrupt_bytecode(self): f = open("empty$py.class", "w") f.close() self.assertRaises(ImportError, __import__, "empty") - f = open("empty.py", "w") - f.close() - self.assertRaises(ImportError, __import__, "empty") class OverrideBuiltinsImportTestCase(unittest.TestCase): def test_override(self): Modified: branches/jy3k/Lib/test/test_java_integration.py =================================================================== --- branches/jy3k/Lib/test/test_java_integration.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_java_integration.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -7,7 +7,7 @@ from test import test_support from java.lang import (ExceptionInInitializerError, String, Runnable, System, Runtime, Math, Byte) -from java.math import BigDecimal +from java.math import BigDecimal, BigInteger from java.io import (FileInputStream, FileNotFoundException, FileOutputStream, FileWriter, OutputStreamWriter, UnsupportedEncodingException) from java.util import ArrayList, Date, HashMap, Hashtable, StringTokenizer, Vector @@ -56,6 +56,11 @@ b = BeanImplementation() self.assertEquals("name", b.getName()) self.assertEquals("name", b.name) + # Tests for #610576 + class SubBean(BeanImplementation): + def __init__(bself): + self.assertEquals("name", bself.getName()) + SubBean() class SysIntegrationTest(unittest.TestCase): @@ -262,7 +267,7 @@ self.assertEquals(len(treePath.path), 3, "Object[] not passed correctly") self.assertEquals(TreePath(treePath.path).path, treePath.path, "Object[] not passed and returned correctly") -class BigDecimalTest(unittest.TestCase): +class BigNumberTest(unittest.TestCase): def test_coerced_bigdecimal(self): from javatests import BigDecimalTest x = BigDecimal("123.4321") @@ -271,6 +276,11 @@ self.assertEqual(type(x), type(y), "BigDecimal coerced") self.assertEqual(x, y, "coerced BigDecimal not equal to directly created version") + def test_biginteger_in_long(self): + '''Checks for #608628, that long can take a BigInteger in its constructor''' + ns = '10000000000' + self.assertEquals(ns, str(long(BigInteger(ns)))) + class JavaStringTest(unittest.TestCase): def test_string_not_iterable(self): x = String('test') @@ -338,7 +348,7 @@ ImportTest, ColorTest, TreePathTest, - BigDecimalTest, + BigNumberTest, JavaStringTest, JavaDelegationTest, SecurityManagerTest) Modified: branches/jy3k/Lib/test/test_java_visibility.py =================================================================== --- branches/jy3k/Lib/test/test_java_visibility.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_java_visibility.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -4,7 +4,7 @@ import sys from test import test_support from java.lang import Byte, Class -from java.util import HashMap, Observable, Observer +from java.util import ArrayList, Collections, HashMap, Observable, Observer from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, Matryoshka, OnlySubclassable, OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results @@ -142,6 +142,14 @@ """Bug #452947 - Class of innerclass inst <> innerclass""" self.assertEquals(id(Matryoshka.Outermost), id(Matryoshka.makeOutermost().__class__)) + def test_super_methods_merged(self): + '''Checks that all signatures on a class' methods are found, not just the first for a name + + Bug #628315''' + synchList = Collections.synchronizedList(ArrayList()) + synchList.add("a string") + self.assertEquals("a string", synchList.remove(0)) + class JavaClassTest(unittest.TestCase): def test_class_methods_visible(self): self.assertFalse(HashMap.isInterface(), Copied: branches/jy3k/Lib/test/test_set_jy.py (from rev 5927, trunk/jython/Lib/test/test_set_jy.py) =================================================================== --- branches/jy3k/Lib/test/test_set_jy.py (rev 0) +++ branches/jy3k/Lib/test/test_set_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,35 @@ +from test import test_support +import unittest + +from java.util import Random +from javatests import PySetInJavaTest + +class SetInJavaTest(unittest.TestCase): + "Tests for derived dict behaviour" + def test_using_PySet_as_Java_Set(self): + PySetInJavaTest.testPySetAsJavaSet() + + def test_accessing_items_added_in_java(self): + s = PySetInJavaTest.createPySetContainingJavaObjects() + for v in s: + self.assert_(v in s) + if isinstance(v, unicode): + self.assertEquals("value", v) + else: + v.nextInt()#Should be a java.util.Random; ensure we can call it + + def test_java_accessing_items_added_in_python(self): + # Test a type that should be coerced into a Java type, a Java instance + # that should be wrapped, and a Python instance that should pass + # through as itself with str, Random and tuple respectively. + s = set(["value", Random(), ("tuple", "of", "stuff")]) + PySetInJavaTest.accessAndRemovePySetItems(s) + self.assertEquals(0, len(s))# Check that the Java removal affected the underlying set + + + +def test_main(): + test_support.run_unittest(SetInJavaTest) + +if __name__ == '__main__': + test_main() Modified: branches/jy3k/Lib/test/test_traceback_jy.py =================================================================== --- branches/jy3k/Lib/test/test_traceback_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_traceback_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -50,8 +50,17 @@ # http://bugs.jython.org/issue437809 traceback.extract_stack() + def test_except_around_raising_call(self): + """[ #452526 ] traceback lineno is the except line""" + from test import except_in_raising_code + try: + except_in_raising_code.foo() + except NameError: + tb = sys.exc_info()[2] + self.assertEquals(6, tb.tb_next.tb_lineno) + else: + self.fail("Should've raised a NameError") - try: raise Exception('foo') except Exception: Modified: branches/jy3k/README.txt =================================================================== --- branches/jy3k/README.txt 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/README.txt 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,7 +1,7 @@ -Welcome to Jython 2.5b0 +Welcome to Jython 2.5b1 ======================= -This is the first beta of the 2.5 version of Jython. It +This is the second beta of the 2.5 version of Jython. It contains most of the new features for the 2.5 release. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. Deleted: branches/jy3k/bugtests/classes/test395j1.java =================================================================== --- branches/jy3k/bugtests/classes/test395j1.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test395j1.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,4 +0,0 @@ -public class test395j1 { - protected test395j1() { - } -} Deleted: branches/jy3k/bugtests/classes/test395j2.java =================================================================== --- branches/jy3k/bugtests/classes/test395j2.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test395j2.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,5 +0,0 @@ -public class test395j2 extends test395j1 { - private test395j2() { - super(); - } -} Deleted: branches/jy3k/bugtests/classes/test396j.java =================================================================== --- branches/jy3k/bugtests/classes/test396j.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test396j.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,8 +0,0 @@ -public abstract class test396j { - public test396j() { - abstractMethod(); - } - - public abstract void abstractMethod(); - -} Deleted: branches/jy3k/bugtests/test320.py =================================================================== --- branches/jy3k/bugtests/test320.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test320.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,28 +0,0 @@ -""" -[ #452526 ] traceback lineno is the except line -""" - -import support -import sys, traceback - -def test(): - print noname - -def foo(): - try: - - - test() - - - except ValueError: - print "shouldn't happen." - -try: - foo() -except: - tb = sys.exc_info()[2] - #print tb.tb_lineno - #traceback.print_tb(tb) - assert tb.tb_next.tb_lineno == 15 - Deleted: branches/jy3k/bugtests/test366.py =================================================================== --- branches/jy3k/bugtests/test366.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test366.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,17 +0,0 @@ -""" -[ 610576 ] Impl of abstract method not found -""" - -import support - -support.compileJava("test366i.java"); -support.compileJava("test366j.java"); - -import test366i, test366j - -class MyCls(test366j, test366i): - def __init__(self): - self.foo(); - -MyCls() - Deleted: branches/jy3k/bugtests/test373.py =================================================================== --- branches/jy3k/bugtests/test373.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test373.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,14 +0,0 @@ -""" -Test for bug [608628] long(java.math.BigInteger) does not work. -""" - -import support - -# local name bugtests/test381.py -ns = '10000000000' -import java -ns2 = str(long(java.math.BigInteger(ns))) -assert ns == ns2, ns2 - - - Deleted: branches/jy3k/bugtests/test391.py =================================================================== --- branches/jy3k/bugtests/test391.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test391.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,14 +0,0 @@ -''' -Checks that all methods on a class are found, not just the first interface that has a method of the same name. - -Reported in bug 628315. -''' -import support -import java - -synchList = java.util.Collections.synchronizedList(java.util.ArrayList()) -synchList.add("a string") - -if not synchList.remove(0) == 'a string': - raise support.TestError, "'a string' should've been returned by the call to remove. The object version of remove was probably called instead of the int version" - Deleted: branches/jy3k/bugtests/test395.py =================================================================== --- branches/jy3k/bugtests/test395.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test395.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,20 +0,0 @@ -""" -Classes with greater a protected constructor can be subclassed and instantiated -Tests bug #649582 -""" - -import support - -support.compileJava("classes/test395j1.java") -support.compileJava("classes/test395j2.java") - -import test395j2 - -class Subclass(test395j2): - def __init__(self): - test395j2.__init__(self) - -try: - Subclass() -except AttributeError: - raise support.TestWarning('Unable to access protected superclass constructor') Deleted: branches/jy3k/bugtests/test396.py =================================================================== --- branches/jy3k/bugtests/test396.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test396.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,19 +0,0 @@ -''' -Checks for bug 663592. Used to be that if an abstract Java class called an -abstract method implemented by a Python subclass in its constructor, an -AttributeError would be thrown. -''' -import support - -support.compileJava("classes/test396j.java") - -import test396j - -class Subclass(test396j): - def __init__(self): - test396j.__init__(self) - - def abstractMethod(self): - pass - -x = Subclass() Modified: branches/jy3k/build.xml =================================================================== --- branches/jy3k/build.xml 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/build.xml 2009-01-14 03:58:51 UTC (rev 5928) @@ -362,7 +362,9 @@ <exec executable="svnversion" failifexecutionfails="false" outputproperty="build.svn.revision"/> </target> - <target name="brand-version" depends="version-init, svnversion"> + <!-- skip-brand can be set in ant.properties or as a system property to keep from updating the + version.properties file and making the jar on every developer build. --> + <target name="brand-version" depends="version-init, svnversion" unless="skip-brand"> <condition property="build.svn.revision" value=""> <not> <isset property="build.svn.revision"/> @@ -520,7 +522,7 @@ <rule pattern="org.jruby.ext.posix.**" result="org.python.posix.@1"/> <zipfileset src="extlibs/constantine-0.4.jar"/> <rule pattern="com.kenai.constantine.**" result="org.python.constantine.@1"/> - <zipfileset src="extlibs/xercesImpl.jar"/> + <zipfileset src="extlibs/xercesImpl-2.9.1.jar"/> <rule pattern="org.apache.**" result="org.python.apache.@1"/> <manifest> <attribute name="Main-Class" value="org.python.util.jython" /> @@ -720,6 +722,15 @@ <fileset dir="${dist.dir}"> <exclude name="${jython.dev.jar}"/> <exclude name="callbacker_test.jar"/> + <exclude name="extlibs/svnant-jars/**" /> + <exclude name="extlibs/antlr*.jar" /> + <exclude name="extlibs/asm*.jar" /> + <exclude name="extlibs/constantine*.jar" /> + <exclude name="extlibs/jarjar*.jar" /> + <exclude name="extlibs/junit*.jar" /> + <exclude name="extlibs/servlet-api*.jar" /> + <exclude name="extlibs/stringtemplate*.jar" /> + <exclude name="extlibs/xerces*.jar" /> </fileset> <manifest> <attribute name="Main-Class" value="org.python.util.install.Installation" /> Copied: branches/jy3k/extlibs/xercesImpl-2.9.1.jar (from rev 5927, trunk/jython/extlibs/xercesImpl-2.9.1.jar) =================================================================== (Binary files differ) Deleted: branches/jy3k/extlibs/xercesImpl.jar =================================================================== (Binary files differ) Modified: branches/jy3k/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/jy3k/src/org/python/antlr/PythonTokenSource.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/antlr/PythonTokenSource.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -146,6 +146,7 @@ } private void generateNewline(Token t) { + //System.out.println("generating newline from token: " + t); CommonToken newline = new CommonToken(PythonLexer.NEWLINE, "\n"); newline.setLine(t.getLine()); newline.setCharPositionInLine(t.getCharPositionInLine()); @@ -153,9 +154,12 @@ } private void handleEOF(CommonToken eof, CommonToken prev) { + //System.out.println("processing eof with token: " + prev); if (prev != null) { eof.setStartIndex(prev.getStopIndex()); eof.setStopIndex(prev.getStopIndex()); + eof.setLine(prev.getLine()); + eof.setCharPositionInLine(prev.getCharPositionInLine()); } } Modified: branches/jy3k/src/org/python/compiler/ProxyMaker.java =================================================================== --- branches/jy3k/src/org/python/compiler/ProxyMaker.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/compiler/ProxyMaker.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -703,9 +703,7 @@ addMethods(superclass, seenmethods); for (Class<?> iface : interfaces) { if (iface.isAssignableFrom(superclass)) { - Py.writeWarning("compiler", - "discarding redundant interface: "+ - iface.getName()); + Py.writeWarning("compiler", "discarding redundant interface: " + iface.getName()); continue; } classfile.addInterface(mapClass(iface)); Modified: branches/jy3k/src/org/python/core/BaseSet.java =================================================================== --- branches/jy3k/src/org/python/core/BaseSet.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/BaseSet.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,41 +1,35 @@ package org.python.core; +import java.lang.reflect.Array; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.Set; public abstract class BaseSet extends PyObject implements Set { /** The underlying Set. */ - protected Set _set; + protected Set<PyObject> _set; /** * Create a new Python set instance from the specified Set object. - * - * @param set An Set object. */ - protected BaseSet(Set set) { + protected BaseSet(Set<PyObject> set) { _set = set; } - protected BaseSet(PyType type, Set set) { + protected BaseSet(PyType type, Set<PyObject> set) { super(type); _set = set; } - protected void _update(PyObject data) throws PyIgnoreMethodTag { + protected void _update(PyObject data) { _update(_set, data); } /** * Update the underlying set with the contents of the iterable. - * - * @param data An iterable instance. - * @throws PyIgnoreMethodTag Ignore. */ - protected static Set _update(Set set, PyObject data) throws PyIgnoreMethodTag { + protected static Set<PyObject> _update(Set<PyObject> set, PyObject data) { if (data == null) { return set; } @@ -53,7 +47,7 @@ /** * The union of <code>this</code> with <code>other</code>. <p/> <br/> (I.e. all elements * that are in either set) - * + * * @param other * A <code>BaseSet</code> instance. * @return The union of the two sets as a new set. @@ -115,9 +109,9 @@ final PyObject baseset_difference(PyObject other) { BaseSet bs = (other instanceof BaseSet) ? (BaseSet)other : new PySet(other); - Set set = bs._set; + Set<PyObject> set = bs._set; BaseSet o = BaseSet.makeNewSet(getType()); - for (Object p : _set) { + for (PyObject p : _set) { if (!set.contains(p)) { o._set.add(p); } @@ -153,12 +147,12 @@ final PyObject baseset_symmetric_difference(PyObject other) { BaseSet bs = (other instanceof BaseSet) ? (BaseSet)other : new PySet(other); BaseSet o = BaseSet.makeNewSet(getType()); - for (Object p : _set) { + for (PyObject p : _set) { if (!bs._set.contains(p)) { o._set.add(p); } } - for (Object p : bs._set) { + for (PyObject p : bs._set) { if (!_set.contains(p)) { o._set.add(p); } @@ -206,7 +200,22 @@ } final PyObject baseset___iter__() { - return new PySetIterator(_set); + return new PyIterator() { + private int size = _set.size(); + + private Iterator<PyObject> iterator = _set.iterator(); + + @Override + public PyObject __iternext__() { + if (_set.size() != size) { + throw Py.RuntimeError("set changed size during iteration"); + } + if (iterator.hasNext()) { + return iterator.next(); + } + return null; + } + }; } public boolean __contains__(PyObject other) { @@ -257,7 +266,7 @@ } final PyObject baseset___le__(PyObject other) { - BaseSet bs = _binary_sanity_check(other); + _binary_sanity_check(other); return baseset_issubset(other); } @@ -266,7 +275,7 @@ } final PyObject baseset___ge__(PyObject other) { - BaseSet bs = _binary_sanity_check(other); + _binary_sanity_check(other); return baseset_issuperset(other); } @@ -299,7 +308,7 @@ public PyObject __reduce__() { return baseset___reduce__(); } - + final PyObject baseset___reduce__(){ PyObject args = new PyTuple(new PyList((PyObject)this)); PyObject dict = __findattr__("__dict__"); @@ -309,19 +318,6 @@ return new PyTuple(getType(), args, dict); } - /** - * Return this instance as a Java object. Only coerces to Collection and subinterfaces. - * - * @param c The Class to coerce to. - * @return the underlying HashSet (not a copy) - */ - public Object __tojava__(Class c) { - if (Collection.class.isAssignableFrom(c)) { - return Collections.unmodifiableSet(_set); - } - return super.__tojava__(c); - } - final PyObject baseset_union(PyObject other) { BaseSet result = BaseSet.makeNewSet(getType(), this); result._update(other); @@ -388,8 +384,8 @@ return name + "(...)"; } StringBuilder buf = new StringBuilder(name).append("(["); - for (Iterator i = _set.iterator(); i.hasNext();) { - buf.append(((PyObject)i.next()).__repr__().toString()); + for (Iterator<PyObject> i = _set.iterator(); i.hasNext();) { + buf.append((i.next()).__repr__().toString()); if (i.hasNext()) { buf.append(", "); } @@ -408,20 +404,20 @@ } /** - * Return a PyFrozenSet whose contents are shared with value when - * value is a BaseSet and pye is a TypeError. + * Return a PyFrozenSet whose contents are shared with value when value is a BaseSet and pye is + * a TypeError. * - * WARNING: The PyFrozenSet returned is only intended to be used - * temporarily (and internally); since its contents are shared - * with value, it could be mutated! - * - * This is better than special-casing behavior based on - * isinstance, because a Python subclass can override, say, - * __hash__ and all of a sudden you can't assume that a - * non-PyFrozenSet is unhashable anymore. + * WARNING: The PyFrozenSet returned is only intended to be used temporarily (and internally); + * since its contents are shared with value, it could be mutated! * - * @param pye The exception thrown from a hashable operation. - * @param value The object which was unhashable. + * This is better than special-casing behavior based on isinstance, because a Python subclass + * can override, say, __hash__ and all of a sudden you can't assume that a non-PyFrozenSet is + * unhashable anymore. + * + * @param pye + * The exception thrown from a hashable operation. + * @param value + * The object which was unhashable. * @return A PyFrozenSet if appropriate, otherwise the pye is rethrown */ protected final PyFrozenSet asFrozen(PyException pye, PyObject value) { @@ -442,7 +438,7 @@ protected static BaseSet makeNewSet(PyType type) { return makeNewSet(type, null); } - + /** * Create a new <et of type from iterable. * @@ -477,43 +473,89 @@ return _set.isEmpty(); } - public Object[] toArray() { - return _set.toArray(); - } - public boolean add(Object o) { - return _set.add(o); + return _set.add(Py.java2py(o)); } public boolean contains(Object o) { - return _set.contains(o); + return _set.contains(Py.java2py(o)); } public boolean remove(Object o) { - return _set.remove(o); + return _set.remove(Py.java2py(o)); } public boolean addAll(Collection c) { - return _set.addAll(c); + boolean added = false; + for (Object object : c) { + added |= add(object); + } + return added; } public boolean containsAll(Collection c) { - return _set.containsAll(c); + for (Object object : c) { + if (!_set.contains(Py.java2py(object))) { + return false; + } + } + return true; } public boolean removeAll(Collection c) { - return _set.removeAll(c); + boolean removed = false; + for (Object object : c) { + removed |= _set.remove(Py.java2py(object)); + } + return removed; } public boolean retainAll(Collection c) { - return _set.retainAll(c); + boolean modified = false; + Iterator e = iterator(); + while (e.hasNext()) { + if (!c.contains(e.next())) { + e.remove(); + modified = true; + } + } + return modified; } public Iterator iterator() { - return _set.iterator(); + return new Iterator() { + Iterator<PyObject> real = _set.iterator(); + + public boolean hasNext() { + return real.hasNext(); + } + + public Object next() { + return Py.tojava(real.next(), Object.class); + } + + public void remove() { + real.remove(); + } + }; } + public Object[] toArray() { + return toArray(new Object[size()]); + } + public Object[] toArray(Object a[]) { - return _set.toArray(a); + int size = size(); + if (a.length < size) { + a = (Object[])Array.newInstance(a.getClass().getComponentType(), size); + } + Iterator<PyObject> it = iterator(); + for (int i = 0; i < size; i++) { + a[i] = it.next(); + } + if (a.length > size) { + a[size] = null; + } + return a; } } Modified: branches/jy3k/src/org/python/core/CompilerFlags.java =================================================================== --- branches/jy3k/src/org/python/core/CompilerFlags.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/CompilerFlags.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -3,54 +3,44 @@ public class CompilerFlags { + private int co_flags; + public boolean nested_scopes = true; public boolean division; public boolean generator_allowed = true; - public boolean with_statement = false; - public boolean absolute_import = false; + public boolean with_statement; + public boolean absolute_import; - public boolean only_ast = false; - public boolean dont_imply_dedent = false; - public boolean source_is_utf8 = false; + public boolean only_ast; + public boolean dont_imply_dedent; + public boolean source_is_utf8; public String encoding; - - public CompilerFlags(){} + public CompilerFlags() {} + public CompilerFlags(int co_flags) { - if ((co_flags & org.python.core.PyTableCode.CO_NESTED) != 0) { - this.nested_scopes = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_FUTUREDIVISION) != 0) { - this.division = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_GENERATOR_ALLOWED) != 0) { - this.generator_allowed = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_FUTURE_ABSOLUTE_IMPORT) != 0) { - this.absolute_import = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_WITH_STATEMENT) != 0) { - this.with_statement = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_ONLY_AST) != 0) { - this.only_ast = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_DONT_IMPLY_DEDENT) != 0) { - this.dont_imply_dedent = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_SOURCE_IS_UTF8) != 0) { - this.source_is_utf8 = true; - } - + this.co_flags = co_flags; + nested_scopes = isEnabled(PyTableCode.CO_NESTED); + division = isEnabled(PyTableCode.CO_FUTUREDIVISION); + generator_allowed = isEnabled(PyTableCode.CO_GENERATOR_ALLOWED); + absolute_import = isEnabled(PyTableCode.CO_FUTURE_ABSOLUTE_IMPORT); + with_statement = isEnabled(PyTableCode.CO_WITH_STATEMENT); + only_ast = isEnabled(PyTableCode.PyCF_ONLY_AST); + dont_imply_dedent = isEnabled(PyTableCode.PyCF_DONT_IMPLY_DEDENT); + source_is_utf8 = isEnabled(PyTableCode.PyCF_SOURCE_IS_UTF8); } + private boolean isEnabled(int codeConstant) { + return (co_flags & codeConstant) != 0; + } + public String toString() { return String.format("CompilerFlags[division=%s nested_scopes=%s generators=%s " + "with_statement=%s absolute_import=%s only_ast=%s " + "dont_imply_dedent=%s source_is_utf8=%s]", division, nested_scopes, - generator_allowed, with_statement, absolute_import, only_ast, + generator_allowed, with_statement, absolute_import, only_ast, dont_imply_dedent, source_is_utf8); } - + } Modified: branches/jy3k/src/org/python/core/ParserFacade.java =================================================================== --- branches/jy3k/src/org/python/core/ParserFacade.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/ParserFacade.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -4,10 +4,13 @@ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.Reader; +import java.io.Writer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; @@ -138,7 +141,7 @@ try { // prepBufReader takes care of encoding detection and universal // newlines: - bufReader = prepBufReader(stream, cflags, filename); + bufReader = prepBufReader(stream, cflags, filename, false); return parse(bufReader, kind, filename, cflags ); } catch (Throwable t) { throw fixParseError(bufReader, t, filename); @@ -223,7 +226,9 @@ private static ExpectedEncodingBufferedReader prepBufReader(InputStream input, CompilerFlags cflags, - String filename) throws IOException { + String filename, + boolean fromString) + throws IOException { input = new BufferedInputStream(input); boolean bom = adjustForBOM(input); String encoding = readEncoding(input); @@ -250,29 +255,45 @@ UniversalIOWrapper textIO = new UniversalIOWrapper(bufferedIO); input = new TextIOInputStream(textIO); - CharsetDecoder dec; + Charset cs; try { // Use ascii for the raw bytes when no encoding was specified - dec = Charset.forName(encoding == null ? "ascii" : encoding).newDecoder(); + if (encoding == null) { + if (fromString) { + cs = Charset.forName("ISO-8859-1"); + } else { + cs = Charset.forName("ascii"); + } + } else { + cs = Charset.forName(encoding); + } } catch (UnsupportedCharsetException exc) { throw new PySyntaxError("Unknown encoding: " + encoding, 1, 0, "", filename); } + CharsetDecoder dec = cs.newDecoder(); dec.onMalformedInput(CodingErrorAction.REPORT); dec.onUnmappableCharacter(CodingErrorAction.REPORT); return new ExpectedEncodingBufferedReader(new InputStreamReader(input, dec), encoding); } - private static ExpectedEncodingBufferedReader prepBufReader(String string, CompilerFlags cflags, - String filename) throws IOException { + private static ExpectedEncodingBufferedReader prepBufReader(String string, + CompilerFlags cflags, + String filename) throws IOException { + byte[] stringBytes; if (cflags.source_is_utf8) { // Passed unicode, re-encode the String to raw bytes // NOTE: This could be more efficient if we duplicate // prepBufReader/adjustForBOM/readEncoding to work on Readers, instead of // encoding - string = new PyUnicode(string).encode("utf-8"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Writer w = new OutputStreamWriter(out, "utf-8"); + w.write(string); + w.close(); + stringBytes = out.toByteArray(); + } else { + stringBytes = StringUtil.toBytes(string); } - InputStream input = new ByteArrayInputStream(StringUtil.toBytes(string)); - return prepBufReader(input, cflags, filename); + return prepBufReader(new ByteArrayInputStream(stringBytes), cflags, filename, true); } /** Modified: branches/jy3k/src/org/python/core/PyDictionary.java =================================================================== --- branches/jy3k/src/org/python/core/PyDictionary.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/PyDictionary.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -12,7 +12,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.python.core.PyMapSet.PySetIter; import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; @@ -27,7 +26,7 @@ public class PyDictionary extends PyObject implements ConcurrentMap { public static final PyType TYPE = PyType.fromClass(PyDictionary.class); - + protected final ConcurrentMap<PyObject, PyObject> table; /** @@ -39,7 +38,6 @@ /** * For derived types - * @param subtype */ public PyDictionary(PyType subtype) { super(subtype); @@ -47,31 +45,27 @@ } /** - * Create an new dictionary which is based on the hashtable. - * @param t the hashtable used. The supplied hashtable is used as - * is and must only contain PyObject key:value pairs. + * Create a new dictionary which is based on given map. */ public PyDictionary(Map<PyObject, PyObject> t) { table = new ConcurrentHashMap<PyObject, PyObject>(t); } - /** - * Create an new dictionary which is based on the map and for derived types. - * @param subtype - * @param t the hashtable used. The supplied hashtable is used as - * is and must only contain PyObject key:value pairs. + /** + * Create a new derived dictionary which is based on the given map. */ public PyDictionary(PyType subtype, Map<PyObject, PyObject> t) { super(subtype); table = new ConcurrentHashMap<PyObject, PyObject>(t); } - + /** * Create a new dictionary with the element as content. - * @param elements The initial elements that is inserted in the - * dictionary. Even numbered elements are keys, - * odd numbered elements are values. + * + * @param elements + * The initial elements that is inserted in the dictionary. Even numbered elements + * are keys, odd numbered elements are values. */ public PyDictionary(PyObject elements[]) { this(); @@ -85,7 +79,7 @@ protected final void dict___init__(PyObject[] args, String[] keywords) { updateCommon(args, keywords, "dict"); } - + public static PyObject fromkeys(PyObject keys) { return fromkeys(keys, Py.None); } @@ -210,10 +204,10 @@ } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___eq___doc) - final PyObject dict___eq__(PyObject ob_other) { + final PyObject dict___eq__(PyObject ob_other) { PyType thisType = getType(); PyType otherType = ob_other.getType(); - if (otherType != thisType && !thisType.isSubType(otherType) + if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType)) { return null; } @@ -291,7 +285,7 @@ final int dict___cmp__(PyObject ob_other) { PyType thisType = getType(); PyType otherType = ob_other.getType(); - if (otherType != thisType && !thisType.isSubType(otherType) + if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType)) { return -2; } @@ -435,7 +429,7 @@ } for (int i = 0; i < keywords.length; i++) { dict___setitem__(Py.newString(keywords[i]), args[nargs + i]); - } + } } /** @@ -539,7 +533,7 @@ } } - + /** * Return a value based on key * from the dictionary. @@ -578,18 +572,17 @@ @ExposedMethod(doc = BuiltinDocs.dict_popitem_doc) final PyObject dict_popitem() { - Iterator it = table.entrySet().iterator(); + Iterator<Entry<PyObject, PyObject>> it = table.entrySet().iterator(); if (!it.hasNext()) throw Py.KeyError("popitem(): dictionary is empty"); - Entry entry = (Entry)it.next(); - PyTuple tuple = new PyTuple( - (PyObject)entry.getKey(), (PyObject)entry.getValue()); + Entry<PyObject, PyObject> entry = it.next(); + PyTuple tuple = new PyTuple(entry.getKey(), entry.getValue()); it.remove(); return tuple; } /** - * Return a copy of the dictionarys list of (key, value) tuple + * Return a copy of the dictionary's list of (key, value) tuple * pairs. */ public PyList items() { @@ -606,7 +599,7 @@ } /** - * Return a copy of the dictionarys list of keys. + * Return a copy of the dictionary's list of keys. */ public PyList keys() { return dict_keys(); @@ -623,7 +616,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over (key, value) pairs. */ public PyObject iteritems() { return dict_iteritems(); @@ -635,7 +628,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over the dictionary's keys. */ public PyObject iterkeys() { return dict_iterkeys(); @@ -647,7 +640,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over the dictionary's values. */ public PyObject itervalues() { return dict_itervalues(); @@ -703,7 +696,7 @@ iterator = items.iterator(); size = items.size(); } - + public PyObject __iternext__() { if (table.size() != size) { throw Py.RuntimeError("dictionary changed size during iteration"); @@ -716,13 +709,12 @@ } } - /* The following methods implement the java.util.Map interface - which allows PyDictionary to be passed to java methods that take - java.util.Map as a parameter. Basically, the Map methods are a - wrapper around the PyDictionary's Map container stored in member - variable 'table'. These methods simply convert java Object to - PyObjects on insertion, and PyObject to Objects on retrieval. */ - + /* + * The following methods implement the java.util.Map interface which allows PyDictionary to be + * passed to java methods that take java.util.Map as a parameter. Basically, the Map methods are + * a wrapper around the PyDictionary's Map container stored in member variable 'table'. These + * methods convert java Object to PyObjects on insertion, and PyObject to Objects on retrieval. + */ /** @see java.util.Map#entrySet() */ public Set entrySet() { return new PyMapEntrySet(table.entrySet()); @@ -733,17 +725,15 @@ return new PyMapKeyValSet(table.keySet()); } - /** Return a copy of the dictionarys list of values. */ + /** @see java.util.Map#values() */ public Collection values() { return new PyMapKeyValSet(table.values()); } - /** @see java.util.Map#putAll(Map map) */ public void putAll(Map map) { - Iterator i = map.entrySet().iterator(); - while (i.hasNext()) { - Entry entry = (Entry)i.next(); + for (Object o : map.entrySet()) { + Entry entry = (Entry)o; table.put(Py.java2py(entry.getKey()), Py.java2py(entry.getValue())); } } @@ -772,19 +762,19 @@ public boolean containsKey(Object key) { return table.containsKey(Py.java2py(key)); } - - /** @see java.util.Map#isEmpty(Object key) */ + + /** @see java.util.Map#isEmpty() */ public boolean isEmpty() { return table.isEmpty(); } - - /** @see java.util.Map#size(Object key) */ + + /** @see java.util.Map#size() */ public int size() { return table.size(); } /** Convert return values to java objects */ - static final Object tojava(Object val) { + final static Object tojava(Object val) { return val == null ? null : ((PyObject)val).__tojava__(Object.class); } @@ -805,19 +795,20 @@ } } + /** Basic implementation of Entry that just holds onto a key and value and returns them. */ -class SimpleEntry<K, V> implements Entry<K, V> { - - public SimpleEntry(K key, V value){ +class SimpleEntry implements Entry { + + public SimpleEntry(Object key, Object value){ this.key = key; this.value = value; } - - public K getKey() { + + public Object getKey() { return key; } - public V getValue() { + public Object getValue() { return value; } @@ -841,31 +832,29 @@ return key + "=" + value; } - public V setValue(V val) { + public Object setValue(Object val) { throw new UnsupportedOperationException("Not supported by this view"); } - protected K key; + protected Object key; - protected V value; + protected Object value; } /** - * Wrapper for a Entry object returned from the java.util.Set - * object which in turn is returned by the entrySet method of - * java.util.Map. This is needed to correctly convert from PyObjects - * to java Objects. Note that we take care in the equals and hashCode - * methods to make sure these methods are consistent with Entry - * objects that contain java Objects for a value so that on the java - * side they can be reliable compared. + * Wrapper for a Entry object returned from the java.util.Set object which in turn is returned by + * the entrySet method of java.util.Map. This is needed to correctly convert from PyObjects to java + * Objects. Note that we take care in the equals and hashCode methods to make sure these methods are + * consistent with Entry objects that contain java Objects for a value so that on the java side they + * can be reliable compared. */ class PyToJavaMapEntry extends SimpleEntry { - /** Create a copy of the Entry with Py.None coverted to null */ + /** Create a copy of the Entry with Py.None converted to null */ PyToJavaMapEntry(Entry entry) { super(entry.getKey(), entry.getValue()); } - + public boolean equals(Object o) { if (o == null || !(o instanceof Entry)) return false; Entry me = new JavaToPyMapEntry((Entry)o); @@ -877,7 +866,7 @@ public Object getKey() { return PyDictionary.tojava(key); } - + public Object getValue() { return PyDictionary.tojava(value); } @@ -892,24 +881,22 @@ } /** - * MapEntry Object for java MapEntry objects passed to the java.util.Set - * interface which is returned by the entrySet method of PyDictionary. - * Essentially like PyTojavaMapEntry, but going t... [truncated message content] |