From: <pj...@us...> - 2008-07-21 01:43:27
|
Revision: 4977 http://jython.svn.sourceforge.net/jython/?rev=4977&view=rev Author: pjenvey Date: 2008-07-21 01:43:14 +0000 (Mon, 21 Jul 2008) Log Message: ----------- add PyFastSequenceIter (for list and tuple) which calls final seq___finditem__. whereas PySequenceIter calls __finditem__ which may be overridden by subclasses Modified Paths: -------------- trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PySequenceIter.java trunk/jython/src/org/python/core/PyTuple.java Added Paths: ----------- trunk/jython/src/org/python/core/PyFastSequenceIter.java Added: trunk/jython/src/org/python/core/PyFastSequenceIter.java =================================================================== --- trunk/jython/src/org/python/core/PyFastSequenceIter.java (rev 0) +++ trunk/jython/src/org/python/core/PyFastSequenceIter.java 2008-07-21 01:43:14 UTC (rev 4977) @@ -0,0 +1,27 @@ +/* Copyright (c) Jython Developers */ +package org.python.core; + +/** + * Sequence iterator specialized for accessing the underlying sequence directly. + */ +public class PyFastSequenceIter extends PyIterator { + + private PySequence seq; + + private int index = 0; + + public PyFastSequenceIter(PySequence seq) { + this.seq = seq; + } + + public PyObject __iternext__() { + try { + return seq.seq___finditem__(index++); + } catch (PyException exc) { + if (Py.matchException(exc, Py.StopIteration)) { + return null; + } + throw exc; + } + } +} Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2008-07-21 01:38:17 UTC (rev 4976) +++ trunk/jython/src/org/python/core/PyList.java 2008-07-21 01:43:14 UTC (rev 4977) @@ -391,9 +391,13 @@ return seq___nonzero__(); } + public PyObject __iter__() { + return list___iter__(); + } + @ExposedMethod public PyObject list___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") Modified: trunk/jython/src/org/python/core/PySequenceIter.java =================================================================== --- trunk/jython/src/org/python/core/PySequenceIter.java 2008-07-21 01:38:17 UTC (rev 4976) +++ trunk/jython/src/org/python/core/PySequenceIter.java 2008-07-21 01:43:14 UTC (rev 4977) @@ -1,23 +1,27 @@ +/* Copyright (c) Jython Developers */ package org.python.core; +/** + * General sequence iterator. + */ public class PySequenceIter extends PyIterator { + private PyObject seq; - private int idx; + private int index = 0; + public PySequenceIter(PyObject seq) { this.seq = seq; - this.idx = 0; } public PyObject __iternext__() { try { - return seq.__finditem__(idx++); + return seq.__finditem__(index++); } catch (PyException exc) { - if (Py.matchException(exc, Py.StopIteration)) + if (Py.matchException(exc, Py.StopIteration)) { return null; + } throw exc; } } - } - Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2008-07-21 01:38:17 UTC (rev 4976) +++ trunk/jython/src/org/python/core/PyTuple.java 2008-07-21 01:43:14 UTC (rev 4977) @@ -191,9 +191,13 @@ return repeat(count); } + public PyObject __iter__() { + return tuple___iter__(); + } + @ExposedMethod public PyObject tuple___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-19 23:34:37
|
Revision: 5211 http://jython.svn.sourceforge.net/jython/?rev=5211&view=rev Author: pjenvey Date: 2008-08-19 23:34:29 +0000 (Tue, 19 Aug 2008) Log Message: ----------- small cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/PyBaseException.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/PyBaseException.java =================================================================== --- trunk/jython/src/org/python/core/PyBaseException.java 2008-08-19 21:43:06 UTC (rev 5210) +++ trunk/jython/src/org/python/core/PyBaseException.java 2008-08-19 23:34:29 UTC (rev 5211) @@ -166,23 +166,20 @@ } } + @Override public String toString() { - return __repr__().toString(); + return BaseException_toString(); } - - public PyString __repr__() { - return BaseException___repr__(); - } - @ExposedMethod - final PyString BaseException___repr__() { + @ExposedMethod(names = ("__repr__")) + final String BaseException_toString() { PyObject reprSuffix = args.__repr__(); String name = getType().fastGetName(); int lastDot = name.lastIndexOf('.'); if (lastDot != -1) { name = name.substring(lastDot + 1); } - return Py.newString(name + reprSuffix.toString()); + return name + reprSuffix.toString(); } @ExposedSet(name = "args") Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2008-08-19 21:43:06 UTC (rev 5210) +++ trunk/jython/src/org/python/core/PyObject.java 2008-08-19 23:34:29 UTC (rev 5211) @@ -281,7 +281,7 @@ * * @param arg0 the first argument to the function. * @param arg1 the second argument to the function. -n **/ + **/ public PyObject __call__(PyObject arg0, PyObject arg1) { return __call__(new PyObject[] { arg0, arg1 }, Py.NoKeywords); } Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-08-19 21:43:06 UTC (rev 5210) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-08-19 23:34:29 UTC (rev 5211) @@ -1410,7 +1410,7 @@ @Override public String toString() { - return "<built-in function min>"; + return "<built-in function max>"; } private static PyObject max(PyObject o, PyObject key) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-22 15:31:59
|
Revision: 5233 http://jython.svn.sourceforge.net/jython/?rev=5233&view=rev Author: fwierzbicki Date: 2008-08-22 15:31:56 +0000 (Fri, 22 Aug 2008) Log Message: ----------- Switch "type"->"kind" for the compile parameter value which specifies the kind of parse/compile "exec", "eval", or "single". CPython's source uses "kind" and other parts of Jython use this term as well. Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-08-21 23:59:46 UTC (rev 5232) +++ trunk/jython/src/org/python/core/Py.java 2008-08-22 15:31:56 UTC (rev 5233) @@ -1641,8 +1641,8 @@ } public static PyObject compile(InputStream istream, String filename, - String type) { - return compile_flags(istream, filename, type, null); + String kind) { + return compile_flags(istream, filename, kind, null); } // with compiler-flags @@ -1664,15 +1664,15 @@ } public static PyObject compile_flags(InputStream istream, String filename, - String type,CompilerFlags cflags) + String kind,CompilerFlags cflags) { - modType node = ParserFacade.parse(istream, type, filename, cflags); + modType node = ParserFacade.parse(istream, kind, filename, cflags); if (cflags != null && cflags.only_ast) { return Py.java2py(node); } boolean printResults = false; - if (type.equals("single")) { + if (kind.equals("single")) { printResults = true; } return Py.compile_flags(node, getName(), filename, true, printResults, cflags); @@ -1680,7 +1680,7 @@ public static PyObject compile_flags(String data, String filename, - String type, + String kind, CompilerFlags cflags) { if (data.contains("\0")) { @@ -1695,7 +1695,7 @@ } return Py.compile_flags(new ByteArrayInputStream(bytes), filename, - type, + kind, cflags); } Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-08-21 23:59:46 UTC (rev 5232) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-08-22 15:31:56 UTC (rev 5233) @@ -455,15 +455,15 @@ throw Py.TypeError("number coercion failed"); } - public static PyObject compile(String data, String filename, String type) { - return Py.compile_flags(data, filename, type, Py.getCompilerFlags()); + public static PyObject compile(String data, String filename, String kind) { + return Py.compile_flags(data, filename, kind, Py.getCompilerFlags()); } - public static PyObject compile(String data, String filename, String type, int flags, boolean dont_inherit) { + public static PyObject compile(String data, String filename, String kind, int flags, boolean dont_inherit) { if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { throw Py.ValueError("compile(): unrecognised flags"); } - return Py.compile_flags(data, filename, type, Py.getCompilerFlags(flags, dont_inherit)); + return Py.compile_flags(data, filename, kind, Py.getCompilerFlags(flags, dont_inherit)); } public static void delattr(PyObject o, String n) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-09-01 06:32:49
|
Revision: 5279 http://jython.svn.sourceforge.net/jython/?rev=5279&view=rev Author: zyasoft Date: 2008-09-01 06:32:39 +0000 (Mon, 01 Sep 2008) Log Message: ----------- The compile builtin function now can take an AST node, as produced by a previous usage of compile with the compiler flag _ast.PyCF_ONLY_AST. Generally this would be after some modification of the AST itself. Another 2.6 feature. Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-09-01 04:21:27 UTC (rev 5278) +++ trunk/jython/src/org/python/core/Py.java 2008-09-01 06:32:39 UTC (rev 5279) @@ -1677,7 +1677,16 @@ } return Py.compile_flags(node, getName(), filename, true, printResults, cflags); } - + + public static PyObject compile_flags(modType node, String filename, + String kind, CompilerFlags cflags) { + boolean printResults = false; + if (kind.equals("single")) { + printResults = true; + } + return Py.compile_flags(node, getName(), filename, true, printResults, cflags); + } + public static PyObject compile_flags(String data, String filename, String kind, @@ -1941,7 +1950,6 @@ return (PyObject[]) objs.getArray(); } } - /** @deprecated */ class FixedFileWrapper extends StdoutWrapper { Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-09-01 04:21:27 UTC (rev 5278) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-09-01 06:32:39 UTC (rev 5279) @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.Map; +import org.python.antlr.ast.modType; import org.python.core.util.RelativeFile; import org.python.expose.ExposedGet; @@ -459,6 +460,10 @@ return Py.compile_flags(data, filename, kind, Py.getCompilerFlags()); } + public static PyObject compile(modType node, String filename, String kind) { + return Py.compile_flags(node, filename, kind, Py.getCompilerFlags()); + } + public static PyObject compile(String data, String filename, String kind, int flags, boolean dont_inherit) { if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { throw Py.ValueError("compile(): unrecognised flags"); @@ -466,6 +471,13 @@ return Py.compile_flags(data, filename, kind, Py.getCompilerFlags(flags, dont_inherit)); } + public static PyObject compile(modType node, String filename, String kind, int flags, boolean dont_inherit) { + if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { + throw Py.ValueError("compile(): unrecognised flags"); + } + return Py.compile_flags(node, filename, kind, Py.getCompilerFlags(flags, dont_inherit)); + } + public static void delattr(PyObject o, String n) { o.__delattr__(n); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-09-24 19:44:31
|
Revision: 5343 http://jython.svn.sourceforge.net/jython/?rev=5343&view=rev Author: pjenvey Date: 2008-09-24 19:44:25 +0000 (Wed, 24 Sep 2008) Log Message: ----------- it's more correct for StdoutWrapper to write the object being printed to the file instead of __str__'ing it refs #1130 Modified Paths: -------------- trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/StdoutWrapper.java Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2008-09-21 00:20:23 UTC (rev 5342) +++ trunk/jython/src/org/python/core/PyFile.java 2008-09-24 19:44:25 UTC (rev 5343) @@ -411,6 +411,10 @@ } } + public void write(PyObject o) { + file_write(o); + } + final synchronized void file_write(String s) { checkClosed(); softspace = false; Modified: trunk/jython/src/org/python/core/StdoutWrapper.java =================================================================== --- trunk/jython/src/org/python/core/StdoutWrapper.java 2008-09-21 00:20:23 UTC (rev 5342) +++ trunk/jython/src/org/python/core/StdoutWrapper.java 2008-09-24 19:44:25 UTC (rev 5343) @@ -105,11 +105,10 @@ file.write(" "); file.softspace = false; } - PyString string = o.__str__(); - String s = string.toString(); - int len = s.length(); - file.write(s); + file.write(o); if (o instanceof PyString) { + String s = o.toString(); + int len = s.length(); if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) || s.charAt(len - 1) == ' ') { file.softspace = space; @@ -128,11 +127,10 @@ obj.invoke("write", Py.Space); obj.__setattr__("softspace", Py.Zero); } - PyString string = o.__str__(); - String s = o.toString(); - int len = s.length(); - obj.invoke("write", string); + obj.invoke("write", o); if (o instanceof PyString) { + String s = o.toString(); + int len = s.length(); if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) || s.charAt(len - 1) == ' ') { obj.__setattr__("softspace", space ? Py.One : Py.Zero); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-09-24 19:56:32
|
Revision: 5344 http://jython.svn.sourceforge.net/jython/?rev=5344&view=rev Author: pjenvey Date: 2008-09-24 19:56:28 +0000 (Wed, 24 Sep 2008) Log Message: ----------- revert r5343, it's broken Modified Paths: -------------- trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/StdoutWrapper.java Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2008-09-24 19:44:25 UTC (rev 5343) +++ trunk/jython/src/org/python/core/PyFile.java 2008-09-24 19:56:28 UTC (rev 5344) @@ -411,10 +411,6 @@ } } - public void write(PyObject o) { - file_write(o); - } - final synchronized void file_write(String s) { checkClosed(); softspace = false; Modified: trunk/jython/src/org/python/core/StdoutWrapper.java =================================================================== --- trunk/jython/src/org/python/core/StdoutWrapper.java 2008-09-24 19:44:25 UTC (rev 5343) +++ trunk/jython/src/org/python/core/StdoutWrapper.java 2008-09-24 19:56:28 UTC (rev 5344) @@ -105,10 +105,11 @@ file.write(" "); file.softspace = false; } - file.write(o); + PyString string = o.__str__(); + String s = string.toString(); + int len = s.length(); + file.write(s); if (o instanceof PyString) { - String s = o.toString(); - int len = s.length(); if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) || s.charAt(len - 1) == ' ') { file.softspace = space; @@ -127,10 +128,11 @@ obj.invoke("write", Py.Space); obj.__setattr__("softspace", Py.Zero); } - obj.invoke("write", o); + PyString string = o.__str__(); + String s = o.toString(); + int len = s.length(); + obj.invoke("write", string); if (o instanceof PyString) { - String s = o.toString(); - int len = s.length(); if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) || s.charAt(len - 1) == ' ') { obj.__setattr__("softspace", space ? Py.One : Py.Zero); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-10-19 03:04:50
|
Revision: 5464 http://jython.svn.sourceforge.net/jython/?rev=5464&view=rev Author: cgroves Date: 2008-10-19 03:04:44 +0000 (Sun, 19 Oct 2008) Log Message: ----------- Some formatting and cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/PyBeanEvent.java trunk/jython/src/org/python/core/PyBeanEventProperty.java trunk/jython/src/org/python/core/PyClass.java trunk/jython/src/org/python/core/PyJavaClass.java Modified: trunk/jython/src/org/python/core/PyBeanEvent.java =================================================================== --- trunk/jython/src/org/python/core/PyBeanEvent.java 2008-10-19 00:01:20 UTC (rev 5463) +++ trunk/jython/src/org/python/core/PyBeanEvent.java 2008-10-19 03:04:44 UTC (rev 5464) @@ -1,6 +1,6 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.lang.reflect.*; +import java.lang.reflect.Method; public class PyBeanEvent extends PyObject { public Method addMethod; @@ -34,7 +34,7 @@ } public String toString() { - return "<beanEvent "+__name__+" for event "+ - eventClass.toString()+" "+Py.idstr(this)+">"; + return "<beanEvent " + __name__ + " for event " + eventClass.toString() + " " + + Py.idstr(this) + ">"; } } Modified: trunk/jython/src/org/python/core/PyBeanEventProperty.java =================================================================== --- trunk/jython/src/org/python/core/PyBeanEventProperty.java 2008-10-19 00:01:20 UTC (rev 5463) +++ trunk/jython/src/org/python/core/PyBeanEventProperty.java 2008-10-19 03:04:44 UTC (rev 5464) @@ -50,17 +50,13 @@ return func; } - private synchronized static Class getAdapterClass(Class c) { - // System.err.println("getting adapter for: "+c+", "+c.getName()); - InternalTables tbl=PyJavaClass.getInternalTables(); - Object o = tbl.getAdapterClass(c); + private synchronized static Class<?> getAdapterClass(Class<?> c) { + InternalTables tbl = PyJavaClass.getInternalTables(); + Class<?> o = tbl.getAdapterClass(c); if (o != null) - return (Class)o; - Class pc = Py.findClass("org.python.proxies."+c.getName()+"$Adapter"); + return o; + Class<?> pc = Py.findClass("org.python.proxies." + c.getName() + "$Adapter"); if (pc == null) { - //System.err.println("adapter not found for: "+ - // "org.python.proxies."+ - // c.getName()+"$Adapter"); pc = MakeProxies.makeAdapter(c); } tbl.putAdapterClass(c, pc); @@ -68,13 +64,11 @@ } private synchronized Object getAdapter(Object self) { - InternalTables tbl=PyJavaClass.getInternalTables(); + InternalTables tbl = PyJavaClass.getInternalTables(); String eventClassName = eventClass.getName(); - Object adapter = tbl.getAdapter(self, eventClassName); if (adapter != null) return adapter; - try { adapter = adapterClass.newInstance(); addMethod.invoke(self, new Object[] {adapter}); @@ -96,8 +90,7 @@ try { adapterField = adapterClass.getField(__name__); } catch (NoSuchFieldException exc) { - throw Py.AttributeError("Internal bean event error: "+ - __name__); + throw Py.AttributeError("Internal bean event error: " + __name__); } } } Modified: trunk/jython/src/org/python/core/PyClass.java =================================================================== --- trunk/jython/src/org/python/core/PyClass.java 2008-10-19 00:01:20 UTC (rev 5463) +++ trunk/jython/src/org/python/core/PyClass.java 2008-10-19 03:04:44 UTC (rev 5464) @@ -2,6 +2,7 @@ package org.python.core; import java.io.Serializable; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -32,7 +33,7 @@ // Holds the classes for which this is a proxy // Only used when subclassing from a Java class - protected Class proxyClass; + protected Class<?> proxyClass; // xxx map 'super__*' names -> array of methods protected java.util.HashMap super__methods; @@ -43,12 +44,12 @@ /** * Create a python class. - * + * * @param name name of the class. * @param bases A list of base classes. * @param dict The class dict. Normally this dict is returned by the class * code object. - * + * * @see org.python.core.Py#makeClass(String, PyObject[], PyCode, PyObject) */ public PyClass(String name, PyTuple bases, PyObject dict) { @@ -60,12 +61,12 @@ * already have generated a proxyclass. If we do not have a pre-generated * proxyclass, the class initialization method will create such a proxyclass * if bases contain a java class. - * + * * @param name name of the class. * @param bases A list of base classes. * @param dict The class dict. Normally this dict is returned by the class * code object. - * + * * @see org.python.core.Py#makeClass(String, PyObject[], PyCode, PyObject, * Class) */ @@ -144,8 +145,7 @@ super__methods = new java.util.HashMap(); - for (int i = 0; i < proxy_methods.length; i++) { - java.lang.reflect.Method meth = proxy_methods[i]; + for (Method meth : proxy_methods) { String meth_name = meth.getName(); if (meth_name.startsWith("super__")) { java.util.ArrayList samename = (java.util.ArrayList) super__methods @@ -193,7 +193,7 @@ } } - public Object __tojava__(Class c) { + public Object __tojava__(Class<?> c) { if ((c == Object.class || c == Class.class || c == Serializable.class) && proxyClass != null) { return proxyClass; @@ -208,9 +208,8 @@ if (result == null && __bases__ != null) { int n = __bases__.__len__(); for (int i = 0; i < n; i++) { - resolvedClass = (PyClass) (__bases__.__getitem__(i)); - PyObject[] res = resolvedClass.lookupGivingClass(name, - stop_at_java); + resolvedClass = (PyClass)(__bases__.__getitem__(i)); + PyObject[] res = resolvedClass.lookupGivingClass(name, stop_at_java); if (res[0] != null) { return res; } @@ -284,8 +283,8 @@ public void __rawdir__(PyDictionary accum) { addKeys(accum, "__dict__"); PyObject[] bases = __bases__.getArray(); - for (int i = 0; i < bases.length; i++) { - bases[i].__rawdir__(accum); + for (PyObject base : bases) { + base.__rawdir__(accum); } } Modified: trunk/jython/src/org/python/core/PyJavaClass.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaClass.java 2008-10-19 00:01:20 UTC (rev 5463) +++ trunk/jython/src/org/python/core/PyJavaClass.java 2008-10-19 03:04:44 UTC (rev 5464) @@ -1,28 +1,37 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import org.python.core.packagecache.PackageManager; - +import java.beans.Introspector; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.EventListener; +import org.python.core.packagecache.PackageManager; + /** * A wrapper around a java class. */ +public class PyJavaClass extends PyClass { -public class PyJavaClass extends PyClass -{ + private static InternalTables tbl; + public PyReflectedConstructor __init__; public PackageManager __mgr__; - private static InternalTables tbl; + public String __module__; + private boolean initialized = false; + + // Prevent recursive calls to initialize() + private boolean initializing = false; + public synchronized final static InternalTables getInternalTables() { - if(tbl == null) - tbl = InternalTables.createInternalTables(); + if (tbl == null) { + tbl = InternalTables.createInternalTables(); + } return tbl; } @@ -30,9 +39,9 @@ return proxyClass == null; } - public static final PyJavaClass lookup(String name,PackageManager mgr) { + public static final PyJavaClass lookup(String name, PackageManager mgr) { if (tbl.queryCanonical(name)) { - Class c = mgr.findClass(null,name,"forced java class"); + Class<?> c = mgr.findClass(null, name, "forced java class"); check_lazy_allowed(c); // xxx return lookup(c); } @@ -41,12 +50,12 @@ return ret; } - public synchronized static final PyJavaClass lookup(Class c) { + public synchronized static final PyJavaClass lookup(Class<?> c) { if (tbl == null) { - tbl = InternalTables.createInternalTables(); + tbl = new InternalTables(); PyJavaClass jc = new PyJavaClass(); jc.init(PyJavaClass.class); - tbl.putCanonical(PyJavaClass.class,jc); + tbl.putCanonical(PyJavaClass.class, jc); } PyJavaClass ret = tbl.getCanonical(c); if (ret != null) @@ -54,28 +63,22 @@ PyJavaClass lazy = tbl.getLazyCanonical(c.getName()); if (lazy != null) { initLazy(lazy); - if (lazy.proxyClass == c) return lazy; + if (lazy.proxyClass == c) { + return lazy; + } } - - Class parent = c.getDeclaringClass(); - if (parent == null) - ret = new PyJavaClass(c); - else - ret = new PyJavaInnerClass(c, lookup(parent)); - tbl.putCanonical(c,ret); - + Class<?> parent = c.getDeclaringClass(); + ret = parent == null ? new PyJavaClass(c) : new PyJavaInnerClass(c, lookup(parent)); + tbl.putCanonical(c, ret); return ret; } - private PyJavaClass() { - super(); - } + private PyJavaClass() {} - protected PyJavaClass(Class c) { + protected PyJavaClass(Class<?> c) { init(c); } - public String __module__; /** * Set the full name of this class. */ @@ -85,7 +88,7 @@ __name__ = name; __module__ = ""; } else { - __name__ = name.substring(name.lastIndexOf(".")+1, name.length()); + __name__ = name.substring(name.lastIndexOf(".") + 1, name.length()); __module__ = name.substring(0, name.lastIndexOf(".")); } } @@ -104,7 +107,7 @@ protected void findModule(PyObject dict) {} - protected Class getProxyClass() { + protected Class<?> getProxyClass() { initialize(); return proxyClass; } @@ -112,138 +115,118 @@ // for the moment trying to lazily load a PyObject subclass // is not allowed, (because of the PyJavaClass vs PyType class mismatch) // pending PyJavaClass becoming likely a subclass of PyType - private static final void check_lazy_allowed(Class c) { + private static final void check_lazy_allowed(Class<?> c) { if (PyObject.class.isAssignableFrom(c)) { // xxx throw Py.TypeError("cannot lazy load PyObject subclass"); } } private static final void initLazy(PyJavaClass jc) { - Class c = jc.__mgr__.findClass(null,jc.fullName(),"lazy java class"); + Class<?> c = jc.__mgr__.findClass(null, jc.fullName(), "lazy java class"); check_lazy_allowed(c); // xxx jc.init(c); - tbl.putCanonical(jc.proxyClass,jc); + tbl.putCanonical(jc.proxyClass, jc); jc.__mgr__ = null; } - private boolean initialized=false; - - // Prevent recursive calls to initialize() - private boolean initializing=false; - private synchronized void initialize() { - if (initialized || initializing) + if (initialized || initializing) { return; + } initializing = true; - synchronized(PyJavaClass.class) { + synchronized (PyJavaClass.class) { if (proxyClass == null) { initLazy(this); } } init__bases__(proxyClass); init__dict__(); - - if (ClassDictInit.class.isAssignableFrom(proxyClass) - && proxyClass != ClassDictInit.class) { + if (ClassDictInit.class.isAssignableFrom(proxyClass) && proxyClass != ClassDictInit.class) { try { - Method m = proxyClass.getMethod("classDictInit", - new Class[] { PyObject.class }); - m.invoke(null, new Object[] { __dict__ }); - } - catch (Exception exc) { - // System.err.println("Got exception: " + exc + " " + - // proxyClass); + Method m = proxyClass.getMethod("classDictInit", PyObject.class); + m.invoke(null, __dict__); + } catch (Exception exc) { throw Py.JavaError(exc); } } - if (InitModule.class.isAssignableFrom(proxyClass)) { try { InitModule m = (InitModule)proxyClass.newInstance(); m.initModule(__dict__); - } - catch (Exception exc) { -// System.err.println("Got exception: " + exc); + } catch (Exception exc) { throw Py.JavaError(exc); } } - initialized = true; initializing = false; } private synchronized void init__dict__() { - if (__dict__ != null) + if (__dict__ != null) { return; + } PyStringMap d = new PyStringMap(); -// d.__setitem__("__module__", Py.None); __dict__ = d; try { Method[] methods = getAccessibleMethods(proxyClass); setBeanInfoCustom(proxyClass, methods); setFields(proxyClass); setMethods(proxyClass, methods); - } catch(SecurityException se) {} + } catch (SecurityException se) {} } - private synchronized void init__bases__(Class c) { - if (__bases__ != null) return; - + private synchronized void init__bases__(Class<?> c) { + if (__bases__ != null) + return; Class interfaces[] = getAccessibleInterfaces(c); int nInterfaces = interfaces.length; int nBases = 0; int i; - for (i=0; i<nInterfaces; i++) { + for (i = 0; i < nInterfaces; i++) { Class inter = interfaces[i]; - if (inter == InitModule.class || inter == PyProxy.class || - inter == ClassDictInit.class) + if (inter == InitModule.class || inter == PyProxy.class || inter == ClassDictInit.class) continue; nBases++; } - Class superclass = c.getSuperclass(); - int index=0; + int index = 0; PyObject[] bases; PyJavaClass tmp; if (superclass == null || superclass == PyObject.class) { bases = new PyObject[nBases]; } else { - bases = new PyObject[nBases+1]; + bases = new PyObject[nBases + 1]; tmp = PyJavaClass.lookup(superclass); bases[0] = tmp; tmp.initialize(); index++; } - - for (i=0; i<nInterfaces; i++) { + for (i = 0; i < nInterfaces; i++) { Class inter = interfaces[i]; - if (inter == InitModule.class || inter == PyProxy.class || - inter == ClassDictInit.class) + if (inter == InitModule.class || inter == PyProxy.class || inter == ClassDictInit.class) continue; tmp = PyJavaClass.lookup(inter); tmp.initialize(); bases[index++] = tmp; } - __bases__ = new PyTuple(bases); } - - private void init(Class c) { + private void init(Class c) { proxyClass = c; setName(c.getName()); } /** - * Return the list of all accessible interfaces for a class. This will - * only the public interfaces. Since we can't set accessibility on - * interfaces, the Options.respectJavaAccessibility is not honored. + * Return the list of all accessible interfaces for a class. This will only the public + * interfaces. Since we can't set accessibility on interfaces, the + * Options.respectJavaAccessibility is not honored. */ private static Class[] getAccessibleInterfaces(Class c) { // can't modify accessibility of interfaces in Java2 // thus get only public interfaces Class[] in = c.getInterfaces(); - java.util.Vector v=new java.util.Vector(); + java.util.Vector v = new java.util.Vector(); for (int i = 0; i < in.length; i++) { if (!Modifier.isPublic(in[i].getModifiers())) continue; @@ -256,11 +239,10 @@ return ret; } - /** - * Return the list of all accessible fields for a class. This will - * only be the public fields unless Options.respectJavaAccessibility is - * false, in which case all fields are returned. - */ + /** + * Return the list of all accessible fields for a class. This will only be the public fields + * unless Options.respectJavaAccessibility is false, in which case all fields are returned. + */ private static Field[] getAccessibleFields(Class c) { if (Options.respectJavaAccessibility) // returns just the public fields @@ -270,17 +252,17 @@ // get all declared fields for this class, mutate their // accessibility and pop it into the array for later Field[] declared = c.getDeclaredFields(); - for (int i=0; i < declared.length; i++) { - // TBD: this is a permanent change. Should we provide a + for (Field element : declared) { + // TBD: this is a permanent change. Should we provide a // way to restore the original accessibility flag? - declared[i].setAccessible(true); - fields.add(declared[i]); + element.setAccessible(true); + fields.add(element); } - // walk down superclass chain. no need to deal specially with + // walk down superclass chain. no need to deal specially with // interfaces... c = c.getSuperclass(); } -// return (Field[])fields.toArray(new Field[fields.size()]); +// return (Field[])fields.toArray(new Field[fields.size()]); Field[] ret = new Field[fields.size()]; ret = (Field[])fields.toArray(ret); return ret; @@ -288,14 +270,11 @@ private void setFields(Class c) { Field[] fields = getAccessibleFields(c); - for (int i=0; i<fields.length; i++) { - Field field = fields[i]; + for (Field field : fields) { if (field.getDeclaringClass() != c) continue; - String name = getName(field.getName()); boolean isstatic = Modifier.isStatic(field.getModifiers()); - if (isstatic) { if (name.startsWith("__doc__") && name.length() > 7) continue; @@ -311,58 +290,51 @@ } } - /* Produce a good Python name for a Java method. If the Java method - ends in '$', strip it (this handles reserved Java keywords) Don't - make any changes to keywords since this is now handled by parser - */ - + /* + * Produce a good Python name for a Java method. If the Java method ends in '$', strip it (this + * handles reserved Java keywords) Don't make any changes to keywords since this is now handled + * by parser + */ private String getName(String name) { - if (name.endsWith("$")) name = name.substring(0, name.length()-1); + if (name.endsWith("$")) + name = name.substring(0, name.length() - 1); return name.intern(); } private void addMethod(Method meth) { String name = getName(meth.getName()); - if (name == "_getPyInstance" || name == "_setPyInstance" || - name == "_getPySystemState" || name == "_setPySystemState") - { + if (name == "_getPyInstance" || name == "_setPyInstance" || name == "_getPySystemState" + || name == "_setPySystemState") { return; } - // Special case to handle a few troublesome methods in java.awt.*. // These methods are all deprecated and interfere too badly with - // bean properties to be tolerated. This is totally a hack, but a + // bean properties to be tolerated. This is totally a hack, but a // lot of code that uses java.awt will break without it. String classname = proxyClass.getName(); - if (classname.startsWith("java.awt.") && - classname.indexOf('.', 9) == -1) - { - if (name == "layout" || name == "insets" || - name == "size" || name == "minimumSize" || - name == "preferredSize" || name == "maximumSize" || - name == "bounds" || name == "enable") - { + if (classname.startsWith("java.awt.") && classname.indexOf('.', 9) == -1) { + if (name == "layout" || name == "insets" || name == "size" || name == "minimumSize" + || name == "preferredSize" || name == "maximumSize" || name == "bounds" + || name == "enable") { return; } } - // See if any of my superclasses are using 'name' for something - // else. Or if I'm already using it myself + // else. Or if I'm already using it myself PyObject o = lookup(name, false); // If it's being used as a function, then things get more // interesting... PyReflectedFunction func; if (o != null && o instanceof PyReflectedFunction) { func = (PyReflectedFunction)o; - PyObject o1 = __dict__.__finditem__(name); - - /* If this function already exists, add this method to the - signature. If this alters the signature of the function in - some significant way, then return a duplicate and stick it in - the __dict__ */ - if(o1 != o) { - if(func.handles(meth)) { + /* + * If this function already exists, add this method to the signature. If this alters the + * signature of the function in some significant way, then return a duplicate and stick + * it in the __dict__ + */ + if (o1 != o) { + if (func.handles(meth)) { __dict__.__setitem__(name, func); return; } @@ -374,39 +346,36 @@ try { Field docField = proxyClass.getField("__doc__" + name); int mods = docField.getModifiers(); - if (docField.getType() == PyString.class && - Modifier.isPublic(mods) && - Modifier.isStatic(mods)); - func.__doc__ = (PyString) docField.get(null); - } catch (NoSuchFieldException ex) { - } catch (SecurityException ex) { - } catch (IllegalAccessException ex) {} + if (docField.getType() == PyString.class && Modifier.isPublic(mods) + && Modifier.isStatic(mods)) + ; + func.__doc__ = (PyString)docField.get(null); + } catch (NoSuchFieldException ex) {} catch (SecurityException ex) {} catch (IllegalAccessException ex) {} } __dict__.__setitem__(name, func); } - - /** - * Return the list of all accessible methods for a class. This will - * only the public methods unless Options.respectJavaAccessibility is - * false, in which case all methods are returned. - */ + + /** + * Return the list of all accessible methods for a class. This will only the public methods + * unless Options.respectJavaAccessibility is false, in which case all methods are returned. + */ private static Method[] getAccessibleMethods(Class c) { if (Options.respectJavaAccessibility) // returns just the public methods return c.getMethods(); Method[] declared = c.getDeclaredMethods(); - for (int i=0; i < declared.length; i++) { - // TBD: this is a permanent change. Should we provide a way to + for (Method element : declared) { + // TBD: this is a permanent change. Should we provide a way to // restore the original accessibility flag? - declared[i].setAccessible(true); + element.setAccessible(true); } return declared; } private boolean ignoreMethod(Method method) { Class[] exceptions = method.getExceptionTypes(); - for (int j = 0; j < exceptions.length; j++) { - if (exceptions[j] == PyIgnoreMethodTag.class) { + for (Class exception : exceptions) { + if (exception == PyIgnoreMethodTag.class) { return true; } } @@ -415,28 +384,25 @@ /* Add all methods declared by this class */ private void setMethods(Class c, Method[] methods) { - for (int i=0; i<methods.length; i++) { - Method method = methods[i]; + for (Method method : methods) { Class dc = method.getDeclaringClass(); if (dc != c) continue; - if(isPackagedProtected(dc) && Modifier.isPublic(method.getModifiers())) { + if (isPackagedProtected(dc) && Modifier.isPublic(method.getModifiers())) { /* - * Set public methods on package protected classes accessible so - * that reflected calls to the method in subclasses of the - * package protected class will succeed. Yes, it's convoluted. - * + * Set public methods on package protected classes accessible so that reflected + * calls to the method in subclasses of the package protected class will succeed. + * Yes, it's convoluted. + * * This fails when done through reflection due to Sun JVM bug - * 4071957(http://tinyurl.com/le9vo). 4533479 actually describes - * the problem we're seeing, but there are a bevy of reflection - * bugs that stem from 4071957. Supposedly it'll be fixed in - * Dolphin but it's been promised in every version since Tiger - * so don't hold your breath. - * + * 4071957(http://tinyurl.com/le9vo). 4533479 actually describes the problem we're + * seeing, but there are a bevy of reflection bugs that stem from 4071957. + * Supposedly it'll be fixed in Dolphin but it's been promised in every version + * since Tiger so don't hold your breath. */ try { method.setAccessible(true); - } catch(SecurityException se) {} + } catch (SecurityException se) {} } if (ignoreMethod(method)) continue; @@ -450,37 +416,26 @@ } /* Adds a bean property to this class */ - void addProperty(String name, Class propClass, - Method getMethod, Method setMethod) - { + void addProperty(String name, Class propClass, Method getMethod, Method setMethod) { // This will skip indexed property types if (propClass == null) return; - boolean set = true; name = getName(name); - - PyBeanProperty prop = new PyBeanProperty(name, propClass, getMethod, - setMethod); - + PyBeanProperty prop = new PyBeanProperty(name, propClass, getMethod, setMethod); // Check to see if this name is already being used... PyObject o = lookup(name, false); - if (o != null) { if (!(o instanceof PyReflectedField)) return; - if (o instanceof PyBeanProperty) { PyBeanProperty oldProp = (PyBeanProperty)o; if (prop.myType == oldProp.myType) { // If this adds nothing over old property, do nothing if ((prop.getMethod == null || oldProp.getMethod != null) - && - (prop.setMethod == null || oldProp.setMethod != null)) - { + && (prop.setMethod == null || oldProp.setMethod != null)) { set = false; } - // Add old get/set methods to current prop // Handles issues with private classes if (oldProp.getMethod != null) { @@ -491,112 +446,63 @@ } } } - // This is now handled in setFields which gets called after - // setBeanProperties -// else { -// // Keep static fields around... -// PyReflectedField field = (PyReflectedField)o; -// if (Modifier.isStatic(field.field.getModifiers())) { -// prop.field = field.field; -// } else { -// // If the field is not static (and thus subsumable) -// // don't overwrite -// return; -// } -// } } if (set) __dict__.__setitem__(name, prop); } /* Adds a bean event to this class */ - void addEvent(String name, Class eventClass, Method addMethod, - Method[] meths) - { - for (int i=0; i<meths.length; i++) { - PyBeanEventProperty prop; - prop = new PyBeanEventProperty(name, eventClass, addMethod, - meths[i]); + void addEvent(String name, Class eventClass, Method addMethod) { + for (Method meth : eventClass.getMethods()) { + PyBeanEventProperty prop = new PyBeanEventProperty(name, eventClass, addMethod, meth); __dict__.__setitem__(prop.__name__, prop); } PyBeanEvent event = new PyBeanEvent(name, eventClass, addMethod); __dict__.__setitem__(event.__name__, event); } - - /* A reimplementation of java.beans.Introspector.decapitalize. - This is needed due to bugs in Netscape Navigator - */ - private static String decapitalize(String s) { - //return java.beans.Introspector.decapitalize(s); - if (s.length() == 0) - return s; - char c0 = s.charAt(0); - if (Character.isUpperCase(c0)) { - if (s.length() > 1 && Character.isUpperCase(s.charAt(1))) - return s; - char[] cs = s.toCharArray(); - cs[0] = Character.toLowerCase(c0); - return new String(cs); - } else { - return s; - } - } - // This method is a workaround for Netscape's stupid security bug! private void setBeanInfoCustom(Class c, Method[] meths) { - //try { - int i; - int n = meths.length; - for (i=0; i<n; i++) { - Method method = meths[i]; - - if (ignoreMethod(method)) + for (Method method : meths) { + if (ignoreMethod(method) || method.getDeclaringClass() != c + || Modifier.isStatic(method.getModifiers())) { continue; - if (method.getDeclaringClass() != c || - Modifier.isStatic(method.getModifiers())) - { - continue; } - String name = method.getName(); Method getter = null; Method setter = null; Class[] args = method.getParameterTypes(); Class ret = method.getReturnType(); - Class myType=null; - - String pname=""; - + Class myType = null; + String pname = ""; if (name.startsWith("get")) { if (args.length != 0) continue; getter = method; - pname = decapitalize(name.substring(3)); + pname = Introspector.decapitalize(name.substring(3)); myType = ret; } else { if (name.startsWith("is")) { if (args.length != 0 || ret != Boolean.TYPE) continue; getter = method; - pname = decapitalize(name.substring(2)); + pname = Introspector.decapitalize(name.substring(2)); myType = ret; } else { if (name.startsWith("set")) { if (args.length != 1) continue; setter = method; - pname = decapitalize(name.substring(3)); + pname = Introspector.decapitalize(name.substring(3)); myType = args[0]; } else { continue; } } } - PyObject o = __dict__.__finditem__(new PyString(pname)); PyBeanProperty prop; - if (o == null || !(o instanceof PyBeanProperty) ) { + if (o == null || !(o instanceof PyBeanProperty)) { addProperty(pname, myType, getter, setter); } else { prop = (PyBeanProperty)o; @@ -605,91 +511,60 @@ addProperty(pname, myType, getter, setter); } } else { - if (getter != null) prop.getMethod = getter; - if (setter != null && (ret == Void.TYPE || prop.setMethod==null)) + if (getter != null) + prop.getMethod = getter; + if (setter != null && (ret == Void.TYPE || prop.setMethod == null)) prop.setMethod = setter; - } } } - - for (i=0; i<n; i++) { - Method method = meths[i]; - - if (method.getDeclaringClass() != c || - Modifier.isStatic(method.getModifiers())) - { + for (Method method : meths) { + if (method.getDeclaringClass() != c || Modifier.isStatic(method.getModifiers())) { continue; } - String mname = method.getName(); - - if (!(mname.startsWith("add") || mname.startsWith("set")) || - !mname.endsWith("Listener")) - { + if (!(mname.startsWith("add") || mname.startsWith("set")) + || !mname.endsWith("Listener")) { continue; } - Class[] args = method.getParameterTypes(); Class ret = method.getReturnType(); if (args.length != 1 || ret != Void.TYPE) continue; - Class eClass = args[0]; - - // This test and call of getClassLoader() function as a - // workaround for a bug in MRJ2.2.4. The bug occured when - // this program was compiled with jythonc: - // import java - // print dir(java.awt.Button) - // The 'actionPerformed' attributed would be missing. - if (eClass.getInterfaces().length > 0) - eClass.getInterfaces()[0].getClassLoader(); - // And of Mac workaround - - if (!(java.util.EventListener.class.isAssignableFrom(eClass))) + if (!EventListener.class.isAssignableFrom(eClass)) continue; - String name = eClass.getName(); int idot = name.lastIndexOf('.'); if (idot != -1) - name = decapitalize(name.substring(idot+1)); - - addEvent(name, eClass, method, eClass.getMethods()); + name = Introspector.decapitalize(name.substring(idot + 1)); + addEvent(name, eClass, method); } - /*} catch (Throwable t) { - System.err.println("Custom Bean error: "+t); - t.printStackTrace(); - }*/ } - /** - * Return the list of all accessible constructors for a class. This - * will only the public constructors unless - * Options.respectJavaAccessibility is false, in which case all - * constructors are returned. Note that constructors are not - * inherited like methods or fields. - */ + /** + * Return the list of all accessible constructors for a class. This will only the public + * constructors unless Options.respectJavaAccessibility is false, in which case all constructors + * are returned. Note that constructors are not inherited like methods or fields. + */ private static Constructor[] getAccessibleConstructors(Class c) { if (Options.respectJavaAccessibility) // returns just the public fields return c.getConstructors(); // return all constructors - - Constructor[] declared = c.getDeclaredConstructors(); - for (int i=0; i < declared.length; i++) { - // TBD: this is a permanent change. Should we provide a way to + for (Constructor element : declared) { + // TBD: this is a permanent change. Should we provide a way to // restore the original accessibility flag? - declared[i].setAccessible(true); + element.setAccessible(true); } return declared; } private boolean ignoreConstructor(Constructor method) { Class[] exceptions = method.getExceptionTypes(); - for (int j = 0; j < exceptions.length; j++) { - if (exceptions[j] == PyIgnoreMethodTag.class) { + for (Class exception : exceptions) { + if (exception == PyIgnoreMethodTag.class) { return true; } } @@ -701,14 +576,14 @@ __init__ = null; } else { Constructor[] constructors = getAccessibleConstructors(c); - for (int i = 0; i < constructors.length; i++) { - if (ignoreConstructor(constructors[i])) { + for (Constructor constructor : constructors) { + if (ignoreConstructor(constructor)) { continue; } if (__init__ == null) { - __init__ = new PyReflectedConstructor(constructors[i]); + __init__ = new PyReflectedConstructor(constructor); } else { - __init__.addConstructor(constructors[i]); + __init__.addConstructor(constructor); } } if (__init__ != null) { @@ -716,7 +591,9 @@ } } } - private boolean constructorsInitialized=false; + + private boolean constructorsInitialized = false; + synchronized void initConstructors() { if (constructorsInitialized) return; @@ -726,20 +603,20 @@ } /* - If the new name conflicts with a Python keyword, add an '_' - */ - private static java.util.Hashtable keywords=null; + * If the new name conflicts with a Python keyword, add an '_' + */ + private static java.util.Hashtable keywords = null; + private static String unmangleKeyword(String name) { if (keywords == null) { keywords = new java.util.Hashtable(); - String[] words = new String[] - {"or", "and", "not", "is", "in", "lambda", "if", "else", "elif", - "while", "for", "try", "except", "def", "class", "finally", - "print", - "pass", "break", "continue", "return", "import", "from", "del", - "raise", "global", "exec", "assert"}; - for (int i=0; i<words.length; i++) { - keywords.put(words[i]+"_", words[i].intern()); + String[] words = + new String[] {"or", "and", "not", "is", "in", "lambda", "if", "else", "elif", + "while", "for", "try", "except", "def", "class", "finally", "print", + "pass", "break", "continue", "return", "import", "from", "del", + "raise", "global", "exec", "assert"}; + for (String word : words) { + keywords.put(word + "_", word.intern()); } } return (String)keywords.get(name); @@ -754,15 +631,14 @@ initConstructors(); return new PyObject[] {__init__, null}; } - // For backwards compatibilty, support keyword_ as a substitute for - // keyword. An improved parser makes this no longer necessary. + // keyword. An improved parser makes this no longer necessary. if (Options.deprecatedKeywordMangling && name.endsWith("_")) { String newName = unmangleKeyword(name); if (newName != null) name = newName; } - return super.lookupGivingClass(name, stop_at_java); + return super.lookupGivingClass(name, stop_at_java); } public PyObject __dir__() { @@ -775,6 +651,7 @@ } private PyStringMap missingAttributes = null; + public PyObject __findattr_ex__(String name) { if (name == "__dict__") { if (__dict__ == null) @@ -796,27 +673,20 @@ return super.lookupGivingClass(name, false)[0]; return __init__; } - PyObject result = lookup(name, false); if (result != null) return result.__get__(null, null); // xxx messy - // A cache of missing attributes to short-circuit later tests - if (missingAttributes != null && - missingAttributes.__finditem__(name) != null) - { + if (missingAttributes != null && missingAttributes.__finditem__(name) != null) { return null; } - // These two tests can be expensive, see above for short-circuiting result = findClassAttr(name); if (result != null) return result; - result = findInnerClass(name); if (result != null) return result; - // Add this attribute to missing attributes cache if (missingAttributes == null) { missingAttributes = new PyStringMap(); @@ -826,22 +696,23 @@ } private PyJavaInstance classInstance; + private PyObject findClassAttr(String name) { if (classInstance == null) { classInstance = new PyJavaInstance(proxyClass); } PyObject result = classInstance.__findattr__(name); return result; - //if (result == null) return null; - //__dict__.__setitem__(name, result); - //return result; + // if (result == null) return null; + // __dict__.__setitem__(name, result); + // return result; } private PyObject findInnerClass(String name) { Class p = getProxyClass(); - Class innerClass = Py.relFindClass(p, p.getName()+"$"+name); - if (innerClass == null) return null; - + Class innerClass = Py.relFindClass(p, p.getName() + "$" + name); + if (innerClass == null) + return null; PyObject jinner = Py.java2py(innerClass); // xxx lookup(innerClass); __dict__.__setitem__(name, jinner); return jinner; @@ -859,9 +730,8 @@ public void __delattr__(String name) { PyObject field = lookup(name, false); if (field == null) { - throw Py.NameError("attribute not found: "+name); + throw Py.NameError("attribute not found: " + name); } - if (!field.jdontdel()) { __dict__.__delitem__(name); } @@ -870,27 +740,22 @@ public PyObject __call__(PyObject[] args, String[] keywords) { if (!constructorsInitialized) initConstructors(); - // xxx instantiation of PyObject subclass, still needed? if (PyObject.class.isAssignableFrom(proxyClass)) { if (Modifier.isAbstract(proxyClass.getModifiers())) { - throw Py.TypeError("can't instantiate abstract class ("+ - fullName()+")"); + throw Py.TypeError("can't instantiate abstract class (" + fullName() + ")"); } if (__init__ == null) { - throw Py.TypeError("no public constructors for "+ - fullName()); + throw Py.TypeError("no public constructors for " + fullName()); } - return __init__.make(args,keywords); + return __init__.make(args, keywords); } - PyInstance inst = new PyJavaInstance(this); inst.__init__(args, keywords); - return inst; } - public Object __tojava__(Class c) { + public Object __tojava__(Class<?> c) { initialize(); return super.__tojava__(c); } @@ -899,7 +764,7 @@ if (!(other instanceof PyJavaClass)) { return -2; } - int c = fullName().compareTo(((PyJavaClass) other).fullName()); + int c = fullName().compareTo(((PyJavaClass)other).fullName()); return c < 0 ? -1 : c > 0 ? 1 : 0; } @@ -907,7 +772,7 @@ return new PyString(fullName()); } - public String toString() { - return "<jclass "+fullName()+" "+Py.idstr(this)+">"; + public String toString() { + return "<jclass " + fullName() + " " + Py.idstr(this) + ">"; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-10-20 02:03:52
|
Revision: 5478 http://jython.svn.sourceforge.net/jython/?rev=5478&view=rev Author: cgroves Date: 2008-10-20 02:03:44 +0000 (Mon, 20 Oct 2008) Log Message: ----------- Cleanup, modernization Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-10-20 01:41:32 UTC (rev 5477) +++ trunk/jython/src/org/python/core/Py.java 2008-10-20 02:03:44 UTC (rev 5478) @@ -5,6 +5,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.io.ObjectStreamException; import java.io.OutputStream; @@ -19,12 +20,12 @@ import java.util.HashSet; import java.util.Set; +import org.python.antlr.ast.modType; import org.python.compiler.Module; import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; import org.python.core.util.StringUtil; import org.python.modules.errno; -import org.python.antlr.ast.modType; public final class Py { @@ -80,7 +81,7 @@ public static PyString Space; /** Set if the type object is dynamically allocated */ public static long TPFLAGS_HEAPTYPE; - + /** Builtin types that are used to setup PyObject. */ static final Set<Class> BOOTSTRAP_TYPES = new HashSet<Class>(4); static { @@ -353,7 +354,7 @@ public static void FutureWarning(String message) { warning(FutureWarning, message); } - + public static PyObject ImportWarning; public static void ImportWarning(String message) { warning(ImportWarning, message); @@ -569,17 +570,17 @@ } static PyObject newUnicode(int codepoint) { - return (PyUnicode) makeCharacter(codepoint, true); + return makeCharacter(codepoint, true); } public static PyUnicode newUnicode(String s) { return new PyUnicode(s); } - + public static PyUnicode newUnicode(String s, boolean isBasic) { return new PyUnicode(s, isBasic); } - + public static PyBoolean newBoolean(boolean t) { return t ? Py.True : Py.False; } @@ -752,7 +753,7 @@ // Pre-initialize the PyJavaClass for OutOfMemoryError so when we need // it it creating the pieces for it won't cause an additional out of // memory error. Fix for bug #1654484 - PyJavaClass.lookup(java.lang.OutOfMemoryError.class); + PyJavaClass.lookup(OutOfMemoryError.class); } public static PySystemState defaultSystemState; // This is a hack to get initializations to work in proper order @@ -889,11 +890,11 @@ } instance.__init__(pargs, Py.NoKeywords); } - + /** * Initializes a default PythonInterpreter and runs the code from * {@link PyRunnable#getMain} as __main__ - * + * * Called by the code generated in {@link Module#addMain()} */ public static void runMain(PyRunnable main, String[] args) throws Exception { @@ -1136,14 +1137,14 @@ // java.io.IOExceptions. This is a hack for 1.0.x until I can do // it right in 1.1 if (exc == Py.IOError) { - if (__builtin__.isinstance(pye.value, PyJavaClass.lookup(java.io.IOException.class))) { + if (__builtin__.isinstance(pye.value, PyJavaClass.lookup(IOException.class))) { return true; } } // FIXME too, same approach for OutOfMemoryError if (exc == Py.MemoryError) { if (__builtin__.isinstance(pye.value, - PyJavaClass.lookup(java.lang.OutOfMemoryError.class))) { + PyJavaClass.lookup(OutOfMemoryError.class))) { return true; } } @@ -1226,7 +1227,7 @@ } Py.runCode(code, locals, globals); } - + private final static ThreadStateMapping threadStateMapping = new ThreadStateMapping(); public static final ThreadState getThreadState() { @@ -1464,7 +1465,7 @@ /** * Uses the PyObjectAdapter passed to {@link PySystemState#initialize} to turn o into a PyObject. - * + * * @see ClassicPyObjectAdapter - default PyObjectAdapter type */ public static PyObject java2py(Object o) { @@ -1483,7 +1484,7 @@ /** * Set the ExtensiblePyObjectAdapter used by java2py. - * + * * @param adapter The new ExtensiblePyObjectAdapter */ protected static void setAdapter(ExtensiblePyObjectAdapter adapter) { @@ -1530,7 +1531,7 @@ /** * Create a new Python class. - * + * * @param name the String name of the class * @param bases an array of PyObject base classes * @param dict the class's namespace, containing the class body @@ -1677,8 +1678,8 @@ } return Py.compile_flags(node, getName(), filename, true, printResults, cflags); } - - public static PyObject compile_flags(modType node, String filename, + + public static PyObject compile_flags(modType node, String filename, String kind, CompilerFlags cflags) { boolean printResults = false; if (kind.equals("single")) { @@ -1686,16 +1687,16 @@ } return Py.compile_flags(node, getName(), filename, true, printResults, cflags); } - + public static PyObject compile_flags(String data, String filename, String kind, CompilerFlags cflags) { - + if (data.contains("\0")) { throw Py.TypeError("compile() expected string without null bytes"); } - + byte[] bytes; if (cflags != null && cflags.dont_imply_dedent) { bytes = StringUtil.toBytes(data + "\n"); @@ -1894,7 +1895,7 @@ return abstract_issubclass(icls, cls); } } - + public static boolean isSubClass(PyObject derived,PyObject cls) { return isSubClass(derived, cls, 0); } Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2008-10-20 01:41:32 UTC (rev 5477) +++ trunk/jython/src/org/python/core/PyObject.java 2008-10-20 02:03:44 UTC (rev 5478) @@ -21,18 +21,18 @@ */ @ExposedType(name = "object") public class PyObject implements Serializable { - + public static final PyType TYPE = PyType.fromClass(PyObject.class); - + @ExposedNew @ExposedMethod final void object___init__(PyObject[] args, String[] keywords) { -// XXX: attempted fix for object(foo=1), etc -// XXX: this doesn't work for metaclasses, for some reason +// XXX: attempted fix for object(foo=1), etc +// XXX: this doesn't work for metaclasses, for some reason // if (args.length > 0) { // throw Py.TypeError("default __new__ takes no parameters"); // } - + } private PyType objtype; @@ -77,16 +77,17 @@ this.objtype = objtype; } - // A package private constructor used by PyJavaClass - // xxx will need variants for PyType of PyType and still PyJavaClass of PyJavaClass - PyObject(boolean dummy) { - objtype = (PyType) this; + /** + * Creates the PyObject for the base type. The argument only exists to make the constructor + * distinct. + */ + PyObject(boolean ignored) { + objtype = (PyType)this; } /** - * The standard constructor for a <code>PyObject</code>. It will set - * the <code>objtype</code> field to correspond to the specific - * subclass of <code>PyObject</code> being instantiated. + * The standard constructor for a <code>PyObject</code>. It will set the <code>objtype</code> + * field to correspond to the specific subclass of <code>PyObject</code> being instantiated. **/ public PyObject() { objtype = PyType.fromClass(getClass()); @@ -145,7 +146,7 @@ public PyUnicode __unicode__() { return new PyUnicode(__str__()); } - + /** * Equivalent to the standard Python __hash__ method. This method can * not be overridden. Instead, you should override the standard Java @@ -342,13 +343,13 @@ if(keys == null) throw Py.TypeError(name + "argument after ** must be a mapping"); - for (int i = 0; i < keywords.length; i++) - if (kwargs.__finditem__(keywords[i]) != null) + for (String keyword : keywords) + if (kwargs.__finditem__(keyword) != null) throw Py.TypeError( name + "got multiple values for " + "keyword argument '" - + keywords[i] + + keyword + "'"); argslen += kwargs.__len__(); } @@ -648,21 +649,21 @@ * <p> * If a PyObject subclass should support iteration based in the __finditem__() method, it must * supply an implementation of __iter__() like this: - * + * * <pre> * public PyObject __iter__() { * return new PySequenceIter(this); * } * </pre> - * + * * When iterating over a python sequence from java code, it should be done with code like this: - * + * * <pre> * for (PyObject item : seq.asIterable()) { * // Do somting with item * } * </pre> - * + * * @since 2.2 */ public PyObject __iter__() { @@ -729,13 +730,13 @@ * Very similar to the standard Python __getattr__ method. Instead of * throwing a AttributeError if the item isn't found, this just returns * null. - * + * * By default, this method will call * <code>__findattr__(name.internedString)</code> with the appropriate - * args. - * + * args. + * * @param name the name to lookup in this namespace - * + * * @return the value corresponding to name or null if name is not found */ public final PyObject __findattr__(PyString name) { @@ -748,7 +749,7 @@ /** * A variant of the __findattr__ method which accepts a Java * <code>String</code> as the name. - * + * * <b>Warning: name must be an interned string!</b> * * @param name the name to lookup in this namespace @@ -763,22 +764,22 @@ return null; } throw exc; - } + } } - + /** - * Attribute lookup hook. If the attribute is not found, null may be - * returned or a Py.AttributeError can be thrown, whatever is more + * Attribute lookup hook. If the attribute is not found, null may be + * returned or a Py.AttributeError can be thrown, whatever is more * correct, efficient and/or convenient for the implementing class. - * - * Client code should use {@link #__getattr__(String)} or - * {@link #__findattr__(String)}. Both methods have a clear policy for - * failed lookups. - * - * @return The looked up value. May return null if the attribute is not found + * + * Client code should use {@link #__getattr__(String)} or + * {@link #__findattr__(String)}. Both methods have a clear policy for + * failed lookups. + * + * @return The looked up value. May return null if the attribute is not found * @throws PyException(AttributeError) if the attribute is not found. This - * is not mandatory, null can be returned if it fits the implementation - * better, or for performance reasons. + * is not mandatory, null can be returned if it fits the implementation + * better, or for performance reasons. */ public PyObject __findattr_ex__(String name) { return object___findattr__(name); @@ -789,7 +790,7 @@ * * By default, this method will call * <code>__getattr__(name.internedString)</code> with the appropriate - * args. + * args. * * @param name the name to lookup in this namespace * @return the value corresponding to name @@ -1002,9 +1003,9 @@ * * This method can not be overridden. * To implement __coerce__ functionality, override __coerce_ex__ instead. - * - * Also, <b>do not</b> call this method from exposed 'coerce' methods. - * Instead, Use adaptToCoerceTuple over the result of the overriden + * + * Also, <b>do not</b> call this method from exposed 'coerce' methods. + * Instead, Use adaptToCoerceTuple over the result of the overriden * __coerce_ex__. * * @param pyo the other object involved in the coercion. @@ -1022,13 +1023,13 @@ /** * Adapts the result of __coerce_ex__ to a tuple of two elements, with the - * resulting coerced values, or to Py.NotImplemented, if o is Py.None. - * - * This is safe to be used from subclasses exposing '__coerce__' + * resulting coerced values, or to Py.NotImplemented, if o is Py.None. + * + * This is safe to be used from subclasses exposing '__coerce__' * (as opposed to {@link #__coerce__(PyObject)}, which calls the virtual * method {@link #__coerce_ex__(PyObject)}) - * - * @param o either a PyObject[2] or a PyObject, as given by + * + * @param o either a PyObject[2] or a PyObject, as given by * {@link #__coerce_ex__(PyObject)}. */ protected final PyObject adaptToCoerceTuple(Object o) { @@ -1292,7 +1293,7 @@ PyObject token = null; PyType t1 = this.getType(); PyType t2 = o.getType(); - + if (t1 != t2 && t2.isSubType(t1)) { return o._eq(this); } @@ -1331,7 +1332,7 @@ PyObject token = null; PyType t1 = this.getType(); PyType t2 = o.getType(); - + if (t1 != t2 && t2.isSubType(t1)) { return o._ne(this); } @@ -1365,7 +1366,7 @@ PyObject token = null; PyType t1 = this.getType(); PyType t2 = o.getType(); - + if (t1 != t2 && t2.isSubType(t1)) { return o._ge(this); } @@ -1399,7 +1400,7 @@ PyObject token = null; PyType t1 = this.getType(); PyType t2 = o.getType(); - + if (t1 != t2 && t2.isSubType(t1)) { return o._gt(this); } @@ -1433,7 +1434,7 @@ PyObject token = null; PyType t1 = this.getType(); PyType t2 = o.getType(); - + if (t1 != t2 && t2.isSubType(t1)) { return o._le(this); } @@ -1467,7 +1468,7 @@ PyObject token = null; PyType t1 = this.getType(); PyType t2 = o.getType(); - + if (t1 != t2 && t2.isSubType(t1)) { return o._lt(this); } @@ -1678,7 +1679,7 @@ throw Py.TypeError(String.format("'%.200s' object cannot be interpreted as an index", getType().fastGetName())); } - + /** * @param op the String form of the op (e.g. "+") * @param o2 the right operand @@ -1705,7 +1706,7 @@ protected String unsupportedopMessage(String op, PyObject o2) { return null; } - + /** * Should return an error message suitable for substitution where. * @@ -3523,7 +3524,7 @@ // backward comp impls. /** * Get descriptor for this PyObject. - * + * * @param obj - * the instance accessing this descriptor. Can be null if this is * being accessed by a type. @@ -3544,7 +3545,7 @@ public void __delete__(PyObject obj) { throw Py.AttributeError("object internal __delete__ impl is abstract"); } - + @ExposedMethod final PyObject object___getattribute__(PyObject arg0) { String name = asName(arg0); @@ -3553,7 +3554,7 @@ noAttributeError(name); return ret; } - + // name must be interned final PyObject object___findattr__(String name) { @@ -3581,12 +3582,12 @@ return null; } - + @ExposedMethod final void object___setattr__(PyObject name, PyObject value) { object___setattr__(asName(name), value); } - + private final void object___setattr__(String name, PyObject value) { PyObject descr = objtype.lookup(name); @@ -3616,7 +3617,7 @@ noAttributeError(name); } - + @ExposedMethod final void object___delattr__(PyObject name) { object___delattr__(asName(name)); @@ -3684,7 +3685,7 @@ /** Used for pickling. If the subclass specifies __reduce__, it will * override __reduce_ex__ in the base-class, even if __reduce_ex__ was * called with an argument. - * + * * @param arg PyInteger specifying reduce algorithm (method without this * argument defaults to 0). * @return a tuple of (class, tuple) @@ -3853,7 +3854,7 @@ throw new ConversionException(index); } - // TODO - remove when all generated users are migrated to @Exposed and asInt() + // TODO - remove when all generated users are migrated to @Exposed and asInt() public int asInt(int index) throws ConversionException { throw new ConversionException(index); } Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-10-20 01:41:32 UTC (rev 5477) +++ trunk/jython/src/org/python/core/PyType.java 2008-10-20 02:03:44 UTC (rev 5478) @@ -27,7 +27,6 @@ /** * The Python Type object implementation. - * */ @ExposedType(name = "type") public class PyType extends PyObject implements Serializable { @@ -54,7 +53,7 @@ private long tp_flags; /** The underlying java class or null. */ - private Class underlying_class; + private Class<?> underlying_class; /** Whether it's a builtin type. */ boolean builtin = false; @@ -79,20 +78,23 @@ private ReferenceQueue<PyType> subclasses_refq = new ReferenceQueue<PyType>(); private HashSet<WeakReference<PyType>> subclasses = new HashSet<WeakReference<PyType>>(); - private final static Class[] O = {PyObject.class}; - private final static Class[] OO = {PyObject.class, PyObject.class}; + private final static Class<?>[] O = {PyObject.class}; + private final static Class<?>[] OO = {PyObject.class, PyObject.class}; /** Mapping of Java classes to their PyTypes. */ - private static HashMap<Class, PyType> class_to_type; + private static Map<Class<?>, PyType> class_to_type; /** Mapping of Java classes to their TypeBuilders. */ - private static HashMap<Class, TypeBuilder> classToBuilder; + private static Map<Class<?>, TypeBuilder> classToBuilder; - private PyType() { - } + private PyType() {} - private PyType(boolean dummy) { - super(true); + /** + * Creates the PyType instance for type itself. The argument just exists to make the constructor + * distinct. + */ + private PyType(boolean ignored) { + super(ignored); } PyType(PyType subtype) { @@ -288,7 +290,7 @@ return newobj; } - private static void fillFromClass(PyType newtype, String name, Class c, Class base, + private static void fillFromClass(PyType newtype, String name, Class<?> c, Class<?> base, TypeBuilder tb) { if (base == null) { base = c.getSuperclass(); @@ -333,7 +335,7 @@ newtype.dict = dict; } - private static void fillInClassic(Class c, Class<?> base, PyObject dict) { + private static void fillInClassic(Class<?> c, Class<?> base, PyObject dict) { if (Py.BOOTSTRAP_TYPES.contains(c)) { // BOOTSTRAP_TYPES will be filled in by addBuilder later return; @@ -341,7 +343,7 @@ Map<String, Object> propnames = new HashMap<String, Object>(); Method[] methods = c.getMethods(); for (Method meth : methods) { - Class declaring = meth.getDeclaringClass(); + Class<?> declaring = meth.getDeclaringClass(); if (declaring != base && base.isAssignableFrom(declaring) && !ignore(meth)) { String methname = meth.getName(); String nmethname = normalize_name(methname); @@ -377,11 +379,11 @@ } Field[] fields = c.getFields(); for (Field field : fields) { - Class declaring = field.getDeclaringClass(); + Class<?> declaring = field.getDeclaringClass(); if (declaring != base && base.isAssignableFrom(declaring)) { String fldname = field.getName(); int fldmods = field.getModifiers(); - Class fldtype = field.getType(); + Class<?> fldtype = field.getType(); if (Modifier.isStatic(fldmods)) { if (fldname.startsWith("__doc__") && fldname.length() > 7 && fldtype == PyString.class) { @@ -409,7 +411,7 @@ } Method getter = null; Method setter = null; - Class proptype = null; + Class<?> proptype = null; getter = get_non_static_method(c, "get" + propname, new Class[] {}); if (getter == null) getter = get_non_static_method(c, "is" + propname, new Class[] {}); @@ -430,10 +432,10 @@ // XXX error } } - Constructor[] ctrs = c.getConstructors(); + Constructor<?>[] ctrs = c.getConstructors(); if (ctrs.length != 0) { final PyReflectedConstructor reflctr = new PyReflectedConstructor("_new_impl"); - for (Constructor ctr : ctrs) { + for (Constructor<?> ctr : ctrs) { reflctr.addConstructor(ctr); } PyObject new_ = new PyNewWrapper(c, "__new__", -1, -1) { @@ -446,16 +448,15 @@ } if (ClassDictInit.class.isAssignableFrom(c) && c != ClassDictInit.class) { try { - @SuppressWarnings("unchecked") Method m = c.getMethod("classDictInit", PyObject.class); - m.invoke(null, new Object[] {dict}); + m.invoke(null, dict); } catch (Exception exc) { throw error(exc); } } } - private static void fillInMRO(PyType type, Class base) { + private static void fillInMRO(PyType type, Class<?> base) { PyType[] mro; if (base == Object.class) { mro = new PyType[] {type}; @@ -564,7 +565,7 @@ } } } catch (PyException t) { - for (Iterator it = savedSubMros.iterator(); it.hasNext();) { + for (Iterator<Object> it = savedSubMros.iterator(); it.hasNext();) { PyType subtype = (PyType)it.next(); PyObject[] subtypeSavedMro = (PyObject[])it.next(); subtype.mro = subtypeSavedMro; @@ -633,7 +634,7 @@ } private void cleanup_subclasses() { - Reference ref; + Reference<?> ref; while ((ref = subclasses_refq.poll()) != null) { subclasses.remove(ref); } @@ -1017,7 +1018,7 @@ return Py.JavaError(e); } - private static Method get_non_static_method(Class<?> c, String name, Class[] parmtypes) { + private static Method get_non_static_method(Class<?> c, String name, Class<?>[] parmtypes) { try { Method meth = c.getMethod(name, parmtypes); if (!Modifier.isStatic(meth.getModifiers())) { @@ -1029,7 +1030,7 @@ return null; } - private static Method get_descr_method(Class c, String name, Class[] parmtypes) { + private static Method get_descr_method(Class<?> c, String name, Class<?>[] parmtypes) { Method meth = get_non_static_method(c, name, parmtypes); if (meth != null && meth.getDeclaringClass() != PyObject.class) { return meth; @@ -1038,8 +1039,8 @@ } private static boolean ignore(Method meth) { - Class[] exceptions = meth.getExceptionTypes(); - for (Class exception : exceptions) { + Class<?>[] exceptions = meth.getExceptionTypes(); + for (Class<?> exception : exceptions) { if (exception == PyIgnoreMethodTag.class) { return true; } @@ -1047,9 +1048,9 @@ return false; } - public static void addBuilder(Class forClass, TypeBuilder builder) { + public static void addBuilder(Class<?> forClass, TypeBuilder builder) { if (classToBuilder == null) { - classToBuilder = new HashMap<Class, TypeBuilder>(); + classToBuilder = new HashMap<Class<?>, TypeBuilder>(); } classToBuilder.put(forClass, builder); @@ -1063,7 +1064,7 @@ PyType objType = fromClass(builder.getTypeClass()); objType.name = builder.getName(); objType.dict = builder.getDict(objType); - Class base = builder.getBase(); + Class<?> base = builder.getBase(); if (base == Object.class) { base = forClass.getSuperclass(); } @@ -1072,13 +1073,13 @@ } } - private static PyType addFromClass(Class c) { + private static PyType addFromClass(Class<?> c) { if (ExposeAsSuperclass.class.isAssignableFrom(c)) { PyType exposedAs = fromClass(c.getSuperclass()); class_to_type.put(c, exposedAs); return exposedAs; } - Class base = null; + Class<?> base = null; String name = null; TypeBuilder tb = classToBuilder == null ? null : classToBuilder.get(c); if (tb != null) { @@ -1089,16 +1090,16 @@ } PyType newtype = class_to_type.get(c); if (newtype == null) { - newtype = c == PyType.class ? new PyType(true) : new PyType(); + newtype = c == PyType.class ? new PyType(false) : new PyType(); class_to_type.put(c, newtype); fillFromClass(newtype, name, c, base, tb); } return newtype; } - public static synchronized PyType fromClass(Class c) { + public static synchronized PyType fromClass(Class<?> c) { if (class_to_type == null) { - class_to_type = new HashMap<Class, PyType>(); + class_to_type = new HashMap<Class<?>, PyType>(); addFromClass(PyType.class); } PyType type = class_to_type.get(c); @@ -1333,7 +1334,7 @@ return doc; } - public Object __tojava__(Class c) { + public Object __tojava__(Class<?> c) { if (underlying_class != null && (c == Object.class || c == Class.class || c == Serializable.class)) { return underlying_class; @@ -1429,19 +1430,20 @@ return new TypeResolver(underlying_class, getModule().toString(), name); } - public static interface Newstyle { - } + private interface OnType { - private interface OnType { boolean onType(PyType type); } static class TypeResolver implements Serializable { - private Class underlying_class; - private String module; + + private Class<?> underlying_class; + + String module; + private String name; - TypeResolver(Class underlying_class, String module, String name) { + TypeResolver(Class<?> underlying_class, String module, String name) { this.underlying_class = underlying_class; this.module = module; this.name = name; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-10-22 04:54:08
|
Revision: 5503 http://jython.svn.sourceforge.net/jython/?rev=5503&view=rev Author: cgroves Date: 2008-10-22 04:53:59 +0000 (Wed, 22 Oct 2008) Log Message: ----------- Split Java-wrapping PyType creation out into its own subclass, PyJavaType. Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Added Paths: ----------- trunk/jython/src/org/python/core/PyJavaType.java Added: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java (rev 0) +++ trunk/jython/src/org/python/core/PyJavaType.java 2008-10-22 04:53:59 UTC (rev 5503) @@ -0,0 +1,189 @@ +package org.python.core; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; + +import org.python.core.util.StringUtil; +import org.python.expose.ExposeAsSuperclass; + +public class PyJavaType extends PyType implements ExposeAsSuperclass { + + private final static Class<?>[] OO = {PyObject.class, PyObject.class}; + + public PyJavaType() { + super(TYPE == null ? fromClass(PyType.class) : TYPE); + } + + @Override + protected void fillDict(Class<?> base) { + dict = new PyStringMap(); + Map<String, Object> propnames = new HashMap<String, Object>(); + Method[] methods = underlying_class.getMethods(); + for (Method meth : methods) { + Class<?> declaring = meth.getDeclaringClass(); + if (declaring != base && base.isAssignableFrom(declaring) && !ignore(meth)) { + String methname = meth.getName(); + String nmethname = normalize_name(methname); + PyReflectedFunction reflfunc = (PyReflectedFunction)dict.__finditem__(nmethname); + boolean added = false; + if (reflfunc == null) { + dict.__setitem__(nmethname, new PyReflectedFunction(meth)); + added = true; + } else { + reflfunc.addMethod(meth); + added = true; + } + if (added && !Modifier.isStatic(meth.getModifiers())) { + // check for xxxX.* + int n = meth.getParameterTypes().length; + if (methname.startsWith("get") && n == 0) { + propnames.put(methname.substring(3), "getter"); + } else if (methname.startsWith("is") && n == 0 + && meth.getReturnType() == Boolean.TYPE) { + propnames.put(methname.substring(2), "getter"); + } else if (methname.startsWith("set") && n == 1) { + propnames.put(methname.substring(3), meth); + } + } + } + } + for (Method meth : methods) { + String nmethname = normalize_name(meth.getName()); + PyReflectedFunction reflfunc = (PyReflectedFunction)dict.__finditem__(nmethname); + if (reflfunc != null) { + reflfunc.addMethod(meth); + } + } + Field[] fields = underlying_class.getFields(); + for (Field field : fields) { + Class<?> declaring = field.getDeclaringClass(); + if (declaring != base && base.isAssignableFrom(declaring)) { + String fldname = field.getName(); + int fldmods = field.getModifiers(); + Class<?> fldtype = field.getType(); + if (Modifier.isStatic(fldmods)) { + if (fldname.startsWith("__doc__") && fldname.length() > 7 + && fldtype == PyString.class) { + String fname = fldname.substring(7).intern(); + PyObject memb = dict.__finditem__(fname); + if (memb != null && memb instanceof PyReflectedFunction) { + PyString doc = null; + try { + doc = (PyString)field.get(null); + } catch (IllegalAccessException e) { + throw error(e); + } + ((PyReflectedFunction)memb).__doc__ = doc; + } + } + } + dict.__setitem__(normalize_name(fldname), new PyReflectedField(field)); + } + } + for (String propname : propnames.keySet()) { + String npropname = normalize_name(StringUtil.decapitalize(propname)); + PyObject prev = dict.__finditem__(npropname); + if (prev != null && prev instanceof PyReflectedFunction) { + continue; + } + Method getter = null; + Method setter = null; + Class<?> proptype = null; + getter = get_non_static_method(underlying_class, "get" + propname); + if (getter == null) + getter = get_non_static_method(underlying_class, "is" + propname); + if (getter != null) { + proptype = getter.getReturnType(); + setter = get_non_static_method(underlying_class, "set" + propname, proptype); + } else { + Object o = propnames.get(propname); + if (o instanceof Method) { + setter = (Method)o; + proptype = setter.getParameterTypes()[0]; + } + } + if (setter != null || getter != null) { + dict.__setitem__(npropname, new PyBeanProperty(npropname, proptype, getter, setter)); + } else { + // XXX error + } + } + Constructor<?>[] ctrs = underlying_class.getConstructors(); + if (ctrs.length != 0) { + final PyReflectedConstructor reflctr = new PyReflectedConstructor("_new_impl"); + for (Constructor<?> ctr : ctrs) { + reflctr.addConstructor(ctr); + } + PyObject new_ = new PyNewWrapper(underlying_class, "__new__", -1, -1) { + + public PyObject new_impl(boolean init, + PyType subtype, + PyObject[] args, + String[] keywords) { + return reflctr.make(args, keywords); + } + }; + dict.__setitem__("__new__", new_); + } + if (ClassDictInit.class.isAssignableFrom(underlying_class) + && underlying_class != ClassDictInit.class) { + try { + Method m = underlying_class.getMethod("classDictInit", PyObject.class); + m.invoke(null, dict); + } catch (Exception exc) { + throw error(exc); + } + } + if (base != Object.class) { + has_set = get_descr_method(underlying_class, "__set__", OO) != null + || get_descr_method(underlying_class, "_doset", OO) != null; + has_delete = get_descr_method(underlying_class, "__delete__", PyObject.class) != null + || get_descr_method(underlying_class, "_dodel", PyObject.class) != null; + } + } + + private static String normalize_name(String name) { + if (name.endsWith("$")) { + name = name.substring(0, name.length() - 1); + } + return name.intern(); + } + + private static Method get_non_static_method(Class<?> c, String name, Class<?>... parmtypes) { + try { + Method meth = c.getMethod(name, parmtypes); + if (!Modifier.isStatic(meth.getModifiers())) { + return meth; + } + } catch (NoSuchMethodException e) { + // ok + } + return null; + } + + private static Method get_descr_method(Class<?> c, String name, Class<?>... parmtypes) { + Method meth = get_non_static_method(c, name, parmtypes); + if (meth != null && meth.getDeclaringClass() != PyObject.class) { + return meth; + } + return null; + } + + private static boolean ignore(Method meth) { + Class<?>[] exceptions = meth.getExceptionTypes(); + for (Class<?> exception : exceptions) { + if (exception == PyIgnoreMethodTag.class) { + return true; + } + } + return false; + } + + private static PyException error(Exception e) { + return Py.JavaError(e); + } +} Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-10-21 22:36:57 UTC (rev 5502) +++ trunk/jython/src/org/python/core/PyType.java 2008-10-22 04:53:59 UTC (rev 5503) @@ -4,18 +4,11 @@ import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import org.python.core.util.StringUtil; import org.python.expose.ExposeAsSuperclass; import org.python.expose.ExposedDelete; import org.python.expose.ExposedGet; @@ -34,44 +27,42 @@ public static PyType TYPE = fromClass(PyType.class); - /** The type's name. builtin types include their fully qualified - * name, e.g.: time.struct_time. */ - private String name; + /** The type's name. builtin types include their fully qualified name, e.g.: time.struct_time. */ + protected String name; /** __base__, the direct base type or null. */ - private PyType base; + protected PyType base; /** __bases__, the base classes. */ - private PyObject[] bases = new PyObject[0]; + protected PyObject[] bases = new PyObject[0]; /** The real, internal __dict__. */ - private PyObject dict; + protected PyObject dict; /** __mro__, the method resolution. order */ - private PyObject[] mro = null; + protected PyObject[] mro; /** __flags__, the type's options. */ private long tp_flags; /** The underlying java class or null. */ - private Class<?> underlying_class; + protected Class<?> underlying_class; /** Whether it's a builtin type. */ - boolean builtin = false; + protected boolean builtin; /** Whether new instances of this type can be instantiated */ - private boolean non_instantiable = false; + protected boolean instantiable = true; /** Whether this type has set/delete descriptors */ boolean has_set; boolean has_delete; - /** Whether finalization is required for this type's instances - * (implements __del__). */ + /** Whether finalization is required for this type's instances (implements __del__). */ private boolean needs_finalizer; /** Whether this type's instances require a __dict__. */ - private boolean needs_userdict = false; + protected boolean needs_userdict; /** The number of __slots__ defined. */ private int numSlots; @@ -79,15 +70,17 @@ private ReferenceQueue<PyType> subclasses_refq = new ReferenceQueue<PyType>(); private Set<WeakReference<PyType>> subclasses = Generic.set(); - private final static Class<?>[] O = {PyObject.class}; - private final static Class<?>[] OO = {PyObject.class, PyObject.class}; - /** Mapping of Java classes to their PyTypes. */ private static Map<Class<?>, PyType> class_to_type; /** Mapping of Java classes to their TypeBuilders. */ private static Map<Class<?>, TypeBuilder> classToBuilder; + protected PyType(PyType subtype) { + super(subtype); + } + + private PyType() {} /** @@ -98,10 +91,6 @@ super(ignored); } - PyType(PyType subtype) { - super(subtype); - } - @ExposedNew public static PyObject type___new__(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { @@ -260,8 +249,7 @@ }); } - newtype.has_set = newtype.lookup("__set__") != null; - newtype.has_delete = newtype.lookup("__delete__") != null; + newtype.fillHasSetAndDelete(); newtype.needs_finalizer = newtype.lookup("__del__") != null; for (PyObject cur : bases_list) { @@ -291,170 +279,18 @@ return newobj; } - private static void fillFromClass(PyType newtype, String name, Class<?> c, Class<?> base, - TypeBuilder tb) { - if (base == null) { - base = c.getSuperclass(); + protected void fillDict(Class<?> base) { + if (Py.BOOTSTRAP_TYPES.contains(underlying_class)) { + return; } - if (name == null) { - name = c.getName(); - // Strip the java fully qualified class name (specifically - // remove org.python.core.Py or fallback to stripping to - // the last dot) - if (name.startsWith("org.python.core.Py")) { - name = name.substring("org.python.core.Py".length()).toLowerCase(); - } else { - int lastDot = name.lastIndexOf('.'); - if (lastDot != -1) { - name = name.substring(lastDot + 1); - } - } - } - newtype.name = name; - newtype.underlying_class = c; - newtype.builtin = true; - // basic mro, base, bases - fillInMRO(newtype, base); - PyObject dict; - if (tb != null) { - dict = tb.getDict(newtype); - newtype.non_instantiable = dict.__finditem__("__new__") == null; - } else { - dict = new PyStringMap(); - fillInClassic(c, base, dict); - } - if (base != Object.class) { - if (get_descr_method(c, "__set__", OO) != null || /* backw comp */ - get_descr_method(c, "_doset", OO) != null) { - newtype.has_set = true; - } - if (get_descr_method(c, "__delete__", O) != null || /* backw comp */ - get_descr_method(c, "_dodel", O) != null) { - newtype.has_delete = true; - } - } - newtype.dict = dict; + dict = classToBuilder.get(underlying_class).getDict(this); + instantiable = dict.__finditem__("__new__") != null; + fillHasSetAndDelete(); } - private static void fillInClassic(Class<?> c, Class<?> base, PyObject dict) { - if (Py.BOOTSTRAP_TYPES.contains(c)) { - // BOOTSTRAP_TYPES will be filled in by addBuilder later - return; - } - Map<String, Object> propnames = new HashMap<String, Object>(); - Method[] methods = c.getMethods(); - for (Method meth : methods) { - Class<?> declaring = meth.getDeclaringClass(); - if (declaring != base && base.isAssignableFrom(declaring) && !ignore(meth)) { - String methname = meth.getName(); - String nmethname = normalize_name(methname); - PyReflectedFunction reflfunc = (PyReflectedFunction)dict.__finditem__(nmethname); - boolean added = false; - if (reflfunc == null) { - dict.__setitem__(nmethname, new PyReflectedFunction(meth)); - added = true; - } else { - reflfunc.addMethod(meth); - added = true; - } - if (added && !Modifier.isStatic(meth.getModifiers())) { - // check for xxxX.* - int n = meth.getParameterTypes().length; - if (methname.startsWith("get") && n == 0) { - propnames.put(methname.substring(3), "getter"); - } else if (methname.startsWith("is") && n == 0 - && meth.getReturnType() == Boolean.TYPE) { - propnames.put(methname.substring(2), "getter"); - } else if (methname.startsWith("set") && n == 1) { - propnames.put(methname.substring(3), meth); - } - } - } - } - for (Method meth : methods) { - String nmethname = normalize_name(meth.getName()); - PyReflectedFunction reflfunc = (PyReflectedFunction)dict.__finditem__(nmethname); - if (reflfunc != null) { - reflfunc.addMethod(meth); - } - } - Field[] fields = c.getFields(); - for (Field field : fields) { - Class<?> declaring = field.getDeclaringClass(); - if (declaring != base && base.isAssignableFrom(declaring)) { - String fldname = field.getName(); - int fldmods = field.getModifiers(); - Class<?> fldtype = field.getType(); - if (Modifier.isStatic(fldmods)) { - if (fldname.startsWith("__doc__") && fldname.length() > 7 - && fldtype == PyString.class) { - String fname = fldname.substring(7).intern(); - PyObject memb = dict.__finditem__(fname); - if (memb != null && memb instanceof PyReflectedFunction) { - PyString doc = null; - try { - doc = (PyString)field.get(null); - } catch (IllegalAccessException e) { - throw error(e); - } - ((PyReflectedFunction)memb).__doc__ = doc; - } - } - } - dict.__setitem__(normalize_name(fldname), new PyReflectedField(field)); - } - } - for (String propname : propnames.keySet()) { - String npropname = normalize_name(StringUtil.decapitalize(propname)); - PyObject prev = dict.__finditem__(npropname); - if (prev != null && prev instanceof PyReflectedFunction) { - continue; - } - Method getter = null; - Method setter = null; - Class<?> proptype = null; - getter = get_non_static_method(c, "get" + propname, new Class[] {}); - if (getter == null) - getter = get_non_static_method(c, "is" + propname, new Class[] {}); - if (getter != null) { - proptype = getter.getReturnType(); - setter = get_non_static_method(c, "set" + propname, new Class[] {proptype}); - } else { - Object o = propnames.get(propname); - if (o instanceof Method) { - setter = (Method)o; - proptype = setter.getParameterTypes()[0]; - } - } - if (setter != null || getter != null) { - dict.__setitem__(npropname, new PyBeanProperty(npropname, proptype, getter, - setter)); - } else { - // XXX error - } - } - Constructor<?>[] ctrs = c.getConstructors(); - if (ctrs.length != 0) { - final PyReflectedConstructor reflctr = new PyReflectedConstructor("_new_impl"); - for (Constructor<?> ctr : ctrs) { - reflctr.addConstructor(ctr); - } - PyObject new_ = new PyNewWrapper(c, "__new__", -1, -1) { - public PyObject new_impl(boolean init, PyType subtype, PyObject[] args, - String[] keywords) { - return reflctr.make(args, keywords); - } - }; - dict.__setitem__("__new__", new_); - } - if (ClassDictInit.class.isAssignableFrom(c) && c != ClassDictInit.class) { - try { - Method m = c.getMethod("classDictInit", PyObject.class); - m.invoke(null, dict); - } catch (Exception exc) { - throw error(exc); - } - } + private void fillHasSetAndDelete() { + has_set = lookup("__set__") != null; + has_delete = lookup("__delete__") != null; } private static void fillInMRO(PyType type, Class<?> base) { @@ -481,8 +317,8 @@ } /** - * Ensures that the physical layout between this type and - * <code>other</code> are compatible. Raises a TypeError if not. + * Ensures that the physical layout between this type and <code>other</code> are compatible. + * Raises a TypeError if not. */ public void compatibleForAssignment(PyType other, String attribute) { if (!getLayout().equals(other.getLayout()) || needs_userdict != other.needs_userdict @@ -493,8 +329,8 @@ } /** - * Gets the most parent PyType that determines the layout of this type ie - * has slots or an underlying_class. Can by this PyType. + * Gets the most parent PyType that determines the layout of this type, ie it has slots or an + * underlying_class. Can be this PyType. */ private PyType getLayout() { if (underlying_class != null) { @@ -609,10 +445,9 @@ } /** - * Collects the subclasses and current mro of this type in mroCollector. If - * this type has subclasses C and D, and D has a subclass E current - * mroCollector will equal [C, C.__mro__, D, D.__mro__, E, E.__mro__] after - * this call. + * Collects the subclasses and current mro of this type in mroCollector. If this type has + * subclasses C and D, and D has a subclass E current mroCollector will equal [C, C.__mro__, D, + * D.__mro__, E, E.__mro__] after this call. */ private void mro_subclasses(List<Object> mroCollector) { for (WeakReference<PyType> ref : subclasses) { @@ -924,7 +759,6 @@ } public boolean isSubType(PyType supertype) { - PyObject[] mro = this.mro; if (mro != null) { for (PyObject base : mro) { if (base == supertype) { @@ -1008,47 +842,6 @@ return null; } - private static String normalize_name(String name) { - if (name.endsWith("$")) { - name = name.substring(0, name.length() - 1); - } - return name.intern(); - } - - private static PyException error(Exception e) { - return Py.JavaError(e); - } - - private static Method get_non_static_method(Class<?> c, String name, Class<?>[] parmtypes) { - try { - Method meth = c.getMethod(name, parmtypes); - if (!Modifier.isStatic(meth.getModifiers())) { - return meth; - } - } catch (NoSuchMethodException e) { - // ok - } - return null; - } - - private static Method get_descr_method(Class<?> c, String name, Class<?>[] parmtypes) { - Method meth = get_non_static_method(c, name, parmtypes); - if (meth != null && meth.getDeclaringClass() != PyObject.class) { - return meth; - } - return null; - } - - private static boolean ignore(Method meth) { - Class<?>[] exceptions = meth.getExceptionTypes(); - for (Class<?> exception : exceptions) { - if (exception == PyIgnoreMethodTag.class) { - return true; - } - } - return false; - } - public static void addBuilder(Class<?> forClass, TypeBuilder builder) { if (classToBuilder == null) { classToBuilder = Generic.map(); @@ -1070,7 +863,7 @@ base = forClass.getSuperclass(); } fillInMRO(objType, base); - objType.non_instantiable = objType.dict.__finditem__("__new__") == null; + objType.instantiable = objType.dict.__finditem__("__new__") != null; } } @@ -1082,19 +875,55 @@ } Class<?> base = null; String name = null; - TypeBuilder tb = classToBuilder == null ? null : classToBuilder.get(c); + TypeBuilder tb = getBuilder(c); if (tb != null) { name = tb.getName(); if (!tb.getBase().equals(Object.class)) { base = tb.getBase(); } } - PyType newtype = class_to_type.get(c); - if (newtype == null) { - newtype = c == PyType.class ? new PyType(false) : new PyType(); - class_to_type.put(c, newtype); - fillFromClass(newtype, name, c, base, tb); + PyType type = class_to_type.get(c); + if (type == null) { + type = createType(c, base, name); } + return type; + } + + private static TypeBuilder getBuilder(Class<?> c) { + return classToBuilder == null ? null : classToBuilder.get(c); + } + + private static PyType createType(Class<?> c, Class<?> base, String name) { + PyType newtype; + if (c == PyType.class) { + newtype = new PyType(false); + } else if (Py.BOOTSTRAP_TYPES.contains(c) || getBuilder(c) != null) { + newtype = new PyType(); + } else { + newtype = new PyJavaType(); + } + class_to_type.put(c, newtype); + if (base == null) { + base = c.getSuperclass(); + } + if (name == null) { + name = c.getName(); + // Strip the java fully qualified class name (specifically remove org.python.core.Py or + // fallback to stripping to the last dot) + if (name.startsWith("org.python.core.Py")) { + name = name.substring("org.python.core.Py".length()).toLowerCase(); + } else { + int lastDot = name.lastIndexOf('.'); + if (lastDot != -1) { + name = name.substring(lastDot + 1); + } + } + } + newtype.name = name; + newtype.underlying_class = c; + newtype.builtin = true; + fillInMRO(newtype, base); // basic mro, base, bases + newtype.fillDict(base); return newtype; } @@ -1244,7 +1073,7 @@ @ExposedMethod final PyObject type___call__(PyObject[] args, String[] keywords) { PyObject new_ = lookup("__new__"); - if (non_instantiable || new_ == null) { + if (!instantiable || new_ == null) { throw Py.TypeError("cannot create '" + name + "' instances"); } return invoke_new_(new_, this, true, args, keywords); @@ -1426,8 +1255,8 @@ return methodname; } - private Object writeReplace() { - // XXX: needed? + /** Used when serializing this type. */ + protected Object writeReplace() { return new TypeResolver(underlying_class, getModule().toString(), name); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-10-25 21:53:54
|
Revision: 5507 http://jython.svn.sourceforge.net/jython/?rev=5507&view=rev Author: pjenvey Date: 2008-10-25 21:53:49 +0000 (Sat, 25 Oct 2008) Log Message: ----------- rename to _update to match the other _update method, we'll keep the underscore for incase we want to add update to go along with set_update Modified Paths: -------------- trunk/jython/src/org/python/core/BaseSet.java trunk/jython/src/org/python/core/PyFrozenSet.java trunk/jython/src/org/python/core/PySet.java Modified: trunk/jython/src/org/python/core/BaseSet.java =================================================================== --- trunk/jython/src/org/python/core/BaseSet.java 2008-10-25 21:47:49 UTC (rev 5506) +++ trunk/jython/src/org/python/core/BaseSet.java 2008-10-25 21:53:49 UTC (rev 5507) @@ -26,7 +26,7 @@ } protected void _update(PyObject data) throws PyIgnoreMethodTag { - update(_set, data); + _update(_set, data); } /** @@ -35,7 +35,7 @@ * @param data An iterable instance. * @throws PyIgnoreMethodTag Ignore. */ - protected static Set update(Set set, PyObject data) throws PyIgnoreMethodTag { + protected static Set _update(Set set, PyObject data) throws PyIgnoreMethodTag { if (data == null) { return set; } Modified: trunk/jython/src/org/python/core/PyFrozenSet.java =================================================================== --- trunk/jython/src/org/python/core/PyFrozenSet.java 2008-10-25 21:47:49 UTC (rev 5506) +++ trunk/jython/src/org/python/core/PyFrozenSet.java 2008-10-25 21:53:49 UTC (rev 5507) @@ -19,11 +19,11 @@ } public PyFrozenSet(PyObject data) { - super(update(new HashSet<PyObject>(), data)); + super(_update(new HashSet<PyObject>(), data)); } public PyFrozenSet(PyType type, PyObject data) { - super(type, update(new HashSet<PyObject>(), data)); + super(type, _update(new HashSet<PyObject>(), data)); } @ExposedNew Modified: trunk/jython/src/org/python/core/PySet.java =================================================================== --- trunk/jython/src/org/python/core/PySet.java 2008-10-25 21:47:49 UTC (rev 5506) +++ trunk/jython/src/org/python/core/PySet.java 2008-10-25 21:53:49 UTC (rev 5507) @@ -23,7 +23,7 @@ } public PySet(PyObject data) { - super(update(new ConcurrentHashSet<PyObject>(), data)); + super(_update(new ConcurrentHashSet<PyObject>(), data)); } @ExposedNew This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-10-26 17:35:15
|
Revision: 5511 http://jython.svn.sourceforge.net/jython/?rev=5511&view=rev Author: cgroves Date: 2008-10-26 17:35:12 +0000 (Sun, 26 Oct 2008) Log Message: ----------- Document magic values n ReflectedCallData Modified Paths: -------------- trunk/jython/src/org/python/core/PyReflectedConstructor.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/src/org/python/core/ReflectedArgs.java trunk/jython/src/org/python/core/ReflectedCallData.java Modified: trunk/jython/src/org/python/core/PyReflectedConstructor.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedConstructor.java 2008-10-26 14:05:35 UTC (rev 5510) +++ trunk/jython/src/org/python/core/PyReflectedConstructor.java 2008-10-26 17:35:12 UTC (rev 5511) @@ -9,7 +9,7 @@ public class PyReflectedConstructor extends PyReflectedFunction { - + public PyReflectedConstructor(String name) { super(name); __name__ = name; @@ -38,16 +38,15 @@ // xxx temporary solution, type ctr will go through __new__ ... PyObject make(PyObject[] args,String[] keywords) { ReflectedArgs[] argsl = argslist; - + ReflectedCallData callData = new ReflectedCallData(); Object method=null; boolean consumes_keywords = false; - int n = nargs; int nkeywords = keywords.length; PyObject[] allArgs = null; - + // Check for a matching constructor to call - if (n > 0) { // PyArgsKeywordsCall signature, if present, is the first + if (nargs > 0) { // PyArgsKeywordsCall signature, if present, is the first if (argsl[0].matches(null, args, keywords, callData)) { method = argsl[0].data; consumes_keywords = argsl[0].flags == ReflectedArgs.PyArgsKeywordsCall; @@ -55,15 +54,16 @@ allArgs = args; int i = 1; if (nkeywords > 0) { - args = new PyObject[allArgs.length-nkeywords]; + args = new PyObject[allArgs.length - nkeywords]; System.arraycopy(allArgs, 0, args, 0, args.length); i = 0; } - for (; i < n; i++) { + for (; i < nargs; i++) { ReflectedArgs rargs = argsl[i]; - if (rargs - .matches(null, args, Py.NoKeywords, callData)) { - method = rargs.data; break; } + if (rargs.matches(null, args, Py.NoKeywords, callData)) { + method = rargs.data; + break; + } } } } @@ -82,14 +82,14 @@ catch (Throwable t) { throw Py.JavaError(t); } - + if (!consumes_keywords) { int offset = args.length; - for (int i=0; i<nkeywords; i++) { - obj.__setattr__(keywords[i], allArgs[i+offset]); - } + for (int i = 0; i < nkeywords; i++) { + obj.__setattr__(keywords[i], allArgs[i + offset]); + } } - + return obj; } Modified: trunk/jython/src/org/python/core/PyReflectedFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedFunction.java 2008-10-26 14:05:35 UTC (rev 5510) +++ trunk/jython/src/org/python/core/PyReflectedFunction.java 2008-10-26 17:35:12 UTC (rev 5511) @@ -3,10 +3,11 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Enumeration; -import java.util.Hashtable; +import java.util.Set; +import org.python.util.Generic; + public class PyReflectedFunction extends PyObject { public String __name__; @@ -136,11 +137,11 @@ } Object cself = callData.self; - Method m = (Method)method; + Method m = (Method)method; // Check to see if we should be using a super__ method instead // This is probably a bit inefficient... if (self == null && cself != null && cself instanceof PyProxy && - !__name__.startsWith("super__")) { + !__name__.startsWith("super__")) { PyInstance iself = ((PyProxy)cself)._getPyInstance(); if (argslist[0].declaringClass != iself.instclass.proxyClass) { String mname = ("super__"+__name__); @@ -148,9 +149,9 @@ Method[] super__methods = (Method[])iself.instclass.super__methods.get(mname); if (super__methods != null) { Class[] msig = m.getParameterTypes(); - for (int i=0; i<super__methods.length;i++) { - if (java.util.Arrays.equals(msig,super__methods[i].getParameterTypes())) { - m = super__methods[i]; + for (Method super__method : super__methods) { + if (java.util.Arrays.equals(msig,super__method.getParameterTypes())) { + m = super__method; break; } } @@ -264,64 +265,40 @@ } protected void throwBadArgError(int errArg, int nArgs, boolean self) { - Hashtable table = new Hashtable(); - ReflectedArgs[] argsl = argslist; - int n = nargs; - for(int i=0; i<n; i++) { - ReflectedArgs rargs = argsl[i]; - Class[] args = rargs.args; - int len = args.length; - /*if (!args.isStatic && !self) { - len = len-1; - }*/ + Set<Class<?>> argTypes = Generic.set(); + for (int i = 0; i < nargs; i++) { + // if (!args.isStatic && !self) { len = len-1; } // This check works almost all the time. // I'm still a little worried about non-static methods // called with an explict self... - if (len == nArgs) { - if (errArg == -1) { - table.put(rargs.declaringClass, rargs.declaringClass); + if (argslist[i].args.length == nArgs) { + if (errArg == ReflectedCallData.UNABLE_TO_CONVERT_SELF) { + argTypes.add(argslist[i].declaringClass); } else { - table.put(args[errArg], args[errArg]); + argTypes.add(argslist[i].args[errArg]); } } } - - StringBuffer buf = new StringBuffer(); - Enumeration keys = table.keys(); - while (keys.hasMoreElements()) { - Class arg = (Class)keys.nextElement(); - String name = niceName(arg); - if (keys.hasMoreElements()) { - buf.append(name); - buf.append(", "); - } else { - if (buf.length() > 2) { - buf.setLength(buf.length()-2); - buf.append(" or "); - } - buf.append(name); - } + StringBuilder buf = new StringBuilder(); + for (Class<?> arg : argTypes) { + buf.append(niceName(arg)); + buf.append(", "); } + if(buf.length() > 2) { + buf.setLength(buf.length() - 2); + } - throwError(ordinal(errArg)+" arg can't be coerced to "+buf); + throwError(ordinal(errArg) + " arg can't be coerced to " + buf); } - protected void throwError(int errArg, int nArgs, boolean self, - boolean keywords) - { - if (keywords) throwError("takes no keyword arguments"); - - if (errArg == -2) { + protected void throwError(int errArg, int nArgs, boolean self, boolean keywords) { + if (keywords) { + throwError("takes no keyword arguments"); + } else if (errArg == ReflectedCallData.BAD_ARG_COUNT) { throwArgCountError(nArgs, self); + } else { + throwBadArgError(errArg, nArgs, self); } - - /*if (errArg == -1) { - throwBadArgError(-1); - throwError("bad self argument"); - // Bad declared class - }*/ - - throwBadArgError(errArg, nArgs, self); } // Included only for debugging purposes... Modified: trunk/jython/src/org/python/core/ReflectedArgs.java =================================================================== --- trunk/jython/src/org/python/core/ReflectedArgs.java 2008-10-26 14:05:35 UTC (rev 5510) +++ trunk/jython/src/org/python/core/ReflectedArgs.java 2008-10-26 17:35:12 UTC (rev 5511) @@ -101,7 +101,7 @@ } // Make error messages clearer - callData.errArg = -1; + callData.errArg = ReflectedCallData.UNABLE_TO_CONVERT_SELF; if (self != null) { Object tmp = self.__tojava__(this.declaringClass); @@ -199,7 +199,7 @@ return cmp > 0 ? +1 : -1; } } - } + } return p1 > p2 ? +2 : (p1 == p2 ? 0 : -2); } @@ -261,8 +261,8 @@ String s = "" + this.declaringClass + ", " + this.isStatic + ", " + this.flags + ", " + this.data + "\n"; s = s + "\t("; - for (int j = 0; j < this.args.length; j++) { - s += this.args[j].getName() + ", "; + for (Class arg : this.args) { + s += arg.getName() + ", "; } s += ")"; return s; Modified: trunk/jython/src/org/python/core/ReflectedCallData.java =================================================================== --- trunk/jython/src/org/python/core/ReflectedCallData.java 2008-10-26 14:05:35 UTC (rev 5510) +++ trunk/jython/src/org/python/core/ReflectedCallData.java 2008-10-26 17:35:12 UTC (rev 5511) @@ -2,21 +2,25 @@ package org.python.core; class ReflectedCallData { - public Object[] args; + /** errArg value if the self passed to a call wasn't compatible with the type of the method. */ + public static final int UNABLE_TO_CONVERT_SELF = -1; + + /** errArg value if the method has no forms that take the number of arguments given. */ + public static final int BAD_ARG_COUNT = -2; + + public Object[] args = Py.EmptyObjects; + public int length; public Object self; - public int errArg; + /** + * Either {@link #BAD_ARG_COUNT}, {@link #UNABLE_TO_CONVERT_SELF}, or the index of the + * unconvertible argument in args. + */ + public int errArg = BAD_ARG_COUNT; - public ReflectedCallData() { - this.args = Py.EmptyObjects; - this.length = 0; - this.self = null; - this.errArg = -2; - } - public void setLength(int newLength) { this.length = newLength; if (newLength <= this.args.length) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-10-27 03:09:58
|
Revision: 5516 http://jython.svn.sourceforge.net/jython/?rev=5516&view=rev Author: cgroves Date: 2008-10-27 03:09:47 +0000 (Mon, 27 Oct 2008) Log Message: ----------- Make non-PyObject subclasses wrapped in PyJavaType instantiable Modified Paths: -------------- trunk/jython/src/org/python/core/PyInstance.java trunk/jython/src/org/python/core/PyJavaClass.java trunk/jython/src/org/python/core/PyJavaInstance.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyReflectedConstructor.java trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyInstance.java =================================================================== --- trunk/jython/src/org/python/core/PyInstance.java 2008-10-27 03:08:48 UTC (rev 5515) +++ trunk/jython/src/org/python/core/PyInstance.java 2008-10-27 03:09:47 UTC (rev 5516) @@ -18,9 +18,6 @@ return instclass; } - //This field is only used by Python subclasses of Java classes - Object javaProxy; - /** The namespace of this instance. Contains all instance attributes. **/ Modified: trunk/jython/src/org/python/core/PyJavaClass.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaClass.java 2008-10-27 03:08:48 UTC (rev 5515) +++ trunk/jython/src/org/python/core/PyJavaClass.java 2008-10-27 03:09:47 UTC (rev 5516) @@ -740,16 +740,6 @@ public PyObject __call__(PyObject[] args, String[] keywords) { if (!constructorsInitialized) initConstructors(); - // xxx instantiation of PyObject subclass, still needed? - if (PyObject.class.isAssignableFrom(proxyClass)) { - if (Modifier.isAbstract(proxyClass.getModifiers())) { - throw Py.TypeError("can't instantiate abstract class (" + fullName() + ")"); - } - if (__init__ == null) { - throw Py.TypeError("no public constructors for " + fullName()); - } - return __init__.make(args, keywords); - } PyInstance inst = new PyJavaInstance(this); inst.__init__(args, keywords); return inst; Modified: trunk/jython/src/org/python/core/PyJavaInstance.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaInstance.java 2008-10-27 03:08:48 UTC (rev 5515) +++ trunk/jython/src/org/python/core/PyJavaInstance.java 2008-10-27 03:09:47 UTC (rev 5516) @@ -66,8 +66,7 @@ PyReflectedConstructor init = ((PyJavaClass)instclass).__init__; if (init == null) { - throw Py.TypeError("no public constructors for "+ - instclass.__name__); + throw Py.TypeError("no public constructors for " + instclass.__name__); } init.__call__(this, args, keywords); } Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2008-10-27 03:08:48 UTC (rev 5515) +++ trunk/jython/src/org/python/core/PyJavaType.java 2008-10-27 03:09:47 UTC (rev 5516) @@ -19,13 +19,15 @@ } @Override - protected void fillDict(Class<?> base) { + protected void fillDict() { dict = new PyStringMap(); Map<String, Object> propnames = new HashMap<String, Object>(); + Class<?> base = underlying_class.getSuperclass(); Method[] methods = underlying_class.getMethods(); for (Method meth : methods) { Class<?> declaring = meth.getDeclaringClass(); - if (declaring != base && base.isAssignableFrom(declaring) && !ignore(meth)) { + if (base == null || + (declaring != base && base.isAssignableFrom(declaring) && !ignore(meth))) { String methname = meth.getName(); String nmethname = normalize_name(methname); PyReflectedFunction reflfunc = (PyReflectedFunction)dict.__finditem__(nmethname); @@ -118,16 +120,20 @@ for (Constructor<?> ctr : ctrs) { reflctr.addConstructor(ctr); } - PyObject new_ = new PyNewWrapper(underlying_class, "__new__", -1, -1) { + if (PyObject.class.isAssignableFrom(underlying_class)) { + PyObject new_ = new PyNewWrapper(underlying_class, "__new__", -1, -1) { - public PyObject new_impl(boolean init, - PyType subtype, - PyObject[] args, - String[] keywords) { - return reflctr.make(args, keywords); - } - }; - dict.__setitem__("__new__", new_); + public PyObject new_impl(boolean init, + PyType subtype, + PyObject[] args, + String[] keywords) { + return reflctr.make(args, keywords); + } + }; + dict.__setitem__("__new__", new_); + } else { + dict.__setitem__("__init__", reflctr); + } } if (ClassDictInit.class.isAssignableFrom(underlying_class) && underlying_class != ClassDictInit.class) { Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2008-10-27 03:08:48 UTC (rev 5515) +++ trunk/jython/src/org/python/core/PyObject.java 2008-10-27 03:09:47 UTC (rev 5516) @@ -35,6 +35,10 @@ } + // This field is only filled on Python wrappers for Java objects and for Python subclasses of + // Java classes. + Object javaProxy; + private PyType objtype; @ExposedGet(name = "__class__") Modified: trunk/jython/src/org/python/core/PyReflectedConstructor.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedConstructor.java 2008-10-27 03:08:48 UTC (rev 5515) +++ trunk/jython/src/org/python/core/PyReflectedConstructor.java 2008-10-27 03:09:47 UTC (rev 5516) @@ -6,10 +6,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.InstantiationException; +public class PyReflectedConstructor extends PyReflectedFunction { -public class PyReflectedConstructor extends PyReflectedFunction -{ - public PyReflectedConstructor(String name) { super(name); __name__ = name; @@ -23,8 +21,7 @@ } private ReflectedArgs makeArgs(Constructor m) { - return new ReflectedArgs(m, m.getParameterTypes(), - m.getDeclaringClass(), true); + return new ReflectedArgs(m, m.getParameterTypes(), m.getDeclaringClass(), true); } public void addConstructor(Constructor m) { @@ -36,15 +33,13 @@ } // xxx temporary solution, type ctr will go through __new__ ... - PyObject make(PyObject[] args,String[] keywords) { + PyObject make(PyObject[] args, String[] keywords) { ReflectedArgs[] argsl = argslist; - ReflectedCallData callData = new ReflectedCallData(); - Object method=null; + Object method = null; boolean consumes_keywords = false; int nkeywords = keywords.length; PyObject[] allArgs = null; - // Check for a matching constructor to call if (nargs > 0) { // PyArgsKeywordsCall signature, if present, is the first if (argsl[0].matches(null, args, keywords, callData)) { @@ -67,140 +62,84 @@ } } } - // Throw an error if no valid set of arguments if (method == null) { - throwError(callData.errArg, args.length, true /*xxx?*/,false); + throwError(callData.errArg, args.length, true /* xxx? */, false); } - // Do the actual constructor call PyObject obj = null; - Constructor ctor = (Constructor)method; try { - obj = (PyObject)ctor.newInstance(callData.getArgsArray()); - } - catch (Throwable t) { + obj = (PyObject)((Constructor<?>)method).newInstance(callData.getArgsArray()); + } catch (Throwable t) { throw Py.JavaError(t); } - if (!consumes_keywords) { int offset = args.length; for (int i = 0; i < nkeywords; i++) { obj.__setattr__(keywords[i], allArgs[i + offset]); } } - return obj; } - public PyObject __call__(PyObject self, PyObject[] args, - String[] keywords) - { - ReflectedArgs[] argsl = argslist; - - if (self == null || !(self instanceof PyInstance)) { + public PyObject __call__(PyObject self, PyObject[] args, String[] keywords) { + if (self == null) { throw Py.TypeError("invalid self argument to constructor"); } - - PyInstance iself = (PyInstance)self; - Class javaClass = iself.instclass.proxyClass; - Class declaringClass = argsl[0].declaringClass; - - // If this is the constructor for a proxy class or not... - if (PyProxy.class.isAssignableFrom(declaringClass)) { -// if (self instanceof PyJavaInstance) { -// throw Py.TypeError( -// "invalid self argument to proxy constructor"); -// } + Class<?> javaClass; + if (self instanceof PyInstance) { + javaClass = ((PyInstance)self).instclass.proxyClass; + } else { + javaClass = self.getType().underlying_class; } - else { - if (!(iself instanceof PyJavaInstance)) { - // Get proxy constructor and call it - if (declaringClass.isAssignableFrom(javaClass)) { - } else { - throw Py.TypeError("invalid self argument"); - } - PyJavaClass jc = PyJavaClass.lookup(javaClass); // xxx - jc.initConstructors(); - return jc.__init__.__call__(iself, args, keywords); - } + Class<?> declaringClass = argslist[0].declaringClass; + if (!declaringClass.isAssignableFrom(javaClass)) { + throw Py.TypeError("self invalid - must implement: " + declaringClass.getName()); } - - if (declaringClass.isAssignableFrom(javaClass)) { - } else { - throw Py.TypeError("self invalid - must implement: "+ - declaringClass.getName()); + if (!PyProxy.class.isAssignableFrom(declaringClass) && !(self instanceof PyJavaInstance)) { + PyJavaClass jc = PyJavaClass.lookup(javaClass); + jc.initConstructors(); + return jc.__init__.__call__(self, args, keywords); } - if (iself.javaProxy != null) { - Class sup = iself.instclass.proxyClass; - if (PyProxy.class.isAssignableFrom(sup)) + if (self.javaProxy != null) { + Class<?> sup = javaClass; + if (PyProxy.class.isAssignableFrom(sup)) { sup = sup.getSuperclass(); - throw Py.TypeError("instance already instantiated for "+ - sup.getName()); + } + throw Py.TypeError("instance already instantiated for " + sup.getName()); } - ReflectedCallData callData = new ReflectedCallData(); - Object method=null; - + Object method = null; // Remove keyword args int nkeywords = keywords.length; PyObject[] allArgs = args; if (nkeywords > 0) { - args = new PyObject[allArgs.length-nkeywords]; + args = new PyObject[allArgs.length - nkeywords]; System.arraycopy(allArgs, 0, args, 0, args.length); } - // Check for a matching constructor to call int n = nargs; - for (int i=0; i<n; i++) { - ReflectedArgs rargs = argsl[i]; + for (int i = 0; i < n; i++) { + ReflectedArgs rargs = argslist[i]; if (rargs.matches(null, args, Py.NoKeywords, callData)) { method = rargs.data; break; } } - // Throw an error if no valid set of arguments if (method == null) { throwError(callData.errArg, args.length, false, false); } - // Do the actual constructor call - Object jself = null; - ThreadState ts = Py.getThreadState(); - try { - ts.pushInitializingProxy(iself); - Constructor ctor = (Constructor)method; - try { - jself = ctor.newInstance(callData.getArgsArray()); - } - catch (InvocationTargetException e) { - if (e.getTargetException() instanceof InstantiationException){ - Class sup = iself.instclass.proxyClass.getSuperclass(); - String msg = "Constructor failed for Java superclass"; - if (sup != null) - msg += " " + sup.getName(); - throw Py.TypeError(msg); - } - else throw Py.JavaError(e); - } - catch (Throwable t) { - throw Py.JavaError(t); - } - } - finally { - ts.popInitializingProxy(); - } + constructProxy(self, (Constructor<?>)method, callData.getArgsArray(), javaClass); - iself.javaProxy = jself; - // Do setattr's for keyword args int offset = args.length; - for (int i=0; i<nkeywords; i++) { - iself.__setattr__(keywords[i], allArgs[i+offset]); + for (int i = 0; i < nkeywords; i++) { + self.__setattr__(keywords[i], allArgs[i + offset]); } return Py.None; } @@ -209,14 +148,44 @@ if (args.length < 1) { throw Py.TypeError("constructor requires self argument"); } - PyObject[] newArgs = new PyObject[args.length-1]; + PyObject[] newArgs = new PyObject[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, newArgs.length); - return __call__(args[0], newArgs, keywords); } + protected void constructProxy(PyObject obj, Constructor<?> ctor, Object[] args, Class<?> proxy) { + // Do the actual constructor call + Object jself = null; + ThreadState ts = Py.getThreadState(); + try { + if (obj instanceof PyInstance) { + ts.pushInitializingProxy((PyInstance)obj); + } + try { + jself = ctor.newInstance(args); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof InstantiationException) { + Class<?> sup = proxy.getSuperclass(); + String msg = "Constructor failed for Java superclass"; + if (sup != null) { + msg += " " + sup.getName(); + } + throw Py.TypeError(msg); + } else + throw Py.JavaError(e); + } catch (Throwable t) { + throw Py.JavaError(t); + } + } finally { + if (obj instanceof PyInstance) { + ts.popInitializingProxy(); + } + } + obj.javaProxy = jself; + } + public String toString() { - //printArgs(); - return "<java constructor "+__name__+" "+Py.idstr(this)+">"; + // printArgs(); + return "<java constructor " + __name__ + " " + Py.idstr(this) + ">"; } } Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-10-27 03:08:48 UTC (rev 5515) +++ trunk/jython/src/org/python/core/PyType.java 2008-10-27 03:09:47 UTC (rev 5516) @@ -279,7 +279,7 @@ return newobj; } - protected void fillDict(Class<?> base) { + protected void fillDict() { if (Py.BOOTSTRAP_TYPES.contains(underlying_class)) { return; } @@ -295,8 +295,13 @@ private static void fillInMRO(PyType type, Class<?> base) { PyType[] mro; - if (base == Object.class) { - mro = new PyType[] {type}; + + if (base == Object.class || base == null) { + if (type.underlying_class == Object.class) { + mro = new PyType[] {type, PyObject.TYPE}; + } else { + mro = new PyType[] {type}; + } } else { PyType baseType = fromClass(base); mro = new PyType[baseType.mro.length + 1]; @@ -923,7 +928,7 @@ newtype.underlying_class = c; newtype.builtin = true; fillInMRO(newtype, base); // basic mro, base, bases - newtype.fillDict(base); + newtype.fillDict(); return newtype; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-11-05 02:39:32
|
Revision: 5542 http://jython.svn.sourceforge.net/jython/?rev=5542&view=rev Author: leosoto Date: 2008-11-05 02:39:25 +0000 (Wed, 05 Nov 2008) Log Message: ----------- Fixing mangling of multibyte characters before parsing PyUnicode input (as described on <http://www.nabble.com/Parsing-and-non-ASCII-Input-td19007415.html>). This doesn't completely solve the parsing problems with unicode input because org.python.antlr.GrammarActions#extractStrings is not aware of the 'current' input encoding yet. But it is a step forward. Refs: #1062 Modified Paths: -------------- trunk/jython/src/org/python/core/ParserFacade.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2008-10-31 22:06:00 UTC (rev 5541) +++ trunk/jython/src/org/python/core/ParserFacade.java 2008-11-05 02:39:25 UTC (rev 5542) @@ -7,7 +7,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.LineNumberReader; import java.io.Reader; +import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -32,14 +34,13 @@ import org.python.core.io.StreamIO; import org.python.core.io.TextIOInputStream; import org.python.core.io.UniversalIOWrapper; -import org.python.core.util.StringUtil; /** * Facade for the classes in the org.python.antlr package. */ public class ParserFacade { - + private static int MARK_LIMIT = 100000; private ParserFacade() {} @@ -70,7 +71,7 @@ reader = null; } } - + if (t instanceof ParseException) { ParseException e = (ParseException)t; PythonTree node = (PythonTree)e.node; @@ -90,76 +91,87 @@ else return Py.JavaError(t); } + /** + * Internal parser entry point. + * + * Users of this method should call fixParseError on any Throwable thrown + * from it, to translate ParserExceptions into PySyntaxErrors or + * PyIndentationErrors. + */ + private static modType parse(BufferedReader reader, + String kind, + String filename, + CompilerFlags cflags) throws Throwable { + reader.mark(MARK_LIMIT); // We need the ability to move back on the + // reader, for the benefit of fixParseError and + // validPartialSentence + if (kind.equals("eval")) { + CharStream cs = new NoCloseReaderStream(reader); + ExpressionParser e = new ExpressionParser(cs, filename); + return e.parse(); + } else if (kind.equals("single")) { + InteractiveParser i = new InteractiveParser(reader, filename); + return i.parse(); + } else if (kind.equals("exec")) { + CharStream cs = new NoCloseReaderStream(reader); + ModuleParser g = new ModuleParser(cs, filename); + return g.file_input(); + } else { + throw Py.ValueError("parse kind must be eval, exec, or single"); + } + } + public static modType parse(InputStream stream, String kind, String filename, CompilerFlags cflags) { - //FIXME: npe? - BufferedReader bufreader = null; - modType node = null; + BufferedReader bufReader = null; try { - if (kind.equals("eval")) { - bufreader = prepBufreader(stream, cflags, filename); - CharStream cs = new NoCloseReaderStream(bufreader); - ExpressionParser e = new ExpressionParser(cs, filename); - node = e.parse(); - } else if (kind.equals("single")) { - bufreader = prepBufreader(stream, cflags, filename); - InteractiveParser i = new InteractiveParser(bufreader, filename); - node = i.parse(); - } else if (kind.equals("exec")) { - bufreader = prepBufreader(stream, cflags, filename); - CharStream cs = new NoCloseReaderStream(bufreader); - ModuleParser g = new ModuleParser(cs, filename); - node = g.file_input(); - } else { - throw Py.ValueError("parse kind must be eval, exec, or single"); - } + // prepBufReader takes care of encoding detection and universal + // newlines: + bufReader = prepBufreader(stream, cflags, filename); + return parse(bufReader, kind, filename, cflags ); } catch (Throwable t) { - throw fixParseError(bufreader, t, filename); + throw fixParseError(bufReader, t, filename); } finally { - try { - if (bufreader != null) { - bufreader.close(); - } - } catch (IOException i) { - //XXX - } + close(bufReader); } - return node; } + public static modType parse(String string, + String kind, + String filename, + CompilerFlags cflags) { + BufferedReader bufReader = null; + try { + bufReader = prepBufReader(string); + return parse(bufReader, kind, filename, cflags); + } catch (Throwable t) { + throw fixParseError(bufReader, t, filename); + } finally { + close(bufReader); + } + } + public static modType partialParse(String string, String kind, String filename, CompilerFlags cflags, boolean stdprompt) { - ByteArrayInputStream istream = new ByteArrayInputStream( - StringUtil.toBytes(string)); - //FIXME: npe? - BufferedReader bufreader = null; - modType node = null; + // XXX: What's the idea of the stdprompt argument? + BufferedReader reader = null; try { - if (kind.equals("single")) { - bufreader = prepBufreader(istream, cflags, filename); - InteractiveParser i = new InteractiveParser(bufreader, filename); - node = i.parse(); - } else if (kind.equals("eval")) { - bufreader = prepBufreader(istream, cflags, filename); - CharStream cs = new NoCloseReaderStream(bufreader); - ExpressionParser e = new ExpressionParser(cs, filename); - node = e.parse(); - } else { - throw Py.ValueError("parse kind must be eval, exec, or single"); - } + reader = prepBufReader(string); + return parse(reader, kind, filename, cflags); } catch (Throwable t) { - PyException p = fixParseError(bufreader, t, filename); - if (validPartialSentence(bufreader, kind, filename)) { + PyException p = fixParseError(reader, t, filename); + if (validPartialSentence(reader, kind, filename)) { return null; } throw p; + } finally { + close(reader); } - return node; } private static boolean validPartialSentence(BufferedReader bufreader, String kind, String filename) { @@ -182,6 +194,7 @@ } } catch (Exception e) { + System.out.println(e); return lexer.eofWhileNested; } return true; @@ -202,8 +215,6 @@ } else if (cflags != null && cflags.encoding != null) { encoding = cflags.encoding; } - } else if (cflags.source_is_utf8) { - throw new ParseException("encoding declaration in Unicode string"); } // Enable universal newlines mode on the input @@ -229,13 +240,29 @@ throw Py.SystemError("Java couldn't find the ISO-8859-1 encoding"); } } - + BufferedReader bufreader = new BufferedReader(reader); - - bufreader.mark(MARK_LIMIT); return bufreader; } + private static BufferedReader prepBufReader(String string) throws IOException { + BufferedReader bufReader; + + // LineNumberReader takes care of universal newlines + bufReader = new LineNumberReader(new StringReader(string)); + + // If the input is a decoded string (implied from the String argument + // for prepBufReader), it can't have an encoding declaration. + bufReader.mark(MARK_LIMIT); + if (findEncoding(bufReader) != null) { + throw new ParseException("encoding declaration in Unicode string"); + } + bufReader.reset(); + + return bufReader; + } + + /** * Check for a BOM mark at the begginning of stream. If there is a BOM * mark, advance the stream passed it. If not, reset() to start at the @@ -262,12 +289,31 @@ } stream.reset(); return false; - } + } private static String readEncoding(InputStream stream) throws IOException { stream.mark(MARK_LIMIT); String encoding = null; BufferedReader br = new BufferedReader(new InputStreamReader(stream), 512); + encoding = findEncoding(br); + // XXX: reset() can still raise an IOException if a line exceeds our large mark + // limit + stream.reset(); + return encodingMap(encoding); + } + + /** + * Reads the first two lines of the reader, searching for an encoding + * declaration. + * + * Note that reseting the reader (if needed) is responsibility of the caller. + * + * @return The declared encoding, or null if no encoding declaration is + * found + */ + private static String findEncoding(BufferedReader br) + throws IOException { + String encoding = null; for (int i = 0; i < 2; i++) { String strLine = br.readLine(); if (strLine == null) { @@ -279,10 +325,7 @@ break; } } - // XXX: reset() can still raise an IOException if a line exceeds our large mark - // limit - stream.reset(); - return encodingMap(encoding); + return encoding; } private static String encodingMap(String encoding) { @@ -308,4 +351,14 @@ return null; } + private static void close(BufferedReader reader) { + try { + if (reader != null) { + reader.close(); + } + } catch (IOException i) { + // XXX: Log the error? + } + } + } Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-10-31 22:06:00 UTC (rev 5541) +++ trunk/jython/src/org/python/core/Py.java 2008-11-05 02:39:25 UTC (rev 5542) @@ -16,6 +16,7 @@ import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; +import java.util.Arrays; import java.util.Calendar; import java.util.HashSet; import java.util.Set; @@ -357,7 +358,7 @@ public static PyObject ImportWarning; public static void ImportWarning(String message) { - warning(ImportWarning, message); + warning(ImportWarning, message); } public static PyObject UnicodeWarning; @@ -1610,34 +1611,31 @@ } // w/o compiler-flags - public static PyObject compile(modType node, String filename) { - return compile(node, getName(), filename); - } - - public static PyObject compile(modType node, String name, - String filename) { - return compile(node, name, filename, true, false); - } - - public static PyObject compile(modType node, String name, - String filename, - boolean linenumbers, - boolean printResults) { - return compile_flags(node, name, filename, linenumbers, - printResults, null); - } - - public static PyObject compile(InputStream istream, String filename, - String kind) { + public static PyObject compile(InputStream istream, String filename, String kind) { return compile_flags(istream, filename, kind, null); } - // with compiler-flags - public static PyObject compile_flags(modType node, String name, - String filename, - boolean linenumbers, - boolean printResults, CompilerFlags cflags) { + /** + * Entry point for compiling modules. + * + * @param node Module node, coming from the parsing process + * @param name Internal name for the compiled code. Typically generated by + * calling {@link #getName()}. + * @param filename Source file name + * @param linenumbers True to track source line numbers on the generated + * code + * @param printResults True to call the sys.displayhook on the result of + * the code + * @param cflags Compiler flags + * @return Code object for the compiled module + */ + public static PyObject compile_flags(modType node, String name, String filename, + boolean linenumbers, boolean printResults, + CompilerFlags cflags) { try { + if (cflags != null && cflags.only_ast) { + return Py.java2py(node); + } ByteArrayOutputStream ostream = new ByteArrayOutputStream(); Module.compile(node, ostream, name, filename, linenumbers, printResults, false, cflags); @@ -1650,62 +1648,75 @@ } } + public static PyObject compile_flags(modType node, String filename, + String kind, CompilerFlags cflags) { + return Py.compile_flags(node, getName(), filename, true, + kind.equals("single"), cflags); + } + + /** + * Compiles python source code coming from a file or another external stream + */ public static PyObject compile_flags(InputStream istream, String filename, - String kind,CompilerFlags cflags) - { + String kind, CompilerFlags cflags) { modType node = ParserFacade.parse(istream, kind, filename, cflags); - if (cflags != null && cflags.only_ast) { - return Py.java2py(node); - } - - boolean printResults = false; - if (kind.equals("single")) { - printResults = true; - } - return Py.compile_flags(node, getName(), filename, true, printResults, cflags); + return Py.compile_flags(node, filename, kind, cflags); } - public static PyObject compile_flags(modType node, String filename, - String kind, CompilerFlags cflags) { - boolean printResults = false; - if (kind.equals("single")) { - printResults = true; + /** + * Compiles python source code coming from decoded Strings. + * + * DO NOT use this for PyString input. Use + * {@link #compile_flags(byte[], String, String, CompilerFlags)} instead. + */ + public static PyObject compile_flags(String data, String filename, + String kind, CompilerFlags cflags) { + if (data.contains("\0")) { + throw Py.TypeError("compile() expected string without null bytes"); } - return Py.compile_flags(node, getName(), filename, true, printResults, cflags); + if (cflags != null && cflags.dont_imply_dedent) { + data += "\n"; + } else { + data += "\n\n"; + } + modType node = ParserFacade.parse(data, kind, filename, cflags); + return Py.compile_flags(node, filename, kind, cflags); } - public static PyObject compile_flags(String data, - String filename, - String kind, - CompilerFlags cflags) { - - if (data.contains("\0")) { - throw Py.TypeError("compile() expected string without null bytes"); + /** + * Compiles python source code coming from bytestrings + */ + public static PyObject compile_flags(byte[] bytes, String filename, + String kind, CompilerFlags cflags) { + for(int i = 0; i < bytes.length; i++) { + if (bytes[i] == 0) { + throw Py.TypeError("compile() expected string without null bytes"); + } } - - byte[] bytes; + byte[] data; if (cflags != null && cflags.dont_imply_dedent) { - bytes = StringUtil.toBytes(data + "\n"); + data = new byte[bytes.length + 1]; + System.arraycopy(bytes, 0, data, 0, bytes.length); + data[data.length - 1] = '\n'; } else { - bytes = StringUtil.toBytes(data + "\n\n"); + data = new byte[bytes.length + 2]; + System.arraycopy(bytes, 0, data, 0, bytes.length); + data[data.length - 1] = data[data.length - 2] = '\n'; } - return Py.compile_flags(new ByteArrayInputStream(bytes), - filename, - kind, - cflags); + modType node = ParserFacade.parse(new ByteArrayInputStream(data), kind, + filename, cflags); + return Py.compile_flags(node, filename, kind, cflags); } - public static PyObject compile_command_flags(String string, - String filename, String kind, CompilerFlags cflags, boolean stdprompt) { + public static PyObject compile_command_flags(String string, String filename, + String kind, CompilerFlags cflags, boolean stdprompt) { modType node = ParserFacade.partialParse(string + "\n", kind, filename, - cflags, stdprompt); - + cflags, stdprompt); if (node == null) { return Py.None; } - return Py.compile_flags(node, Py.getName(), filename, true, true, - cflags); + return Py.compile_flags(node, Py.getName(), filename, true, true, cflags); } public static PyObject[] unpackSequence(PyObject obj, int length) { Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-10-31 22:06:00 UTC (rev 5541) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-11-05 02:39:25 UTC (rev 5542) @@ -1,6 +1,8 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.util.Iterator; import java.util.Map; @@ -281,7 +283,7 @@ if (args[0] instanceof PyUnicode) { flags += PyTableCode.PyCF_SOURCE_IS_UTF8; } - return __builtin__.compile(args[0].toString(), args[1].toString(), args[2].toString(), flags, dont_inherit); + return __builtin__.compile((PyString)args[0], args[1].toString(), args[2].toString(), flags, dont_inherit); case 29: return __builtin__.map(args); case 43: @@ -412,7 +414,7 @@ } public static PyObject apply(PyObject o) { - return o.__call__(); + return o.__call__(); } public static PyObject apply(PyObject o, PyObject args) { @@ -473,19 +475,29 @@ throw Py.TypeError("number coercion failed"); } - public static PyObject compile(String data, String filename, String kind) { - return Py.compile_flags(data, filename, kind, Py.getCompilerFlags()); + public static PyObject compile(PyString data, String filename, String kind) { + if (data instanceof PyUnicode) { + return Py.compile_flags(data.toString(), filename, kind, Py.getCompilerFlags()); + } else { + return Py.compile_flags(data.toBytes(), filename, kind, Py.getCompilerFlags()); + } } public static PyObject compile(modType node, String filename, String kind) { return Py.compile_flags(node, filename, kind, Py.getCompilerFlags()); } - public static PyObject compile(String data, String filename, String kind, int flags, boolean dont_inherit) { + public static PyObject compile(PyString data, String filename, String kind, int flags, boolean dont_inherit) { if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { throw Py.ValueError("compile(): unrecognised flags"); } - return Py.compile_flags(data, filename, kind, Py.getCompilerFlags(flags, dont_inherit)); + if (data instanceof PyUnicode) { + return Py.compile_flags(data.toString(), filename, kind, + Py.getCompilerFlags(flags, dont_inherit)); + } else { + return Py.compile_flags(data.toBytes(), filename, kind, + Py.getCompilerFlags(flags, dont_inherit)); + } } public static PyObject compile(modType node, String filename, String kind, int flags, boolean dont_inherit) { @@ -550,7 +562,7 @@ code = (PyCode) o; } else { if (o instanceof PyString) { - code = (PyCode)compile(o.toString(), "<string>", "eval"); + code = (PyCode)compile((PyString)o, "<string>", "eval"); } else { throw Py.TypeError("eval: argument 1 must be string or code object"); } @@ -1164,7 +1176,7 @@ } public static PyObject reload(PySystemState o) { - // reinitialize methods + // reinitialize methods o.reload(); return o; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Frank W. <fwi...@gm...> - 2008-11-05 19:11:19
|
On Tue, Nov 4, 2008 at 9:39 PM, <le...@us...> wrote: > Log Message: > ----------- > Fixing mangling of multibyte characters before parsing PyUnicode input (as described on <http://www.nabble.com/Parsing-and-non-ASCII-Input-td19007415.html>). This doesn't completely solve the parsing problems with unicode input because org.python.antlr.GrammarActions#extractStrings is not aware of the 'current' input encoding yet. But it is a step forward. Refs: #1062 Hey Leo, If you haven't started on making GrammarActions aware of the current input encoding, I can take a look at that. -Frank |
From: Philip J. <pj...@un...> - 2008-11-05 21:16:55
|
On Nov 5, 2008, at 11:11 AM, Frank Wierzbicki wrote: > On Tue, Nov 4, 2008 at 9:39 PM, <le...@us...> > wrote: >> Log Message: >> ----------- >> Fixing mangling of multibyte characters before parsing PyUnicode >> input (as described on <http://www.nabble.com/Parsing-and-non-ASCII-Input-td19007415.html >> >). This doesn't completely solve the parsing problems with unicode >> input because org.python.antlr.GrammarActions#extractStrings is not >> aware of the 'current' input encoding yet. But it is a step >> forward. Refs: #1062 > > Hey Leo, > > If you haven't started on making GrammarActions aware of the current > input encoding, I can take a look at that. Frank - No need, I'm already pretty far along on that. -- Philip Jenvey |
From: <pj...@us...> - 2008-11-10 00:36:47
|
Revision: 5560 http://jython.svn.sourceforge.net/jython/?rev=5560&view=rev Author: pjenvey Date: 2008-11-10 00:36:41 +0000 (Mon, 10 Nov 2008) Log Message: ----------- pretty up SyntaxError surrounding output: o don't initialize an exception traceback if there's no frame o port over CPython's pythonrun::print_error_text o always include a trailing nl in SyntaxError text like CPython Modified Paths: -------------- trunk/jython/src/org/python/core/ParserFacade.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyException.java Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2008-11-09 20:15:15 UTC (rev 5559) +++ trunk/jython/src/org/python/core/ParserFacade.java 2008-11-10 00:36:41 UTC (rev 5560) @@ -40,16 +40,16 @@ private ParserFacade() {} - static String getLine(BufferedReader reader, int line) { + private static String getLine(BufferedReader reader, int line) { if (reader == null) { return ""; } String text = null; try { - for(int i=0; i < line; i++) { + for (int i = 0; i < line; i++) { text = reader.readLine(); } - return text; + return text == null ? text : text + "\n"; } catch (IOException ioe) { } return text; Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-11-09 20:15:15 UTC (rev 5559) +++ trunk/jython/src/org/python/core/Py.java 2008-11-10 00:36:41 UTC (rev 5560) @@ -1007,18 +1007,23 @@ stderr.print(((PyTraceback) tb).dumpStack()); } if (__builtin__.isinstance(value, Py.SyntaxError)) { - stderr.println(" File \"" + value.__findattr__("filename") + - "\", line " + value.__findattr__("lineno")); + PyObject filename = value.__findattr__("filename"); PyObject text = value.__findattr__("text"); - if (text != Py.None && text.__len__() != 0) { - stderr.println("\t" + text); - String space = "\t"; - int col = ((PyInteger) value.__findattr__("offset").__int__()).getValue(); - for (int j = 1; j < col; j++) { - space = space + " "; - } - stderr.println(space + "^"); + PyObject lineno = value.__findattr__("lineno"); + stderr.print(" File \""); + stderr.print(filename == Py.None || filename == null ? + "<string>" : filename.toString()); + stderr.print("\", line "); + stderr.print(lineno == null ? Py.newString("0") : lineno); + stderr.print("\n"); + if (text != Py.None && text != null && text.__len__() != 0) { + printSyntaxErrorText(stderr, value.__findattr__("offset").asInt(), + text.toString()); } + value = value.__findattr__("msg"); + if (value == null) { + value = Py.None; + } } if (value instanceof PyJavaInstance) { @@ -1031,6 +1036,56 @@ stderr.println(formatException(type, value, tb)); } + /** + * Print the two lines showing where a SyntaxError was caused. + * + * @param out StdoutWrapper to print to + * @param offset the offset into text + * @param text a source code String line + */ + private static void printSyntaxErrorText(StdoutWrapper out, int offset, String text) { + if (offset >= 0) { + if (offset > 0 && offset == text.length()) { + offset--; + } + + // Eat lines if the offset is on a subsequent line + while (true) { + int nl = text.indexOf("\n"); + if (nl == -1 || nl >= offset) { + break; + } + offset -= nl + 1; + text = text.substring(nl + 1, text.length()); + } + + // lstrip + int i = 0; + for (; i < text.length(); i++) { + char c = text.charAt(i); + if (c != ' ' && c != '\t') { + break; + } + offset--; + } + text = text.substring(i, text.length()); + } + + out.print(" "); + out.print(text); + if (text.length() == 0 || !text.endsWith("\n")) { + out.print("\n"); + } + if (offset == -1) { + return; + } + out.print(" "); + for (offset--; offset > 0; offset--) { + out.print(" "); + } + out.print("^\n"); + } + static String formatException(PyObject type, PyObject value, PyObject tb) { StringBuffer buf = new StringBuffer(); Modified: trunk/jython/src/org/python/core/PyException.java =================================================================== --- trunk/jython/src/org/python/core/PyException.java 2008-11-09 20:15:15 UTC (rev 5559) +++ trunk/jython/src/org/python/core/PyException.java 2008-11-10 00:36:41 UTC (rev 5560) @@ -44,14 +44,17 @@ this.type = type; this.value = value; - if (traceback == null) { + if (traceback != null) { + this.traceback = traceback; + } else { PyFrame frame = Py.getFrame(); - traceback = new PyTraceback(frame); - if (frame != null && frame.tracefunc != null) { - frame.tracefunc = frame.tracefunc.traceException(frame, this); + if (frame != null) { + this.traceback = new PyTraceback(frame); + if (frame.tracefunc != null) { + frame.tracefunc = frame.tracefunc.traceException(frame, this); + } } } - this.traceback = traceback; } public PyException(PyObject type, String value) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-23 01:57:14
|
Revision: 5606 http://jython.svn.sourceforge.net/jython/?rev=5606&view=rev Author: pjenvey Date: 2008-11-23 01:57:09 +0000 (Sun, 23 Nov 2008) Log Message: ----------- o allow open({In,Out}putStream) but with a deprecation warning. make open a function o add optional bufsize args to FileUtil.wrap fixes #1171 Modified Paths: -------------- trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/__builtin__.java trunk/jython/src/org/python/core/util/FileUtil.java Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2008-11-23 00:46:06 UTC (rev 5605) +++ trunk/jython/src/org/python/core/PyFile.java 2008-11-23 01:57:09 UTC (rev 5606) @@ -96,13 +96,19 @@ } /** - * Creates a file object wrapping the given <code>InputStream</code>. The builtin methods - * <code>file</code> and <code>open</code> don't expose this functionality as it isn't available - * to regular Python code. To wrap an InputStream in a file from Python, use + * Creates a file object wrapping the given <code>InputStream</code>. The builtin + * method <code>file</code> doesn't expose this functionality (<code>open</code> does + * albeit deprecated) as it isn't available to regular Python code. To wrap an + * InputStream in a file from Python, use + * {@link FileUtil#wrap(InputStream, int)} * {@link FileUtil#wrap(InputStream)} */ + public PyFile(InputStream istream, int bufsize) { + this(istream, "<Java InputStream '" + istream + "' as file>", "r", bufsize, true); + } + public PyFile(InputStream istream) { - this(istream, "<Java InputStream '" + istream + "' as file>", "r", -1, true); + this(istream, -1); } PyFile(OutputStream ostream, String name, String mode, int bufsize, boolean closefd) { @@ -111,13 +117,19 @@ } /** - * Creates a file object wrapping the given <code>OutputStream</code>. The builtin methods - * <code>file</code> and <code>open</code> don't expose this functionality as it isn't available - * to regular Python code. To wrap an OutputStream in a file from Python, use + * Creates a file object wrapping the given <code>OutputStream</code>. The builtin + * method <code>file</code> doesn't expose this functionality (<code>open</code> does + * albeit deprecated) as it isn't available to regular Python code. To wrap an + * OutputStream in a file from Python, use + * {@link FileUtil#wrap(OutputStream, int)} * {@link FileUtil#wrap(OutputStream)} */ + public PyFile(OutputStream ostream, int bufsize) { + this(ostream, "<Java OutputStream '" + ostream + "' as file>", "w", bufsize, true); + } + public PyFile(OutputStream ostream) { - this(ostream, "<Java OutputStream '" + ostream + "' as file>", "w", -1, true); + this(ostream, -1); } public PyFile(String name, String mode, int bufsize) { Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-11-23 00:46:06 UTC (rev 5605) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-11-23 01:57:09 UTC (rev 5606) @@ -1,6 +1,8 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Iterator; import java.util.Map; @@ -305,7 +307,6 @@ dict.__setitem__("unicode", PyUnicode.TYPE); dict.__setitem__("basestring", PyBaseString.TYPE); dict.__setitem__("file", PyFile.TYPE); - dict.__setitem__("open", PyFile.TYPE); dict.__setitem__("slice", PySlice.TYPE); dict.__setitem__("xrange", PyXRange.TYPE); @@ -364,6 +365,7 @@ dict.__setitem__("vars", new BuiltinFunctions("vars", 41, 0, 1)); dict.__setitem__("zip", new BuiltinFunctions("zip", 43, 0, -1)); dict.__setitem__("compile", new CompileFunction()); + dict.__setitem__("open", new OpenFunction()); dict.__setitem__("reversed", new BuiltinFunctions("reversed", 45, 1)); dict.__setitem__("__import__", new ImportFunction()); dict.__setitem__("sorted", new SortedFunction()); @@ -1567,3 +1569,31 @@ return (modType)node; } } + +class OpenFunction extends PyBuiltinFunction { + OpenFunction() { + super("open", "Open a file using the file() type, returns a file object. This is the\n" + + "preferred way to open a file."); + } + + private static final String warning = + "Passing an Input/OutputStream to open is deprecated, use " + + "org.python.core.util.FileUtil.wrap(stream[, bufsize]) instead."; + + public PyObject __call__(PyObject args[], String kwds[]) { + ArgParser ap = new ArgParser("file", args, kwds, new String[] {"name", "mode", "bufsize"}, + 1); + PyObject obj = ap.getPyObject(0); + if (obj instanceof PyJavaInstance) { + int bufsize = ap.getInt(2, -1); + if (obj.javaProxy instanceof InputStream) { + Py.warning(Py.DeprecationWarning, warning); + return new PyFile((InputStream)obj.javaProxy, bufsize); + } else if (obj.javaProxy instanceof OutputStream) { + Py.warning(Py.DeprecationWarning, warning); + return new PyFile((OutputStream)obj.javaProxy, bufsize); + } + } + return PyFile.TYPE.__call__(args, kwds); + } +} Modified: trunk/jython/src/org/python/core/util/FileUtil.java =================================================================== --- trunk/jython/src/org/python/core/util/FileUtil.java 2008-11-23 00:46:06 UTC (rev 5605) +++ trunk/jython/src/org/python/core/util/FileUtil.java 2008-11-23 01:57:09 UTC (rev 5606) @@ -14,17 +14,31 @@ public class FileUtil { /** + * Creates a PyFile that reads from the given <code>InputStream</code> with bufsize. + */ + public static PyFile wrap(InputStream is, int bufsize) { + return new PyFile(is, bufsize); + } + + /** * Creates a PyFile that reads from the given <code>InputStream</code>. */ public static PyFile wrap(InputStream is) { - return new PyFile(is); + return wrap(is, -1); } /** + * Creates a PyFile that writes to the given <code>OutputStream</code> with bufsize. + */ + public static PyFile wrap(OutputStream os, int bufsize) { + return new PyFile(os, bufsize); + } + + /** * Creates a PyFile that writes to the given <code>OutputStream</code>. */ public static PyFile wrap(OutputStream os) { - return new PyFile(os); + return wrap(os, -1); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-31 21:56:51
|
Revision: 5822 http://jython.svn.sourceforge.net/jython/?rev=5822&view=rev Author: cgroves Date: 2008-12-31 21:56:48 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Patch from David Morley to rename set in PySequence to pyset such that PySequence can be subclassed by List without requiring a type on List. See http://www.nabble.com/PySequence-set-method-incompatible-with-List%3CPyObject%3E--to14964846.html Modified Paths: -------------- trunk/jython/src/org/python/core/AstList.java trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PySequence.java trunk/jython/src/org/python/core/PySequenceList.java Modified: trunk/jython/src/org/python/core/AstList.java =================================================================== --- trunk/jython/src/org/python/core/AstList.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/AstList.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -454,10 +454,6 @@ return new AstList(newList); } - protected void set(int i, PyObject value) { - data.set(i, value); - } - protected void setslice(int start, int stop, int step, PyObject value) { if(stop < start) { stop = start; @@ -587,13 +583,12 @@ return adapter.ast2py(data.get(index)); } - public PyObject pyset(int index, PyObject element) { + public void pyset(int index, PyObject element) { if (adapter == null) { - return (PyObject)data.set(index, element); + data.set(index, element); } Object o = adapter.py2ast(element); data.set(index, o); - return element; } public Object remove(int index) { Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/PyArray.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -1312,6 +1312,10 @@ * value to set the element to */ public void set(int i, PyObject value) { + pyset(i, value); + } + + protected void pyset(int i, PyObject value) { if ("u".equals(typecode)) { Array.setInt(data, i, getCodePoint(value)); return; Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/PyList.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -116,10 +116,6 @@ remove(start, stop); } - protected void set(int i, PyObject value) { - list.pyset(i, value); - } - protected void setslice(int start, int stop, int step, PyObject value) { if(stop < start) { stop = start; Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/PySequence.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -63,7 +63,7 @@ * @param value * the value to set this element to. */ - protected void set(int index, PyObject value) { + protected void pyset(int index, PyObject value) { throw Py.TypeError("can't assign to immutable object"); } @@ -399,7 +399,7 @@ @Override public void setItem(int idx, PyObject value) { - set(idx, value); + pyset(idx, value); } @Override Modified: trunk/jython/src/org/python/core/PySequenceList.java =================================================================== --- trunk/jython/src/org/python/core/PySequenceList.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/PySequenceList.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -99,8 +99,8 @@ return list.pyget(index); } - public PyObject pyset(int index, PyObject element) { - return list.pyset(index, element); + public void pyset(int index, PyObject element) { + list.pyset(index, element); } public Object remove(int index) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-01 00:37:53
|
Revision: 5827 http://jython.svn.sourceforge.net/jython/?rev=5827&view=rev Author: cgroves Date: 2009-01-01 00:37:49 +0000 (Thu, 01 Jan 2009) Log Message: ----------- Remove the last vestiges of lazily loaded classes. Will reevaluate their presence if performance problems come up. Modified Paths: -------------- trunk/jython/src/org/python/core/PyJavaPackage.java trunk/jython/src/org/python/core/packagecache/PackageManager.java trunk/jython/src/org/python/core/packagecache/PathPackageManager.java Modified: trunk/jython/src/org/python/core/PyJavaPackage.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaPackage.java 2009-01-01 00:35:27 UTC (rev 5826) +++ trunk/jython/src/org/python/core/PyJavaPackage.java 2009-01-01 00:37:49 UTC (rev 5827) @@ -91,13 +91,11 @@ return ret; } - public PyObject addLazyClass(String name) { - // TODO - make lazy PyJavaType - return null; - } - - /** Add statically known classes. - * @param classes their names as comma-separated string + /** + * Add statically known classes. + * + * @param classes + * their names as comma-separated string */ public void addPlaceholders(String classes) { StringTokenizer tok = new StringTokenizer(classes, ",@"); @@ -114,11 +112,10 @@ } /** - * Used for 'from xyz import *', dynamically dir pkg filling up __dict__. - * It uses {@link PackageManager#doDir} implementation furnished by - * the control package manager with instatiate true. The package - * manager should lazily load classes with {@link #addLazyClass} in - * the package. + * Used for 'from xyz import *', dynamically dir pkg filling up __dict__. It uses + * {@link PackageManager#doDir} implementation furnished by the control package manager with + * instantiate true. The package manager should load classes with {@link #addClass} in the + * package. * * @return list of member names */ Modified: trunk/jython/src/org/python/core/packagecache/PackageManager.java =================================================================== --- trunk/jython/src/org/python/core/packagecache/PackageManager.java 2009-01-01 00:35:27 UTC (rev 5826) +++ trunk/jython/src/org/python/core/packagecache/PackageManager.java 2009-01-01 00:37:49 UTC (rev 5827) @@ -3,6 +3,7 @@ package org.python.core.packagecache; +import org.python.core.Py; import org.python.core.PyJavaPackage; import org.python.core.PyList; import org.python.core.PyObject; @@ -33,7 +34,7 @@ /** * Dynamically check if pkg.name exists as java pkg in the controlled * hierarchy. Should be overriden. - * + * * @param pkg parent pkg name * @param name candidate name * @return true if pkg exists @@ -43,7 +44,7 @@ /** * Reports the specified package content names. Should be overriden. Used by * {@link PyJavaPackage#__dir__} and {@link PyJavaPackage#fillDir}. - * + * * @return resulting list of names (PyList of PyString) * @param jpkg queried package * @param instantiate if true then instatiate reported names in package dict @@ -55,7 +56,7 @@ /** * Append a directory to the list of directories searched for java packages * and java classes. - * + * * @param dir A directory. */ public abstract void addDirectory(java.io.File dir); @@ -63,7 +64,7 @@ /** * Append a directory to the list of directories searched for java packages * and java classes. - * + * * @param dir A directory name. */ public abstract void addJarDir(String dir, boolean cache); @@ -71,7 +72,7 @@ /** * Append a jar file to the list of locations searched for java packages and * java classes. - * + * * @param jarfile A directory name. */ public abstract void addJar(String jarfile, boolean cache); @@ -102,12 +103,12 @@ return ret; } - PyList clsNames = cls.keys(); - for (int i = 0; i < clsNames.__len__(); i++) { - PyObject name = clsNames.pyget(i); - if (!dict.has_key(name)) - jpkg.addLazyClass(name.toString()); + for (PyObject pyname : cls.keys().asIterable()) { + if (!dict.has_key(pyname)) { + String name = pyname.toString(); + jpkg.addClass(name, Py.findClass(name)); + } } return dict.keys(); @@ -149,7 +150,7 @@ * Creates package/updates statically known classes info. Uses * {@link PyJavaPackage#addPackage(java.lang.String, java.lang.String) }, * {@link PyJavaPackage#addPlaceholders}. - * + * * @param name package name * @param classes comma-separated string * @param jarfile involved jarfile; can be null @@ -184,11 +185,11 @@ //Empty or 1 byte file. return -1; } - //int minor = + //int minor = istream.readShort(); //int major = istream.readShort(); - + // Check versions??? // System.out.println("magic: "+magic+", "+major+", "+minor); int nconstants = istream.readShort(); Modified: trunk/jython/src/org/python/core/packagecache/PathPackageManager.java =================================================================== --- trunk/jython/src/org/python/core/packagecache/PathPackageManager.java 2009-01-01 00:35:27 UTC (rev 5826) +++ trunk/jython/src/org/python/core/packagecache/PathPackageManager.java 2009-01-01 00:37:49 UTC (rev 5827) @@ -164,7 +164,7 @@ if (pkgCand) { jpkg.addPackage(jname); } else { - jpkg.addLazyClass(jname); + jpkg.addClass(jname, Py.findClass(jname)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-01 22:18:16
|
Revision: 5829 http://jython.svn.sourceforge.net/jython/?rev=5829&view=rev Author: fwierzbicki Date: 2009-01-01 21:52:35 +0000 (Thu, 01 Jan 2009) Log Message: ----------- Some __doc__ for super, slice, and list. Modified Paths: -------------- trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PySlice.java trunk/jython/src/org/python/core/PySuper.java Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-01-01 01:13:50 UTC (rev 5828) +++ trunk/jython/src/org/python/core/PyList.java 2009-01-01 21:52:35 UTC (rev 5829) @@ -62,7 +62,7 @@ } @ExposedNew - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list___init___doc) final void list___init__(PyObject[] args, String[] kwds) { ArgParser ap = new ArgParser("list", args, kwds, new String[] {"sequence"}, 0); PyObject seq = ap.getPyObject(0, null); @@ -84,7 +84,7 @@ return list___len__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list___len___doc) final int list___len__() { return size(); } @@ -206,32 +206,32 @@ return new PyList(newArray); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___ne___doc) final PyObject list___ne__(PyObject o) { return seq___ne__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___eq___doc) final PyObject list___eq__(PyObject o) { return seq___eq__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___lt___doc) final PyObject list___lt__(PyObject o) { return seq___lt__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___le___doc) final PyObject list___le__(PyObject o) { return seq___le__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___gt___doc) final PyObject list___gt__(PyObject o) { return seq___gt__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___ge___doc) final PyObject list___ge__(PyObject o) { return seq___ge__(o); } @@ -240,7 +240,7 @@ return list___imul__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___imul___doc) final PyObject list___imul__(PyObject o) { if (!o.isIndex()) { return null; @@ -276,7 +276,7 @@ return list___mul__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___mul___doc) final PyObject list___mul__(PyObject o) { if (!o.isIndex()) { return null; @@ -289,7 +289,7 @@ return list___rmul__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___rmul___doc) final PyObject list___rmul__(PyObject o) { if (!o.isIndex()) { return null; @@ -301,7 +301,7 @@ return list___add__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___add___doc) final PyObject list___add__(PyObject o) { PyList sum = null; if(o instanceof PyList) { @@ -331,6 +331,7 @@ return list___radd__(o); } + //XXX: needs __doc__ @ExposedMethod(type = MethodType.BINARY) final PyObject list___radd__(PyObject o) { // Support adding java.util.List, but prevent adding PyTuple. @@ -348,22 +349,22 @@ return sum; } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list___contains___doc) final boolean list___contains__(PyObject o) { return object___contains__(o); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list___delitem___doc) final void list___delitem__(PyObject index) { seq___delitem__(index); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list___setitem___doc) final void list___setitem__(PyObject o, PyObject def) { seq___setitem__(o, def); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list___getitem___doc) final PyObject list___getitem__(PyObject o) { PyObject ret = seq___finditem__(o); if(ret == null) { @@ -376,22 +377,22 @@ return list___iter__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list___iter___doc) public PyObject list___iter__() { return new PyFastSequenceIter(this); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.list___getslice___doc) final PyObject list___getslice__(PyObject start, PyObject stop, PyObject step) { return seq___getslice__(start, stop, step); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.list___setslice___doc) final void list___setslice__(PyObject start, PyObject stop, PyObject step, PyObject value) { seq___setslice__(start, stop, step, value); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.list___delslice___doc) final void list___delslice__(PyObject start, PyObject stop, PyObject step) { seq___delslice__(start, stop, step); } @@ -407,6 +408,7 @@ return list_toString(); } + //XXX: needs __doc__ @ExposedMethod(names = "__repr__") final String list_toString() { ThreadState ts = Py.getThreadState(); @@ -438,7 +440,7 @@ list_append(o); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list_append_doc) final void list_append(PyObject o) { pyadd(o); gListAllocatedStatus = __len__(); @@ -454,7 +456,7 @@ return list_count(o); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list_count_doc) final int list_count(PyObject o) { int count = 0; PyObject[] array = getArray(); @@ -484,7 +486,7 @@ return list_index(o, start, stop); } - @ExposedMethod(defaults = {"null", "null"}) + @ExposedMethod(defaults = {"null", "null"}, doc = BuiltinDocs.list_index_doc) final int list_index(PyObject o, PyObject start, PyObject stop) { int startInt = start == null ? 0 : PySlice.calculateSliceIndex(start); int stopInt = stop == null ? size() : PySlice.calculateSliceIndex(stop); @@ -529,7 +531,7 @@ list_insert(index, o); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list_insert_doc) final void list_insert(int index, PyObject o) { if(index < 0) { index = Math.max(0, size() + index); @@ -553,7 +555,7 @@ list_remove(o); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list_remove_doc) final void list_remove(PyObject o) { del(_index(o, "list.remove(x): x not in list", 0, size())); gListAllocatedStatus = __len__(); @@ -568,7 +570,7 @@ list_reverse(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list_reverse_doc) final void list_reverse() { PyObject tmp; int n = size(); @@ -599,7 +601,7 @@ return list_pop(n); } - @ExposedMethod(defaults = "-1") + @ExposedMethod(defaults = "-1", doc = BuiltinDocs.list_pop_doc) final PyObject list_pop(int n) { int length = size(); if(length == 0) { @@ -627,7 +629,7 @@ list_extend(o); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list_extend_doc) final void list_extend(PyObject o) { int length = size(); setslice(length, length, 1, o); @@ -638,7 +640,7 @@ return list___iadd__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___iadd___doc) final PyObject list___iadd__(PyObject o) { PyType oType = o.getType(); if (oType == TYPE || oType == PyTuple.TYPE || this == o) { @@ -677,7 +679,7 @@ */ - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list_sort_doc) final void list_sort(PyObject[] args, String[] kwds) { ArgParser ap = new ArgParser("list", args, kwds, new String[]{"cmp", "key", "reverse"}, 0); PyObject cmp = ap.getPyObject(0, Py.None); @@ -703,7 +705,7 @@ return list___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.list___hash___doc) final int list___hash__() { throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName())); } Modified: trunk/jython/src/org/python/core/PySlice.java =================================================================== --- trunk/jython/src/org/python/core/PySlice.java 2009-01-01 01:13:50 UTC (rev 5828) +++ trunk/jython/src/org/python/core/PySlice.java 2009-01-01 21:52:35 UTC (rev 5829) @@ -69,7 +69,7 @@ return slice___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.slice___hash___doc) final int slice___hash__() { throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName())); } @@ -111,7 +111,7 @@ return slice_indices(len); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.slice_indices_doc) final PyObject slice_indices(PyObject len) { int[] indices = indicesEx(len.asIndex(Py.OverflowError)); return new PyTuple(Py.newInteger(indices[0]), Py.newInteger(indices[1]), Modified: trunk/jython/src/org/python/core/PySuper.java =================================================================== --- trunk/jython/src/org/python/core/PySuper.java 2009-01-01 01:13:50 UTC (rev 5828) +++ trunk/jython/src/org/python/core/PySuper.java 2009-01-01 21:52:35 UTC (rev 5829) @@ -110,7 +110,7 @@ return super.__findattr_ex__(name); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.super___getattribute___doc) final PyObject super___getattribute__(PyObject name) { PyObject ret = super___findattr_ex__(asName(name)); if (ret == null) { @@ -123,7 +123,7 @@ return super___get__(obj, type); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.super___get___doc) final PyObject super___get__(PyObject obj, PyObject type) { if (obj == null || obj == Py.None || this.obj != null) { return this; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-02 03:27:37
|
Revision: 5831 http://jython.svn.sourceforge.net/jython/?rev=5831&view=rev Author: fwierzbicki Date: 2009-01-02 03:27:32 +0000 (Fri, 02 Jan 2009) Log Message: ----------- __doc__ for staticmethod and float Modified Paths: -------------- trunk/jython/src/org/python/core/PyFloat.java trunk/jython/src/org/python/core/PyStaticMethod.java Modified: trunk/jython/src/org/python/core/PyFloat.java =================================================================== --- trunk/jython/src/org/python/core/PyFloat.java 2009-01-01 22:32:02 UTC (rev 5830) +++ trunk/jython/src/org/python/core/PyFloat.java 2009-01-02 03:27:32 UTC (rev 5831) @@ -90,7 +90,7 @@ return float___str__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___str___doc) final PyString float___str__() { return Py.newString(formatDouble(PREC_STR)); } @@ -99,7 +99,7 @@ return float___repr__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___repr___doc) final PyString float___repr__() { return Py.newString(formatDouble(PREC_REPR)); } @@ -131,7 +131,7 @@ return float___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___hash___doc) final int float___hash__() { double intPart = Math.floor(value); double fractPart = value-intPart; @@ -151,7 +151,7 @@ return float___nonzero__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___nonzero___doc) final boolean float___nonzero__() { return value != 0; } @@ -188,6 +188,7 @@ return float___cmp__(other); } + //XXX: needs __doc__ @ExposedMethod(type = MethodType.CMP) final int float___cmp__(PyObject other) { double i = value; @@ -230,7 +231,7 @@ return float___coerce_ex__(other); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___coerce___doc) final PyObject float___coerce__(PyObject other) { return adaptToCoerceTuple(float___coerce_ex__(other)); } @@ -272,7 +273,7 @@ return float___add__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___add___doc) final PyObject float___add__(PyObject right) { if (!canCoerce(right)) return null; @@ -284,7 +285,7 @@ return float___radd__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___radd___doc) final PyObject float___radd__(PyObject left) { return __add__(left); } @@ -293,7 +294,7 @@ return float___sub__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___sub___doc) final PyObject float___sub__(PyObject right) { if (!canCoerce(right)) return null; @@ -305,7 +306,7 @@ return float___rsub__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rsub___doc) final PyObject float___rsub__(PyObject left) { if (!canCoerce(left)) return null; @@ -317,7 +318,7 @@ return float___mul__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___mul___doc) final PyObject float___mul__(PyObject right) { if (!canCoerce(right)) return null; @@ -329,7 +330,7 @@ return float___rmul__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rmul___doc) final PyObject float___rmul__(PyObject left) { return __mul__(left); } @@ -338,7 +339,7 @@ return float___div__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___div___doc) final PyObject float___div__(PyObject right) { if (!canCoerce(right)) return null; @@ -354,7 +355,7 @@ return float___rdiv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rdiv___doc) final PyObject float___rdiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -370,7 +371,7 @@ return float___floordiv__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___floordiv___doc) final PyObject float___floordiv__(PyObject right) { if (!canCoerce(right)) return null; @@ -384,7 +385,7 @@ return float___rfloordiv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rfloordiv___doc) final PyObject float___rfloordiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -398,7 +399,7 @@ return float___truediv__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___truediv___doc) final PyObject float___truediv__(PyObject right) { if (!canCoerce(right)) return null; @@ -412,7 +413,7 @@ return float___rtruediv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rtruediv___doc) final PyObject float___rtruediv__(PyObject left) { if (!canCoerce(left)) return null; @@ -435,7 +436,7 @@ return float___mod__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___mod___doc) final PyObject float___mod__(PyObject right) { if (!canCoerce(right)) return null; @@ -447,7 +448,7 @@ return float___rmod__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rmod___doc) final PyObject float___rmod__(PyObject left) { if (!canCoerce(left)) return null; @@ -459,7 +460,7 @@ return float___divmod__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___divmod___doc) final PyObject float___divmod__(PyObject right) { if (!canCoerce(right)) return null; @@ -484,7 +485,7 @@ return new PyTuple(new PyFloat(z), new PyFloat(leftv - z * value)); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rdivmod___doc) final PyObject float___rdivmod__(PyObject left) { return __rdivmod__(left); } @@ -494,7 +495,7 @@ return float___pow__(right, modulo); } - @ExposedMethod(type = MethodType.BINARY, defaults = "null") + @ExposedMethod(type = MethodType.BINARY, defaults = "null", doc = BuiltinDocs.float___pow___doc) final PyObject float___pow__(PyObject right, PyObject modulo) { if (!canCoerce(right)) return null; @@ -507,7 +508,7 @@ return _pow(value, coerce(right), modulo); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___rpow___doc) final PyObject float___rpow__(PyObject left) { return __rpow__(left); } @@ -548,7 +549,7 @@ return float___neg__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___neg___doc) final PyObject float___neg__() { return new PyFloat(-value); } @@ -557,7 +558,7 @@ return float___pos__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___pos___doc) final PyObject float___pos__() { return Py.newFloat(value); } @@ -570,7 +571,7 @@ return float___abs__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___abs___doc) final PyObject float___abs__() { if (value >= 0) return Py.newFloat(value); @@ -582,7 +583,7 @@ return float___int__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___int___doc) final PyObject float___int__() { if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) { return new PyInteger((int)value); @@ -594,7 +595,7 @@ return float___long__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___long___doc) final PyObject float___long__() { return new PyLong(value); } @@ -603,7 +604,7 @@ return float___float__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___float___doc) final PyFloat float___float__() { return Py.newFloat(value); } @@ -611,7 +612,7 @@ return new PyComplex(value, 0.); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.float___getnewargs___doc) final PyTuple float___getnewargs__() { return new PyTuple(new PyObject[] {new PyFloat(getValue())}); } Modified: trunk/jython/src/org/python/core/PyStaticMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyStaticMethod.java 2009-01-01 22:32:02 UTC (rev 5830) +++ trunk/jython/src/org/python/core/PyStaticMethod.java 2009-01-02 03:27:32 UTC (rev 5831) @@ -34,7 +34,7 @@ return staticmethod___get__(obj, type); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.staticmethod___get___doc) final PyObject staticmethod___get__(PyObject obj, PyObject type) { return callable; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-02 03:51:11
|
Revision: 5832 http://jython.svn.sourceforge.net/jython/?rev=5832&view=rev Author: fwierzbicki Date: 2009-01-02 03:51:08 +0000 (Fri, 02 Jan 2009) Log Message: ----------- __doc__ for long and enumerate Modified Paths: -------------- trunk/jython/src/org/python/core/PyEnumerate.java trunk/jython/src/org/python/core/PyLong.java Modified: trunk/jython/src/org/python/core/PyEnumerate.java =================================================================== --- trunk/jython/src/org/python/core/PyEnumerate.java 2009-01-02 03:27:32 UTC (rev 5831) +++ trunk/jython/src/org/python/core/PyEnumerate.java 2009-01-02 03:51:08 UTC (rev 5832) @@ -37,12 +37,12 @@ return enumerate_next(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.enumerate_next_doc) final PyObject enumerate_next() { return doNext(enumerate___iternext__()); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.enumerate___iter___doc) final PyObject enumerate___iter__() { return super.__iter__(); } Modified: trunk/jython/src/org/python/core/PyLong.java =================================================================== --- trunk/jython/src/org/python/core/PyLong.java 2009-01-02 03:27:32 UTC (rev 5831) +++ trunk/jython/src/org/python/core/PyLong.java 2009-01-02 03:51:08 UTC (rev 5832) @@ -118,7 +118,7 @@ return long_toString(); } - @ExposedMethod(names = {"__str__", "__repr__"}) + @ExposedMethod(names = {"__str__", "__repr__"}, doc = BuiltinDocs.long___str___doc) final String long_toString() { return value.toString()+"L"; } @@ -127,7 +127,7 @@ return long___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___hash___doc) final int long___hash__() { return value.intValue(); } @@ -136,7 +136,7 @@ return !value.equals(BigInteger.valueOf(0)); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___nonzero___doc) public boolean long___nonzero__() { return __nonzero__(); } @@ -248,7 +248,7 @@ return long___cmp__(other); } - @ExposedMethod(type = MethodType.CMP) + @ExposedMethod(type = MethodType.CMP, doc = BuiltinDocs.long___cmp___doc) final int long___cmp__(PyObject other) { if (!canCoerce(other)) return -2; @@ -259,7 +259,7 @@ return long___coerce_ex__(other); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___coerce___doc) final PyObject long___coerce__(PyObject other) { return adaptToCoerceTuple(long___coerce_ex__(other)); } @@ -297,7 +297,7 @@ return long___add__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___add___doc) final PyObject long___add__(PyObject right) { if (!canCoerce(right)) return null; @@ -308,7 +308,7 @@ return long___radd__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___radd___doc) final PyObject long___radd__(PyObject left) { return __add__(left); } @@ -317,7 +317,7 @@ return long___sub__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___sub___doc) final PyObject long___sub__(PyObject right) { if (!canCoerce(right)) return null; @@ -328,7 +328,7 @@ return long___rsub__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rsub___doc) final PyObject long___rsub__(PyObject left) { return Py.newLong(coerce(left).subtract(value)); } @@ -337,7 +337,7 @@ return long___mul__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___mul___doc) final PyObject long___mul__(PyObject right) { if (right instanceof PySequence) return ((PySequence) right).repeat(coerceInt(this)); @@ -351,7 +351,7 @@ return long___rmul__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rmul___doc) final PyObject long___rmul__(PyObject left) { if (left instanceof PySequence) return ((PySequence) left).repeat(coerceInt(this)); @@ -382,7 +382,7 @@ return long___div__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___div___doc) final PyObject long___div__(PyObject right) { if (!canCoerce(right)) return null; @@ -395,7 +395,7 @@ return long___rdiv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rdiv___doc) final PyObject long___rdiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -408,7 +408,7 @@ return long___floordiv__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___floordiv___doc) final PyObject long___floordiv__(PyObject right) { if (!canCoerce(right)) return null; @@ -419,7 +419,7 @@ return long___rfloordiv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rfloordiv___doc) final PyObject long___rfloordiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -458,7 +458,7 @@ return long___truediv__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___truediv___doc) final PyObject long___truediv__(PyObject right) { if (!canCoerce(right)) return null; @@ -469,7 +469,7 @@ return long___rtruediv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rtruediv___doc) final PyObject long___rtruediv__(PyObject left) { if (!canCoerce(left)) return null; @@ -484,7 +484,7 @@ return long___mod__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___mod___doc) final PyObject long___mod__(PyObject right) { if (!canCoerce(right)) return null; @@ -496,7 +496,7 @@ return long___rmod__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rmod___doc) final PyObject long___rmod__(PyObject left) { if (!canCoerce(left)) return null; @@ -508,7 +508,7 @@ return long___divmod__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___divmod___doc) final PyObject long___divmod__(PyObject right) { if (!canCoerce(right)) return null; @@ -522,7 +522,7 @@ return long___rdivmod__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rdivmod___doc) final PyObject long___rdivmod__(PyObject left) { if (!canCoerce(left)) return null; @@ -536,7 +536,7 @@ return long___pow__(right, modulo); } - @ExposedMethod(type = MethodType.BINARY, defaults = {"null"}) + @ExposedMethod(type = MethodType.BINARY, defaults = {"null"}, doc = BuiltinDocs.long___pow___doc) final PyObject long___pow__(PyObject right, PyObject modulo) { if (!canCoerce(right)) return null; @@ -550,7 +550,7 @@ return long___rpow__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rpow___doc) final PyObject long___rpow__(PyObject left) { if (!canCoerce(left)) return null; @@ -615,7 +615,7 @@ return long___lshift__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___lshift___doc) final PyObject long___lshift__(PyObject right) { if (!canCoerce(right)) return null; @@ -625,7 +625,7 @@ return Py.newLong(value.shiftLeft(rightv)); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rlshift___doc) final PyObject long___rlshift__(PyObject left) { if (!canCoerce(left)) return null; @@ -638,7 +638,7 @@ return long___rshift__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rshift___doc) final PyObject long___rshift__(PyObject right) { if (!canCoerce(right)) return null; @@ -648,7 +648,7 @@ return Py.newLong(value.shiftRight(rightv)); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rrshift___doc) final PyObject long___rrshift__(PyObject left) { if (!canCoerce(left)) return null; @@ -661,7 +661,7 @@ return long___and__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___and___doc) final PyObject long___and__(PyObject right) { if (!canCoerce(right)) return null; @@ -672,7 +672,7 @@ return long___rand__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rand___doc) final PyObject long___rand__(PyObject left) { if (!canCoerce(left)) return null; @@ -683,7 +683,7 @@ return long___xor__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___xor___doc) final PyObject long___xor__(PyObject right) { if (!canCoerce(right)) return null; @@ -694,7 +694,7 @@ return long___rxor__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rxor___doc) final PyObject long___rxor__(PyObject left) { if (!canCoerce(left)) return null; @@ -705,7 +705,7 @@ return long___or__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___or___doc) final PyObject long___or__(PyObject right) { if (!canCoerce(right)) return null; @@ -716,7 +716,7 @@ return long___ror__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___ror___doc) final PyObject long___ror__(PyObject left) { if (!canCoerce(left)) return null; @@ -727,7 +727,7 @@ return long___neg__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___neg___doc) final PyObject long___neg__() { return Py.newLong(value.negate()); } @@ -736,7 +736,7 @@ return long___pos__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___pos___doc) final PyObject long___pos__() { return Py.newLong(value); } @@ -745,7 +745,7 @@ return long___abs__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___abs___doc) final PyObject long___abs__() { return Py.newLong(value.abs()); } @@ -754,7 +754,7 @@ return long___invert__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___invert___doc) final PyObject long___invert__() { return Py.newLong(value.not()); } @@ -763,7 +763,7 @@ return long___int__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___int___doc) final PyObject long___int__() { if (value.compareTo(PyInteger.maxInt) <= 0 && value.compareTo(PyInteger.minInt) >= 0) { return Py.newInteger(value.intValue()); @@ -776,7 +776,7 @@ return long___long__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___long___doc) final PyObject long___long__() { return Py.newLong(value); } @@ -785,7 +785,7 @@ return long___float__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___float___doc) final PyFloat long___float__() { return new PyFloat(doubleValue()); } @@ -802,7 +802,7 @@ return long___oct__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___oct___doc) final PyString long___oct__() { String s = value.toString(8); if (s.startsWith("-")) @@ -818,7 +818,7 @@ return long___hex__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___hex___doc) final PyString long___hex__() { String s = value.toString(16); if (s.startsWith("-")) @@ -835,7 +835,7 @@ return new PyUnicode(value.toString()); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___getnewargs___doc) final PyTuple long___getnewargs__() { return new PyTuple(new PyLong(this.getValue())); } @@ -849,7 +849,7 @@ return long___index__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.long___index___doc) final PyObject long___index__() { return this; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-02 15:37:02
|
Revision: 5833 http://jython.svn.sourceforge.net/jython/?rev=5833&view=rev Author: fwierzbicki Date: 2009-01-02 15:36:57 +0000 (Fri, 02 Jan 2009) Log Message: ----------- __doc__ for int, property and tuple. Modified Paths: -------------- trunk/jython/src/org/python/core/PyInteger.java trunk/jython/src/org/python/core/PyProperty.java trunk/jython/src/org/python/core/PyTuple.java Modified: trunk/jython/src/org/python/core/PyInteger.java =================================================================== --- trunk/jython/src/org/python/core/PyInteger.java 2009-01-02 03:51:08 UTC (rev 5832) +++ trunk/jython/src/org/python/core/PyInteger.java 2009-01-02 15:36:57 UTC (rev 5833) @@ -104,7 +104,8 @@ return int_toString(); } - @ExposedMethod(names = {"__str__", "__repr__"}) + //XXX: need separate __doc__ for __repr__ + @ExposedMethod(names = {"__str__", "__repr__"}, doc = BuiltinDocs.int___str___doc) final String int_toString() { return Integer.toString(getValue()); } @@ -113,7 +114,7 @@ return int_hashCode(); } - @ExposedMethod(names = "__hash__") + @ExposedMethod(names = "__hash__", doc = BuiltinDocs.int___hash___doc) final int int_hashCode() { return getValue(); } @@ -122,7 +123,7 @@ return int___nonzero__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___nonzero___doc) final boolean int___nonzero__() { return getValue() != 0; } @@ -155,7 +156,7 @@ return int___cmp__(other); } - @ExposedMethod(type = MethodType.CMP) + @ExposedMethod(type = MethodType.CMP, doc = BuiltinDocs.int___cmp___doc) final int int___cmp__(PyObject other) { if (!canCoerce(other)) return -2; @@ -167,7 +168,7 @@ return int___coerce_ex__(other); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___coerce___doc) final PyObject int___coerce__(PyObject other) { return adaptToCoerceTuple(int___coerce_ex__(other)); } @@ -199,7 +200,7 @@ return int___add__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___add___doc) final PyObject int___add__(PyObject right) { if (!canCoerce(right)) return null; @@ -216,7 +217,7 @@ return int___radd__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___radd___doc) final PyObject int___radd__(PyObject left) { return __add__(left); } @@ -232,7 +233,7 @@ return int___sub__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___sub___doc) final PyObject int___sub__(PyObject right) { if (!canCoerce(right)) return null; @@ -243,7 +244,7 @@ return int___rsub__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rsub___doc) final PyObject int___rsub__(PyObject left) { if (!canCoerce(left)) return null; @@ -254,7 +255,7 @@ return int___mul__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___mul___doc) final PyObject int___mul__(PyObject right) { if (right instanceof PySequence) return ((PySequence) right).repeat(getValue()); @@ -277,7 +278,7 @@ return int___rmul__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rmul___doc) final PyObject int___rmul__(PyObject left) { return __mul__(left); } @@ -310,7 +311,7 @@ return int___div__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___div___doc) final PyObject int___div__(PyObject right) { if (!canCoerce(right)) return null; @@ -323,7 +324,7 @@ return int___rdiv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rdiv___doc) final PyObject int___rdiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -336,7 +337,7 @@ return int___floordiv__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___floordiv___doc) final PyObject int___floordiv__(PyObject right) { if (!canCoerce(right)) return null; @@ -347,7 +348,7 @@ return int___rfloordiv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rfloordiv___doc) final PyObject int___rfloordiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -358,7 +359,7 @@ return int___truediv__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___truediv___doc) final PyObject int___truediv__(PyObject right) { if (right instanceof PyInteger) return __float__().__truediv__(right); @@ -372,7 +373,7 @@ return int___rtruediv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rtruediv___doc) final PyObject int___rtruediv__(PyObject left) { if (left instanceof PyInteger) return left.__float__().__truediv__(this); @@ -390,7 +391,7 @@ return int___mod__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___mod___doc) final PyObject int___mod__(PyObject right) { if (!canCoerce(right)) return null; @@ -403,7 +404,7 @@ return int___rmod__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rmod___doc) final PyObject int___rmod__(PyObject left) { if (!canCoerce(left)) return null; @@ -416,7 +417,7 @@ return int___divmod__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___divmod___doc) final PyObject int___divmod__(PyObject right) { if (!canCoerce(right)) return null; @@ -427,7 +428,7 @@ return new PyTuple(Py.newInteger(xdivy), Py.newInteger(modulo(v, rightv, xdivy))); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rdivmod___doc) final PyObject int___rdivmod__(PyObject left){ if (!canCoerce(left)) return null; @@ -442,7 +443,7 @@ return int___pow__(right,modulo); } - @ExposedMethod(type = MethodType.BINARY, defaults = {"null"}) + @ExposedMethod(type = MethodType.BINARY, defaults = {"null"}, doc = BuiltinDocs.int___pow___doc) final PyObject int___pow__(PyObject right, PyObject modulo) { if (!canCoerce(right)) return null; @@ -463,7 +464,7 @@ return _pow(coerce(left), getValue(), modulo, left, this); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rpow___doc) final PyObject int___rpow__(PyObject left){ return __rpow__(left, null); } @@ -533,7 +534,7 @@ return int___lshift__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___lshift___doc) final PyObject int___lshift__(PyObject right) { int rightv; if (right instanceof PyInteger) @@ -555,7 +556,7 @@ return Py.newInteger(result); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rlshift___doc) final PyObject int___rlshift__(PyObject left) { int leftv; if (left instanceof PyInteger) @@ -581,7 +582,7 @@ return int___rshift__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rshift___doc) final PyObject int___rshift__(PyObject right) { int rightv; if (right instanceof PyInteger) @@ -606,7 +607,7 @@ return Py.newInteger(getValue() >> rightv); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rrshift___doc) final PyObject int___rrshift__(PyObject left) { int leftv; if (left instanceof PyInteger) @@ -635,7 +636,7 @@ return int___and__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___and___doc) final PyObject int___and__(PyObject right) { int rightv; if (right instanceof PyInteger) @@ -648,7 +649,7 @@ return Py.newInteger(getValue() & rightv); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rand___doc) final PyObject int___rand__(PyObject left){ return int___and__(left); } @@ -657,7 +658,7 @@ return int___xor__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___xor___doc) final PyObject int___xor__(PyObject right) { int rightv; if (right instanceof PyInteger) @@ -670,7 +671,7 @@ return Py.newInteger(getValue() ^ rightv); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rxor___doc) final PyObject int___rxor__(PyObject left){ int leftv; if (left instanceof PyInteger) @@ -687,7 +688,7 @@ return int___or__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___or___doc) final PyObject int___or__(PyObject right) { int rightv; if (right instanceof PyInteger) @@ -700,7 +701,7 @@ return Py.newInteger(getValue() | rightv); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___ror___doc) final PyObject int___ror__(PyObject left){ return int___or__(left); } @@ -709,7 +710,7 @@ return int___neg__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___neg___doc) final PyObject int___neg__() { long x = -getValue(); return Py.newInteger(x); @@ -719,7 +720,7 @@ return int___pos__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___pos___doc) final PyObject int___pos__() { return Py.newInteger(getValue()); } @@ -728,7 +729,7 @@ return int___abs__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___abs___doc) final PyObject int___abs__() { if (getValue() >= 0) return Py.newInteger(getValue()); @@ -740,7 +741,7 @@ return int___invert__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___invert___doc) final PyObject int___invert__() { return Py.newInteger(~getValue()); } @@ -749,7 +750,7 @@ return int___int__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___int___doc) final PyInteger int___int__() { return Py.newInteger(getValue()); } @@ -758,7 +759,7 @@ return int___long__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___long___doc) final PyObject int___long__() { return new PyLong(getValue()); } @@ -767,7 +768,7 @@ return int___float__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___float___doc) final PyFloat int___float__() { return new PyFloat((double)getValue()); } @@ -780,7 +781,7 @@ return int___oct__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___oct___doc) final PyString int___oct__() { if (getValue() < 0) { return new PyString("-0" + Integer.toString(getValue() * -1, 8)); @@ -794,7 +795,7 @@ return int___hex__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___hex___doc) final PyString int___hex__() { if (getValue() < 0) { return new PyString("-0x" + Integer.toString(getValue() * -1, 16)); @@ -804,7 +805,7 @@ } } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___getnewargs___doc) final PyTuple int___getnewargs__() { return new PyTuple(new PyObject[]{new PyInteger(this.getValue())}); } @@ -818,7 +819,7 @@ return int___index__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.int___index___doc) final PyObject int___index__() { return this; } Modified: trunk/jython/src/org/python/core/PyProperty.java =================================================================== --- trunk/jython/src/org/python/core/PyProperty.java 2009-01-02 03:51:08 UTC (rev 5832) +++ trunk/jython/src/org/python/core/PyProperty.java 2009-01-02 15:36:57 UTC (rev 5833) @@ -31,6 +31,7 @@ super(subType); } + //XXX: needs __doc__ @ExposedNew @ExposedMethod public void property___init__(PyObject[] args, String[] keywords) { @@ -58,7 +59,7 @@ return property___get__(obj,type); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.property___get___doc) final PyObject property___get__(PyObject obj, PyObject type) { if (obj == null || obj == Py.None) { return this; @@ -73,7 +74,7 @@ property___set__(obj, value); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.property___set___doc) final void property___set__(PyObject obj, PyObject value) { if (fset == null) { throw Py.AttributeError("can't set attribute"); @@ -85,7 +86,7 @@ property___delete__(obj); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.property___delete___doc) final void property___delete__(PyObject obj) { if (fdel == null) { throw Py.AttributeError("can't delete attribute"); Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-01-02 03:51:08 UTC (rev 5832) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-01-02 15:36:57 UTC (rev 5833) @@ -120,42 +120,42 @@ return tuple___len__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.tuple___len___doc) final int tuple___len__() { return size(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.tuple___contains___doc) final boolean tuple___contains__(PyObject o) { return super.__contains__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___ne___doc) final PyObject tuple___ne__(PyObject o) { return super.__ne__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___eq___doc) final PyObject tuple___eq__(PyObject o) { return super.__eq__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___gt___doc) final PyObject tuple___gt__(PyObject o) { return super.__gt__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___ge___doc) final PyObject tuple___ge__(PyObject o) { return super.__ge__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___lt___doc) final PyObject tuple___lt__(PyObject o) { return super.__lt__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___le___doc) final PyObject tuple___le__(PyObject o) { return super.__le__(o); } @@ -164,7 +164,7 @@ return tuple___add__(generic_other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___add___doc) final PyObject tuple___add__(PyObject generic_other) { PyTuple sum = null; if (generic_other instanceof PyTuple) { @@ -186,7 +186,7 @@ return tuple___mul__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___mul___doc) final PyObject tuple___mul__(PyObject o) { if (!o.isIndex()) { return null; @@ -199,7 +199,7 @@ return tuple___rmul__(o); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___rmul___doc) final PyObject tuple___rmul__(PyObject o) { if (!o.isIndex()) { return null; @@ -211,17 +211,17 @@ return tuple___iter__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.tuple___iter___doc) public PyObject tuple___iter__() { return new PyFastSequenceIter(this); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.tuple___getslice___doc) final PyObject tuple___getslice__(PyObject s_start, PyObject s_stop, PyObject s_step) { return seq___getslice__(s_start,s_stop,s_step); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.tuple___getitem___doc) final PyObject tuple___getitem__(PyObject index) { PyObject ret = seq___finditem__(index); if(ret == null) { @@ -230,7 +230,7 @@ return ret; } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.tuple___getnewargs___doc) final PyTuple tuple___getnewargs__() { return new PyTuple(new PyTuple(list.getArray())); } @@ -243,7 +243,7 @@ return tuple___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.tuple___hash___doc) final int tuple___hash__() { // strengthened hash to avoid common collisions. from CPython // tupleobject.tuplehash. See http://bugs.python.org/issue942952 @@ -270,7 +270,7 @@ return tuple___repr__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.tuple___repr___doc) final String tuple___repr__() { StringBuilder buf = new StringBuilder("("); PyObject[] array = getArray(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-03 02:47:58
|
Revision: 5834 http://jython.svn.sourceforge.net/jython/?rev=5834&view=rev Author: fwierzbicki Date: 2009-01-03 02:47:53 +0000 (Sat, 03 Jan 2009) Log Message: ----------- __doc__ for complex, xrange, file. Modified Paths: -------------- trunk/jython/src/org/python/core/PyComplex.java trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/PyXRange.java Modified: trunk/jython/src/org/python/core/PyComplex.java =================================================================== --- trunk/jython/src/org/python/core/PyComplex.java 2009-01-02 15:36:57 UTC (rev 5833) +++ trunk/jython/src/org/python/core/PyComplex.java 2009-01-03 02:47:53 UTC (rev 5834) @@ -130,7 +130,7 @@ return complex_toString(); } - @ExposedMethod(names = {"__repr__", "__str__"}) + @ExposedMethod(names = {"__repr__", "__str__"}, doc = BuiltinDocs.complex___str___doc) final String complex_toString() { if (real == 0.) { return toString(imag)+"j"; @@ -147,7 +147,7 @@ return complex___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___hash___doc) final int complex___hash__() { if (imag == 0) { return new PyFloat(real).hashCode(); @@ -162,7 +162,7 @@ return complex___nonzero__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___nonzero___doc) final boolean complex___nonzero__() { return real != 0 && imag != 0; } @@ -193,7 +193,7 @@ return complex___eq__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___eq___doc) final PyObject complex___eq__(PyObject other) { if (!canCoerce(other)) return null; @@ -208,7 +208,7 @@ return complex___ne__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___ne___doc) final PyObject complex___ne__(PyObject other) { if (!canCoerce(other)) return null; @@ -226,7 +226,7 @@ return complex___ge__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___ge___doc) final PyObject complex___ge__(PyObject other) { return unsupported_comparison(other); } @@ -235,7 +235,7 @@ return complex___gt__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___gt___doc) final PyObject complex___gt__(PyObject other) { return unsupported_comparison(other); } @@ -244,7 +244,7 @@ return complex___le__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___le___doc) final PyObject complex___le__(PyObject other) { return unsupported_comparison(other); } @@ -253,7 +253,7 @@ return complex___lt__(other); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___lt___doc) final PyObject complex___lt__(PyObject other) { return unsupported_comparison(other); } @@ -262,7 +262,7 @@ return complex___coerce_ex__(other); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___coerce___doc) final PyObject complex___coerce__(PyObject other) { return adaptToCoerceTuple(complex___coerce_ex__(other)); } @@ -306,7 +306,7 @@ return complex___add__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___add___doc) final PyObject complex___add__(PyObject right) { if (!canCoerce(right)) return null; @@ -318,7 +318,7 @@ return complex___radd__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___radd___doc) final PyObject complex___radd__(PyObject left) { return __add__(left); } @@ -331,7 +331,7 @@ return complex___sub__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___sub___doc) final PyObject complex___sub__(PyObject right) { if (!canCoerce(right)) return null; @@ -342,7 +342,7 @@ return complex___rsub__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___rsub___doc) final PyObject complex___rsub__(PyObject left) { if (!canCoerce(left)) return null; @@ -358,7 +358,7 @@ return complex___mul__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___mul___doc) final PyObject complex___mul__(PyObject right) { if (!canCoerce(right)) return null; @@ -369,7 +369,7 @@ return complex___rmul__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___rmul___doc) final PyObject complex___rmul__(PyObject left) { if (!canCoerce(left)) return null; @@ -401,7 +401,7 @@ return complex___div__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___div___doc) final PyObject complex___div__(PyObject right) { if (!canCoerce(right)) return null; @@ -414,7 +414,7 @@ return complex___rdiv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___rdiv___doc) final PyObject complex___rdiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -427,7 +427,7 @@ return complex___floordiv__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___floordiv___doc) final PyObject complex___floordiv__(PyObject right) { if (!canCoerce(right)) return null; @@ -438,7 +438,7 @@ return complex___rfloordiv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___rfloordiv___doc) final PyObject complex___rfloordiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -449,7 +449,7 @@ return complex___truediv__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___truediv___doc) final PyObject complex___truediv__(PyObject right) { if (!canCoerce(right)) return null; @@ -460,7 +460,7 @@ return complex___rtruediv__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___rtruediv___doc) final PyObject complex___rtruediv__(PyObject left) { if (!canCoerce(left)) return null; @@ -471,7 +471,7 @@ return complex___mod__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___mod___doc) final PyObject complex___mod__(PyObject right) { if (!canCoerce(right)) return null; @@ -482,7 +482,7 @@ return complex___rmod__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___rmod___doc) final PyObject complex___rmod__(PyObject left) { if (!canCoerce(left)) return null; @@ -503,7 +503,7 @@ return complex___divmod__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___divmod___doc) final PyObject complex___divmod__(PyObject right) { if (!canCoerce(right)) return null; @@ -514,7 +514,7 @@ return complex___rdivmod__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___rdivmod___doc) final PyObject complex___rdivmod__(PyObject left) { if (!canCoerce(left)) return null; @@ -569,7 +569,7 @@ return complex___pow__(right, modulo); } - @ExposedMethod(type = MethodType.BINARY, defaults = "null") + @ExposedMethod(type = MethodType.BINARY, defaults = "null", doc = BuiltinDocs.complex___pow___doc) final PyObject complex___pow__(PyObject right, PyObject modulo) { if (modulo != null) { throw Py.ValueError("complex modulo"); @@ -583,7 +583,7 @@ return complex___rpow__(left); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.complex___rpow___doc) final PyObject complex___rpow__(PyObject left) { if (!canCoerce(left)) return null; @@ -628,7 +628,7 @@ return complex___neg__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___neg___doc) final PyObject complex___neg__() { return new PyComplex(-real, -imag); } @@ -637,7 +637,7 @@ return complex___pos__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___pos___doc) final PyObject complex___pos__() { return new PyComplex(real, imag); } @@ -650,7 +650,7 @@ return complex___abs__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___abs___doc) final PyObject complex___abs__() { return new PyFloat(Math.hypot(real, imag)); } @@ -659,7 +659,7 @@ return complex___int__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___int___doc) final PyInteger complex___int__() { throw Py.TypeError( "can't convert complex to int; use e.g. int(abs(z))"); @@ -669,7 +669,7 @@ return complex___long__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___long___doc) final PyObject complex___long__() { throw Py.TypeError( "can't convert complex to long; use e.g. long(abs(z))"); @@ -679,7 +679,7 @@ return complex___float__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___float___doc) final PyFloat complex___float__() { throw Py.TypeError("can't convert complex to float; use e.g. abs(z)"); } @@ -692,12 +692,12 @@ return complex_conjugate(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex_conjugate_doc) final PyComplex complex_conjugate() { return new PyComplex(real, -imag); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.complex___getnewargs___doc) final PyTuple complex___getnewargs__() { return new PyTuple(new PyComplex(real, imag)); } Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2009-01-02 15:36:57 UTC (rev 5833) +++ trunk/jython/src/org/python/core/PyFile.java 2009-01-03 02:47:53 UTC (rev 5834) @@ -140,7 +140,7 @@ } @ExposedNew - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file___init___doc) final void file___init__(PyObject[] args, String[] kwds) { ArgParser ap = new ArgParser("file", args, kwds, new String[] {"name", "mode", "bufsize"}, 1); @@ -239,7 +239,7 @@ + (updating ? "+" : ""); } - @ExposedMethod(defaults = {"-1"}) + @ExposedMethod(defaults = {"-1"}, doc = BuiltinDocs.file_read_doc) final synchronized PyString file_read(int n) { checkClosed(); return new PyString(file.read(n)); @@ -253,7 +253,7 @@ return file_read(-1); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_readinto_doc) final synchronized int file_readinto(PyObject buf) { checkClosed(); return file.readinto(buf); @@ -263,7 +263,7 @@ return file_readinto(buf); } - @ExposedMethod(defaults = {"-1"}) + @ExposedMethod(defaults = {"-1"}, doc = BuiltinDocs.file_readline_doc) final synchronized PyString file_readline(int max) { checkClosed(); return new PyString(file.readline(max)); @@ -277,7 +277,7 @@ return file_readline(-1); } - @ExposedMethod(defaults = {"0"}) + @ExposedMethod(defaults = {"0"}, doc = BuiltinDocs.file_readlines_doc) final synchronized PyObject file_readlines(int sizehint) { checkClosed(); PyList list = new PyList(); @@ -316,7 +316,7 @@ return new PyString(next); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_next_doc) final PyObject file_next() { PyObject ret = file___iternext__(); if (ret == null) { @@ -329,7 +329,7 @@ return file_next(); } - @ExposedMethod(names = {"__enter__", "__iter__", "xreadlines"}) + @ExposedMethod(names = {"__enter__", "__iter__", "xreadlines"}, doc = BuiltinDocs.file___iter___doc) final PyObject file_self() { checkClosed(); return this; @@ -347,7 +347,7 @@ return file_self(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_write_doc) final void file_write(PyObject o) { if (o instanceof PyUnicode) { // Call __str__ on unicode objects to encode them before writing @@ -369,7 +369,7 @@ file_write(s); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_writelines_doc) final synchronized void file_writelines(PyObject a) { checkClosed(); PyObject iter = Py.iter(a, "writelines() requires an iterable argument"); @@ -387,7 +387,7 @@ file_writelines(a); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_tell_doc) final synchronized long file_tell() { checkClosed(); return file.tell(); @@ -397,7 +397,7 @@ return file_tell(); } - @ExposedMethod(defaults = {"0"}) + @ExposedMethod(defaults = {"0"}, doc = BuiltinDocs.file_seek_doc) final synchronized void file_seek(long pos, int how) { checkClosed(); file.seek(pos, how); @@ -411,7 +411,7 @@ file_seek(pos, 0); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_flush_doc) final synchronized void file_flush() { checkClosed(); file.flush(); @@ -421,7 +421,7 @@ file_flush(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_close_doc) final synchronized void file_close() { if (closer != null) { closer.close(); @@ -435,7 +435,7 @@ file_close(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file___exit___doc) final void file___exit__(PyObject type, PyObject value, PyObject traceback) { file_close(); } @@ -444,7 +444,7 @@ file___exit__(type, value, traceback); } - @ExposedMethod(defaults = {"null"}) + @ExposedMethod(defaults = {"null"}, doc = BuiltinDocs.file_truncate_doc) final void file_truncate(PyObject position) { if (position == null) { file_truncate(); @@ -477,7 +477,7 @@ return file_isatty(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_isatty_doc) final boolean file_isatty() { return file.isatty(); } @@ -486,12 +486,12 @@ return file_fileno(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.file_fileno_doc) final PyObject file_fileno() { return PyJavaType.wrapJavaObject(file.fileno()); } - @ExposedMethod(names = {"__str__", "__repr__"}) + @ExposedMethod(names = {"__str__", "__repr__"}, doc = BuiltinDocs.file___str___doc) final String file_toString() { StringBuilder s = new StringBuilder("<"); if (file.closed()) { Modified: trunk/jython/src/org/python/core/PyXRange.java =================================================================== --- trunk/jython/src/org/python/core/PyXRange.java 2009-01-02 15:36:57 UTC (rev 5833) +++ trunk/jython/src/org/python/core/PyXRange.java 2009-01-03 02:47:53 UTC (rev 5834) @@ -93,7 +93,7 @@ return xrange___len__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.xrange___len___doc) final int xrange___len__() { return len; } @@ -103,7 +103,7 @@ return xrange___getitem__(index); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.xrange___getitem___doc) final PyObject xrange___getitem__(PyObject index) { PyObject ret = seq___finditem__(index); if (ret == null) { @@ -112,7 +112,7 @@ return ret; } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.xrange___iter___doc) public PyObject xrange___iter__() { return seq___iter__(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-03 04:19:54
|
Revision: 5835 http://jython.svn.sourceforge.net/jython/?rev=5835&view=rev Author: fwierzbicki Date: 2009-01-03 04:19:44 +0000 (Sat, 03 Jan 2009) Log Message: ----------- __doc__ for classmethod, instancemethod, bool, function. Modified Paths: -------------- trunk/jython/src/org/python/core/PyBoolean.java trunk/jython/src/org/python/core/PyClassMethod.java trunk/jython/src/org/python/core/PyFunction.java trunk/jython/src/org/python/core/PyMethod.java Modified: trunk/jython/src/org/python/core/PyBoolean.java =================================================================== --- trunk/jython/src/org/python/core/PyBoolean.java 2009-01-03 02:47:53 UTC (rev 5834) +++ trunk/jython/src/org/python/core/PyBoolean.java 2009-01-03 04:19:44 UTC (rev 5835) @@ -50,7 +50,7 @@ return bool_toString(); } - @ExposedMethod(names = {"__str__", "__repr__"}) + @ExposedMethod(names = {"__str__", "__repr__"}, doc = BuiltinDocs.bool___str___doc) final String bool_toString() { return value ? "True" : "False"; } @@ -59,7 +59,7 @@ return bool___hash__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.bool___hash___doc) final int bool___hash__() { return value ? 1 : 0; } @@ -68,7 +68,7 @@ return bool___nonzero__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.bool___nonzero___doc) final boolean bool___nonzero__() { return value; } @@ -99,7 +99,7 @@ return bool___and__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.bool___and___doc) final PyObject bool___and__(PyObject right) { if (right instanceof PyBoolean) { return Py.newBoolean(value & ((PyBoolean)right).value); @@ -114,7 +114,7 @@ return bool___xor__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.bool___xor___doc) final PyObject bool___xor__(PyObject right) { if (right instanceof PyBoolean) { return Py.newBoolean(value ^ ((PyBoolean)right).value); @@ -129,7 +129,7 @@ return bool___or__(right); } - @ExposedMethod(type = MethodType.BINARY) + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.bool___or___doc) final PyObject bool___or__(PyObject right) { if (right instanceof PyBoolean) { return Py.newBoolean(value | ((PyBoolean)right).value); @@ -144,7 +144,7 @@ return bool___neg__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.bool___neg___doc) final PyObject bool___neg__() { return Py.newInteger(value ? -1 : 0); } @@ -153,7 +153,7 @@ return bool___pos__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.bool___pos___doc) final PyObject bool___pos__() { return Py.newInteger(value ? 1 : 0); } @@ -162,7 +162,7 @@ return bool___abs__(); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.bool___abs___doc) final PyObject bool___abs__() { return Py.newInteger(value ? 1 : 0); } Modified: trunk/jython/src/org/python/core/PyClassMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyClassMethod.java 2009-01-03 02:47:53 UTC (rev 5834) +++ trunk/jython/src/org/python/core/PyClassMethod.java 2009-01-03 04:19:44 UTC (rev 5835) @@ -41,7 +41,7 @@ return classmethod___get__(obj, type); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.classmethod___get___doc) final PyObject classmethod___get__(PyObject obj, PyObject type) { if(type == null) { type = obj.getType(); Modified: trunk/jython/src/org/python/core/PyFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyFunction.java 2009-01-03 02:47:53 UTC (rev 5834) +++ trunk/jython/src/org/python/core/PyFunction.java 2009-01-03 04:19:44 UTC (rev 5835) @@ -276,7 +276,7 @@ function___setattr__(name, value); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.function___setattr___doc) final void function___setattr__(String name, PyObject value) { ensureDict(); super.__setattr__(name, value); @@ -292,7 +292,7 @@ return function___get__(obj, type); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.function___get___doc) final PyObject function___get__(PyObject obj, PyObject type) { return new PyMethod(this, obj, type); } @@ -323,7 +323,7 @@ return function___call__(args, keywords); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.function___call___doc) final PyObject function___call__(PyObject[] args, String[] keywords) { return func_code.call(args, keywords, func_globals, func_defaults, func_closure); } Modified: trunk/jython/src/org/python/core/PyMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyMethod.java 2009-01-03 02:47:53 UTC (rev 5834) +++ trunk/jython/src/org/python/core/PyMethod.java 2009-01-03 04:19:44 UTC (rev 5835) @@ -67,7 +67,7 @@ return im_func.__findattr_ex__(name); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.instancemethod___getattribute___doc) final PyObject instancemethod___getattribute__(PyObject arg0) { String name = asName(arg0); PyObject ret = instancemethod___findattr_ex__(name); @@ -82,7 +82,7 @@ return instancemethod___get__(obj, type); } - @ExposedMethod(defaults = "null") + @ExposedMethod(defaults = "null", doc = BuiltinDocs.instancemethod___get___doc) final PyObject instancemethod___get__(PyObject obj, PyObject type) { // Only if classes are compatible if (obj == null || im_self != null) { @@ -99,7 +99,7 @@ return instancemethod___call__(args, keywords); } - @ExposedMethod + @ExposedMethod(doc = BuiltinDocs.instancemethod___call___doc) final PyObject instancemethod___call__(PyObject[] args, String[] keywords) { PyObject self = im_self; @@ -136,7 +136,7 @@ return instancemethod___cmp__(other); } - @ExposedMethod(type = MethodType.CMP) + @ExposedMethod(type = MethodType.CMP, doc = BuiltinDocs.instancemethod___cmp___doc) final int instancemethod___cmp__(PyObject other) { if (!(other instanceof PyMethod)) { return -2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |