From: <cg...@us...> - 2006-12-03 22:23:59
|
Revision: 3005 http://svn.sourceforge.net/jython/?rev=3005&view=rev Author: cgroves Date: 2006-12-03 14:23:58 -0800 (Sun, 03 Dec 2006) Log Message: ----------- make mro an instance method of a type, not a classmethod Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java trunk/jython/src/templates/type.expose Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2006-12-03 22:23:26 UTC (rev 3004) +++ trunk/jython/src/org/python/core/PyType.java 2006-12-03 22:23:58 UTC (rev 3005) @@ -62,7 +62,7 @@ } } - dict.__setitem__("mro",new PyClassMethod(new PyMethodDescr("mro",PyType.class,0,1,new exposed_mro(null,null)))); + dict.__setitem__("mro",new PyMethodDescr("mro",PyType.class,0,1,new exposed_mro(null,null))); class exposed___getattribute__ extends PyBuiltinFunctionNarrow { private PyType self; @@ -726,8 +726,8 @@ if(metatype.underlying_class != PyType.class && metatype.lookup("mro") != null) { newtype.mro = Py.make_array(metatype.lookup("mro") - .__get__(newtype, metatype) - .__call__()); + .__get__(null, metatype) + .__call__(newtype)); } // __dict__ descriptor Modified: trunk/jython/src/templates/type.expose =================================================================== --- trunk/jython/src/templates/type.expose 2006-12-03 22:23:26 UTC (rev 3004) +++ trunk/jython/src/templates/type.expose 2006-12-03 22:23:58 UTC (rev 3005) @@ -7,9 +7,8 @@ expose_getset: __base__ getBase expose_getset: __bases__ getBases expose_getset: __mro__ getMro -# classmethods -expose_cmeth: :o mro o? # exposed methods +expose_meth: :o mro o? expose_meth: __getattribute__ n{attribute name} String name = `arg0; PyObject ret = self.type___findattr__(name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kz...@us...> - 2006-12-09 05:33:32
|
Revision: 3009 http://svn.sourceforge.net/jython/?rev=3009&view=rev Author: kzuberi Date: 2006-12-08 21:33:30 -0800 (Fri, 08 Dec 2006) Log Message: ----------- add __delete__ support to PyGetSetDescr, and update code generator Modified Paths: -------------- trunk/jython/src/org/python/core/PyGetSetDescr.java trunk/jython/src/templates/gexpose-defs trunk/jython/src/templates/gexpose.py Modified: trunk/jython/src/org/python/core/PyGetSetDescr.java =================================================================== --- trunk/jython/src/org/python/core/PyGetSetDescr.java 2006-12-08 08:12:26 UTC (rev 3008) +++ trunk/jython/src/org/python/core/PyGetSetDescr.java 2006-12-09 05:33:30 UTC (rev 3009) @@ -10,6 +10,8 @@ private Method set_meth; + private Method del_meth; + private Class getset_type; public PyGetSetDescr(PyType dtype, @@ -17,6 +19,18 @@ Class c, String get, String set) { + this(dtype, name, c, get, set, null); + } + public PyGetSetDescr(String name, Class c, String get, String set) { + this(PyType.fromClass(c), name, c, get, set, null); + } + + public PyGetSetDescr(PyType dtype, + String name, + Class c, + String get, + String set, + String del) { this.name = name; this.dtype = dtype; try { @@ -36,10 +50,19 @@ if(Modifier.isStatic(set_meth.getModifiers())) throw Py.SystemError("static getset not supported"); } - } + if(del != null) { + try { + del_meth = c.getMethod(del, new Class[] {}); + } catch(NoSuchMethodException e) { + throw Py.SystemError("bogus getset spec"); + } + if(Modifier.isStatic(del_meth.getModifiers())) + throw Py.SystemError("static getset not supported"); + } + } - public PyGetSetDescr(String name, Class c, String get, String set) { - this(PyType.fromClass(c), name, c, get, set); + public PyGetSetDescr(String name, Class c, String get, String set, String del) { + this(PyType.fromClass(c), name, c, get, set, del); } public String toString() { @@ -97,6 +120,23 @@ } } + public void __delete__(PyObject obj) { + try { + if(obj != null) { + PyType objtype = obj.getType(); + if(objtype != dtype && !objtype.isSubType(dtype)) + throw get_wrongtype(objtype); + del_meth.invoke(obj, new Object[0]); + } + } catch(IllegalArgumentException e) { + throw Py.JavaError(e); + } catch(IllegalAccessException e) { + throw Py.JavaError(e); // unexpected + } catch(InvocationTargetException e) { + throw Py.JavaError(e); + } + } + /** * @see org.python.core.PyObject#implementsDescrSet() */ @@ -104,10 +144,15 @@ return set_meth != null; } + public boolean implementsDescrDelete() { + return del_meth != null; + } + /** * @see org.python.core.PyObject#isDataDescr() */ public boolean isDataDescr() { return true; } + } Modified: trunk/jython/src/templates/gexpose-defs =================================================================== --- trunk/jython/src/templates/gexpose-defs 2006-12-08 08:12:26 UTC (rev 3008) +++ trunk/jython/src/templates/gexpose-defs 2006-12-09 05:33:30 UTC (rev 3009) @@ -17,8 +17,8 @@ define: getset dict.__setitem__( `strfy`(`name), - new PyGetSetDescr(`strfy`(`name), `typ.class, `get, `set)); - + new PyGetSetDescr(`strfy`(`name), `typ.class, `get, `set, `del)); + define: (ClassBodyDeclarations)call_meths args body public PyObject __call__(`args) { `body; Modified: trunk/jython/src/templates/gexpose.py =================================================================== --- trunk/jython/src/templates/gexpose.py 2006-12-08 08:12:26 UTC (rev 3008) +++ trunk/jython/src/templates/gexpose.py 2006-12-09 05:33:30 UTC (rev 3009) @@ -148,26 +148,33 @@ parms = parm.strip().split() - if len(parms) not in (2,3): + if len(parms) not in (2,3,4): self.invalid(name, parm) name = parms[0] get = '"%s"' % parms[1] - if len(parms) == 3: + + if len(parms) >= 3: set = '"%s"' % parms[2] else: set = "null" + if len(parms) == 4: + del_meth = '"%s"' % parms[3] + else: + del_meth = "null" + getset_bindings = self.global_bindings.copy() getset_bindings['name'] = JavaTemplate(make_id(name)) getset_bindings['get'] = JavaTemplate(make_literal(get)) getset_bindings['set'] = JavaTemplate(make_literal(set)) + getset_bindings['del'] = JavaTemplate(make_literal(del_meth)) getset = self.get_aux('getset') self.statements.append(getset.tbind(getset_bindings)) - + NOARGS = JavaTemplate("void()") EMPTYALL = JavaTemplate(jast_make(jast.Expressions)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kz...@us...> - 2006-12-09 05:54:20
|
Revision: 3010 http://svn.sourceforge.net/jython/?rev=3010&view=rev Author: kzuberi Date: 2006-12-08 21:54:19 -0800 (Fri, 08 Dec 2006) Log Message: ----------- make instance dicts assignable, bug 1506749 Modified Paths: -------------- trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyType.java trunk/jython/src/templates/gderived-defs trunk/jython/src/templates/type.expose Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2006-12-09 05:33:30 UTC (rev 3009) +++ trunk/jython/src/org/python/core/PyObject.java 2006-12-09 05:54:19 UTC (rev 3010) @@ -17,8 +17,8 @@ public static final String exposed_name="object"; public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - dict.__setitem__("__class__",new PyGetSetDescr("__class__",PyObject.class,"getType",null)); - dict.__setitem__("__doc__",new PyGetSetDescr("__doc__",PyObject.class,"getDoc",null)); + dict.__setitem__("__class__",new PyGetSetDescr("__class__",PyObject.class,"getType",null,null)); + dict.__setitem__("__doc__",new PyGetSetDescr("__doc__",PyObject.class,"getDoc",null,null)); class exposed___reduce__ extends PyBuiltinFunctionNarrow { private PyObject self; @@ -2791,7 +2791,16 @@ return null; } + public void setDict(PyObject newDict) { + // fallback if setDict not implemented in subclass + throw Py.TypeError("can't set attribute '__dict__' of instance of " + getType().safeRepr()); + } + public void delDict() { + // fallback to error + throw Py.TypeError("can't delete attribute '__dict__' of instance of '" + getType().safeRepr()+ "'"); + } + public boolean implementsDescrSet() { return objtype.has_set; } Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2006-12-09 05:33:30 UTC (rev 3009) +++ trunk/jython/src/org/python/core/PyType.java 2006-12-09 05:54:19 UTC (rev 3010) @@ -21,11 +21,11 @@ public static final String exposed_name="type"; public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - dict.__setitem__("__dict__",new PyGetSetDescr("__dict__",PyType.class,"getDict",null)); - dict.__setitem__("__name__",new PyGetSetDescr("__name__",PyType.class,"fastGetName",null)); - dict.__setitem__("__base__",new PyGetSetDescr("__base__",PyType.class,"getBase",null)); - dict.__setitem__("__bases__",new PyGetSetDescr("__bases__",PyType.class,"getBases",null)); - dict.__setitem__("__mro__",new PyGetSetDescr("__mro__",PyType.class,"getMro",null)); + dict.__setitem__("__dict__",new PyGetSetDescr("__dict__",PyType.class,"getDict","setDict","delDict")); + dict.__setitem__("__name__",new PyGetSetDescr("__name__",PyType.class,"fastGetName",null,null)); + dict.__setitem__("__base__",new PyGetSetDescr("__base__",PyType.class,"getBase",null,null)); + dict.__setitem__("__bases__",new PyGetSetDescr("__bases__",PyType.class,"getBases",null,null)); + dict.__setitem__("__mro__",new PyGetSetDescr("__mro__",PyType.class,"getMro",null,null)); class exposed_mro extends PyBuiltinFunctionNarrow { private PyType self; @@ -732,7 +732,7 @@ // __dict__ descriptor if (newtype.needs_userdict && newtype.lookup("__dict__")==null) { - dict.__setitem__("__dict__",new PyGetSetDescr(newtype,"__dict__",PyObject.class,"getDict",null)); + dict.__setitem__("__dict__",new PyGetSetDescr(newtype,"__dict__",PyObject.class,"getDict","setDict","delDict")); } newtype.has_set = newtype.lookup("__set__") != null; @@ -1296,7 +1296,15 @@ public PyObject getDict() { // xxx return dict-proxy return dict; } + + public void setDict(PyObject newDict) { + throw Py.TypeError("can't set attribute '__dict__' of type '" + name + "'"); + } + public void delDict() { + throw Py.TypeError("can't delete attribute '__dict__' of type '" + name + "'"); + } + public Object __tojava__(Class c) { if (underlying_class!= null &&( c == Object.class || c == Class.class || c == Serializable.class)) { Modified: trunk/jython/src/templates/gderived-defs =================================================================== --- trunk/jython/src/templates/gderived-defs 2006-12-09 05:33:30 UTC (rev 3009) +++ trunk/jython/src/templates/gderived-defs 2006-12-09 05:54:19 UTC (rev 3010) @@ -70,6 +70,20 @@ return dict; } + public void setDict(PyObject newDict) { + if (newDict instanceof PyStringMap || newDict instanceof PyDictionary ) { + dict = newDict; + } + else { + throw Py.TypeError("__dict__ must be set to a Dictionary " + newDict.getClass().getName()); + } + } + + public void delDict() { + // deleting an object's instance dict makes it grow a new one + dict = new PyStringMap(); + } + define: (ClassBodyDeclarations)ctr public `concat`(`base,Derived)(PyType subtype,`extraargs) { super(subtype,`extra); Modified: trunk/jython/src/templates/type.expose =================================================================== --- trunk/jython/src/templates/type.expose 2006-12-09 05:33:30 UTC (rev 3009) +++ trunk/jython/src/templates/type.expose 2006-12-09 05:54:19 UTC (rev 3010) @@ -2,7 +2,7 @@ type_name: type type_class: PyType # getsets -expose_getset: __dict__ getDict +expose_getset: __dict__ getDict setDict delDict expose_getset: __name__ fastGetName expose_getset: __base__ getBase expose_getset: __bases__ getBases This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2006-12-09 18:05:06
|
Revision: 3014 http://svn.sourceforge.net/jython/?rev=3014&view=rev Author: cgroves Date: 2006-12-09 10:05:00 -0800 (Sat, 09 Dec 2006) Log Message: ----------- added set and del for __class__ Modified Paths: -------------- trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/templates/object.expose Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2006-12-09 17:54:13 UTC (rev 3013) +++ trunk/jython/src/org/python/core/PyObject.java 2006-12-09 18:05:00 UTC (rev 3014) @@ -17,7 +17,7 @@ public static final String exposed_name="object"; public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - dict.__setitem__("__class__",new PyGetSetDescr("__class__",PyObject.class,"getType",null,null)); + dict.__setitem__("__class__",new PyGetSetDescr("__class__",PyObject.class,"getType","setType","delType")); dict.__setitem__("__doc__",new PyGetSetDescr("__doc__",PyObject.class,"getDoc",null,null)); class exposed___reduce__ extends PyBuiltinFunctionNarrow { @@ -394,6 +394,21 @@ return objtype; } + public void setType(PyType type) { + PyType objectType = PyType.fromClass(PyObject.class); + if(PyObjectDerived.class.isAssignableFrom(getClass()) + && type.getStatic().equals(objectType) && + !type.equals(objectType)) { + this.objtype = type; + } else { + throw Py.TypeError("Can only assign subtypes of object to __class__ on subclasses of object"); + } + } + + public void delType() { + throw Py.TypeError("Can't delete __class__ attribute"); + } + // xxx public PyObject fastGetClass() { return objtype; Modified: trunk/jython/src/templates/object.expose =================================================================== --- trunk/jython/src/templates/object.expose 2006-12-09 17:54:13 UTC (rev 3013) +++ trunk/jython/src/templates/object.expose 2006-12-09 18:05:00 UTC (rev 3014) @@ -2,7 +2,7 @@ type_name: object type_class: PyObject # getsets -expose_getset: __class__ getType +expose_getset: __class__ getType setType delType expose_getset: __doc__ getDoc # exposed methods This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2006-12-09 18:25:51
|
Revision: 3015 http://svn.sourceforge.net/jython/?rev=3015&view=rev Author: pedronis Date: 2006-12-09 10:25:49 -0800 (Sat, 09 Dec 2006) Log Message: ----------- use java_templating in templates/make_binops.py to generate the non-comparison binary op dispatching logic in PyObject.java, for now simply regnerate the old code. Modified Paths: -------------- trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/templates/java_pretty.py trunk/jython/src/templates/java_templating.py Added Paths: ----------- trunk/jython/src/templates/make_binops.py Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2006-12-09 18:05:00 UTC (rev 3014) +++ trunk/jython/src/org/python/core/PyObject.java 2006-12-09 18:25:49 UTC (rev 3015) @@ -2010,15 +2010,13 @@ * with these operands. **/ public final PyObject _add(PyObject o2) { - PyObject x = __add__(o2); - if (x != null) { + PyObject x=__add__(o2); + if (x!=null) return x; - } - x = o2.__radd__(this); - if (x != null) { + x=o2.__radd__(this); + if (x!=null) return x; - } - throw Py.TypeError(_unsupportedop("+", o2)); + throw Py.TypeError(_unsupportedop("+",o2)); } /** @@ -2062,13 +2060,13 @@ * with these operands. **/ public final PyObject _sub(PyObject o2) { - PyObject x = __sub__(o2); - if (x != null) + PyObject x=__sub__(o2); + if (x!=null) return x; - x = o2.__rsub__(this); - if (x != null) + x=o2.__rsub__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("-", o2)); + throw Py.TypeError(_unsupportedop("-",o2)); } /** @@ -2112,13 +2110,13 @@ * with these operands. **/ public final PyObject _mul(PyObject o2) { - PyObject x = __mul__(o2); - if (x != null) + PyObject x=__mul__(o2); + if (x!=null) return x; - x = o2.__rmul__(this); - if (x != null) + x=o2.__rmul__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("*", o2)); + throw Py.TypeError(_unsupportedop("*",o2)); } /** @@ -2164,13 +2162,13 @@ public final PyObject _div(PyObject o2) { if (Options.Qnew) return _truediv(o2); - PyObject x = __div__(o2); - if (x != null) + PyObject x=__div__(o2); + if (x!=null) return x; - x = o2.__rdiv__(this); - if (x != null) + x=o2.__rdiv__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("/", o2)); + throw Py.TypeError(_unsupportedop("/",o2)); } /** @@ -2214,13 +2212,13 @@ * with these operands. **/ public final PyObject _floordiv(PyObject o2) { - PyObject x = __floordiv__(o2); - if (x != null) + PyObject x=__floordiv__(o2); + if (x!=null) return x; - x = o2.__rfloordiv__(this); - if (x != null) + x=o2.__rfloordiv__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("//", o2)); + throw Py.TypeError(_unsupportedop("//",o2)); } /** @@ -2264,13 +2262,13 @@ * with these operands. **/ public final PyObject _truediv(PyObject o2) { - PyObject x = __truediv__(o2); - if (x != null) + PyObject x=__truediv__(o2); + if (x!=null) return x; - x = o2.__rtruediv__(this); - if (x != null) + x=o2.__rtruediv__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("/", o2)); + throw Py.TypeError(_unsupportedop("/",o2)); } /** @@ -2314,13 +2312,13 @@ * with these operands. **/ public final PyObject _mod(PyObject o2) { - PyObject x = __mod__(o2); - if (x != null) + PyObject x=__mod__(o2); + if (x!=null) return x; - x = o2.__rmod__(this); - if (x != null) + x=o2.__rmod__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("%", o2)); + throw Py.TypeError(_unsupportedop("%",o2)); } /** @@ -2364,14 +2362,13 @@ * with these operands. **/ public final PyObject _divmod(PyObject o2) { - PyObject x = __divmod__(o2); - if (x != null) + PyObject x=__divmod__(o2); + if (x!=null) return x; - x = o2.__rdivmod__(this); - if (x != null) + x=o2.__rdivmod__(this); + if (x!=null) return x; - //FIXME: - throw Py.TypeError(_unsupportedop("divmod", o2)); + throw Py.TypeError(_unsupportedop("divmod",o2)); } /** @@ -2382,7 +2379,7 @@ * is not defined **/ public PyObject __pow__(PyObject other) { - return __pow__(other, null); + return __pow__(other,null); } /** @@ -2415,13 +2412,13 @@ * with these operands. **/ public final PyObject _pow(PyObject o2) { - PyObject x = __pow__(o2); - if (x != null) + PyObject x=__pow__(o2); + if (x!=null) return x; - x = o2.__rpow__(this); - if (x != null) + x=o2.__rpow__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("**", o2)); + throw Py.TypeError(_unsupportedop("**",o2)); } /** @@ -2465,13 +2462,13 @@ * with these operands. **/ public final PyObject _lshift(PyObject o2) { - PyObject x = __lshift__(o2); - if (x != null) + PyObject x=__lshift__(o2); + if (x!=null) return x; - x = o2.__rlshift__(this); - if (x != null) + x=o2.__rlshift__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("<<", o2)); + throw Py.TypeError(_unsupportedop("<<",o2)); } /** @@ -2515,13 +2512,13 @@ * with these operands. **/ public final PyObject _rshift(PyObject o2) { - PyObject x = __rshift__(o2); - if (x != null) + PyObject x=__rshift__(o2); + if (x!=null) return x; - x = o2.__rrshift__(this); - if (x != null) + x=o2.__rrshift__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop(">>", o2)); + throw Py.TypeError(_unsupportedop(">>",o2)); } /** @@ -2565,13 +2562,13 @@ * with these operands. **/ public final PyObject _and(PyObject o2) { - PyObject x = __and__(o2); - if (x != null) + PyObject x=__and__(o2); + if (x!=null) return x; - x = o2.__rand__(this); - if (x != null) + x=o2.__rand__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("&", o2)); + throw Py.TypeError(_unsupportedop("&",o2)); } /** @@ -2615,13 +2612,13 @@ * with these operands. **/ public final PyObject _or(PyObject o2) { - PyObject x = __or__(o2); - if (x != null) + PyObject x=__or__(o2); + if (x!=null) return x; - x = o2.__ror__(this); - if (x != null) + x=o2.__ror__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("|", o2)); + throw Py.TypeError(_unsupportedop("|",o2)); } /** @@ -2665,13 +2662,13 @@ * with these operands. **/ public final PyObject _xor(PyObject o2) { - PyObject x = __xor__(o2); - if (x != null) + PyObject x=__xor__(o2); + if (x!=null) return x; - x = o2.__rxor__(this); - if (x != null) + x=o2.__rxor__(this); + if (x!=null) return x; - throw Py.TypeError(_unsupportedop("^", o2)); + throw Py.TypeError(_unsupportedop("^",o2)); } // Generated by make_binops.py (End) Modified: trunk/jython/src/templates/java_pretty.py =================================================================== --- trunk/jython/src/templates/java_pretty.py 2006-12-09 18:05:00 UTC (rev 3014) +++ trunk/jython/src/templates/java_pretty.py 2006-12-09 18:25:49 UTC (rev 3015) @@ -66,7 +66,17 @@ def dedent(self): self.indent_level.pop() self.col = self.indent_level[-1] + +class substs: + def __init__(self, dic): + self.dic = dic + def __getitem__(self, key): + try: + return self.dic[key] + except KeyError: + return "<%s>" % key + class JavaPrinter(IndentPrinter): clashes = ("//","/*","++","--") @@ -86,7 +96,7 @@ col = comment.col comment = comment.value if subst is not None: - comment = comment % subst + comment = comment % substs(subst) lines = comment.split('\n') first = lines[0] self.write(first) Modified: trunk/jython/src/templates/java_templating.py =================================================================== --- trunk/jython/src/templates/java_templating.py 2006-12-09 18:05:00 UTC (rev 3014) +++ trunk/jython/src/templates/java_templating.py 2006-12-09 18:25:49 UTC (rev 3015) @@ -331,6 +331,9 @@ return output.getvalue() else: return None + + def __str__(self): + return self.texpand({}) def tvisit(self,visitor,args=None,paren=[],bindings=None,expect=None,ctxt=None): before = [] Added: trunk/jython/src/templates/make_binops.py =================================================================== --- trunk/jython/src/templates/make_binops.py (rev 0) +++ trunk/jython/src/templates/make_binops.py 2006-12-09 18:25:49 UTC (rev 3015) @@ -0,0 +1,102 @@ +"""generates code for binops in PyObject and for all "simple" ops in PyInstance""" + +from java_templating import JavaTemplate as jt, concat, csub + +binops = \ + [('add', '+'), ('sub', '-'), ('mul', '*'), ('div', '/'), + ('floordiv', '//'), ('truediv', '/'), + ('mod', '%'), ('divmod', 'divmod'), ('pow', '**'), + ('lshift', '<<'), ('rshift', '>>'), ('and', '&'), ('or', '|'), ('xor', '^')] + +template = jt(""" + `csub`( + /** + * Equivalent to the standard Python __%(name)s__ method + * @param other the object to perform this binary operation with + * (the right-hand operand). + * @return the result of the %(name)s, or null if this operation + * is not defined + **/ + ); + public PyObject `concat`(__,`name, __)(PyObject other) { `function; } + + `csub`( + /** + * Equivalent to the standard Python __r%(name)s__ method + * @param other the object to perform this binary operation with + * (the left-hand operand). + * @return the result of the %(name)s, or null if this operation + * is not defined. + **/ + ); + public PyObject `concat`(__r,`name, __)(PyObject other) { `rfunction; } + + `csub`( + /** + * Equivalent to the standard Python __i%(name)s__ method + * @param other the object to perform this binary operation with + * (the right-hand operand). + * @return the result of the %(name)s, or null if this operation + * is not defined + **/ + ); + public PyObject `concat`(__i, `name, __)(PyObject other) { + return `concat`(_, `name)(other); + } + + `csub`( + /** + * Implements the Python expression <code>this %(bareop)s other</code> + * @param o2 the object to perform this binary operation with. + * @return the result of the %(name)s. + * @exception Py.TypeError if this operation can't be performed + * with these operands. + **/ + ); + public final PyObject `concat`(_, `name)(PyObject o2) { + `divhook; + PyObject x = `concat`(__,`name,__)(o2); + if (x != null) + return x; + x = o2.`concat`(__r,`name,__)(this); + if (x != null) + return x; + throw Py.TypeError(_unsupportedop(`op, o2)); + } +""", bindings={'csub': csub, 'concat': concat }, start='ClassBodyDeclarations') + +def main(): + fp = open('binops.txt', 'w') + + fp.write(' // Generated by make_binops.py (Begin)\n\n') + + for name, op in binops: + rfunction = function = jt('return null;') + divhook = jt("") + + if name == 'pow': + function = jt('return __pow__(other, null);') + if name == 'div': + divhook = jt(''' + if (Options.Qnew) + return _truediv(o2);''') + + + template.tnaked().texpand( + { + 'name': jt(name), + 'op': jt('"%s"' % op), + 'bareop': op, + 'function':function, + 'rfunction':rfunction, + 'divhook':divhook + }, output=fp, nindent=1) + fp.write('\n') + fp.write('\n') + + fp.write(' // Generated by make_binops.py (End)\n\n') + + fp.close() + +if __name__ == '__main__': + main() Property changes on: trunk/jython/src/templates/make_binops.py ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-01-03 03:44:06
|
Revision: 3040 http://svn.sourceforge.net/jython/?rev=3040&view=rev Author: cgroves Date: 2007-01-02 19:44:04 -0800 (Tue, 02 Jan 2007) Log Message: ----------- turned off dict for PyTypeDerived so it gets the dict implementation from PyType. If PyTypeDerived makes its own dict, it doesn't get the items added to the type's dict in a __new__ Modified Paths: -------------- trunk/jython/src/org/python/core/PyTypeDerived.java trunk/jython/src/templates/type.derived Modified: trunk/jython/src/org/python/core/PyTypeDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyTypeDerived.java 2007-01-02 01:44:34 UTC (rev 3039) +++ trunk/jython/src/org/python/core/PyTypeDerived.java 2007-01-03 03:44:04 UTC (rev 3040) @@ -12,33 +12,9 @@ private PyObject[]slots; - private PyObject dict; - - public PyObject fastGetDict() { - return dict; - } - - public PyObject getDict() { - return dict; - } - - public void setDict(PyObject newDict) { - if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { - dict=newDict; - } else { - throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); - } - } - - public void delDict() { - // deleting an object's instance dict makes it grow a new one - dict=new PyStringMap(); - } - public PyTypeDerived(PyType subtype) { super(subtype); slots=new PyObject[subtype.getNumSlots()]; - dict=subtype.instDict(); } public PyString __str__() { Modified: trunk/jython/src/templates/type.derived =================================================================== --- trunk/jython/src/templates/type.derived 2007-01-02 01:44:34 UTC (rev 3039) +++ trunk/jython/src/templates/type.derived 2007-01-03 03:44:04 UTC (rev 3040) @@ -1,4 +1,4 @@ base_class: PyType -want_dict: true +want_dict: false ctr: incl: object This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-01-23 06:02:25
|
Revision: 3058 http://svn.sourceforge.net/jython/?rev=3058&view=rev Author: cgroves Date: 2007-01-22 22:02:23 -0800 (Mon, 22 Jan 2007) Log Message: ----------- expose __mod__ Modified Paths: -------------- trunk/jython/src/org/python/core/PyString.java trunk/jython/src/templates/str.expose Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2007-01-22 21:19:38 UTC (rev 3057) +++ trunk/jython/src/org/python/core/PyString.java 2007-01-23 06:02:23 UTC (rev 3058) @@ -237,6 +237,34 @@ } dict.__setitem__("__add__",new PyMethodDescr("__add__",PyString.class,1,1,new exposed___add__(null,null))); + class exposed___mod__ extends PyBuiltinFunctionNarrow { + + private PyString self; + + public PyObject getSelf() { + return self; + } + + exposed___mod__(PyString self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed___mod__((PyString)self,info); + } + + public PyObject __call__(PyObject arg0) { + return self.str___mod__(arg0); + } + + public PyObject inst_call(PyObject gself,PyObject arg0) { + PyString self=(PyString)gself; + return self.str___mod__(arg0); + } + + } + dict.__setitem__("__mod__",new PyMethodDescr("__mod__",PyString.class,1,1,new exposed___mod__(null,null))); class exposed___mul__ extends PyBuiltinFunctionNarrow { private PyString self; @@ -3343,6 +3371,10 @@ } public PyObject __mod__(PyObject other) { + return str___mod__(other); + } + + public PyObject str___mod__(PyObject other){ StringFormatter fmt = new StringFormatter(string); return createInstance(fmt.format(other)); } Modified: trunk/jython/src/templates/str.expose =================================================================== --- trunk/jython/src/templates/str.expose 2007-01-22 21:19:38 UTC (rev 3057) +++ trunk/jython/src/templates/str.expose 2007-01-23 06:02:23 UTC (rev 3058) @@ -9,6 +9,7 @@ expose_meth: :b __contains__ o expose_meth: :i __len__ expose_meth: __add__ o +expose_meth: __mod__ o expose_meth: __mul__ o expose_meth: __reduce__ expose_meth: __rmul__ o This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-02-24 14:50:54
|
Revision: 3121 http://svn.sourceforge.net/jython/?rev=3121&view=rev Author: cgroves Date: 2007-02-24 06:50:53 -0800 (Sat, 24 Feb 2007) Log Message: ----------- Cleaned up the PyBuiltinFunction hierarchy as a preface to merging things using PyBuiltinFunctionSet to live inside it. Removed inst_call stuff in favor of just binding and calling Updated newstyle stuff in packages other than core by hand as gderived.py can't handle things out of core Modified Paths: -------------- trunk/jython/src/org/python/core/PyBuiltinFunction.java trunk/jython/src/org/python/core/PyClassMethod.java trunk/jython/src/org/python/core/PyClassMethodDescr.java trunk/jython/src/org/python/core/PyComplex.java trunk/jython/src/org/python/core/PyDictionary.java trunk/jython/src/org/python/core/PyEnumerate.java trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/PyFloat.java trunk/jython/src/org/python/core/PyInteger.java trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyLong.java trunk/jython/src/org/python/core/PyMethodDescr.java trunk/jython/src/org/python/core/PyNewWrapper.java trunk/jython/src/org/python/core/PyNone.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyProperty.java trunk/jython/src/org/python/core/PyString.java trunk/jython/src/org/python/core/PySuper.java trunk/jython/src/org/python/core/PyTuple.java trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/core/PyUnicode.java trunk/jython/src/org/python/modules/sets/BaseSet.java trunk/jython/src/org/python/modules/sets/PyImmutableSet.java trunk/jython/src/org/python/modules/sets/PySet.java trunk/jython/src/org/python/modules/sets/PySetDerived.java trunk/jython/src/org/python/modules/time/PyTimeTuple.java trunk/jython/src/templates/bool.expose trunk/jython/src/templates/complex.expose trunk/jython/src/templates/file.expose trunk/jython/src/templates/float.expose trunk/jython/src/templates/gexpose-defs trunk/jython/src/templates/gexpose.py trunk/jython/src/templates/int.expose trunk/jython/src/templates/long.expose trunk/jython/src/templates/mappings trunk/jython/src/templates/property.expose trunk/jython/src/templates/set.expose trunk/jython/src/templates/str.expose trunk/jython/src/templates/super.expose trunk/jython/src/templates/type.expose Added Paths: ----------- trunk/jython/src/org/python/core/PyBuiltinMethod.java trunk/jython/src/org/python/core/PyBuiltinMethodNarrow.java trunk/jython/src/org/python/modules/sets/PyImmutableSetDerived.java trunk/jython/src/templates/immutableset.derived trunk/jython/src/templates/set.derived Removed Paths: ------------- trunk/jython/src/org/python/core/PyBuiltinFunctionNarrow.java trunk/jython/src/org/python/core/PyBuiltinFunctionWide.java Modified: trunk/jython/src/org/python/core/PyBuiltinFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinFunction.java 2007-02-24 14:45:00 UTC (rev 3120) +++ trunk/jython/src/org/python/core/PyBuiltinFunction.java 2007-02-24 14:50:53 UTC (rev 3121) @@ -1,40 +1,54 @@ package org.python.core; -public abstract class PyBuiltinFunction extends PyObject implements PyType.Newstyle { +public abstract class PyBuiltinFunction extends PyObject implements + PyType.Newstyle { - public static final String exposed_name="builtin_function_or_method"; + public static final String exposed_name = "builtin_function_or_method"; - public static void typeSetup(PyObject dict,PyType.Newstyle marker) { + public static void typeSetup(PyObject dict, PyType.Newstyle marker) { dict.__setitem__("__name__", new PyGetSetDescr("__name__", - PyBuiltinFunction.class, "fastGetName", null)); + PyBuiltinFunction.class, + "fastGetName", + null)); dict.__setitem__("__self__", new PyGetSetDescr("__self__", - PyBuiltinFunction.class, "getSelf", null)); + PyBuiltinFunction.class, + "getSelf", + null)); dict.__setitem__("__doc__", new PyGetSetDescr("__doc__", - PyBuiltinFunction.class, "fastGetDoc", null)); + PyBuiltinFunction.class, + "fastGetDoc", + null)); dict.__setitem__("__call__", new PyGetSetDescr("__call__", - PyBuiltinFunction.class, "makeCall", null)); + PyBuiltinFunction.class, + "makeCall", + null)); } - + public interface Info { + String getName(); + int getMaxargs(); + int getMinargs(); + PyException unexpectedCall(int nargs, boolean keywords); } public static class DefaultInfo implements Info { - public DefaultInfo(String name,int minargs,int maxargs) { + public DefaultInfo(String name, int minargs, int maxargs) { this.name = name; this.minargs = minargs; this.maxargs = maxargs; } - public DefaultInfo(String name,int nargs) { - this(name,nargs,nargs); + public DefaultInfo(String name, int nargs) { + this(name, nargs, nargs); } private String name; + private int maxargs, minargs; public String getName() { @@ -44,56 +58,52 @@ public int getMaxargs() { return maxargs; } + public int getMinargs() { return minargs; } - public static boolean check(int nargs,int minargs,int maxargs) { - if (nargs < minargs) + public static boolean check(int nargs, int minargs, int maxargs) { + if(nargs < minargs) return false; - if (maxargs != -1 && nargs > maxargs) + if(maxargs != -1 && nargs > maxargs) return false; return true; } - public static PyException unexpectedCall( - int nargs, - boolean keywords, - String name, - int minargs, - int maxargs) { - if (keywords) + public static PyException unexpectedCall(int nargs, + boolean keywords, + String name, + int minargs, + int maxargs) { + if(keywords) return Py.TypeError(name + "() takes no keyword arguments"); String argsblurb; - if (minargs == maxargs) { - if (minargs == 0) + if(minargs == maxargs) { + if(minargs == 0) argsblurb = "no arguments"; - else if (minargs == 1) + else if(minargs == 1) argsblurb = "exactly one argument"; else argsblurb = minargs + " arguments"; - } else if (maxargs == -1) { - return Py.TypeError(name + "() requires at least " + - minargs + " (" + nargs + " given)"); + } else if(maxargs == -1) { + return Py.TypeError(name + "() requires at least " + minargs + + " (" + nargs + " given)"); } else { - if (minargs <= 0) - argsblurb = "at most "+ maxargs + " arguments"; + if(minargs <= 0) + argsblurb = "at most " + maxargs + " arguments"; else argsblurb = minargs + "-" + maxargs + " arguments"; } - - return Py.TypeError( - name + "() takes " + argsblurb + " (" + nargs + " given)"); + return Py.TypeError(name + "() takes " + argsblurb + " (" + nargs + + " given)"); } public PyException unexpectedCall(int nargs, boolean keywords) { return unexpectedCall(nargs, keywords, name, minargs, maxargs); } - } - protected PyBuiltinFunction() {} - protected PyBuiltinFunction(Info info) { this.info = info; } @@ -104,7 +114,10 @@ this.info = info; } - abstract protected PyBuiltinFunction makeBound(PyObject self); + /** + * @return a new instance of this type of PyBuiltinFunction bound to self + */ + abstract protected PyBuiltinFunction bind(PyObject self); public PyObject getSelf() { return null; @@ -112,41 +125,15 @@ public String toString() { PyObject self = getSelf(); - if (self == null) + if(self == null) return "<built-in function " + info.getName() + ">"; else { String typename = self.getType().fastGetName(); - return "<built-in method " - + info.getName() - + " of " - + typename - + " object>"; + return "<built-in method " + info.getName() + " of " + typename + + " object>"; } } - abstract public PyObject inst_call(PyObject self); - abstract public PyObject inst_call(PyObject self, PyObject arg0); - abstract public PyObject inst_call( - PyObject self, - PyObject arg0, - PyObject arg1); - abstract public PyObject inst_call( - PyObject self, - PyObject arg0, - PyObject arg1, - PyObject arg2); - abstract public PyObject inst_call( - PyObject self, - PyObject arg0, - PyObject arg1, - PyObject arg2, - PyObject arg3); - abstract public PyObject inst_call(PyObject self, PyObject[] args); - abstract public PyObject inst_call( - PyObject self, - PyObject[] args, - String[] keywords); - public PyObject fastGetName() { return Py.newString(this.info.getName()); } @@ -154,8 +141,8 @@ public PyObject fastGetDoc() { return Py.None; } - - public PyObject makeCall(){ + + public PyObject makeCall() { return this; } } Deleted: trunk/jython/src/org/python/core/PyBuiltinFunctionNarrow.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinFunctionNarrow.java 2007-02-24 14:45:00 UTC (rev 3120) +++ trunk/jython/src/org/python/core/PyBuiltinFunctionNarrow.java 2007-02-24 14:50:53 UTC (rev 3121) @@ -1,123 +0,0 @@ -package org.python.core; - -public abstract class PyBuiltinFunctionNarrow extends PyBuiltinFunction { - - public static final Class exposed_as = PyBuiltinFunction.class; - - public PyBuiltinFunctionNarrow(Info info) { - super(info); - } - - public PyObject __call__(PyObject[] args, String[] keywords) { - if (keywords.length != 0) { - throw info.unexpectedCall(args.length, true); - } - return __call__(args); - - } - - public PyObject __call__(PyObject[] args) { - switch (args.length) { - case 0 : - return __call__(); - case 1 : - return __call__(args[0]); - case 2 : - return __call__(args[0], args[1]); - case 3 : - return __call__(args[0], args[1], args[2]); - case 4 : - return __call__(args[0], args[1], args[2], args[3]); - default : - return wide_call(getSelf(), args); - } - } - - public PyObject inst_call( - PyObject self, - PyObject[] args, - String[] keywords) { - if (keywords.length != 0) { - throw info.unexpectedCall(args.length, true); - } - return inst_call(self, args); - } - - public PyObject inst_call(PyObject self, PyObject[] args) { - switch (args.length) { - case 0 : - return inst_call(self); - case 1 : - return inst_call(self, args[0]); - case 2 : - return inst_call(self, args[0], args[1]); - case 3 : - return inst_call(self, args[0], args[1], args[2]); - case 4 : - return inst_call(self, args[0], args[1], args[2], args[3]); - default : - return wide_call(self, args); - } - - } - - /* hooks */ - - public PyObject __call__() { - return inst_call(getSelf()); - } - - public PyObject __call__(PyObject arg0) { - return inst_call(getSelf(), arg0); - } - - public PyObject __call__(PyObject arg0, PyObject arg1) { - return inst_call(getSelf(), arg0, arg1); - } - - public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) { - return inst_call(getSelf(), arg0, arg1, arg2); - } - - public PyObject __call__( - PyObject arg0, - PyObject arg1, - PyObject arg2, - PyObject arg3) { - return inst_call(getSelf(), arg0, arg1, arg2, arg3); - } - - protected PyObject wide_call(PyObject self, PyObject[] wide_args) { - throw info.unexpectedCall(wide_args.length, false); - } - - public PyObject inst_call(PyObject self) { - throw info.unexpectedCall(0, false); - } - - public PyObject inst_call(PyObject self, PyObject arg0) { - throw info.unexpectedCall(1, false); - } - - public PyObject inst_call(PyObject self, PyObject arg0, PyObject arg1) { - throw info.unexpectedCall(2, false); - } - - public PyObject inst_call( - PyObject self, - PyObject arg0, - PyObject arg1, - PyObject arg2) { - throw info.unexpectedCall(3, false); - } - - public PyObject inst_call( - PyObject self, - PyObject arg0, - PyObject arg1, - PyObject arg2, - PyObject arg3) { - throw info.unexpectedCall(4, false); - } - -} Deleted: trunk/jython/src/org/python/core/PyBuiltinFunctionWide.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinFunctionWide.java 2007-02-24 14:45:00 UTC (rev 3120) +++ trunk/jython/src/org/python/core/PyBuiltinFunctionWide.java 2007-02-24 14:50:53 UTC (rev 3121) @@ -1,62 +0,0 @@ -package org.python.core; - -public abstract class PyBuiltinFunctionWide extends PyBuiltinFunction { - - public static final Class exposed_as = PyBuiltinFunction.class; - - public PyBuiltinFunctionWide(Info info) { - super(info); - } - - public PyObject inst_call(PyObject self) { - return inst_call(self,Py.EmptyObjects); - } - - public PyObject inst_call(PyObject self, PyObject arg0) { - return inst_call(self,new PyObject[] {arg0}); - } - - public PyObject inst_call(PyObject self, PyObject arg0, PyObject arg1) { - return inst_call(self,new PyObject[] {arg0,arg1}); - } - - public PyObject inst_call( - PyObject self, - PyObject arg0, - PyObject arg1, - PyObject arg2) { - return inst_call(self,new PyObject[] {arg0,arg1,arg2}); - } - - public PyObject inst_call( - PyObject self, - PyObject arg0, - PyObject arg1, - PyObject arg2, - PyObject arg3) { - return inst_call(self,new PyObject[] {arg0,arg1,arg2,arg3}); - } - - /* to override */ - - public PyObject inst_call( - PyObject self, - PyObject[] args, - String[] keywords) { - if (keywords.length != 0 ) { - throw info.unexpectedCall(args.length,true); - } - return inst_call(self,args); - } - - abstract public PyObject inst_call(PyObject self, PyObject[] args); - - public PyObject __call__(PyObject[] args, String[] keywords) { - return inst_call(getSelf(),args, keywords); - } - - public PyObject __call__(PyObject[] args) { - return inst_call(getSelf(),args); - } - -} Added: trunk/jython/src/org/python/core/PyBuiltinMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinMethod.java (rev 0) +++ trunk/jython/src/org/python/core/PyBuiltinMethod.java 2007-02-24 14:50:53 UTC (rev 3121) @@ -0,0 +1,18 @@ +package org.python.core; + + +public abstract class PyBuiltinMethod extends PyBuiltinFunction { + + public static final Class exposed_as = PyBuiltinFunction.class; + + protected PyBuiltinMethod(PyObject self, Info info) { + super(info); + this.self = self; + } + + public PyObject getSelf(){ + return self; + } + + protected PyObject self; +} Copied: trunk/jython/src/org/python/core/PyBuiltinMethodNarrow.java (from rev 3098, trunk/jython/src/org/python/core/PyBuiltinFunctionNarrow.java) =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinMethodNarrow.java (rev 0) +++ trunk/jython/src/org/python/core/PyBuiltinMethodNarrow.java 2007-02-24 14:50:53 UTC (rev 3121) @@ -0,0 +1,55 @@ +package org.python.core; + +public abstract class PyBuiltinMethodNarrow extends PyBuiltinMethod { + + public PyBuiltinMethodNarrow(PyObject self, Info info) { + super(self, info); + } + + public PyObject __call__(PyObject[] args, String[] keywords) { + if(keywords.length != 0) { + throw info.unexpectedCall(args.length, true); + } + return __call__(args); + } + + public PyObject __call__(PyObject[] args) { + switch(args.length){ + case 0: + return __call__(); + case 1: + return __call__(args[0]); + case 2: + return __call__(args[0], args[1]); + case 3: + return __call__(args[0], args[1], args[2]); + case 4: + return __call__(args[0], args[1], args[2], args[3]); + default: + throw info.unexpectedCall(args.length, false); + } + } + + public PyObject __call__() { + throw info.unexpectedCall(0, false); + } + + public PyObject __call__(PyObject arg0) { + throw info.unexpectedCall(1, false); + } + + public PyObject __call__(PyObject arg0, PyObject arg1) { + throw info.unexpectedCall(2, false); + } + + public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) { + throw info.unexpectedCall(3, false); + } + + public PyObject __call__(PyObject arg0, + PyObject arg1, + PyObject arg2, + PyObject arg3) { + throw info.unexpectedCall(4, false); + } +} Modified: trunk/jython/src/org/python/core/PyClassMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyClassMethod.java 2007-02-24 14:45:00 UTC (rev 3120) +++ trunk/jython/src/org/python/core/PyClassMethod.java 2007-02-24 14:50:53 UTC (rev 3121) @@ -9,41 +9,24 @@ public static final String exposed_name="classmethod"; public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - class exposed___get__ extends PyBuiltinFunctionNarrow { + class exposed___get__ extends PyBuiltinMethodNarrow { - private PyClassMethod self; - - public PyObject getSelf() { - return self; + exposed___get__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___get__(PyClassMethod self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___get__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___get__((PyClassMethod)self,info); - } - public PyObject __call__(PyObject arg0,PyObject arg1) { - return self.classmethod___get__(arg0,arg1); + return((PyClassMethod)self).classmethod___get__(arg0,arg1); } - public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { - PyClassMethod self=(PyClassMethod)gself; - return self.classmethod___get__(arg0,arg1); - } - public PyObject __call__(PyObject arg0) { - return self.classmethod___get__(arg0); + return((PyClassMethod)self).classmethod___get__(arg0); } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyClassMethod self=(PyClassMethod)gself; - return self.classmethod___get__(arg0); - } - } dict.__setitem__("__get__",new PyMethodDescr("__get__",PyClassMethod.class,1,2,new exposed___get__(null,null))); dict.__setitem__("__new__",new PyNewWrapper(PyClassMethod.class,"__new__",1,1) { Modified: trunk/jython/src/org/python/core/PyClassMethodDescr.java =================================================================== --- trunk/jython/src/org/python/core/PyClassMethodDescr.java 2007-02-24 14:45:00 UTC (rev 3120) +++ trunk/jython/src/org/python/core/PyClassMethodDescr.java 2007-02-24 14:50:53 UTC (rev 3121) @@ -6,8 +6,8 @@ Class c, int minargs, int maxargs, - PyBuiltinFunction func) { - super(name, c, minargs, maxargs, func); + PyBuiltinFunction meth) { + super(name, c, minargs, maxargs, meth); } protected void checkCallerType(PyObject obj) { @@ -18,10 +18,10 @@ public PyObject __get__(PyObject obj, PyObject type) { if (obj != null) { checkCallerType(obj.getType()); - return func.makeBound(obj.getType()); + return meth.bind(obj.getType()); }else if(type != null){ checkCallerType(type); - return func.makeBound(type); + return meth.bind(type); } return this; } Modified: trunk/jython/src/org/python/core/PyComplex.java =================================================================== --- trunk/jython/src/org/python/core/PyComplex.java 2007-02-24 14:45:00 UTC (rev 3120) +++ trunk/jython/src/org/python/core/PyComplex.java 2007-02-24 14:50:53 UTC (rev 3121) @@ -18,967 +18,545 @@ public static void typeSetup(PyObject dict,PyType.Newstyle marker) { dict.__setitem__("imag",new PyGetSetDescr("imag",PyComplex.class,"getImag",null,null)); dict.__setitem__("real",new PyGetSetDescr("real",PyComplex.class,"getReal",null,null)); - class exposed___abs__ extends PyBuiltinFunctionNarrow { + class exposed___abs__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___abs__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___abs__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___abs__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___abs__((PyComplex)self,info); - } - public PyObject __call__() { - return self.complex___abs__(); + return((PyComplex)self).complex___abs__(); } - public PyObject inst_call(PyObject gself) { - PyComplex self=(PyComplex)gself; - return self.complex___abs__(); - } - } dict.__setitem__("__abs__",new PyMethodDescr("__abs__",PyComplex.class,0,0,new exposed___abs__(null,null))); - class exposed___float__ extends PyBuiltinFunctionNarrow { + class exposed___float__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___float__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___float__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___float__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___float__((PyComplex)self,info); - } - public PyObject __call__() { - return self.complex___float__(); + return((PyComplex)self).complex___float__(); } - public PyObject inst_call(PyObject gself) { - PyComplex self=(PyComplex)gself; - return self.complex___float__(); - } - } dict.__setitem__("__float__",new PyMethodDescr("__float__",PyComplex.class,0,0,new exposed___float__(null,null))); - class exposed___int__ extends PyBuiltinFunctionNarrow { + class exposed___int__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___int__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___int__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___int__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___int__((PyComplex)self,info); - } - public PyObject __call__() { - return self.complex___int__(); + return((PyComplex)self).complex___int__(); } - public PyObject inst_call(PyObject gself) { - PyComplex self=(PyComplex)gself; - return self.complex___int__(); - } - } dict.__setitem__("__int__",new PyMethodDescr("__int__",PyComplex.class,0,0,new exposed___int__(null,null))); - class exposed___long__ extends PyBuiltinFunctionNarrow { + class exposed___long__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___long__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___long__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___long__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___long__((PyComplex)self,info); - } - public PyObject __call__() { - return self.complex___long__(); + return((PyComplex)self).complex___long__(); } - public PyObject inst_call(PyObject gself) { - PyComplex self=(PyComplex)gself; - return self.complex___long__(); - } - } dict.__setitem__("__long__",new PyMethodDescr("__long__",PyComplex.class,0,0,new exposed___long__(null,null))); - class exposed___neg__ extends PyBuiltinFunctionNarrow { + class exposed___neg__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___neg__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___neg__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___neg__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___neg__((PyComplex)self,info); - } - public PyObject __call__() { - return self.complex___neg__(); + return((PyComplex)self).complex___neg__(); } - public PyObject inst_call(PyObject gself) { - PyComplex self=(PyComplex)gself; - return self.complex___neg__(); - } - } dict.__setitem__("__neg__",new PyMethodDescr("__neg__",PyComplex.class,0,0,new exposed___neg__(null,null))); - class exposed___pos__ extends PyBuiltinFunctionNarrow { + class exposed___pos__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___pos__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___pos__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___pos__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___pos__((PyComplex)self,info); - } - public PyObject __call__() { - return self.complex___pos__(); + return((PyComplex)self).complex___pos__(); } - public PyObject inst_call(PyObject gself) { - PyComplex self=(PyComplex)gself; - return self.complex___pos__(); - } - } dict.__setitem__("__pos__",new PyMethodDescr("__pos__",PyComplex.class,0,0,new exposed___pos__(null,null))); - class exposed___add__ extends PyBuiltinFunctionNarrow { + class exposed___add__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___add__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___add__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___add__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___add__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___add__(arg0); + PyObject ret=((PyComplex)self).complex___add__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___add__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__add__",new PyMethodDescr("__add__",PyComplex.class,1,1,new exposed___add__(null,null))); - class exposed___div__ extends PyBuiltinFunctionNarrow { + class exposed___div__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___div__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___div__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___div__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___div__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___div__(arg0); + PyObject ret=((PyComplex)self).complex___div__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___div__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__div__",new PyMethodDescr("__div__",PyComplex.class,1,1,new exposed___div__(null,null))); - class exposed___divmod__ extends PyBuiltinFunctionNarrow { + class exposed___divmod__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___divmod__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___divmod__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___divmod__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___divmod__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___divmod__(arg0); + PyObject ret=((PyComplex)self).complex___divmod__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___divmod__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__divmod__",new PyMethodDescr("__divmod__",PyComplex.class,1,1,new exposed___divmod__(null,null))); - class exposed___floordiv__ extends PyBuiltinFunctionNarrow { + class exposed___floordiv__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___floordiv__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___floordiv__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___floordiv__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___floordiv__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___floordiv__(arg0); + PyObject ret=((PyComplex)self).complex___floordiv__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___floordiv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__floordiv__",new PyMethodDescr("__floordiv__",PyComplex.class,1,1,new exposed___floordiv__(null,null))); - class exposed___mod__ extends PyBuiltinFunctionNarrow { + class exposed___mod__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___mod__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___mod__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___mod__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___mod__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___mod__(arg0); + PyObject ret=((PyComplex)self).complex___mod__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___mod__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__mod__",new PyMethodDescr("__mod__",PyComplex.class,1,1,new exposed___mod__(null,null))); - class exposed___mul__ extends PyBuiltinFunctionNarrow { + class exposed___mul__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___mul__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___mul__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___mul__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___mul__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___mul__(arg0); + PyObject ret=((PyComplex)self).complex___mul__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___mul__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__mul__",new PyMethodDescr("__mul__",PyComplex.class,1,1,new exposed___mul__(null,null))); - class exposed___radd__ extends PyBuiltinFunctionNarrow { + class exposed___radd__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___radd__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___radd__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___radd__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___radd__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___radd__(arg0); + PyObject ret=((PyComplex)self).complex___radd__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___radd__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__radd__",new PyMethodDescr("__radd__",PyComplex.class,1,1,new exposed___radd__(null,null))); - class exposed___rdiv__ extends PyBuiltinFunctionNarrow { + class exposed___rdiv__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___rdiv__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___rdiv__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___rdiv__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___rdiv__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___rdiv__(arg0); + PyObject ret=((PyComplex)self).complex___rdiv__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___rdiv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__rdiv__",new PyMethodDescr("__rdiv__",PyComplex.class,1,1,new exposed___rdiv__(null,null))); - class exposed___rdivmod__ extends PyBuiltinFunctionNarrow { + class exposed___rdivmod__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___rdivmod__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___rdivmod__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___rdivmod__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___rdivmod__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___rdivmod__(arg0); + PyObject ret=((PyComplex)self).complex___rdivmod__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___rdivmod__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__rdivmod__",new PyMethodDescr("__rdivmod__",PyComplex.class,1,1,new exposed___rdivmod__(null,null))); - class exposed___rfloordiv__ extends PyBuiltinFunctionNarrow { + class exposed___rfloordiv__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___rfloordiv__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___rfloordiv__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___rfloordiv__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___rfloordiv__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___rfloordiv__(arg0); + PyObject ret=((PyComplex)self).complex___rfloordiv__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___rfloordiv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__rfloordiv__",new PyMethodDescr("__rfloordiv__",PyComplex.class,1,1,new exposed___rfloordiv__(null,null))); - class exposed___rmod__ extends PyBuiltinFunctionNarrow { + class exposed___rmod__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___rmod__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___rmod__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___rmod__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___rmod__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___rmod__(arg0); + PyObject ret=((PyComplex)self).complex___rmod__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___rmod__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__rmod__",new PyMethodDescr("__rmod__",PyComplex.class,1,1,new exposed___rmod__(null,null))); - class exposed___rmul__ extends PyBuiltinFunctionNarrow { + class exposed___rmul__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___rmul__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___rmul__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___rmul__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___rmul__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___rmul__(arg0); + PyObject ret=((PyComplex)self).complex___rmul__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___rmul__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__rmul__",new PyMethodDescr("__rmul__",PyComplex.class,1,1,new exposed___rmul__(null,null))); - class exposed___rpow__ extends PyBuiltinFunctionNarrow { + class exposed___rpow__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___rpow__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___rpow__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___rpow__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___rpow__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___rpow__(arg0); + PyObject ret=((PyComplex)self).complex___rpow__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___rpow__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__rpow__",new PyMethodDescr("__rpow__",PyComplex.class,1,1,new exposed___rpow__(null,null))); - class exposed___rsub__ extends PyBuiltinFunctionNarrow { + class exposed___rsub__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___rsub__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___rsub__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___rsub__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___rsub__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___rsub__(arg0); + PyObject ret=((PyComplex)self).complex___rsub__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___rsub__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__rsub__",new PyMethodDescr("__rsub__",PyComplex.class,1,1,new exposed___rsub__(null,null))); - class exposed___rtruediv__ extends PyBuiltinFunctionNarrow { + class exposed___rtruediv__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___rtruediv__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___rtruediv__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___rtruediv__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___rtruediv__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___rtruediv__(arg0); + PyObject ret=((PyComplex)self).complex___rtruediv__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___rtruediv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__rtruediv__",new PyMethodDescr("__rtruediv__",PyComplex.class,1,1,new exposed___rtruediv__(null,null))); - class exposed___sub__ extends PyBuiltinFunctionNarrow { + class exposed___sub__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___sub__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___sub__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___sub__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___sub__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___sub__(arg0); + PyObject ret=((PyComplex)self).complex___sub__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___sub__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__sub__",new PyMethodDescr("__sub__",PyComplex.class,1,1,new exposed___sub__(null,null))); - class exposed___truediv__ extends PyBuiltinFunctionNarrow { + class exposed___truediv__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___truediv__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___truediv__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___truediv__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___truediv__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___truediv__(arg0); + PyObject ret=((PyComplex)self).complex___truediv__(arg0); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___truediv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__truediv__",new PyMethodDescr("__truediv__",PyComplex.class,1,1,new exposed___truediv__(null,null))); - class exposed___pow__ extends PyBuiltinFunctionNarrow { + class exposed___pow__ extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed___pow__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed___pow__(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed___pow__(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed___pow__((PyComplex)self,info); - } - public PyObject __call__(PyObject arg0,PyObject arg1) { - PyObject ret=self.complex___pow__(arg0,arg1); + PyObject ret=((PyComplex)self).complex___pow__(arg0,arg1); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___pow__(arg0,arg1); - if (ret==null) - return Py.NotImplemented; - return ret; - } - public PyObject __call__(PyObject arg0) { - PyObject ret=self.complex___pow__(arg0,null); + PyObject ret=((PyComplex)self).complex___pow__(arg0,null); if (ret==null) return Py.NotImplemented; return ret; } - public PyObject inst_call(PyObject gself,PyObject arg0) { - PyComplex self=(PyComplex)gself; - PyObject ret=self.complex___pow__(arg0,null); - if (ret==null) - return Py.NotImplemented; - return ret; - } - } dict.__setitem__("__pow__",new PyMethodDescr("__pow__",PyComplex.class,1,2,new exposed___pow__(null,null))); - class exposed_conjugate extends PyBuiltinFunctionNarrow { + class exposed_conjugate extends PyBuiltinMethodNarrow { - private PyComplex self; - - public PyObject getSelf() { - return self; + exposed_conjugate(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); } - exposed_conjugate(PyComplex self,PyBuiltinFunction.Info info) { - super(info); - this.self=self; + public PyBuiltinFunction bind(PyObject self) { + return new exposed_conjugate(self,info); } - public PyBuiltinFunction makeBound(PyObject self) { - return new exposed_conjugate((PyComplex)self,info); - } - public PyObject __call__() { - return self.complex_conjugate(); + retu... [truncated message content] |
From: <cg...@us...> - 2007-02-27 19:23:32
|
Revision: 3124 http://svn.sourceforge.net/jython/?rev=3124&view=rev Author: cgroves Date: 2007-02-27 11:23:31 -0800 (Tue, 27 Feb 2007) Log Message: ----------- made array a new-style class, removed the class dict init and use of PyBuitinFunctionSet from PySequence Modified Paths: -------------- trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PySequence.java trunk/jython/src/org/python/modules/ArrayModule.java trunk/jython/src/org/python/modules/jarray.java trunk/jython/src/templates/mappings Added Paths: ----------- trunk/jython/src/org/python/core/PyArrayDerived.java trunk/jython/src/templates/array.derived trunk/jython/src/templates/array.expose Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2007-02-26 17:57:58 UTC (rev 3123) +++ trunk/jython/src/org/python/core/PyArray.java 2007-02-27 19:23:31 UTC (rev 3124) @@ -13,60 +13,588 @@ /** * A wrapper class around native java arrays. - * - * Instances of PyArray are created either by java functions or - * directly by the jarray module. + * + * Instances of PyArray are created either by java functions or directly by the + * jarray module. * <p> * See also the jarray module. */ -public class PyArray extends PySequence implements Cloneable, ClassDictInit { +public class PyArray extends PySequence implements Cloneable { - protected Object data; - protected Class type; - protected String typecode; - protected ArrayDelegate delegate; + //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py + /* type info */ + public static final String exposed_name="array"; + + public static final Class exposed_base=PyObject.class; + + public static void typeSetup(PyObject dict,PyType.Newstyle marker) { + class exposed___ne__ extends PyBuiltinMethodNarrow { + + exposed___ne__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___ne__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyArray)self).seq___ne__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ne__",new PyMethodDescr("__ne__",PyArray.class,1,1,new exposed___ne__(null,null))); + class exposed___eq__ extends PyBuiltinMethodNarrow { + + exposed___eq__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___eq__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyArray)self).seq___eq__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyArray.class,1,1,new exposed___eq__(null,null))); + class exposed___getitem__ extends PyBuiltinMethodNarrow { + + exposed___getitem__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___getitem__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyArray)self).seq___finditem__(arg0); + if (ret==null) { + throw Py.IndexError("index out of range: "+arg0); + } + return ret; + } + + } + dict.__setitem__("__getitem__",new PyMethodDescr("__getitem__",PyArray.class,1,1,new exposed___getitem__(null,null))); + class exposed___contains__ extends PyBuiltinMethodNarrow { + + exposed___contains__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___contains__(self,info); + } + + public PyObject __call__(PyObject arg0) { + return Py.newBoolean(((PyArray)self).object___contains__(arg0)); + } + + } + dict.__setitem__("__contains__",new PyMethodDescr("__contains__",PyArray.class,1,1,new exposed___contains__(null,null))); + class exposed___delitem__ extends PyBuiltinMethodNarrow { + + exposed___delitem__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___delitem__(self,info); + } + + public PyObject __call__(PyObject arg0) { + ((PyArray)self).seq___delitem__(arg0); + return Py.None; + } + + } + dict.__setitem__("__delitem__",new PyMethodDescr("__delitem__",PyArray.class,1,1,new exposed___delitem__(null,null))); + class exposed___setitem__ extends PyBuiltinMethodNarrow { + + exposed___setitem__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___setitem__(self,info); + } + + public PyObject __call__(PyObject arg0,PyObject arg1) { + ((PyArray)self).seq___setitem__(arg0,arg1); + return Py.None; + } + + } + dict.__setitem__("__setitem__",new PyMethodDescr("__setitem__",PyArray.class,2,2,new exposed___setitem__(null,null))); + class exposed___nonzero__ extends PyBuiltinMethodNarrow { + + exposed___nonzero__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___nonzero__(self,info); + } + + public PyObject __call__() { + return Py.newBoolean(((PyArray)self).seq___nonzero__()); + } + + } + dict.__setitem__("__nonzero__",new PyMethodDescr("__nonzero__",PyArray.class,0,0,new exposed___nonzero__(null,null))); + class exposed___getslice__ extends PyBuiltinMethodNarrow { + + exposed___getslice__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___getslice__(self,info); + } + + public PyObject __call__(PyObject arg0,PyObject arg1,PyObject arg2) { + return((PyArray)self).seq___getslice__(arg0,arg1,arg2); + } + + public PyObject __call__(PyObject arg0,PyObject arg1) { + return((PyArray)self).seq___getslice__(arg0,arg1); + } + + } + dict.__setitem__("__getslice__",new PyMethodDescr("__getslice__",PyArray.class,2,3,new exposed___getslice__(null,null))); + class exposed___delslice__ extends PyBuiltinMethodNarrow { + + exposed___delslice__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___delslice__(self,info); + } + + public PyObject __call__(PyObject arg0,PyObject arg1,PyObject arg2) { + ((PyArray)self).seq___delslice__(arg0,arg1,arg2); + return Py.None; + } + + } + dict.__setitem__("__delslice__",new PyMethodDescr("__delslice__",PyArray.class,3,3,new exposed___delslice__(null,null))); + class exposed___setslice__ extends PyBuiltinMethodNarrow { + + exposed___setslice__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___setslice__(self,info); + } + + public PyObject __call__(PyObject arg0,PyObject arg1,PyObject arg2,PyObject arg3) { + ((PyArray)self).seq___setslice__(arg0,arg1,arg2,arg3); + return Py.None; + } + + public PyObject __call__(PyObject arg0,PyObject arg1,PyObject arg2) { + ((PyArray)self).seq___setslice__(arg0,arg1,arg2); + return Py.None; + } + + } + dict.__setitem__("__setslice__",new PyMethodDescr("__setslice__",PyArray.class,3,4,new exposed___setslice__(null,null))); + dict.__setitem__("itemsize",new PyGetSetDescr("itemsize",PyArray.class,"getItemsize",null,null)); + dict.__setitem__("typecode",new PyGetSetDescr("typecode",PyArray.class,"getTypecode",null,null)); + class exposed_append extends PyBuiltinMethodNarrow { + + exposed_append(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_append(self,info); + } + + public PyObject __call__(PyObject arg0) { + ((PyArray)self).array_append(arg0); + return Py.None; + } + + } + dict.__setitem__("append",new PyMethodDescr("append",PyArray.class,1,1,new exposed_append(null,null))); + class exposed_byteswap extends PyBuiltinMethodNarrow { + + exposed_byteswap(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_byteswap(self,info); + } + + public PyObject __call__() { + ((PyArray)self).array_byteswap(); + return Py.None; + } + + } + dict.__setitem__("byteswap",new PyMethodDescr("byteswap",PyArray.class,0,0,new exposed_byteswap(null,null))); + class exposed_count extends PyBuiltinMethodNarrow { + + exposed_count(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_count(self,info); + } + + public PyObject __call__(PyObject arg0) { + return Py.newInteger(((PyArray)self).array_count(arg0)); + } + + } + dict.__setitem__("count",new PyMethodDescr("count",PyArray.class,1,1,new exposed_count(null,null))); + class exposed_extend extends PyBuiltinMethodNarrow { + + exposed_extend(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_extend(self,info); + } + + public PyObject __call__(PyObject arg0) { + ((PyArray)self).array_extend(arg0); + return Py.None; + } + + } + dict.__setitem__("extend",new PyMethodDescr("extend",PyArray.class,1,1,new exposed_extend(null,null))); + class exposed_fromfile extends PyBuiltinMethodNarrow { + + exposed_fromfile(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_fromfile(self,info); + } + + public PyObject __call__(PyObject arg0,PyObject arg1) { + try { + ((PyArray)self).array_fromfile(arg0,arg1.asInt(1)); + return Py.None; + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 1: + msg="expected an integer"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + } + dict.__setitem__("fromfile",new PyMethodDescr("fromfile",PyArray.class,2,2,new exposed_fromfile(null,null))); + class exposed_fromlist extends PyBuiltinMethodNarrow { + + exposed_fromlist(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_fromlist(self,info); + } + + public PyObject __call__(PyObject arg0) { + ((PyArray)self).array_fromlist(arg0); + return Py.None; + } + + } + dict.__setitem__("fromlist",new PyMethodDescr("fromlist",PyArray.class,1,1,new exposed_fromlist(null,null))); + class exposed_index extends PyBuiltinMethodNarrow { + + exposed_index(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_index(self,info); + } + + public PyObject __call__(PyObject arg0) { + return Py.newInteger(((PyArray)self).array_index(arg0)); + } + + } + dict.__setitem__("index",new PyMethodDescr("index",PyArray.class,1,1,new exposed_index(null,null))); + class exposed_insert extends PyBuiltinMethodNarrow { + + exposed_insert(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_insert(self,info); + } + + public PyObject __call__(PyObject arg0,PyObject arg1) { + try { + ((PyArray)self).array_insert(arg0.asInt(0),arg1); + return Py.None; + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + msg="expected an integer"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + } + dict.__setitem__("insert",new PyMethodDescr("insert",PyArray.class,2,2,new exposed_insert(null,null))); + class exposed_pop extends PyBuiltinMethodNarrow { + + exposed_pop(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_pop(self,info); + } + + public PyObject __call__(PyObject arg0) { + try { + return((PyArray)self).array_pop(arg0.asInt(0)); + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + msg="expected an integer"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + public PyObject __call__() { + return((PyArray)self).array_pop(); + } + + } + dict.__setitem__("pop",new PyMethodDescr("pop",PyArray.class,0,1,new exposed_pop(null,null))); + class exposed_remove extends PyBuiltinMethodNarrow { + + exposed_remove(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_remove(self,info); + } + + public PyObject __call__(PyObject arg0) { + ((PyArray)self).array_remove(arg0); + return Py.None; + } + + } + dict.__setitem__("remove",new PyMethodDescr("remove",PyArray.class,1,1,new exposed_remove(null,null))); + class exposed_reverse extends PyBuiltinMethodNarrow { + + exposed_reverse(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_reverse(self,info); + } + + public PyObject __call__() { + ((PyArray)self).array_reverse(); + return Py.None; + } + + } + dict.__setitem__("reverse",new PyMethodDescr("reverse",PyArray.class,0,0,new exposed_reverse(null,null))); + class exposed_tofile extends PyBuiltinMethodNarrow { + + exposed_tofile(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_tofile(self,info); + } + + public PyObject __call__(PyObject arg0) { + ((PyArray)self).array_tofile(arg0); + return Py.None; + } + + } + dict.__setitem__("tofile",new PyMethodDescr("tofile",PyArray.class,1,1,new exposed_tofile(null,null))); + class exposed_tolist extends PyBuiltinMethodNarrow { + + exposed_tolist(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_tolist(self,info); + } + + public PyObject __call__() { + return((PyArray)self).array_tolist(); + } + + } + dict.__setitem__("tolist",new PyMethodDescr("tolist",PyArray.class,0,0,new exposed_tolist(null,null))); + class exposed_tostring extends PyBuiltinMethodNarrow { + + exposed_tostring(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_tostring(self,info); + } + + public PyObject __call__() { + return((PyArray)self).array_tostring(); + } + + } + dict.__setitem__("tostring",new PyMethodDescr("tostring",PyArray.class,0,0,new exposed_tostring(null,null))); + class exposed_write extends PyBuiltinMethodNarrow { + + exposed_write(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_write(self,info); + } + + public PyObject __call__(PyObject arg0) { + ((PyArray)self).array_write(arg0); + return Py.None; + } + + } + dict.__setitem__("write",new PyMethodDescr("write",PyArray.class,1,1,new exposed_write(null,null))); + class exposed___init__ extends PyBuiltinMethod { + + exposed___init__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___init__(self,info); + } + + public PyObject __call__(PyObject[]args) { + return __call__(args,Py.NoKeywords); + } + + public PyObject __call__(PyObject[]args,String[]keywords) { + ((PyArray)self).array_init(args,keywords); + return Py.None; + } + + } + dict.__setitem__("__init__",new PyMethodDescr("__init__",PyArray.class,-1,-1,new exposed___init__(null,null))); + dict.__setitem__("__new__",new PyNewWrapper(PyArray.class,"__new__",-1,-1) { + + public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { + PyArray newobj; + if (for_type==subtype) { + newobj=new PyArray(); + if (init) + newobj.array_init(args,keywords); + } else { + newobj=new PyArrayDerived(subtype); + } + return newobj; + } + + }); + } + //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py + private Object data; + + private Class type; + + private String typecode; + + private ArrayDelegate delegate; + // PyArray can't extend anymore, so delegate private class ArrayDelegate extends AbstractArray { - + final PyArray pyArray; - + private ArrayDelegate(PyArray pyArray) { super((pyArray.data == null) ? 0 : Array.getLength(pyArray.data)); this.pyArray = pyArray; } - + protected Object getArray() { return pyArray.data; } + protected void setArray(Object array) { pyArray.data = array; } - + protected void makeInsertSpace(int index) { super.makeInsertSpace(index, 1); } - + protected void makeInsertSpace(int index, int length) { super.makeInsertSpace(index, length); } - + public void remove(int index) { super.remove(index); } } private PyArray() { - // do nothing, shell instance + // do nothing, shell instance } + public PyArray(PyType type){ + super(type); + } + public PyArray(PyArray toCopy) { - data = toCopy.delegate.copyArray(); delegate = new ArrayDelegate(this); type = toCopy.type; } - + public PyArray(Class type, Object data) { this.type = type; this.data = data; @@ -76,15 +604,43 @@ public PyArray(Class type, int n) { this(type, Array.newInstance(type, n)); } + + private void array_init(PyObject[] args, String[] kwds){ + ArgParser ap = new ArgParser("array", + args, + kwds, + new String[] {"typecode", "seq"}, + 1); + PyObject obj = ap.getPyObject(0); + if(obj instanceof PyString) { + String code = obj.toString(); + if(code.length() != 1) { + throw Py.ValueError("typecode must be in [zcbhilfd]"); + } + type = char2class(code.charAt(0)); + typecode = code; + }else if(obj instanceof PyJavaClass){ + type = ((PyJavaClass)obj).proxyClass; + typecode = type.getName(); + } + data = Array.newInstance(type, 0); + delegate = new ArrayDelegate(this); + + PyObject seq = ap.getPyObject(1, null); + if(seq == null){ + return; + } + extendInternal(seq); + } public static PyArray zeros(int n, char typecode) { PyArray array = zeros(n, char2class(typecode)); - //Character.toString(char) is jdk 1.4 - //array.typecode = Character.toString(typecode); + // Character.toString(char) is jdk 1.4 + // array.typecode = Character.toString(typecode); array.typecode = "" + typecode; return array; } - + public static PyArray zeros(int n, Class ctype) { PyArray array = new PyArray(ctype, n); array.typecode = ctype.getName(); @@ -93,57 +649,55 @@ public static PyArray array(PyObject seq, char typecode) { PyArray array = PyArray.array(seq, char2class(typecode)); - //Character.toString(char) is jdk 1.4 - //array.typecode = Character.toString(typecode); - array.typecode = "" + typecode; + array.typecode = Character.toString(typecode); return array; } - - /** - * Create a PyArray storing <em>ctype</em> types and being initialised - * with <em>initialiser</em>. - * - * @param init an initialiser for the array - can be PyString or - * PySequence (including PyArray) or iterable type. - * @param ctype <code>Class</code> type of the elements stored in the array. + + /** + * Create a PyArray storing <em>ctype</em> types and being initialised + * with <em>initialiser</em>. + * + * @param init + * an initialiser for the array - can be PyString or PySequence + * (including PyArray) or iterable type. + * @param ctype + * <code>Class</code> type of the elements stored in the array. * @return a new PyArray - */ + */ public static PyArray array(PyObject init, Class ctype) { - PyArray array = new PyArray(ctype, 0); array.typecode = ctype.getName(); - - array.extendInternal(init); - - return array; + array.extendInternal(init); + return array; } - /** - * Adds (appends) two PyArrays together - * - * @param other a PyArray to be added to the instance - * @return the result of the addition as a new PyArray instance - */ + /** + * Adds (appends) two PyArrays together + * + * @param other + * a PyArray to be added to the instance + * @return the result of the addition as a new PyArray instance + */ public PyObject __add__(PyObject other) { PyArray otherArr = null; - if (!(other instanceof PyArray)) { + if(!(other instanceof PyArray)) { throw Py.TypeError("can only append another array to an array"); } otherArr = (PyArray)other; - if (!otherArr.type.equals(this.type)) { - throw Py.TypeError( - "can only append arrays of the same type, " + - "expected '" + this.type + ", found " + otherArr.type); - } + if(!otherArr.type.equals(this.type)) { + throw Py.TypeError("can only append arrays of the same type, " + + "expected '" + this.type + ", found " + otherArr.type); + } PyArray ret = new PyArray(this); ret.delegate.appendArray(otherArr.delegate.copyArray()); return ret; } - + /** * Finds the attribute. - * - * @param name the name of the attribute of interest + * + * @param name + * the name of the attribute of interest * @return the value for the attribute of the specified name */ public PyObject __findattr__(String name) { @@ -153,690 +707,777 @@ return super.__findattr__(name); } - /** - * Length of the array - * - * @return number of elements in the array - */ + /** + * Length of the array + * + * @return number of elements in the array + */ public int __len__() { return delegate.getSize(); } - /** - * String representation of PyArray - * - * @return string representation of PyArray - */ + /** + * String representation of PyArray + * + * @return string representation of PyArray + */ public PyString __repr__() { StringBuffer buf = new StringBuffer(128); buf.append("array(").append(class2char(type)).append(",["); - for (int i=0; i<__len__()-1; i++) { + for(int i = 0; i < __len__() - 1; i++) { buf.append(pyget(i).__repr__().toString()); buf.append(", "); } - if (__len__() > 0) { - buf.append(pyget(__len__()-1).__repr__().toString()); + if(__len__() > 0) { + buf.append(pyget(__len__() - 1).__repr__().toString()); } buf.append("]) "); return new PyString(buf.toString()); } - + /** - * - * @param c target <em>Class</em> for the conversion + * + * @param c + * target <em>Class</em> for the conversion * @return Java object converted to required class type if possible. */ public Object __tojava__(Class c) { - if (c == Object.class || - (c.isArray() && c.getComponentType().isAssignableFrom(type))) - { + if(c == Object.class + || (c.isArray() && c.getComponentType().isAssignableFrom(type))) { return data; } - if (c.isInstance(this)) return this; + if(c.isInstance(this)) + return this; return Py.NoConversion; } - /** - * Append new value x to the end of the array. - * - * @param value item to be appended to the array - */ + public void array_append(PyObject value) { + append(value); + } + + /** + * Append new value x to the end of the array. + * + * @param value + * item to be appended to the array + */ public void append(PyObject value) { // Currently, this is asymmetric with extend, which // *will* do conversions like append(5.0) to an int array. - // Also, cpython 2.2 will do the append coersion. However, - // it is deprecated in cpython 2.3, so maybe we are just + // Also, cpython 2.2 will do the append coersion. However, + // it is deprecated in cpython 2.3, so maybe we are just // ahead of our time ;-) - int afterLast = delegate.getSize(); delegate.makeInsertSpace(afterLast); try { - set(afterLast, value); - } catch (PyException e) { - delegate.setSize(afterLast); - throw new PyException(e.type, e.value); + set(afterLast, value); + } catch(PyException e) { + delegate.setSize(afterLast); + throw new PyException(e.type, e.value); } } - + + public void array_byteswap() { + byteswap(); + } + /** - * "Byteswap" all items of the array. This is only supported for values - * which are 1, 2, 4, or 8 bytes in size; for other types of values, - * RuntimeError is raised. It is useful when reading data from a file + * "Byteswap" all items of the array. This is only supported for values + * which are 1, 2, 4, or 8 bytes in size; for other types of values, + * RuntimeError is raised. It is useful when reading data from a file * written on a machine with a different byte order. */ public void byteswap() { - //unknown type - throw RuntimeError - if (getItemsize() == 0) { + // unknown type - throw RuntimeError + if(getItemsize() == 0) { throw Py.RuntimeError("don't know how to byteswap this array type"); } - ByteSwapper.swap(data); } - /** - * Initialised class dictionary - */ - public static void classDictInit(PyObject dict) throws PyIgnoreMethodTag { - PySequence.classDictInit(dict); - dict.__setitem__("clone", null); - dict.__setitem__("classDictInit", null); - } - - /** - * Implementation of <em>Cloneable</em> interface. - * - * @return copy of current PyArray - */ - public Object clone() { + /** + * Implementation of <em>Cloneable</em> interface. + * + * @return copy of current PyArray + */ + public Object clone() { return new PyArray(this); } /** - * Converts a character code for the array type to a Java - * <code>Class</code>.<p /> + * Converts a character code for the array type to a Java <code>Class</code>. + * <p /> * * The following character codes and their native types are supported:<br /> * <table> - * <tr><td><strong>Type code</strong></td> - * <td><strong>native type</strong></td></tr> - * <tr><td>z</td><td><code>boolean</code></td></tr> - * <tr><td>c</td><td><code>char</code></td></tr> - * <tr><td>b</td><td><code>byte</code></td></tr> - * <tr><td>h</td><td><code>short</code></td></tr> - * <tr><td>i</td><td><code>int</code></td></tr> - * <tr><td>l</td><td><code>long</code></td></tr> - * <tr><td>f</td><td><code>float</code></td></tr> - * <tr><td>d</td><td><code>double</code></td></tr> + * <tr> + * <td><strong>Type code</strong></td> + * <td><strong>native type</strong></td> + * </tr> + * <tr> + * <td>z</td> + * <td><code>boolean</code></td> + * </tr> + * <tr> + * <td>c</td> + * <td><code>char</code></td> + * </tr> + * <tr> + * <td>b</td> + * <td><code>byte</code></td> + * </tr> + * <tr> + * <td>h</td> + * <td><code>short</code></td> + * </tr> + * <tr> + * <td>i</td> + * <td><code>int</code></td> + * </tr> + * <tr> + * <td>l</td> + * <td><code>long</code></td> + * </tr> + * <tr> + * <td>f</td> + * <td><code>float</code></td> + * </tr> + * <tr> + * <td>d</td> + * <td><code>double</code></td> + * </tr> * </table> * <p /> - * - * @param type character code for the array type - * - * @return <code>Class</code> of the native type + * + * @param type + * character code for the array type + * + * @return <code>Class</code> of the native type */ public static Class char2class(char type) throws PyIgnoreMethodTag { - switch (type) { - case 'z': - return Boolean.TYPE; - case 'c': - return Character.TYPE; - case 'b': - return Byte.TYPE; - case 'h': - return Short.TYPE; - case 'i': - return Integer.TYPE; - case 'l': - return Long.TYPE; - case 'f': - return Float.TYPE; - case 'd': - return Double.TYPE; - default: - throw Py.ValueError("typecode must be in [zcbhilfd]"); + switch(type){ + case 'z': + return Boolean.TYPE; + case 'c': + return Character.TYPE; + case 'b': + return Byte.TYPE; + case 'h': + return Short.TYPE; + case 'i': + return Integer.TYPE; + case 'l': + return Long.TYPE; + case 'f': + return Float.TYPE; + case 'd': + return Double.TYPE; + default: + throw Py.ValueError("typecode must be in [zcbhilfd]"); } } - + private static String class2char(Class cls) { - - if (cls.equals(Boolean.TYPE) ) return "'z'"; - else if (cls.equals(Character.TYPE)) return "'c'"; - else if (cls.equals(Byte.TYPE) ) return "'b'"; - else if (cls.equals(Short.TYPE) ) return "'h'"; - else if (cls.equals(Integer.TYPE) ) return "'i'"; - else if (cls.equals(Long.TYPE) ) return "'l'"; - else if (cls.equals(Float.TYPE) ) return "'f'"; - else if (cls.equals(Double.TYPE) ) return "'d'"; - else return cls.getName(); + if(cls.equals(Boolean.TYPE)) + return "'z'"; + else if(cls.equals(Character.TYPE)) + return "'c'"; + else if(cls.equals(Byte.TYPE)) + return "'b'"; + else if(cls.equals(Short.TYPE)) + return "'h'"; + else if(cls.equals(Integer.TYPE)) + return "'i'"; + else if(cls.equals(Long.TYPE)) + return "'l'"; + else if(cls.equals(Float.TYPE)) + return "'f'"; + else if(cls.equals(Double.TYPE)) + return "'d'"; + else + return cls.getName(); } - /** - * Return the number of occurrences of x in the array. - * - * @param value instances of the value to be counted - * @return number of time value was found in the array. - */ - public PyObject count(PyObject value) { - // note: cpython does not raise type errors based on item type + public int array_count(PyObject value) { + // note: cpython does not raise type errors based on item type; int iCount = 0; - for (int i = 0; i < delegate.getSize(); i++) { - if (value.equals(Py.java2py(Array.get(data, i)))) iCount++; + for(int i = 0; i < delegate.getSize(); i++) { + if(value.equals(Py.java2py(Array.get(data, i)))) + iCount++; } - return new PyInteger(iCount); + return iCount; } - + /** + * Return the number of occurrences of x in the array. + * + * @param value + * instances of the value to be counted + * @return number of time value was found in the array. + */ + public PyInteger count(PyObject value) { + return Py.newInteger(array_count(value)); + } + + /** * Delete the element at position <em>i</em> from the array - * - * @param i index of the item to be deleted from the array + * + * @param i + * index of the item to be deleted from the array */ protected void del(int i) { - //Now the AbstractArray can support this: - //throw Py.TypeError("can't remove from array"); + // Now the AbstractArray can support this: + // throw Py.TypeError("can't remove from array"); delegate.remove(i); } - + /** - * Delete the slice defined by <em>start</em>, <em>stop</em> and + * Delete the slice defined by <em>start</em>, <em>stop</em> and * <em>step</em> from the array. - * - * @param start starting index of slice - * @param stop finishing index of slice - * @param step stepping increment between start and stop + * + * @param start + * starting index of slice + * @param stop + * finishing index of slice + * @param step + * stepping increment between start and stop */ protected void delRange(int start, int stop, int step) { // Now the AbstractArray can support this: - //throw Py.TypeError("can't remove from array"); - if (step > 0 && stop < start) stop = start; - - if (step == 1) { + // throw Py.TypeError("can't remove from array"); + if(step > 0 && stop < start) + stop = start; + if(step == 1) { delegate.remove(start, stop); } else { int n = sliceLength(start, stop, step); - - for (int i = start, j = 0; j < n; i += step, j++) { + for(int i = start, j = 0; j < n; i += step, j++) { delegate.remove(i); } } } + + public void array_extend(PyObject iterable){ + extendInternal(iterable); + } /** - * Append items from <em>iterable</em> to the end of the array. If iterable - * is another array, it must have exactly the same type code; if not, - * TypeError will be raised. If iterable is not an array, it must be - * iterable and its elements must be the right type to be appended to the - * array. - * Changed in version 2.4: Formerly, the argument could only be another - * array. - * - * @param iterable iterable object used to extend the array + * Append items from <em>iterable</em> to the end of the array. If + * iterable is another array, it must have exactly the same type code; if + * not, TypeError will be raised. If iterable is not an array, it must be + * iterable and its elements must be the right type to be appended to the + * array. Changed in version 2.4: Formerly, the argument could only be + * another array. + * + * @param iterable + * iterable object used to extend the array */ public void extend(PyObject iterable) { - extendInternal(iterable); + extendInternal(iterable); } - + /** * Internal extend function, provides basic interface for extending arrays. - * Handles specific cases of <em>iterable</em> being PyStrings or PyArrays. - * Default behaviour is to defer to - * {@link #extendInternalIter(PyObject) extendInternalIter } - * - * @param iterable object of type PyString, PyArray or any object that can - * be iterated over. + * Handles specific cases of <em>iterable</em> being PyStrings or + * PyArrays. Default behaviour is to defer to + * {@link #extendInternalIter(PyObject) extendInternalIter } + * + * @param iterable + * object of type PyString, PyArray or any object that can be + * iterated over. */ private void extendInternal(PyObject iterable) { + // string input + if(iterable instanceof PyString) { + fromstring(((PyString)iterable).toString()); + // PyArray input + } else if(iterable instanceof PyArray) { + PyArray source = (PyArray)iterable; + if(!source.type.equals(this.type)) { + throw Py.TypeError("can only extend with an array of the same kind"); + } + delegate.appendArray(source.delegate.copyArray()); + } else { + extendInternalIter(iterable); + } + } - //string input - if (iterable instanceof PyString) { - fromstring( ((PyString)iterable).toString() ); - - //PyArray input - } else if (iterable instanceof PyArray) { - PyArray source = (PyArray)iterable; - - if(! source.type.equals(this.type)) { - throw Py.TypeError( - "can only extend with an array of the same kind"); - } - - delegate.appendArray(source.delegate.copyArray()); - - } else { - extendInternalIter(iterable); - } - } - /** * Internal extend function to process iterable objects. - * - * @param iterable any object that can be iterated over. + * + * @param iterable + * any object that can be iterated over. */ private void extendInternalIter(PyObject iterable) { - PyObject iter = iterable.__iter__(); - PyObject item = null; - - // iterable object without a length property - cannot presize the - // array, so append each item - if (iterable.__findattr__("__len__") == null) { - for (int i = 0; (item = iter.__iternext__()) != null; i++) { - append(item); - } - } else { - - //create room - int last = delegate.getSize(); - delegate.ensureCapacity(last + iterable.__len__() ); - - for (int i = last; (item = iter.__iternext__()) != null; i++) { - set(i, item); - delegate.size++; - } - } - } + PyObject iter = iterable.__iter__(); + PyObject item = null; + // iterable object without a length property - cannot presize the + // array, so append each item + if(iterable.__findattr__("__len__") == null) { + for(int i = 0; (item = iter.__iternext__()) != null; i++) { + append(item); + } + } else { + // create room + int last = delegate.getSize(); + delegate.ensureCapacity(last + iterable.__len__()); + for(int i = last; (item = iter.__iternext__()) != null; i++) { + set(i, item); + delegate.size++; + } + } + } + private void array_fromfile(PyObject f, int count){ + fromfile(f, count); + } + /** - * Read <em>count</em> items (as machine values) from the file object - * <em>f</em> and append them to the end of the array. If less than - * <em>count</em> items are available, EOFError is raised, but the items - * that were available are still inserted into the array. <em>f</em> must - * be a real built-in file object; something else with a read() method - * won't do. - * - * @param f Python builtin file object to retrieve data - * @param count number of array elements to read + * Read <em>count</em> items (as machine values) from the file object + * <em>f</em> and append them to the end of the array. If less than + * <em>count</em> items are available, EOFError is raised, but the items + * that were available are still inserted into the array. <em>f</em> must + * be a real built-in file object; something else with a read() method won't + * do. + * + * @param f + * Python builtin file object to retrieve data + * @param count + * number of array elements to read */ public void fromfile(PyObject f, int count) { - - //check for arg1 as file object - if(!(f instanceof PyFile)) { - throw Py.TypeError("arg1 must be open file"); - } - - PyFile file = (PyFile)f; - - // check for read only - if (file.mode.indexOf("r") == -1) { - throw Py.TypeError("file needs to be in read mode"); - } - - - // read the data via the PyFile - int readbytes = count * getItemsize(); - String buffer = file.read(readbytes).toString(); - - // load whatever was collected into the array - fromstring(buffer); - - // check for underflow - if (buffer.length() < readbytes) { - int readcount = buffer.length() / getItemsize(); - throw Py.EOFError("not enough items in file. "+ - Integer.toString(count)+" requested, "+ - Integer.toString(readcount)+" actually read" - ); - } + // check for arg1 as file object + if(!(f instanceof PyFile)) { + throw Py.TypeError("arg1 must be open file"); + } + PyFile file = (PyFile)f; + // check for read only + if(file.mode.indexOf("r") == -1) { + throw Py.TypeError("file needs to be in read mode"); + } + // read the data via the PyFile + int readbytes = count * getItemsize(); + String buffer = file.read(readbytes).toString(); + // load whatever was collected into the array + fromstring(buffer); + // check for underflow + if(buffer.length() < readbytes) { + int readcount = buffer.length() / getItemsize(); + throw Py.EOFError("not enough items in file. " + + Integer.toString(count) + " requested, " + + Integer.toString(readcount) + " actually read"); + } } + public void array_fromlist(PyObject obj){ + fromlist(obj); + } + /** - * Append items from the list. This is equivalent to - * "for x in list: a.append(x)"except that if there is a type error, the - * array is unchanged. - * - * @param obj input list object that will be appended to the array + * Append items from the list. This is equivalent to "for x in list: + * a.append(x)"except that if there is a type error, the array is unchanged. + * + * @param obj + * input list object that will be appended to the array */ public void fromlist(PyObject obj) { - //check for list - if(!(obj instanceof PyList)) - throw Py.TypeError("expected list argument"); - - //store the current size of the internal array - int size = delegate.getSize(); - - try { - extendInternalIter(obj); - } catch (PyException e) { - //trap any exception - any error invalidates the whole list - delegate.setSize(size); - //re-throw - throw new PyException(e.type, e.value); - } + // check for list + if(!(obj instanceof PyList)) + throw Py.TypeError("expected list argument"); + // store the current size of the internal array + int size = delegate.getSize(); + try { + extendInternalIter(obj); + } catch(PyException e) { + // trap any exception - any error invalidates the whole list + delegate.setSize(size); + // re-throw + throw new PyException(e.type, e.value); + } } - + /** - * Generic stream reader to read the entire contents of a stream into the + * Generic stream reader to read the entire contents of a stream into the * array. - * - * @param is InputStream to source the data from - * + * + * @param is + * InputStream to source the data from + * * @return number of primitives successfully read - * + * * @throws IOException * @throws EOFException */ private int fromStream(InputStream is) throws IOException, EOFException { - return fromStream(is, is.available() / getItemsize()); + return fromStream(is, is.available() / getItemsize()); } - + /** * Generic stream reader to read <em>count</em> primitive types from a * stream into the array. - * - * @param is InputStream to source the data from - * @param count number of primitive types to read from the stream - * + * + * @param is + * InputStream to source the data from + * @param count + * number of primitive types to read from the stream + * * @return number of primitives successfully read - * + * * @throws IOException * @throws EOFException */ - private int fromStream(InputStream is, int count) throws IOException, EOFException { - - DataInputStream dis = new DataInputStream(is); - + private int fromStream(InputStream is, int count) throws IOException, + EOFException { + DataInputStream dis = new DataInputStream(is); // current number of items present int origsize = delegate.getSize(); // position to start inserting into int index = origsize; - // create capacity for 'count' items delegate.ensureCapacity(index + count); + if(type.isPrimitive()) { + if(type == Boolean.TYPE) { + for(int i = 0; i < count; i++, index++) { + Array.setBoolean(data, index, dis.readBoolean()); + delegate.size++; + } + } else if(type == Byte.TYPE) { + for(int i = 0; i < count; i++, index++) { + Array.setByte(data, index, dis.readByte()); + delegate.size++; + } + } else if(type == Character.TYPE) { + for(int i = 0; i < count; i++, index++) { + Array.setChar(data, index, (char)dis.readByte()); + delegate.size++; + } + } else if(type == Integer.TYPE) { + for(int i = 0; i < count; i++, index++) { + Array.setInt(data, index, dis.readInt()); + delegate.size++; + } + } else if(type == Short.TYPE) { + for(int i = 0; i < count; i++, index++) { + Array.setShort(data, index, dis.readShort()); + delegate.size++; + } + } else if(type == Long.TYPE) { + for(int i = 0; i < count; i++, index++) { + Array.setLong(data, index, dis.readLong()); + delegate.size++; + } + } else if(type == Float.TYPE) { + for(int i = 0; i < count; i++, index++) { + Array.setFloat(data, index, dis.readFloat()); + delegate.size++; + } + } else if(type == Double.TYPE) { + for(int i = 0; i < count; i++, index++) { + Array.setDouble(data, index, dis.readDouble()); + delegate.size++; + } + } + } + dis.close(); + return (index - origsize); + } - if (type.isPrimitive()) { - - if (type == Boolean.TYPE) { - for (int i = 0; i < count; i++, index++) { - Array.setBoolean(data, index, dis.readBoolean()); - delegate.size++; - } - } else if (type == Byte.TYPE) { - for (int i = 0; i < count; i++, index++) { - Array.setByte(data, index, dis.readByte()); - delegate.size++; - } - } else if (type == Character.TYPE) { - for (int i = 0; i < count; i++, index++) { - Array.setChar(data, index, (char)dis.readByte()); - delegate.size++; - } - } else if(type == Integer.TYPE) { - for (int i = 0; i < count; i++, index++) { - Array.setInt(data, index, dis.readInt()); - delegate.size++; - } - } else if (type == Short.TYPE) { - for (int i = 0; i < count; i++, index++) { - Array.setShort(data, index, dis.readShort()); - delegate.size++; - } - } else if (type == Long.TYPE) { - for (int i = 0; i < count; i++, index++) { - Array.setLong(data, index, dis.readLong()); - delegate.size++; - } - } else if (type == Float.TYPE) { - for (int i = 0; i < count; i++, index++) { - Array.setFloat(data, index, dis.readFloat()); - delegate.size++; - } - } else if (type == Double.TYPE) { - for (int i = 0; i < count; i++, index++) { - Array.setDouble(data, index, dis.readDouble()); - delegate.size++; - } - } - } - dis.close(); - - - return (index - origsize); - } - /** - * Appends items from the string, interpreting the string as an array of - * machine values (as if it had been read from a file using the - * {@link #fromfile(PyObject, int) fromfile()} method). - * - * @param input string of bytes containing array data + * Appends items from the string, interpreting the string as an array of + * machine values (as if it had been read from a file using the + * {@link #fromfile(PyObject, int) fromfile()} method). + * + * @param input + * string of bytes containing array data */ public void fromstring(String input) { - - int itemsize = getItemsize(); - int strlen = input.length(); - if((strlen % itemsize) != 0) { - throw Py.ValueError("string length not a multiple of item size"); - } - - ByteArrayInputStream bis = new ByteArrayInputStream(input.getBytes()); - - int origsize = delegate.getSize(); - - try { - fromStream(bis); - } - catch(EOFException e) { - //stubbed catch for fromStream throws - throw Py.EOFError("not enough items in string"); - } - catch(IOException e) { - //discard anything successfully loaded - delegate.setSize(origsize); - throw Py.IOError(e); - } + int itemsize = getItemsize(); + int strlen = input.length(); + if((strlen % itemsize) != 0) { + throw Py.ValueError("string length not a multiple of item size"); + } + ByteArrayInputStream bis = new ByteArrayInputStream(input.getBytes()); + int origsize = delegate.getSize(); + try { + fromStream(bis); + } catch(EOFException e) { + // stubbed catch for fromStream throws + throw Py.EOFError("not enough items in string"); + } catch(IOException e) { + // discard anything successfully loaded + delegate.setSize(origsize); + throw Py.IOError(e); + } } - + /** * Get the element at position <em>i</em> from the array - * - * @param i index of the item to be retrieved from the array + * + * @param i + * index of the item to be retrieved from the array */ protected PyObject pyget(int i) { return Py.java2py(Array.get(data, i)); } - + /** * Return the internal Java array storage of the PyArray instance - * + * * @return the <code>Array</code> store. */ public Object getArray() throws PyIgnoreMethodTag { return delegate.copyArray(); } - + /** - * Getter for the storage size of the array's type.<p /> + * Getter for the storage size of the array's type. + * <p /> * - * The sizes returned by this method represent the number of bytes used - * to store the type. In the case of streams, this is the number of bytes - * written to, or read from a stream. For memory this value is the - * <em>minimum</em> number of bytes required to store the type.<p /> - * + * The sizes returned by this method represent the number of bytes used to + * store the type. In the case of streams, this is the number of bytes + * written to, or read from a stream. For memory this value is the + * <em>minimum</em> number of bytes required to store the type. + * <p /> + * * This method is used by other methods to define read/write quanta from - * strings and streams. <p /> - * + * strings and streams. + * <p /> + * * Values returned are:<br /> * <table> - * <tr><td><strong>Type</strong></td> <td><strong>Size</strong></td></tr> - * <tr><td><code>boolean</code></td> <td>1</td></tr> - * <tr><td><code>byte</code></td> <td>1</td></tr> - * <tr><td><code>char</code></td> <td>1</td></tr> - * <tr><td><code>short</code></td> <td>2</td></tr> - * <tr><td><code>int</code></td> <td>4</td></tr> - * <tr><td><code>long</code></td> <td>8</td></tr> - * <tr><td><code>float</code></td> <td>4</td></tr> - * <tr><td><code>double</code></td> <td>8</td></tr> + * <tr> + * <td><strong>Type</strong></td> + * <td><strong>Size</strong></td> + * </tr> + * <tr> + * <td><code>boolean</code></td> + * <td>1</td> + * </tr> + * <tr> + * <td><code>byte</code></td> + * <td>1</td> + * </tr> + * <tr> + * <td><code>char</code></td> + * <td>1</td> + * </tr> + * <tr> + * <td><code>short</code></td> + * <td>2</td> + * </tr> + * <tr> + * <td><code>int</code></td> + * <td>4</td> + * </tr> + * <tr> + * <td><code>long</code></td> + * <td>8</td> + * </tr> + * <tr> + * <td><code>float</code></td> + * <td>4</td> + * </tr> + * <tr> + * <td><code>double</code></td> + * <td>8</td> + * </tr> * </table> - * - * @return number of bytes used to store array type. + * + * @return number of bytes used to store array type. */ public int getItemsize() { + if(type.isPrimitive()) { + if(type == Boolean.TYPE) + return 1; + else if(type == Byte.TYPE) + return 1; + else if(type == Cha... [truncated message content] |
From: <cg...@us...> - 2007-02-27 22:40:32
|
Revision: 3125 http://svn.sourceforge.net/jython/?rev=3125&view=rev Author: cgroves Date: 2007-02-27 14:40:29 -0800 (Tue, 27 Feb 2007) Log Message: ----------- make PyBuiltinFunctionSet a subclass of PyBuiltinFunction and break method versions of PyBuiltingFunction sets out into PyBuiltinMethodSet Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/PyConnection.java trunk/jython/src/com/ziclix/python/sql/PyCursor.java trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java trunk/jython/src/com/ziclix/python/sql/util/BCP.java trunk/jython/src/com/ziclix/python/sql/zxJDBC.java trunk/jython/src/org/python/core/PyBuiltinFunction.java trunk/jython/src/org/python/core/PyBuiltinFunctionSet.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/__builtin__.java trunk/jython/src/org/python/modules/MD5Module.java trunk/jython/src/org/python/modules/_jython.java trunk/jython/src/org/python/modules/operator.java trunk/jython/src/org/python/modules/time/Time.java Added Paths: ----------- trunk/jython/src/org/python/core/PyBuiltinMethodSet.java Modified: trunk/jython/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -8,23 +8,22 @@ */ package com.ziclix.python.sql; -import com.ziclix.python.sql.util.PyArgParser; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; import org.python.core.ClassDictInit; import org.python.core.Py; -import org.python.core.PyBuiltinFunctionSet; +import org.python.core.PyBuiltinMethodSet; import org.python.core.PyClass; import org.python.core.PyInteger; import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; +import com.ziclix.python.sql.util.PyArgParser; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - /** * A connection to the database. * @@ -460,9 +459,9 @@ } } -class ConnectionFunc extends PyBuiltinFunctionSet { +class ConnectionFunc extends PyBuiltinMethodSet { ConnectionFunc(String name, int index, int minargs, int maxargs, String doc) { - super(name, index, minargs, maxargs, true, doc); + super(name, index, minargs, maxargs, doc); } public PyObject __call__() { @@ -480,7 +479,7 @@ c.rollback(); return Py.None; default : - throw argCountError(0); + throw info.unexpectedCall(0, false); } } @@ -492,7 +491,7 @@ case 4: return c.nativesql(arg); default : - throw argCountError(1); + throw info.unexpectedCall(1, false); } } @@ -502,7 +501,7 @@ case 2: return c.cursor(arg1.__nonzero__(), arg2, arg3); default : - throw argCountError(3); + throw info.unexpectedCall(3, false); } } @@ -522,7 +521,7 @@ return c.cursor(dynamic.__nonzero__(), rstype, rsconcur); default : - throw argCountError(args.length); + throw info.unexpectedCall(args.length, true); } } } Modified: trunk/jython/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -9,10 +9,14 @@ */ package com.ziclix.python.sql; -import com.ziclix.python.sql.util.PyArgParser; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Statement; +import java.util.List; import org.python.core.ClassDictInit; import org.python.core.Py; -import org.python.core.PyBuiltinFunctionSet; +import org.python.core.PyBuiltinMethodSet; import org.python.core.PyClass; import org.python.core.PyDictionary; import org.python.core.PyException; @@ -21,13 +25,8 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyTuple; +import com.ziclix.python.sql.util.PyArgParser; -import java.sql.DatabaseMetaData; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.Statement; -import java.util.List; - /** * These objects represent a database cursor, which is used to manage the * context of a fetch operation. @@ -874,12 +873,12 @@ } } -class CursorFunc extends PyBuiltinFunctionSet { +class CursorFunc extends PyBuiltinMethodSet { CursorFunc(String name, int index, int argcount, String doc) { - super(name, index, argcount, argcount, true, doc); + super(name, index, argcount, argcount, doc); } CursorFunc(String name, int index, int minargs, int maxargs, String doc) { - super(name, index, minargs, maxargs, true, doc); + super(name, index, minargs, maxargs, doc); } public PyObject __call__() { @@ -897,7 +896,7 @@ case 4 : return cursor.nextset(); default : - throw argCountError(0); + throw info.unexpectedCall(0, false); } } @@ -927,7 +926,7 @@ case 12 : return cursor.prepare(arg); default : - throw argCountError(1); + throw info.unexpectedCall(1, false); } } @@ -949,7 +948,7 @@ cursor.scroll(((PyInteger)arga.__int__()).getValue(), argb.toString()); return Py.None; default : - throw argCountError(2); + throw info.unexpectedCall(2, false); } } @@ -966,7 +965,7 @@ cursor.executemany(arga, argb, argc, Py.None); return Py.None; default : - throw argCountError(3); + throw info.unexpectedCall(3, false); } } @@ -994,7 +993,7 @@ cursor.executemany(sql, params, bindings, maxrows); return Py.None; default : - throw argCountError(args.length); + throw info.unexpectedCall(args.length, true); } } } Modified: trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -8,18 +8,17 @@ */ package com.ziclix.python.sql; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; +import java.util.HashSet; +import java.util.Set; import org.python.core.Py; -import org.python.core.PyBuiltinFunctionSet; +import org.python.core.PyBuiltinMethodSet; import org.python.core.PyClass; import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; -import java.sql.DatabaseMetaData; -import java.sql.SQLException; -import java.util.HashSet; -import java.util.Set; - /** * A cursor with extensions to the DB API 2.0. * @@ -487,14 +486,14 @@ } } -class ExtendedCursorFunc extends PyBuiltinFunctionSet { +class ExtendedCursorFunc extends PyBuiltinMethodSet { ExtendedCursorFunc(String name, int index, int argcount, String doc) { - super(name, index, argcount, argcount, true, doc); + super(name, index, argcount, argcount, doc); } ExtendedCursorFunc(String name, int index, int minargs, int maxargs, String doc) { - super(name, index, minargs, maxargs, true, doc); + super(name, index, minargs, maxargs, doc); } public PyObject __call__() { @@ -514,7 +513,7 @@ return Py.None; default : - throw argCountError(0); + throw info.unexpectedCall(0, false); } } @@ -530,7 +529,7 @@ return Py.None; default : - throw argCountError(1); + throw info.unexpectedCall(1, false); } } @@ -561,7 +560,7 @@ return Py.None; default : - throw argCountError(3); + throw info.unexpectedCall(3, false); } } @@ -582,7 +581,7 @@ return Py.None; default : - throw argCountError(args.length); + throw info.unexpectedCall(args.length, true); } } @@ -608,7 +607,7 @@ return Py.None; default : - throw argCountError(4); + throw info.unexpectedCall(4, false); } } } Modified: trunk/jython/src/com/ziclix/python/sql/util/BCP.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/util/BCP.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/com/ziclix/python/sql/util/BCP.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -8,18 +8,18 @@ */ package com.ziclix.python.sql.util; -import com.ziclix.python.sql.PyConnection; -import com.ziclix.python.sql.pipe.Pipe; -import com.ziclix.python.sql.pipe.db.DBSink; -import com.ziclix.python.sql.pipe.db.DBSource; -import com.ziclix.python.sql.zxJDBC; import org.python.core.ClassDictInit; import org.python.core.Py; -import org.python.core.PyBuiltinFunctionSet; +import org.python.core.PyBuiltinMethodSet; import org.python.core.PyClass; import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; +import com.ziclix.python.sql.PyConnection; +import com.ziclix.python.sql.zxJDBC; +import com.ziclix.python.sql.pipe.Pipe; +import com.ziclix.python.sql.pipe.db.DBSink; +import com.ziclix.python.sql.pipe.db.DBSource; /** * A class to perform efficient Bulk CoPy of database tables. @@ -204,40 +204,19 @@ } /** - * Class BCPFunc - * - * @author * @author last modified by $Author$ * @version $Revision$ - * @date $today.date$ * @date last modified on $Date$ * @copyright 2001 brian zimmer */ -class BCPFunc extends PyBuiltinFunctionSet { +class BCPFunc extends PyBuiltinMethodSet { - /** - * Constructor BCPFunc - * - * @param name - * @param index - * @param argcount - * @param doc - */ BCPFunc(String name, int index, int argcount, String doc) { - super(name, index, argcount, argcount, true, doc); + super(name, index, argcount, argcount, doc); } - /** - * Constructor BCPFunc - * - * @param name - * @param index - * @param minargs - * @param maxargs - * @param doc - */ BCPFunc(String name, int index, int minargs, int maxargs, String doc) { - super(name, index, minargs, maxargs, true, doc); + super(name, index, minargs, maxargs, doc); } /** @@ -264,7 +243,7 @@ return count; default : - throw argCountError(1); + throw info.unexpectedCall(1, false); } } @@ -287,7 +266,7 @@ return count; default : - throw argCountError(2); + throw info.unexpectedCall(2, false); } } @@ -310,7 +289,7 @@ return count; default : - throw argCountError(3); + throw info.unexpectedCall(3, false); } } @@ -361,7 +340,7 @@ return count; default : - throw argCountError(3); + throw info.unexpectedCall(3, false); } } } Modified: trunk/jython/src/com/ziclix/python/sql/zxJDBC.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/zxJDBC.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/com/ziclix/python/sql/zxJDBC.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -122,13 +122,13 @@ dict.__setitem__("threadsafety", new PyInteger(1)); dict.__setitem__("paramstyle", new PyString("qmark")); dict.__setitem__("__version__", Py.newString("$Revision$").__getslice__(Py.newInteger(11), Py.newInteger(-2), null)); - dict.__setitem__("Date", new zxJDBCFunc("Date", 1, 3, 3, false, "construct a Date from year, month, day")); - dict.__setitem__("Time", new zxJDBCFunc("Time", 2, 3, 3, false, "construct a Date from hour, minute, second")); - dict.__setitem__("Timestamp", new zxJDBCFunc("Timestamp", 3, 6, 6, false, "construct a Timestamp from year, month, day, hour, minute, second")); - dict.__setitem__("DateFromTicks", new zxJDBCFunc("DateFromTicks", 4, 1, 1, false, "construct a Date from seconds since the epoch")); - dict.__setitem__("TimeFromTicks", new zxJDBCFunc("TimeFromTicks", 5, 1, 1, false, "construct a Time from seconds since the epoch")); - dict.__setitem__("TimestampFromTicks", new zxJDBCFunc("TimestampFromTicks", 6, 1, 1, false, "construct a Timestamp from seconds since the epoch")); - dict.__setitem__("Binary", new zxJDBCFunc("Binary", 7, 1, 1, false, "construct an object capable of holding binary data")); + dict.__setitem__("Date", new zxJDBCFunc("Date", 1, 3, 3, "construct a Date from year, month, day")); + dict.__setitem__("Time", new zxJDBCFunc("Time", 2, 3, 3, "construct a Date from hour, minute, second")); + dict.__setitem__("Timestamp", new zxJDBCFunc("Timestamp", 3, 6, 6, "construct a Timestamp from year, month, day, hour, minute, second")); + dict.__setitem__("DateFromTicks", new zxJDBCFunc("DateFromTicks", 4, 1, 1, "construct a Date from seconds since the epoch")); + dict.__setitem__("TimeFromTicks", new zxJDBCFunc("TimeFromTicks", 5, 1, 1, "construct a Time from seconds since the epoch")); + dict.__setitem__("TimestampFromTicks", new zxJDBCFunc("TimestampFromTicks", 6, 1, 1, "construct a Timestamp from seconds since the epoch")); + dict.__setitem__("Binary", new zxJDBCFunc("Binary", 7, 1, 1, "construct an object capable of holding binary data")); zxJDBC._addSqlTypes(dict); zxJDBC._addConnectors(dict); zxJDBC._buildExceptions(dict); @@ -417,8 +417,8 @@ class zxJDBCFunc extends PyBuiltinFunctionSet { - zxJDBCFunc(String name, int index, int minargs, int maxargs, boolean func, String doc) { - super(name, index, minargs, maxargs, func, doc); + zxJDBCFunc(String name, int index, int minargs, int maxargs, String doc) { + super(name, index, minargs, maxargs, doc); } public PyObject __call__(PyObject arg) { @@ -436,7 +436,7 @@ case 7: return arg; default : - throw argCountError(1); + throw info.unexpectedCall(1, false); } } @@ -453,7 +453,7 @@ int second = ((Number) argc.__tojava__(Number.class)).intValue(); return zxJDBC.datefactory.Time(hour, minute, second); default : - throw argCountError(3); + throw info.unexpectedCall(3, false); } } @@ -468,7 +468,7 @@ int second = ((Number) args[5].__tojava__(Number.class)).intValue(); return zxJDBC.datefactory.Timestamp(year, month, day, hour, minute, second); default : - throw argCountError(args.length); + throw info.unexpectedCall(args.length, false); } } } Modified: trunk/jython/src/org/python/core/PyBuiltinFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinFunction.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/org/python/core/PyBuiltinFunction.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -120,7 +120,7 @@ abstract protected PyBuiltinFunction bind(PyObject self); public PyObject getSelf() { - return null; + return Py.None; } public String toString() { Modified: trunk/jython/src/org/python/core/PyBuiltinFunctionSet.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinFunctionSet.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/org/python/core/PyBuiltinFunctionSet.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -2,148 +2,125 @@ package org.python.core; /** - * A helper class for faster implementations of commonly called - * methods. + * A helper class for faster implementations of commonly called methods. * <p> - * Subclasses of PyBuiltinFunctionSet will implement some or all - * of the __call__ method with a switch on the index number. - * + * Subclasses of PyBuiltinFunctionSet will implement some or all of the __call__ + * method with a switch on the index number. + * */ -public class PyBuiltinFunctionSet extends PyObject implements Cloneable -{ - // part of the public interface for built-in functions - public PyObject __name__; - public PyObject __doc__; - public PyObject __self__; - public static PyObject __members__; +public class PyBuiltinFunctionSet extends PyBuiltinFunction { - // internal implementation - protected String name; - protected int minargs, maxargs; - protected boolean isMethod; + public static final Class exposed_as = PyBuiltinFunction.class; + // used as an index into a big switch statement in the various derived // class's __call__() methods. protected int index; - protected String doc; - static { - PyString[] members = new PyString[3]; - members[0] = new PyString("__doc__"); - members[1] = new PyString("__name__"); - members[2] = new PyString("__self__"); - __members__ = new PyList(members); + private PyObject doc = Py.None; + + /** + * Creates a PyBuiltinFunctionSet that expects 1 argument. + */ + public PyBuiltinFunctionSet(String name, int index){ + this(name, index, 1); } + + public PyBuiltinFunctionSet(String name, int index, int numargs){ + this(name, index, numargs, numargs); + } + + public PyBuiltinFunctionSet(String name, int index, int minargs, int maxargs){ + this(name, index, minargs, maxargs, null); + } // full-blown constructor, specifying everything - public PyBuiltinFunctionSet(String name, int index, int minargs, - int maxargs, boolean isMethod, String doc) - { - this.name = name; + public PyBuiltinFunctionSet(String name, + int index, + int minargs, + int maxargs, + String doc) { + super(new DefaultInfo(name, minargs, maxargs)); this.index = index; - this.minargs = minargs; - this.maxargs = maxargs; - this.isMethod = isMethod; - this.doc = doc; - - __name__ = new PyString(name); - if (doc == null) - __doc__ = Py.None; - else - __doc__ = new PyString(doc); - __self__ = Py.None; + if(doc != null) { + this.doc = Py.newString(doc); + } } - public PyObject _doget(PyObject container) { - return _doget(container, null); + public PyObject fastGetDoc() { + return doc; } - public PyObject _doget(PyObject container, PyObject wherefound) { - // Eventually we may want to allow rebinding of builtins - // when container is a subclass of __self__.__class__. - if (isMethod && __self__ == Py.None) { - // TBD: is there a better way? - try { - PyBuiltinFunctionSet unique = (PyBuiltinFunctionSet)clone(); - unique.__self__ = container; - return unique; - } - catch (CloneNotSupportedException e) {} - } - return this; + public boolean isMappingType() { + return false; } - public String toString() { - if (isMethod) - return "<built-in method "+name+">"; - else - return "<built-in function "+name+">"; + public boolean isNumberType() { + return false; } - public boolean isMappingType() { return false; } - public boolean isNumberType() { return false; } - public boolean isSequenceType() { return false; } - - public PyException argCountError(int nargs) { - if (minargs == maxargs) { - return Py.TypeError(name+"(): expected "+minargs+" args; got "+ - nargs); - } else { - return Py.TypeError(name+"(): expected "+minargs+"-"+maxargs+ - " args; got "+nargs); - } + public boolean isSequenceType() { + return false; } public PyObject fancyCall(PyObject[] args) { - throw Py.TypeError("surprising call"); + throw info.unexpectedCall(args.length, false); } public PyObject __call__(PyObject[] args) { int nargs = args.length; - if (minargs != -1 && (nargs > maxargs || nargs < minargs)) { - throw argCountError(nargs); + switch(nargs){ + case 0: + return __call__(); + case 1: + return __call__(args[0]); + case 2: + return __call__(args[0], args[1]); + case 3: + return __call__(args[0], args[1], args[2]); + case 4: + return __call__(args[0], args[1], args[2], args[3]); + default: + return fancyCall(args); } - switch (nargs) { - case 0: - return __call__(); - case 1: - return __call__(args[0]); - case 2: - return __call__(args[0], args[1]); - case 3: - return __call__(args[0], args[1], args[2]); - case 4: - return __call__(args[0], args[1], args[2], args[3]); - default: - return fancyCall(args); - } } public PyObject __call__(PyObject[] args, String[] kws) { - if (kws.length != 0) - throw Py.TypeError( - name+"(): this function takes no keyword arguments"); + if(kws.length != 0) { + throw Py.TypeError(safeRepr() + + "(): this function takes no keyword arguments"); + } return __call__(args); } public PyObject __call__() { - throw argCountError(0); + throw info.unexpectedCall(0, false); } public PyObject __call__(PyObject arg1) { - throw argCountError(1); + throw info.unexpectedCall(1, false); } public PyObject __call__(PyObject arg1, PyObject arg2) { - throw argCountError(2); + throw info.unexpectedCall(2, false); } public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { - throw argCountError(3); + throw info.unexpectedCall(3, false); } - public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3, - PyObject arg4) - { - throw argCountError(4); + public PyObject __call__(PyObject arg1, + PyObject arg2, + PyObject arg3, + PyObject arg4) { + throw info.unexpectedCall(4, false); } + + protected PyBuiltinFunction bind(PyObject self) { + throw Py.TypeError("Can't bind a builtin function"); + } + + public String toString(){ + return "<built-in function "+info.getName()+">"; + } + } Added: trunk/jython/src/org/python/core/PyBuiltinMethodSet.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinMethodSet.java (rev 0) +++ trunk/jython/src/org/python/core/PyBuiltinMethodSet.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -0,0 +1,38 @@ +package org.python.core; + +public class PyBuiltinMethodSet extends PyBuiltinFunctionSet implements + Cloneable { + + public PyBuiltinMethodSet(String name, + int index, + int minargs, + int maxargs, + String doc) { + super(name, index, minargs, maxargs, doc); + } + + public PyBuiltinFunction bind(PyObject bindTo) { + if(__self__ == Py.None) { + PyBuiltinMethodSet bindable; + try { + bindable = (PyBuiltinMethodSet)clone(); + } catch(CloneNotSupportedException e) { + throw new RuntimeException("Didn't expect PyBuiltinMethodSet to throw CloneNotSupported since it implements Cloneable", + e); + } + bindable.__self__ = bindTo; + return bindable; + } + return this; + } + + public PyObject getSelf() { + return __self__; + } + + public String toString(){ + return "<built-in method "+info.getName()+">"; + } + + protected PyObject __self__ = Py.None; +} Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/org/python/core/PySystemState.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -857,7 +857,7 @@ class PySystemStateFunctions extends PyBuiltinFunctionSet { PySystemStateFunctions(String name, int index, int minargs, int maxargs) { - super(name, index, minargs, maxargs, false, null); + super(name, index, minargs, maxargs); } public PyObject __call__(PyObject arg) { @@ -866,7 +866,7 @@ PySystemState.displayhook(arg); return Py.None; default: - throw argCountError(1); + throw info.unexpectedCall(1, false); } } public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { @@ -875,7 +875,7 @@ PySystemState.excepthook(arg1, arg2, arg3); return Py.None; default: - throw argCountError(3); + throw info.unexpectedCall(3, false); } } } Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/org/python/core/__builtin__.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -5,11 +5,11 @@ class BuiltinFunctions extends PyBuiltinFunctionSet { public BuiltinFunctions(String name, int index, int argcount) { - super(name, index, argcount, argcount, false, null); + this(name, index, argcount, argcount); } public BuiltinFunctions(String name, int index, int minargs, int maxargs) { - super(name, index, minargs, maxargs, false, null); + super(name, index, minargs, maxargs); } public PyObject __call__() { @@ -17,7 +17,7 @@ case 4: return __builtin__.globals(); default: - throw argCountError(0); + throw info.unexpectedCall(0, false); } } @@ -43,7 +43,7 @@ case 12: return __builtin__.sum(arg1); default: - throw argCountError(1); + throw info.unexpectedCall(1, false); } } @@ -62,7 +62,7 @@ case 12: return __builtin__.sum(arg1, arg2); default: - throw argCountError(2); + throw info.unexpectedCall(2, false); } } @@ -91,7 +91,7 @@ + "dictionary with string keys"); } default: - throw argCountError(3); + throw info.unexpectedCall(3, false); } } } @@ -100,7 +100,7 @@ * The builtin module. All builtin functions are defined here */ public class __builtin__ implements ClassDictInit { - /** <i>Internal use only. Do not call this method explicit.</i> */ + /** <i>Internal use only. Do not call this method explicitly.</i> */ public static void classDictInit(PyObject dict) { /* newstyle */ Modified: trunk/jython/src/org/python/modules/MD5Module.java =================================================================== --- trunk/jython/src/org/python/modules/MD5Module.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/org/python/modules/MD5Module.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -16,7 +16,7 @@ class MD5Functions extends PyBuiltinFunctionSet { public MD5Functions(String name, int index, int minargs, int maxargs) { - super(name, index, minargs, maxargs, false, null); + super(name, index, minargs, maxargs); } public PyObject __call__() { @@ -24,7 +24,7 @@ case 0: return new MD5Object(""); default: - throw argCountError(0); + throw info.unexpectedCall(0, false); } } @@ -33,7 +33,7 @@ case 0: return new MD5Object(arg1); default: - throw argCountError(1); + throw info.unexpectedCall(1, false); } } } Modified: trunk/jython/src/org/python/modules/_jython.java =================================================================== --- trunk/jython/src/org/python/modules/_jython.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/org/python/modules/_jython.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -6,7 +6,7 @@ class JythonInternalFunctions extends PyBuiltinFunctionSet { public JythonInternalFunctions(String name, int index, int argcount) { - super(name, index, argcount, argcount, false, null); + super(name, index, argcount); } public PyObject __call__(PyObject arg) { @@ -16,7 +16,7 @@ throw Py.TypeError("is_lazy(): arg is not a jclass"); return Py.newBoolean(((PyJavaClass)arg).isLazy()); default: - throw argCountError(1); + throw info.unexpectedCall(1, false); } } } Modified: trunk/jython/src/org/python/modules/operator.java =================================================================== --- trunk/jython/src/org/python/modules/operator.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/org/python/modules/operator.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -6,12 +6,12 @@ class OperatorFunctions extends PyBuiltinFunctionSet { public OperatorFunctions(String name, int index, int argcount) { - super(name, index, argcount, argcount, false, null); + this(name, index, argcount, argcount); } public OperatorFunctions(String name, int index, int minargs, int maxargs) { - super(name, index, minargs, maxargs, false, null); + super(name, index, minargs, maxargs); } public PyObject __call__(PyObject arg1) { @@ -28,7 +28,7 @@ case 19: return Py.newBoolean(arg1.isSequenceType()); case 32: return arg1.__invert__(); default: - throw argCountError(1); + throw info.unexpectedCall(1, false); } } @@ -58,7 +58,7 @@ case 34: return arg1._ne(arg2); case 35: return arg1._truediv(arg2); default: - throw argCountError(2); + throw info.unexpectedCall(2, false); } } @@ -68,7 +68,7 @@ case 24: return arg1.__getslice__(arg2, arg3); case 25: arg1.__setitem__(arg2, arg3); return Py.None; default: - throw argCountError(3); + throw info.unexpectedCall(3, false); } } @@ -80,7 +80,7 @@ arg1.__setslice__(arg2, arg3, arg4); return Py.None; default: - throw argCountError(4); + throw info.unexpectedCall(4, false); } } } Modified: trunk/jython/src/org/python/modules/time/Time.java =================================================================== --- trunk/jython/src/org/python/modules/time/Time.java 2007-02-27 19:23:31 UTC (rev 3124) +++ trunk/jython/src/org/python/modules/time/Time.java 2007-02-27 22:40:29 UTC (rev 3125) @@ -44,7 +44,7 @@ class TimeFunctions extends PyBuiltinFunctionSet { public TimeFunctions(String name, int index, int argcount) { - super(name, index, argcount, argcount, false, null); + super(name, index, argcount); } public PyObject __call__() { @@ -54,7 +54,7 @@ case 1: return Py.newFloat(Time.clock()); default: - throw argCountError(0); + throw info.unexpectedCall(0, false); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-04-22 22:13:35
|
Revision: 3177 http://svn.sourceforge.net/jython/?rev=3177&view=rev Author: cgroves Date: 2007-04-22 15:13:34 -0700 (Sun, 22 Apr 2007) Log Message: ----------- expose translate on unicode Modified Paths: -------------- trunk/jython/src/org/python/core/PyUnicode.java trunk/jython/src/templates/unicode.expose Modified: trunk/jython/src/org/python/core/PyUnicode.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicode.java 2007-04-22 21:09:32 UTC (rev 3176) +++ trunk/jython/src/org/python/core/PyUnicode.java 2007-04-22 22:13:34 UTC (rev 3177) @@ -1359,6 +1359,22 @@ } dict.__setitem__("title",new PyMethodDescr("title",PyUnicode.class,0,0,new exposed_title(null,null))); + class exposed_translate extends PyBuiltinMethodNarrow { + + exposed_translate(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_translate(self,info); + } + + public PyObject __call__(PyObject arg0) { + return new PyUnicode(((PyUnicode)self).unicode_translate(arg0)); + } + + } + dict.__setitem__("translate",new PyMethodDescr("translate",PyUnicode.class,1,1,new exposed_translate(null,null))); class exposed_upper extends PyBuiltinMethodNarrow { exposed_upper(PyObject self,PyBuiltinFunction.Info info) { Modified: trunk/jython/src/templates/unicode.expose =================================================================== --- trunk/jython/src/templates/unicode.expose 2007-04-22 21:09:32 UTC (rev 3176) +++ trunk/jython/src/templates/unicode.expose 2007-04-22 22:13:34 UTC (rev 3177) @@ -51,7 +51,7 @@ expose_meth: :u strip S? expose_meth: :u swapcase expose_meth: :u title -#expose_meth: :u translate s s? +expose_meth: :u translate o expose_meth: :u upper expose_meth: :u zfill i expose_new_immutable: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-05-30 05:19:25
|
Revision: 3248 http://svn.sourceforge.net/jython/?rev=3248&view=rev Author: cgroves Date: 2007-05-29 22:19:19 -0700 (Tue, 29 May 2007) Log Message: ----------- add __get__ to PyBuiltinMethodSet so it functions properly as a descriptor Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/PyConnection.java trunk/jython/src/com/ziclix/python/sql/PyCursor.java trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java trunk/jython/src/com/ziclix/python/sql/util/BCP.java trunk/jython/src/org/python/core/PyBuiltinMethodSet.java Modified: trunk/jython/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2007-05-29 06:14:37 UTC (rev 3247) +++ trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2007-05-30 05:19:19 UTC (rev 3248) @@ -461,7 +461,7 @@ class ConnectionFunc extends PyBuiltinMethodSet { ConnectionFunc(String name, int index, int minargs, int maxargs, String doc) { - super(name, index, minargs, maxargs, doc); + super(name, index, minargs, maxargs, doc, PyConnection.class); } public PyObject __call__() { Modified: trunk/jython/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2007-05-29 06:14:37 UTC (rev 3247) +++ trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2007-05-30 05:19:19 UTC (rev 3248) @@ -875,10 +875,10 @@ class CursorFunc extends PyBuiltinMethodSet { CursorFunc(String name, int index, int argcount, String doc) { - super(name, index, argcount, argcount, doc); + this(name, index, argcount, argcount, doc); } CursorFunc(String name, int index, int minargs, int maxargs, String doc) { - super(name, index, minargs, maxargs, doc); + super(name, index, minargs, maxargs, doc, PyCursor.class); } public PyObject __call__() { Modified: trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java 2007-05-29 06:14:37 UTC (rev 3247) +++ trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java 2007-05-30 05:19:19 UTC (rev 3248) @@ -489,11 +489,11 @@ class ExtendedCursorFunc extends PyBuiltinMethodSet { ExtendedCursorFunc(String name, int index, int argcount, String doc) { - super(name, index, argcount, argcount, doc); + this(name, index, argcount, argcount, doc); } ExtendedCursorFunc(String name, int index, int minargs, int maxargs, String doc) { - super(name, index, minargs, maxargs, doc); + super(name, index, minargs, maxargs, doc, PyExtendedCursor.class); } public PyObject __call__() { Modified: trunk/jython/src/com/ziclix/python/sql/util/BCP.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/util/BCP.java 2007-05-29 06:14:37 UTC (rev 3247) +++ trunk/jython/src/com/ziclix/python/sql/util/BCP.java 2007-05-30 05:19:19 UTC (rev 3248) @@ -212,11 +212,11 @@ class BCPFunc extends PyBuiltinMethodSet { BCPFunc(String name, int index, int argcount, String doc) { - super(name, index, argcount, argcount, doc); + this(name, index, argcount, argcount, doc); } BCPFunc(String name, int index, int minargs, int maxargs, String doc) { - super(name, index, minargs, maxargs, doc); + super(name, index, minargs, maxargs, doc, BCP.class); } /** Modified: trunk/jython/src/org/python/core/PyBuiltinMethodSet.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinMethodSet.java 2007-05-29 06:14:37 UTC (rev 3247) +++ trunk/jython/src/org/python/core/PyBuiltinMethodSet.java 2007-05-30 05:19:19 UTC (rev 3248) @@ -7,10 +7,24 @@ int index, int minargs, int maxargs, - String doc) { + String doc, + Class type) { super(name, index, minargs, maxargs, doc); + this.type = type; } + public PyObject __get__(PyObject obj, PyObject type) { + if(obj != null) { + if(this.type.isAssignableFrom(obj.getClass())) { + return bind(obj); + } else { + throw Py.TypeError("descriptor '" + info.getName() + "' for '" + PyType.fromClass(this.type) + + "' objects doesn't apply to '" + obj.getType() + "' object"); + } + } + return this; + } + public PyBuiltinFunction bind(PyObject bindTo) { if(__self__ == Py.None) { PyBuiltinMethodSet bindable; @@ -34,5 +48,7 @@ return "<built-in method "+info.getName()+">"; } + private Class type; + protected PyObject __self__ = Py.None; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-08-31 22:15:10
|
Revision: 3463 http://jython.svn.sourceforge.net/jython/?rev=3463&view=rev Author: pjenvey Date: 2007-08-31 15:15:04 -0700 (Fri, 31 Aug 2007) Log Message: ----------- replace ZipFileImporter with a CPython compatible zipimport module patch: #1783554 Modified Paths: -------------- trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/exceptions.java trunk/jython/src/org/python/modules/Setup.java trunk/jython/src/templates/mappings Added Paths: ----------- trunk/jython/src/org/python/modules/zipimport/ trunk/jython/src/org/python/modules/zipimport/zipimport.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java trunk/jython/src/templates/zipimporter.derived trunk/jython/src/templates/zipimporter.expose Removed Paths: ------------- trunk/jython/src/org/python/core/ZipFileImporter.java Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2007-08-31 22:09:57 UTC (rev 3462) +++ trunk/jython/src/org/python/core/PySystemState.java 2007-08-31 22:15:04 UTC (rev 3463) @@ -24,6 +24,7 @@ import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; import org.python.modules.Setup; +import org.python.modules.zipimport.zipimporter; /** * The "sys" module. @@ -267,7 +268,7 @@ meta_path.append(new PrecompiledImporter()); path_hooks = new PyList(); path_hooks.append(new JavaImporter()); - path_hooks.append(PyJavaClass.lookup(ZipFileImporter.class)); + path_hooks.append(PyJavaClass.lookup(zipimporter.class)); path_importer_cache = new PyDictionary(); // Set up the initial standard ins and outs Deleted: trunk/jython/src/org/python/core/ZipFileImporter.java =================================================================== --- trunk/jython/src/org/python/core/ZipFileImporter.java 2007-08-31 22:09:57 UTC (rev 3462) +++ trunk/jython/src/org/python/core/ZipFileImporter.java 2007-08-31 22:15:04 UTC (rev 3463) @@ -1,217 +0,0 @@ -package org.python.core; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.zip.ZipEntry; - -/** - * Load python source from jar or zip files. - */ -public class ZipFileImporter extends PyObject { - - private SyspathArchive archive; - private String pathToArchive; - - /** - * If this path is not an archive (.zip or .jar) then raise an ImportError, - * otherwise this instance will handle this path. - * - * @param path the path to check for modules - */ - public ZipFileImporter(PyObject path) { - if (!(path instanceof SyspathArchive)) { - throw Py.ImportError(path.toString()); - } - this.archive = (SyspathArchive) path; - String archiveName = SyspathArchive.getArchiveName(archive.string); - this.pathToArchive = new File(archiveName).getAbsolutePath() + File.separatorChar; - } - - /** - * Find the module for the fully qualified name. - * - * @param name the fully qualified name of the module - * @return a loader instance if this importer can load the module, None - * otherwise - */ - public PyObject find_module(String name) { - return find_module(name, Py.None); - } - - /** - * Find the module for the fully qualified name. - * - * @param name the fully qualified name of the module - * @param path if installed on the meta-path None or a module path - * @return a loader instance if this importer can load the module, None - * otherwise - */ - public PyObject find_module(String name, PyObject path) { - ZipModuleInfo zip = getModuleInfo(name, this.archive); - return (zip == null) ? Py.None : new ZipFileLoader(zip); - } - - /** - * Returns a string representation of the object. - * - * @return a string representation of the object. - */ - public String toString() { - return this.getType().toString(); - } - - /** - * Returns the last part of a fully qualified name. For example, the name - * <p> - * <code> - * a.b.c - * </code> - * </p> - * would return <code>c</code>. - * - * @param name a fully qualified name - * @return the last part of a fully qualified name - */ - private String getSubName(String name) { - int x = name.lastIndexOf("."); - if (x >= 0) { - return name.substring(x + 1); - } - return name; - } - - /** - * Find the module name starting at the zipArchive root. This method will - * look for both package and non-package names in the archive. If the name - * is not found null will be returned. - * - * @param name the fully qualified module name - * @param zipArchive the root of the path to begin looking - * @return null if the module is not found, a ZipModuleInfo instance - * otherwise - */ - private ZipModuleInfo getModuleInfo(String name, SyspathArchive zipArchive) { - String entryName = getSubName(name); - - String sourceName = entryName + "/__init__.py"; - String compiledName = entryName + "/__init__$py.class"; - ZipEntry sourceEntry = zipArchive.getEntry(sourceName); - ZipEntry compiledEntry = zipArchive.getEntry(compiledName); - - boolean pkg = (sourceEntry != null || compiledEntry != null); - if (!pkg) { - sourceName = entryName + ".py"; - compiledName = entryName + "$py.class"; - sourceEntry = zipArchive.getEntry(sourceName); - compiledEntry = zipArchive.getEntry(compiledName); - } else { - zipArchive = zipArchive.makeSubfolder(entryName); - } - - ZipModuleInfo info = null; - if (sourceEntry != null) { - Py.writeDebug("import", "trying source entry: " + sourceName - + " from jar/zip file " + zipArchive); - if (compiledEntry != null) { - Py.writeDebug("import", "trying precompiled entry " - + compiledName + " from jar/zip file " + zipArchive); - long pyTime = sourceEntry.getTime(); - long classTime = compiledEntry.getTime(); - if (classTime >= pyTime) { - info = new ZipModuleInfo(zipArchive, compiledEntry, true); - } - } - if (info == null) { - info = new ZipModuleInfo(zipArchive, sourceEntry, false); - } - } - - if (pkg && info != null) { - info.path = new PyList(new PyObject[] { zipArchive }); - } - - return info; - } - - /** - * Loader for zipfile python sources. - */ - public class ZipFileLoader extends PyObject { - - private ZipModuleInfo _info; - - public ZipFileLoader(ZipModuleInfo info) { - this._info = info; - } - - /** - * A loaded module for the fully qualified name. - * - * @param moduleName the fully qualified name - * @return a loaded module (added to sys.path) - */ - public PyObject load_module(String moduleName) { - PyModule m = null; - if (this._info.path != null) { - m = imp.addModule(moduleName); - m.__dict__.__setitem__("__path__", this._info.path); - m.__dict__.__setitem__("__loader__", this); - } - - InputStream is = null; // should this be closed? - ZipEntry entry = this._info.zipEntry; - try { - is = this._info.archive.getInputStream(entry); - } catch (IOException e) { - Py.writeDebug("import", "loadFromZipFile exception: " - + e.toString()); - throw Py.ImportError("error loading from zipfile"); - } - String pathToEntry = pathToArchive + entry.getName(); - PyObject o; - if (this._info.compiled) { - o = imp.createFromPyClass(moduleName, is, true, pathToEntry); - } else { - o = imp.createFromSource(moduleName, is,pathToEntry, null); - } - return (m == null) ? o : m; - } - - /** - * Returns a string representation of the object. - * - * @return a string representation of the object. - */ - public String toString() { - return this.getType().toString(); - } - } - - private class ZipModuleInfo { - /** The path of the package if it is a package. */ - public PyObject path; - - /** Whether the code is already compiled. */ - public boolean compiled; - - /** The zip entry for the file to load. */ - public ZipEntry zipEntry; - - /** The archive in which the zip entry resides. */ - public SyspathArchive archive; - - public ZipModuleInfo(SyspathArchive archive, ZipEntry zipEntry, - boolean compiled) { - this(archive, zipEntry, compiled, null); - } - - public ZipModuleInfo(SyspathArchive archive, ZipEntry zipEntry, - boolean compiled, PyObject path) { - this.path = path; - this.archive = archive; - this.zipEntry = zipEntry; - this.compiled = compiled; - } - } -} Modified: trunk/jython/src/org/python/core/exceptions.java =================================================================== --- trunk/jython/src/org/python/core/exceptions.java 2007-08-31 22:09:57 UTC (rev 3462) +++ trunk/jython/src/org/python/core/exceptions.java 2007-08-31 22:15:04 UTC (rev 3463) @@ -1,6 +1,7 @@ // Copyright 2001 Finn Bock package org.python.core; +import org.python.modules.zipimport.zipimport; /** * The builtin exceptions module. The entire module should be imported from @@ -242,6 +243,10 @@ buildClass(dict, "FutureWarning", "Warning", "empty__init__", "Base class for warnings about constructs that will change semantically in the future."); + // Initialize ZipImportError here, where it's safe to; it's + // needed immediately + zipimport.initClassExceptions(dict); + ts.frame = ts.frame.f_back; } Modified: trunk/jython/src/org/python/modules/Setup.java =================================================================== --- trunk/jython/src/org/python/modules/Setup.java 2007-08-31 22:09:57 UTC (rev 3462) +++ trunk/jython/src/org/python/modules/Setup.java 2007-08-31 22:15:04 UTC (rev 3463) @@ -55,6 +55,7 @@ "sets:org.python.modules.sets.Sets", "_random:org.python.modules.random.RandomModule", "cmath", - "itertools" + "itertools", + "zipimport:org.python.modules.zipimport.zipimport" }; } Added: trunk/jython/src/org/python/modules/zipimport/zipimport.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimport.java (rev 0) +++ trunk/jython/src/org/python/modules/zipimport/zipimport.java 2007-08-31 22:15:04 UTC (rev 3463) @@ -0,0 +1,64 @@ +/* Copyright (c) 2007 Jython Developers */ +package org.python.modules.zipimport; + +import org.python.core.ClassDictInit; +import org.python.core.Py; +import org.python.core.PyDictionary; +import org.python.core.PyException; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyType; +import org.python.core.exceptions; + +/** + * This module adds the ability to import Python modules (*.py, + * *$py.class) and packages from ZIP-format archives. + * + * @author Philip Jenvey + */ +public class zipimport implements ClassDictInit { + + public static final PyString __doc__ = new PyString( + "zipimport provides support for importing Python modules from Zip archives.\n" + + "\n" + + "This module exports three objects:\n" + + "- zipimporter: a class; its constructor takes a path to a Zip archive.\n" + + "- ZipImportError: exception raised by zipimporter objects. It's a\n" + + "subclass of ImportError, so it can be caught as ImportError, too.\n" + + "- _zip_directory_cache: a dict, mapping archive paths to zip directory\n" + + "info dicts, as used in zipimporter._files.\n" + + "\n" + + "It is usually not needed to use the zipimport module explicitly; it is\n" + + "used by the builtin import mechanism for sys.path items that are paths\n" + + "to Zip archives."); + + public static PyObject ZipImportError; + public static PyException ZipImportError(String message) { + return new PyException(ZipImportError, message); + } + + // XXX: Ideally this cache would be per PySystemState + public static PyDictionary _zip_directory_cache = new PyDictionary(); + + public static void classDictInit(PyObject dict) { + dict.__setitem__("__name__", new PyString("zipimport")); + dict.__setitem__("__doc__", __doc__); + dict.__setitem__("zipimporter", PyType.fromClass(zipimporter.class)); + dict.__setitem__("_zip_directory_cache", _zip_directory_cache); + dict.__setitem__("ZipImportError", ZipImportError); + + // Hide from Python + dict.__setitem__("classDictInit", null); + } + + /** + * Initialize the ZipImportError exception during startup + * + */ + public static void initClassExceptions(PyObject exceptions) { + PyObject ImportError = exceptions.__finditem__("ImportError"); + ZipImportError = Py.makeClass("ZipImportError", new PyObject[] {ImportError}, + Py.newJavaCode(exceptions.class, "empty__init__"), + null); + } +} Added: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java (rev 0) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2007-08-31 22:15:04 UTC (rev 3463) @@ -0,0 +1,891 @@ +/* Copyright (c) 2007 Jython Developers */ +package org.python.modules.zipimport; + +import java.io.File; +import java.io.InputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +import org.python.core.imp; +import org.python.core.ArgParser; +import org.python.core.BytecodeLoader; +import org.python.core.FileUtil; +import org.python.core.Py; +import org.python.core.PyBuiltinFunction; +import org.python.core.PyBuiltinMethod; +import org.python.core.PyBuiltinMethodNarrow; +import org.python.core.PyCode; +import org.python.core.PyDictionary; +import org.python.core.PyGetSetDescr; +import org.python.core.PyInteger; +import org.python.core.PyList; +import org.python.core.PyLong; +import org.python.core.PyMethodDescr; +import org.python.core.PyModule; +import org.python.core.PyNewWrapper; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyTuple; +import org.python.core.PyType; + +import java.util.Date; +import java.util.Enumeration; + +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +/** + * Import Python modules and packages from ZIP-format archives. + * + * @author Philip Jenvey + */ +public class zipimporter extends PyObject { + + //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py + /* type info */ + + public static final String exposed_name="zipimporter"; + + public static void typeSetup(PyObject dict,PyType.Newstyle marker) { + dict.__setitem__("archive",new PyGetSetDescr("archive",zipimporter.class,"getArchive",null,null)); + dict.__setitem__("prefix",new PyGetSetDescr("prefix",zipimporter.class,"getPrefix",null,null)); + dict.__setitem__("_files",new PyGetSetDescr("_files",zipimporter.class,"getFiles",null,null)); + dict.__setitem__("__doc__",new PyGetSetDescr("__doc__",zipimporter.class,"getDoc",null,null)); + class exposed_find_module extends PyBuiltinMethodNarrow { + + exposed_find_module(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_find_module(self,info); + } + + public PyObject __call__(PyObject arg0,PyObject arg1) { + try { + return((zipimporter)self).zipimporter_find_module(arg0.asString(0),arg1.asString(1)); + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + case 1: + msg="expected a string"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + public PyObject __call__(PyObject arg0) { + try { + return((zipimporter)self).zipimporter_find_module(arg0.asString(0)); + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + msg="expected a string"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + } + dict.__setitem__("find_module",new PyMethodDescr("find_module",zipimporter.class,1,2,new exposed_find_module(null,null))); + class exposed_load_module extends PyBuiltinMethodNarrow { + + exposed_load_module(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_load_module(self,info); + } + + public PyObject __call__(PyObject arg0) { + try { + return((zipimporter)self).zipimporter_load_module(arg0.asString(0)); + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + msg="expected a string"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + } + dict.__setitem__("load_module",new PyMethodDescr("load_module",zipimporter.class,1,1,new exposed_load_module(null,null))); + class exposed_get_data extends PyBuiltinMethodNarrow { + + exposed_get_data(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_get_data(self,info); + } + + public PyObject __call__(PyObject arg0) { + try { + return new PyString(((zipimporter)self).zipimporter_get_data(arg0.asString(0))); + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + msg="expected a string"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + } + dict.__setitem__("get_data",new PyMethodDescr("get_data",zipimporter.class,1,1,new exposed_get_data(null,null))); + class exposed_is_package extends PyBuiltinMethodNarrow { + + exposed_is_package(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_is_package(self,info); + } + + public PyObject __call__(PyObject arg0) { + try { + return Py.newBoolean(((zipimporter)self).zipimporter_is_package(arg0.asString(0))); + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + msg="expected a string"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + } + dict.__setitem__("is_package",new PyMethodDescr("is_package",zipimporter.class,1,1,new exposed_is_package(null,null))); + class exposed_get_code extends PyBuiltinMethodNarrow { + + exposed_get_code(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_get_code(self,info); + } + + public PyObject __call__(PyObject arg0) { + try { + return((zipimporter)self).zipimporter_get_code(arg0.asString(0)); + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + msg="expected a string"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + } + dict.__setitem__("get_code",new PyMethodDescr("get_code",zipimporter.class,1,1,new exposed_get_code(null,null))); + class exposed_get_source extends PyBuiltinMethodNarrow { + + exposed_get_source(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed_get_source(self,info); + } + + public PyObject __call__(PyObject arg0) { + try { + return new PyString(((zipimporter)self).zipimporter_get_source(arg0.asString(0))); + } catch (PyObject.ConversionException e) { + String msg; + switch (e.index) { + case 0: + msg="expected a string"; + break; + default: + msg="xxx"; + } + throw Py.TypeError(msg); + } + } + + } + dict.__setitem__("get_source",new PyMethodDescr("get_source",zipimporter.class,1,1,new exposed_get_source(null,null))); + class exposed___repr__ extends PyBuiltinMethodNarrow { + + exposed___repr__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___repr__(self,info); + } + + public PyObject __call__() { + return new PyString(((zipimporter)self).zipimporter_toString()); + } + + } + dict.__setitem__("__repr__",new PyMethodDescr("__repr__",zipimporter.class,0,0,new exposed___repr__(null,null))); + class exposed___init__ extends PyBuiltinMethod { + + exposed___init__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___init__(self,info); + } + + public PyObject __call__(PyObject[]args) { + return __call__(args,Py.NoKeywords); + } + + public PyObject __call__(PyObject[]args,String[]keywords) { + ((zipimporter)self).zipimporter_init(args,keywords); + return Py.None; + } + + } + dict.__setitem__("__init__",new PyMethodDescr("__init__",zipimporter.class,-1,-1,new exposed___init__(null,null))); + dict.__setitem__("__new__",new PyNewWrapper(zipimporter.class,"__new__",-1,-1) { + + public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { + zipimporter newobj; + if (for_type==subtype) { + newobj=new zipimporter(); + if (init) + newobj.zipimporter_init(args,keywords); + } else { + newobj=new zipimporterDerived(subtype); + } + return newobj; + } + + }); + } + //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py + + private static final PyString __doc__ = new PyString( + "zipimporter(archivepath) -> zipimporter object\n" + + "\n" + + "Create a new zipimporter instance. 'archivepath' must be a path to\n" + + "a zipfile. ZipImportError is raised if 'archivepath' doesn't point to\n" + + "a valid Zip archive."); + + /** zip_searchorder defines how we search for a module in the Zip + * archive */ + static final int IS_SOURCE = 0; + static final int IS_BYTECODE = 1; + static final int IS_PACKAGE = 2; + static final SearchOrderEntry[] zip_searchorder = new SearchOrderEntry[] { + new SearchOrderEntry("/__init__$py.class", IS_PACKAGE | IS_BYTECODE), + new SearchOrderEntry("/__init__.py", IS_PACKAGE | IS_SOURCE), + new SearchOrderEntry("$py.class", IS_BYTECODE), + new SearchOrderEntry(".py", IS_SOURCE), + new SearchOrderEntry("", 0) + }; + + /** Module information */ + static enum ModuleInfo {ERROR, NOT_FOUND, MODULE, PACKAGE}; + + /** Pathname of the Zip archive */ + private String archive; + + /** File prefix: "a/sub/directory/" */ + private String prefix; + + /** Dict with file info {path: tocEntry} */ + private PyObject files; + + public zipimporter() { + super(); + } + + public zipimporter(PyType subType) { + super(subType); + } + + public zipimporter(String path) { + super(); + zipimporter_init(path); + } + + final void zipimporter_init(PyObject[] args, String[] kwds) { + ArgParser ap = new ArgParser("__init__", args, kwds, new String[] {"path"}); + String path = ap.getString(0); + zipimporter_init(path); + } + + private void zipimporter_init(String path) { + if (path == null || path.length() == 0) { + throw zipimport.ZipImportError("archive path is empty"); + } + + File pathFile = new File(path); + prefix = ""; + while (true) { + if (pathFile.isFile()) { + archive = pathFile.getPath(); + break; + } + + // back up one path element + File parentFile = pathFile.getParentFile(); + if (parentFile == null) { + break; + } + + String childFile = pathFile.getPath(); + prefix = childFile.substring(childFile.lastIndexOf(File.separator) + 1) + + File.separator + prefix; + pathFile = parentFile; + } + + if (archive != null) { + files = zipimport._zip_directory_cache.__finditem__(archive); + if (files == null) { + files = readDirectory(archive); + zipimport._zip_directory_cache.__setitem__(archive, files); + } + } + else { + throw zipimport.ZipImportError("not a Zip file"); + } + + if (prefix != "" && !prefix.endsWith(File.separator)) { + prefix += File.separator; + } + } + + public PyObject find_module(String fullname) { + return zipimporter_find_module(fullname); + } + + /** + * Find the module for the fully qualified name. + * + * @param fullname the fully qualified name of the module + * @return a loader instance if this importer can load the module, None + * otherwise + */ + final PyObject zipimporter_find_module(String fullname) { + return find_module(fullname, null); + } + + public PyObject find_module(String fullname, String path) { + return zipimporter_find_module(fullname, path); + } + + /** + * Find the module for the fully qualified name. + * + * @param fullname the fully qualified name of the module + * @param path if not installed on the meta-path None or a module path + * @return a loader instance if this importer can load the module, None + * otherwise + */ + final PyObject zipimporter_find_module(String fullname, String path) { + ModuleInfo moduleInfo = getModuleInfo(fullname); + if (moduleInfo == ModuleInfo.ERROR || moduleInfo == ModuleInfo.NOT_FOUND) { + return Py.None; + } + return this; + } + + public PyObject load_module(String fullname) { + return zipimporter_load_module(fullname); + } + + /** + * Load a module for the fully qualified name. + * + * @param fullname the fully qualified name of the module + * @return a loaded PyModule + */ + final PyObject zipimporter_load_module(String fullname) { + ModuleCodeData moduleCodeData = getModuleCode(fullname); + if (moduleCodeData == null) { + return Py.None; + } + + // the module *must* be in sys.modules before the loader + // executes the module code; the module code may (directly or + // indirectly) import itself + PyModule mod = imp.addModule(fullname); + + mod.__dict__.__setitem__("__loader__", this); + if (moduleCodeData.ispackage) { + // add __path__ to the module *before* the code gets + // executed + String fullpath = archive + File.separator + prefix + getSubname(fullname); + PyList pkgpath = new PyList(); + pkgpath.add(fullpath); + mod.__dict__.__setitem__("__path__", pkgpath); + } + + imp.createFromCode(fullname, moduleCodeData.code, moduleCodeData.path); + Py.writeDebug("import", "import " + fullname + " # loaded from Zip " + + moduleCodeData.path); + return mod; + } + + public String get_data(String path) { + return zipimporter_get_data(path); + } + + /** + * Return the uncompressed data for the file at the specified path + * as a String. + * + * @param path a String path name within the archive + * @return a String of data in binary mode (no CRLF) + */ + final String zipimporter_get_data(String path) { + int len = archive.length(); + if (len < path.length() && path.startsWith(archive + File.separator)) { + path = path.substring(len + 1); + } + + PyObject tocEntry = files.__finditem__(path); + if (tocEntry == null) { + throw Py.IOError(path); + } + + InputStream dataStream = getDataStream(path); + byte[] data; + try { + data = FileUtil.readBytes(dataStream); + } + catch (IOException ioe) { + throw Py.IOError(ioe); + } + finally { + try { + dataStream.close(); + } + catch (IOException ioe) { + // continue + } + } + try { + return new String(data, "iso-8859-1"); + } + catch (UnsupportedEncodingException uee) { + // should never happen + throw new RuntimeException(uee); + } + } + + public boolean is_package(String fullname) { + return zipimporter_is_package(fullname); + } + + /** + * Return a boolean signifying whether the module is a package or + * not. + * + * @param fullname the fully qualified name of the module + * @return a boolean describing if the module is a package + */ + final boolean zipimporter_is_package(String fullname) { + ModuleInfo moduleInfo = getModuleInfo(fullname); + if (moduleInfo == ModuleInfo.NOT_FOUND) { + throw zipimport.ZipImportError("can't find module '" + fullname + "'"); + } + return moduleInfo == ModuleInfo.PACKAGE; + } + + public PyObject get_code(String fullname) { + return zipimporter_get_code(fullname); + } + + /** + * Return the code object associated with the module. + * + * @param fullname the fully qualified name of the module + * @return the module's PyCode object or None + */ + final PyObject zipimporter_get_code(String fullname) { + ModuleCodeData moduleCodeData = getModuleCode(fullname); + if (moduleCodeData != null) { + return moduleCodeData.code; + } + return Py.None; + } + + public String get_source(String fullname) { + return zipimporter_get_source(fullname); + } + + /** + * Return the source code for the module as a string (using + * newline characters for line endings) + * + * @param fullname the fully qualified name of the module + * @return a String of the module's source code or null + */ + final String zipimporter_get_source(String fullname) { + ModuleInfo moduleInfo = getModuleInfo(fullname); + + if (moduleInfo == ModuleInfo.ERROR) { + return null; + } + if (moduleInfo == ModuleInfo.NOT_FOUND) { + throw zipimport.ZipImportError("can't find module '" + fullname + "'"); + } + + String path = makeFilename(prefix, getSubname(fullname)); + if (moduleInfo == ModuleInfo.PACKAGE) { + path += File.separator + "__init__.py"; + } + else { + path += ".py"; + } + + PyObject tocEntry = files.__finditem__(path); + if (tocEntry != null) { + return get_data(path); + } + + // we have the module, but no source + return null; + } + + /** + * Given a path to a compressed file in the archive, return the + * file's (uncompressed) data stream. + * + * @param datapath file's filename inside of the archive + * @return an InputStream yielding the file's uncompressed data + */ + public InputStream getDataStream(String datapath) { + ZipFile zipArchive; + try { + zipArchive = new ZipFile(new File(archive)); + } + catch (IOException ioe) { + throw zipimport.ZipImportError("zipimport: can not open file: " + archive); + } + + ZipEntry data = zipArchive.getEntry(datapath); + try { + return zipArchive.getInputStream(data); + } + catch (IOException ioe) { + Py.writeDebug("import", "zipimporter.getDataStream exception: " + + ioe.toString()); + throw zipimport.ZipImportError("zipimport: can not open file: " + archive); + + } + } + + /** + * Return module information for the module with the fully + * qualified name. + * + * @param fullname the fully qualified name of the module + * @return the module's information + */ + private ModuleInfo getModuleInfo(String fullname) { + String path = makeFilename(prefix, getSubname(fullname)); + + for (int i = 0; i < zip_searchorder.length; i++) { + SearchOrderEntry entry = zip_searchorder[i]; + PyObject tocEntry = files.__finditem__(path + entry.suffix); + if (tocEntry == null) + continue; + + if ((entry.type & IS_PACKAGE) == IS_PACKAGE) { + return ModuleInfo.PACKAGE; + } + return ModuleInfo.MODULE; + } + return ModuleInfo.NOT_FOUND; + } + + /** + * Return the code object and its associated data for the module + * with the fully qualified name. + * + * @param fullname the fully qualified name of the module + * @return the module's ModuleCodeData object + */ + private ModuleCodeData getModuleCode(String fullname) { + String path = makeFilename(prefix, getSubname(fullname)); + + if (path.length() < 0) { + return null; + } + + for (int i = 0; i < zip_searchorder.length; i++) { + SearchOrderEntry entry = zip_searchorder[i]; + String suffix = entry.suffix; + String searchPath = path + suffix; + + Py.writeDebug("import", "# trying " + archive + File.separator + path); + PyObject tocEntry = files.__finditem__(searchPath); + if (tocEntry == null) { + continue; + } + + boolean ispackage = (entry.type & IS_PACKAGE) == IS_PACKAGE; + boolean isbytecode = (entry.type & IS_BYTECODE) == IS_BYTECODE; + + if (isbytecode && isOutdatedBytecode(searchPath, tocEntry)) { + continue; + } + + String pathToEntry = archive + File.separator + searchPath; + InputStream dataStream = getDataStream(searchPath); + byte[] codeBytes; + if (isbytecode) { + codeBytes = imp.unmarshalCode(fullname, dataStream, true); + } + else { + codeBytes = imp.compileSource(fullname, dataStream, pathToEntry); + } + imp.cacheCompiledSource(pathToEntry, null, codeBytes); + + PyCode code; + code = BytecodeLoader.makeCode(fullname + "$py", codeBytes, pathToEntry); + + if (code == null) { + continue; + } + return new ModuleCodeData(code, ispackage, pathToEntry); + } + return null; + } + + /** + * Determine if the byte code at path with the specified toc entry + * has a modification time greater than its accompanying source + * code's. + * + * @param path a String path to the byte code + * @param tocEntry the byte code's PyObject toc entry + * @return boolean whether or not the byte code is older + */ + private boolean isOutdatedBytecode(String path, PyObject tocEntry) { + String sourcePath = path.substring(0, path.length() - 9) + ".py"; + PyObject sourceTocEntry = files.__finditem__(sourcePath); + if (sourceTocEntry == null) { + return false; + } + try { + long bytecodeTime = dosTimeToEpoch(tocEntry.__finditem__(5).asInt(0), + tocEntry.__finditem__(6).asInt(0)); + long sourceTime = dosTimeToEpoch(sourceTocEntry.__finditem__(5).asInt(0), + sourceTocEntry.__finditem__(6).asInt(0)); + return bytecodeTime < sourceTime; + } + catch (PyObject.ConversionException ce) { + return false; + } + } + + /** + * readDirectory(archive) -> files dict (new reference) + * + * Given a path to a Zip archive, build a dict, mapping file names + * (local to the archive, using SEP as a separator) to toc entries. + * + * A tocEntry is a tuple: + * + * (__file__, # value to use for __file__, available for all files + * compress, # compression kind; 0 for uncompressed + * data_size, # size of compressed data on disk + * file_size, # size of decompressed data + * file_offset, # offset of file header from start of archive (or -1 in Jython) + * time, # mod time of file (in dos format) + * date, # mod data of file (in dos format) + * crc, # crc checksum of the data + * ) + * + * Directories can be recognized by the trailing SEP in the name, + * data_size and file_offset are 0. + * + * @param archive PyString path to the archive + * @return a PyDictionary of tocEntrys + */ + private PyObject readDirectory(String archive) { + File file = new File(archive); + if (!file.canRead()) { + throw zipimport.ZipImportError("can't open Zip file: '" + archive + "'"); + } + + ZipFile zipFile; + try { + zipFile = new ZipFile(file); + } + catch (IOException ioe) { + throw zipimport.ZipImportError("can't read Zip file: '" + archive + "'"); + } + + PyObject files = new PyDictionary(); + for (Enumeration zipEntries = zipFile.entries(); zipEntries.hasMoreElements();) { + ZipEntry zipEntry = (ZipEntry)zipEntries.nextElement(); + + PyObject __file__ = new PyString(archive + File.separator + + zipEntry.getName()); + PyObject compress = new PyInteger(zipEntry.getMethod()); + PyObject data_size = new PyLong(zipEntry.getCompressedSize()); + PyObject file_size = new PyLong(zipEntry.getSize()); + // file_offset is a CPython optimization; it's used to + // seek directly to the file when reading it later. Jython + // doesn't do this nor is the offset available + PyObject file_offset = new PyInteger(-1); + PyObject time = new PyInteger(epochToDosTime(zipEntry.getTime())); + PyObject date = new PyInteger(epochToDosDate(zipEntry.getTime())); + PyObject crc = new PyLong(zipEntry.getCrc()); + + PyTuple entry = new PyTuple(new PyObject[] { + __file__, compress, data_size, file_size, file_offset, time, date, + crc}); + files.__setitem__(new PyString(zipEntry.getName()), entry); + } + + return files; + } + + /** + * Return fullname.split(".")[-1]. + * + * @param fullname a String value + * @return a split(".")[-1] String value + */ + private String getSubname(String fullname) { + int i = fullname.lastIndexOf("."); + if (i >= 0) { + return fullname.substring(i + 1); + } + return fullname; + } + + /** + * Given a (sub)modulename, return the potential file path in the + * archive (without extension). + * + * @param prefix a String value + * @param name a String modulename value + * @return the file path String value + */ + private String makeFilename(String prefix, String name) { + return prefix + name.replace('.', File.separatorChar); + } + + /** + * Convert a time in milliseconds since epoch to DOS date format + * + * @param time in milliseconds, a long value + * @return an int, dos style date value + */ + private int epochToDosDate(long time) { + Date d = new Date(time); + int year = d.getYear() + 1900; + if (year < 1980) { + return (1 << 21) | (1 << 16); + } + return (year - 1980) << 9 | (d.getMonth() + 1) << 5 | d.getDate() << 0; + } + + /** + * Convert a time in milliseconds since epoch to DOS time format + * + * @param time in milliseconds, a long value + * @return an int, dos style time value + */ + private int epochToDosTime(long time) { + Date d = new Date(time); + return d.getHours() << 11 | d.getMinutes() << 5 | d.getSeconds() >> 1; + } + + /** + * Convert the date/time values found in the Zip archive to a long + * time (in milliseconds) value. + * + * @param dostime a dos style timestamp (only time) integer + * @param dosdate a dos style date integer + * @return a long time (in milliseconds) value + */ + private long dosTimeToEpoch(int dosTime, int dosDate) { + Date d = new Date(((dosDate >> 9) & 0x7f) + 80, + ((dosDate >> 5) & 0x0f) - 1, + dosDate & 0x1f, + (dosTime >> 11) & 0x1f, + (dosTime >> 5) & 0x3f, + (dosTime & 0x1f) * 2); + return d.getTime(); + } + + public String toString() { + return zipimporter_toString(); + } + + final String zipimporter_toString() { + return "<zipimporter object \"" + archive + "\">"; + } + + public String getArchive() { return archive; } + public String getPrefix() { return prefix; } + public PyObject getFiles() { return files; } + public PyObject getDoc() { return __doc__; } + + /** + * Container for PyModule code, whether or not it's a package and + * its path. + * + */ + private class ModuleCodeData { + PyCode code; + boolean ispackage; + String path; + + public ModuleCodeData(PyCode code, boolean ispackage, String path) { + this.code = code; + this.ispackage = ispackage; + this.path = path; + } + } + + /** + * A step in the module search order: the file suffix and its file + * type. + * + */ + protected static class SearchOrderEntry { + public String suffix; + public int type; + + public SearchOrderEntry(String suffix, int type) { + this.suffix = suffix; + this.type = type; + } + } +} Added: trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java (rev 0) +++ trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java 2007-08-31 22:15:04 UTC (rev 3463) @@ -0,0 +1,951 @@ +package org.python.modules.zipimport; + +import java.util.Iterator; + +import org.python.core.Py; +import org.python.core.PyBuiltinFunction; +import org.python.core.PyBuiltinMethod; +import org.python.core.PyBuiltinMethodNarrow; +import org.python.core.PyComplex; +import org.python.core.PyException; +import org.python.core.PyInteger; +import org.python.core.PyFloat; +import org.python.core.PyLong; +import org.python.core.PyMethodDescr; +import org.python.core.PyNewWrapper; +import org.python.core.PyObject; +import org.python.core.PySequenceIter; +import org.python.core.PyString; +import org.python.core.PyType; +import org.python.core.PyUnicode; +import org.python.core.Slotted; +import org.python.core.ThreadState; + +public class zipimporterDerived extends zipimporter implements Slotted { + + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index,PyObject value) { + slots[index]=value; + } + + private PyObject[]slots; + + public zipimporterDerived(PyType subtype) { + super(subtype); + slots=new PyObject[subtype.getNumSlots()]; + } + + public PyString __str__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__str__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__str__"+" should return a "+"string"); + } + return super.__str__(); + } + + public PyString __repr__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__repr__"+" should return a "+"string"); + } + return super.__repr__(); + } + + public PyString __hex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__hex__"+" should return a "+"string"); + } + return super.__hex__(); + } + + public PyString __oct__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__oct__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__oct__"+" should return a "+"string"); + } + return super.__oct__(); + } + + public PyFloat __float__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__float__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyFloat) + return(PyFloat)res; + throw Py.TypeError("__float__"+" should return a "+"float"); + } + return super.__float__(); + } + + public PyLong __long__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__long__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyLong) + return(PyLong)res; + throw Py.TypeError("__long__"+" should return a "+"long"); + } + return super.__long__(); + } + + public PyComplex __complex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__complex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyComplex) + return(PyComplex)res; + throw Py.TypeError("__complex__"+" should return a "+"complex"); + } + return super.__complex__(); + } + + public PyObject __pos__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pos__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__pos__(); + } + + public PyObject __neg__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__neg__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__neg__(); + } + + public PyObject __abs__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__abs__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__abs__(); + } + + public PyObject __invert__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__invert__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__invert__(); + } + + public PyObject __reduce__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__reduce__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__reduce__(); + } + + public PyObject __add__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__add__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__add__(other); + } + + public PyObject __radd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__radd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__radd__(other); + } + + public PyObject __sub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__sub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__sub__(other); + } + + public PyObject __rsub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rsub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rsub__(other); + } + + public PyObject __mul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mul__(other); + } + + public PyObject __rmul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmul__(other); + } + + public PyObject __div__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__div__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__div__(other); + } + + public PyObject __rdiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdiv__(other); + } + + public PyObject __floordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__floordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__floordiv__(other); + } + + public PyObject __rfloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rfloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rfloordiv__(other); + } + + public PyObject __truediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__truediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__truediv__(other); + } + + public PyObject __rtruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rtruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rtruediv__(other); + } + + public PyObject __mod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mod__(other); + } + + public PyObject __rmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmod__(other); + } + + public PyObject __divmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__divmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__divmod__(other); + } + + public PyObject __rdivmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdivmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdivmod__(other); + } + + public PyObject __pow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__pow__(other); + } + + public PyObject __rpow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rpow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rpow__(other); + } + + public PyObject __lshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lshift__(other); + } + + public PyObject __rlshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rlshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rlshift__(other); + } + + public PyObject __rshift__(PyObject other) { + ... [truncated message content] |
From: <cg...@us...> - 2007-09-21 08:23:17
|
Revision: 3490 http://jython.svn.sourceforge.net/jython/?rev=3490&view=rev Author: cgroves Date: 2007-09-21 01:23:09 -0700 (Fri, 21 Sep 2007) Log Message: ----------- Calendar.HOUR is in AM/PM, Calendar.HOUR_OF_DAY is in 24 hour time. Fixes bug #1782856 Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/JavaDateFactory.java trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyString.java Modified: trunk/jython/src/com/ziclix/python/sql/JavaDateFactory.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/JavaDateFactory.java 2007-09-21 08:17:32 UTC (rev 3489) +++ trunk/jython/src/com/ziclix/python/sql/JavaDateFactory.java 2007-09-21 08:23:09 UTC (rev 3490) @@ -55,7 +55,7 @@ Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR, hour); + c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, second); @@ -80,7 +80,7 @@ c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month - 1); c.set(Calendar.DATE, day); - c.set(Calendar.HOUR, hour); + c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, second); c.set(Calendar.MILLISECOND, 0); @@ -106,7 +106,7 @@ Calendar c = Calendar.getInstance(); c.setTime(new java.util.Date(ticks * 1000)); - c.set(Calendar.HOUR, 0); + c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2007-09-21 08:17:32 UTC (rev 3489) +++ trunk/jython/src/org/python/core/PyArray.java 2007-09-21 08:23:09 UTC (rev 3490) @@ -1674,7 +1674,7 @@ delegate.replaceSubArray(chars, start); } else { if(value instanceof PyString && type == Byte.TYPE) { - byte[] chars = ((PyString)value).getBytes(); + byte[] chars = ((PyString)value).toBytes(); if(chars.length == stop - start && step == 1) { System.arraycopy(chars, 0, data, start, chars.length); } else { Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2007-09-21 08:17:32 UTC (rev 3489) +++ trunk/jython/src/org/python/core/PyString.java 2007-09-21 08:23:09 UTC (rev 3490) @@ -2104,7 +2104,7 @@ * underlying String. Each byte contains the low-order bits of its * corresponding char. */ - public byte[] getBytes() { + public byte[] toBytes() { return to_bytes(string); } @@ -2147,7 +2147,7 @@ if (c.isArray()) { if (c.getComponentType() == Byte.TYPE) - return getBytes(); + return toBytes(); if (c.getComponentType() == Character.TYPE) return string.toCharArray(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-09-22 11:55:53
|
Revision: 3506 http://jython.svn.sourceforge.net/jython/?rev=3506&view=rev Author: cgroves Date: 2007-09-22 04:55:50 -0700 (Sat, 22 Sep 2007) Log Message: ----------- patch #1799330 from leosoto to fix bug #1799328. Has string formatting call __unicode__ on %s in unicode objects Modified Paths: -------------- trunk/jython/src/org/python/core/PyString.java trunk/jython/src/org/python/core/PyUnicode.java trunk/jython/src/templates/unicode.expose Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2007-09-22 11:36:57 UTC (rev 3505) +++ trunk/jython/src/org/python/core/PyString.java 2007-09-22 11:55:50 UTC (rev 3506) @@ -3655,6 +3655,7 @@ int precision; int argIndex; PyObject args; + boolean unicodeCoercion; final char pop() { try { @@ -3673,8 +3674,13 @@ } public StringFormatter(String format) { + this(format, false); + } + + public StringFormatter(String format, boolean unicodeCoercion) { index = 0; this.format = format; + this.unicodeCoercion = unicodeCoercion; buffer = new StringBuffer(format.length()+100); } @@ -3977,7 +3983,10 @@ case 'r': fill = ' '; if (c == 's') - string = arg.__str__().toString(); + if (unicodeCoercion) + string = arg.__unicode__().toString(); + else + string = arg.__str__().toString(); else string = arg.__repr__().toString(); if (precision >= 0 && string.length() > precision) { Modified: trunk/jython/src/org/python/core/PyUnicode.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicode.java 2007-09-22 11:36:57 UTC (rev 3505) +++ trunk/jython/src/org/python/core/PyUnicode.java 2007-09-22 11:55:50 UTC (rev 3506) @@ -110,6 +110,25 @@ } dict.__setitem__("__rmul__",new PyMethodDescr("__rmul__",PyUnicode.class,1,1,new exposed___rmul__(null,null))); + class exposed___mod__ extends PyBuiltinMethodNarrow { + + exposed___mod__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___mod__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyUnicode)self).unicode___mod__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__mod__",new PyMethodDescr("__mod__",PyUnicode.class,1,1,new exposed___mod__(null,null))); class exposed___getitem__ extends PyBuiltinMethodNarrow { exposed___getitem__(PyObject self,PyBuiltinFunction.Info info) { @@ -1515,9 +1534,14 @@ } public PyObject __mod__(PyObject other) { - return str___mod__(other).__unicode__(); + return unicode___mod__(other); } + final PyObject unicode___mod__(PyObject other){ + StringFormatter fmt = new StringFormatter(string, true); + return fmt.format(other).__unicode__(); + } + final PyUnicode unicode___unicode__() { return str___unicode__(); } Modified: trunk/jython/src/templates/unicode.expose =================================================================== --- trunk/jython/src/templates/unicode.expose 2007-09-22 11:36:57 UTC (rev 3505) +++ trunk/jython/src/templates/unicode.expose 2007-09-22 11:55:50 UTC (rev 3506) @@ -5,7 +5,7 @@ expose_index_getitem: seq_> expose_meth: seq_> __getslice__ ooo? # -expose_binary: __ne__ __eq__ __add__ __mul__ __rmul__ +expose_binary: __ne__ __eq__ __add__ __mul__ __rmul__ __mod__ expose_meth: :b __contains__ o expose_meth: :i __len__ expose_meth: __str__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-09-25 04:25:09
|
Revision: 3538 http://jython.svn.sourceforge.net/jython/?rev=3538&view=rev Author: cgroves Date: 2007-09-24 21:25:04 -0700 (Mon, 24 Sep 2007) Log Message: ----------- Remove the __unicode__ descriptor from object since it just calls through to str which isn't very useful, confuses code that expects __unicode__ to do something, and diverges from CPython. From patch #1800381 from tristanlk to fix bug #1800378 Modified Paths: -------------- trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/templates/object.expose Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2007-09-24 08:30:59 UTC (rev 3537) +++ trunk/jython/src/org/python/core/PyObject.java 2007-09-25 04:25:04 UTC (rev 3538) @@ -209,22 +209,6 @@ } dict.__setitem__("__repr__",new PyMethodDescr("__repr__",PyObject.class,0,0,new exposed___repr__(null,null))); - class exposed___unicode__ extends PyBuiltinMethodNarrow { - - exposed___unicode__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___unicode__(self,info); - } - - public PyObject __call__() { - return new PyUnicode(self.__str__()); - } - - } - dict.__setitem__("__unicode__",new PyMethodDescr("__unicode__",PyObject.class,0,0,new exposed___unicode__(null,null))); class exposed___init__ extends PyBuiltinMethod { exposed___init__(PyObject self,PyBuiltinFunction.Info info) { Modified: trunk/jython/src/templates/object.expose =================================================================== --- trunk/jython/src/templates/object.expose 2007-09-24 08:30:59 UTC (rev 3537) +++ trunk/jython/src/templates/object.expose 2007-09-25 04:25:04 UTC (rev 3538) @@ -21,8 +21,6 @@ return new PyInteger(self.object_hashCode()); expose_meth: __repr__ return new PyString(self.object_toString()); -expose_meth: __unicode__ - return new PyUnicode(self.__str__()); expose_new_mutable: expose_wide_meth: __init__ -1 -1 `vdeleg`(init); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-09-27 06:22:05
|
Revision: 3547 http://jython.svn.sourceforge.net/jython/?rev=3547&view=rev Author: cgroves Date: 2007-09-26 23:22:01 -0700 (Wed, 26 Sep 2007) Log Message: ----------- decode str going in to unicode objects and don't put the results from unicode_join into a PyUnicode object since it already is one Modified Paths: -------------- trunk/jython/src/org/python/core/PyString.java trunk/jython/src/org/python/core/PyUnicode.java trunk/jython/src/templates/unicode.expose Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2007-09-27 04:57:24 UTC (rev 3546) +++ trunk/jython/src/org/python/core/PyString.java 2007-09-27 06:22:01 UTC (rev 3547) @@ -1624,7 +1624,7 @@ } final PyUnicode str___unicode__() { - return new PyUnicode(this.toString()); + return new PyUnicode(this); } public int __len__() { Modified: trunk/jython/src/org/python/core/PyUnicode.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicode.java 2007-09-27 04:57:24 UTC (rev 3546) +++ trunk/jython/src/org/python/core/PyUnicode.java 2007-09-27 06:22:01 UTC (rev 3547) @@ -878,7 +878,7 @@ } public PyObject __call__(PyObject arg0) { - return new PyUnicode(((PyUnicode)self).unicode_join(arg0)); + return((PyUnicode)self).unicode_join(arg0); } } @@ -1482,7 +1482,7 @@ } public PyUnicode(PyType subtype, PyString pystring) { - this(subtype, (String)pystring.__tojava__(String.class)); + this(subtype, pystring.decode().toString()); } Modified: trunk/jython/src/templates/unicode.expose =================================================================== --- trunk/jython/src/templates/unicode.expose 2007-09-27 04:57:24 UTC (rev 3546) +++ trunk/jython/src/templates/unicode.expose 2007-09-27 06:22:01 UTC (rev 3547) @@ -33,7 +33,7 @@ expose_meth: :b istitle expose_meth: :b isunicode expose_meth: :b isupper -expose_meth: :u join o +expose_meth: join o expose_meth: :u ljust i expose_meth: :u lower expose_meth: :u lstrip S? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-11-20 20:03:51
|
Revision: 3708 http://jython.svn.sourceforge.net/jython/?rev=3708&view=rev Author: pjenvey Date: 2007-11-20 12:03:46 -0800 (Tue, 20 Nov 2007) Log Message: ----------- move to_bytes/from_bytes into a new StringUtil class so they're accessible from Jython code. camel case their names since their main use is from Java Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/DataHandler.java trunk/jython/src/com/ziclix/python/sql/JDBC20DataHandler.java trunk/jython/src/com/ziclix/python/sql/handler/MySQLDataHandler.java trunk/jython/src/org/python/core/FilelikeInputStream.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyString.java trunk/jython/src/org/python/core/StdoutWrapper.java trunk/jython/src/org/python/core/io/BinaryIOWrapper.java trunk/jython/src/org/python/core/parser.java trunk/jython/src/org/python/modules/SHA1.java trunk/jython/src/org/python/modules/binascii.java trunk/jython/src/org/python/modules/sha.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java Added Paths: ----------- trunk/jython/src/org/python/core/util/ trunk/jython/src/org/python/core/util/StringUtil.java Modified: trunk/jython/src/com/ziclix/python/sql/DataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/DataHandler.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/com/ziclix/python/sql/DataHandler.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -14,6 +14,7 @@ import org.python.core.PyObject; import org.python.core.PyList; import org.python.core.PyString; +import org.python.core.util.StringUtil; import java.io.BufferedInputStream; import java.io.BufferedReader; @@ -250,7 +251,7 @@ byte[] bytes = DataHandler.read(longvarchar); if (bytes != null) { - obj = Py.newString(PyString.from_bytes(bytes)); + obj = Py.newString(StringUtil.fromBytes(bytes)); } } finally { try { Modified: trunk/jython/src/com/ziclix/python/sql/JDBC20DataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/JDBC20DataHandler.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/com/ziclix/python/sql/JDBC20DataHandler.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -12,6 +12,7 @@ import org.python.core.PyFile; import org.python.core.PyObject; import org.python.core.PyString; +import org.python.core.util.StringUtil; import java.io.BufferedInputStream; import java.io.BufferedReader; @@ -66,7 +67,7 @@ String clob = (String) object.__tojava__(String.class); int length = clob.length(); - InputStream stream = new ByteArrayInputStream(PyString.to_bytes(clob)); + InputStream stream = new ByteArrayInputStream(StringUtil.toBytes(clob)); stream = new BufferedInputStream(stream); Modified: trunk/jython/src/com/ziclix/python/sql/handler/MySQLDataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/handler/MySQLDataHandler.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/com/ziclix/python/sql/handler/MySQLDataHandler.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -11,7 +11,7 @@ import com.ziclix.python.sql.DataHandler; import org.python.core.PyFile; import org.python.core.PyObject; -import org.python.core.PyString; +import org.python.core.util.StringUtil; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -60,7 +60,7 @@ } else { varchar = (String) object.__tojava__(String.class); } - InputStream stream = new ByteArrayInputStream(PyString.to_bytes(varchar)); + InputStream stream = new ByteArrayInputStream(StringUtil.toBytes(varchar)); stream = new BufferedInputStream(stream); Modified: trunk/jython/src/org/python/core/FilelikeInputStream.java =================================================================== --- trunk/jython/src/org/python/core/FilelikeInputStream.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/core/FilelikeInputStream.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -3,6 +3,8 @@ import java.io.IOException; import java.io.InputStream; +import org.python.core.util.StringUtil; + public class FilelikeInputStream extends InputStream { private PyObject filelike; @@ -34,7 +36,7 @@ if(result.length() == 0) { return -1; } - System.arraycopy(PyString.to_bytes(result), 0, b, off, result.length()); + System.arraycopy(StringUtil.toBytes(result), 0, b, off, result.length()); return result.length(); } Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/core/Py.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -16,6 +16,7 @@ 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.parser.ast.modType; public final class Py @@ -1782,7 +1783,7 @@ String filename, String type, CompilerFlags cflags) { - return Py.compile_flags(new ByteArrayInputStream(PyString.to_bytes(data + "\n\n")), + return Py.compile_flags(new ByteArrayInputStream(StringUtil.toBytes(data + "\n\n")), filename, type, cflags); Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/core/PyArray.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -12,6 +12,8 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.Array; +import org.python.core.util.StringUtil; + /** * A wrapper class around native java arrays. * @@ -1270,7 +1272,7 @@ if((strlen % itemsize) != 0) { throw Py.ValueError("string length not a multiple of item size"); } - ByteArrayInputStream bis = new ByteArrayInputStream(PyString.to_bytes(input)); + ByteArrayInputStream bis = new ByteArrayInputStream(StringUtil.toBytes(input)); int origsize = delegate.getSize(); try { fromStream(bis); @@ -1803,6 +1805,6 @@ } catch(IOException e) { throw Py.IOError(e); } - return PyString.from_bytes(bos.toByteArray()); + return StringUtil.fromBytes(bos.toByteArray()); } } Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/core/PyString.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -1,8 +1,7 @@ /// Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; +import org.python.core.util.StringUtil; /** * A builtin python string. @@ -2108,47 +2107,9 @@ * corresponding char. */ public byte[] toBytes() { - return to_bytes(string); + return StringUtil.toBytes(string); } - /** - * @return a byte array with one byte for each char in s. Each byte contains - * the low-order bits of its corresponding char. - */ - public static byte[] to_bytes(String s) { - try { - return s.getBytes("ISO-8859-1"); - } catch(UnsupportedEncodingException e) { - // This JVM is whacked, it doesn't even have iso-8859-1 - throw Py.SystemError("Java couldn't find the ISO-8859-1 encoding"); - } - } - - /** - * @return A String with chars corresponding to the bytes in buf - */ - public static String from_bytes(byte[] buf) { - return from_bytes(buf, 0, buf.length); - } - - /** - * @return A String with chars corresponding to the bytes in buf - */ - public static String from_bytes(ByteBuffer buf) { - return from_bytes(buf.array(), buf.arrayOffset() + buf.position(), - buf.arrayOffset() + buf.limit()); - } - - /** - * @return A String of len buff with chars corresponding to buf from off to - * off + len - */ - public static String from_bytes(byte[] buf, int off, int len) { - // Yes, I known the method is deprecated, but it is the fastest - // way of converting between between byte[] and String - return new String(buf, 0, off, len); - } - public Object __tojava__(Class c) { if (c.isAssignableFrom(String.class)) { return string; Modified: trunk/jython/src/org/python/core/StdoutWrapper.java =================================================================== --- trunk/jython/src/org/python/core/StdoutWrapper.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/core/StdoutWrapper.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -3,6 +3,8 @@ import java.io.OutputStream; +import org.python.core.util.StringUtil; + public class StdoutWrapper extends OutputStream { protected String name; @@ -63,7 +65,7 @@ } public void write(byte[] data, int off, int len) { - write(PyString.from_bytes(data, off, len)); + write(StringUtil.fromBytes(data, off, len)); } public void clearSoftspace() { Modified: trunk/jython/src/org/python/core/io/BinaryIOWrapper.java =================================================================== --- trunk/jython/src/org/python/core/io/BinaryIOWrapper.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/core/io/BinaryIOWrapper.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -3,7 +3,7 @@ import java.nio.ByteBuffer; -import org.python.core.PyString; +import org.python.core.util.StringUtil; /** * A Buffered text stream in binary mode. @@ -29,7 +29,7 @@ } if (!readahead.hasRemaining()) { - return PyString.from_bytes(bufferedIO.read(size)); + return StringUtil.fromBytes(bufferedIO.read(size)); } ByteBuffer data = ByteBuffer.allocate(size); @@ -40,7 +40,7 @@ data.put(readahead); readahead.limit(readaheadLimit); data.flip(); - return PyString.from_bytes(data); + return StringUtil.fromBytes(data); } // Drain the readahead then request more from the buffer @@ -48,13 +48,13 @@ clearReadahead(); bufferedIO.readinto(data); data.flip(); - return PyString.from_bytes(data); + return StringUtil.fromBytes(data); } /** {@inheritDoc} */ public String readall() { if (!readahead.hasRemaining()) { - return PyString.from_bytes(bufferedIO.readall()); + return StringUtil.fromBytes(bufferedIO.readall()); } ByteBuffer remaining = bufferedIO.readall(); @@ -64,7 +64,7 @@ clearReadahead(); all.put(remaining); all.flip(); - return PyString.from_bytes(all); + return StringUtil.fromBytes(all); } /** {@inheritDoc} */ @@ -116,6 +116,6 @@ if (readahead.hasRemaining()) { clearReadahead(); } - return bufferedIO.write(ByteBuffer.wrap(PyString.to_bytes(buf))); + return bufferedIO.write(ByteBuffer.wrap(StringUtil.toBytes(buf))); } } Modified: trunk/jython/src/org/python/core/parser.java =================================================================== --- trunk/jython/src/org/python/core/parser.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/core/parser.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -10,6 +10,7 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; +import org.python.core.util.StringUtil; import org.python.parser.IParserHost; import org.python.parser.Node; import org.python.parser.ParseException; @@ -87,7 +88,7 @@ } public static Node parse(String string, String kind) { - return parse(new ByteArrayInputStream(PyString.to_bytes(string)), + return parse(new ByteArrayInputStream(StringUtil.toBytes(string)), kind, "<string>", null); } @@ -115,7 +116,7 @@ modType node = null; //System.err.println(new PyString(string).__repr__().toString()); - BufferedReader bufreader = prepBufreader(new ByteArrayInputStream(PyString.to_bytes(string)), + BufferedReader bufreader = prepBufreader(new ByteArrayInputStream(StringUtil.toBytes(string)), cflags); PythonGrammar g = new PythonGrammar(new ReaderCharStream(bufreader), Added: trunk/jython/src/org/python/core/util/StringUtil.java =================================================================== --- trunk/jython/src/org/python/core/util/StringUtil.java (rev 0) +++ trunk/jython/src/org/python/core/util/StringUtil.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -0,0 +1,66 @@ +/* Copyright (c) 2007 Jython Developers */ +package org.python.core.util; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +import org.python.core.Py; + +/** + * String Utility methods. + * + */ +public class StringUtil { + + /** + * Encodes this String into a sequence of bytes. Each byte + * contains the low-order bits of its corresponding char. + * + * @param string a String value + * @return a byte array with one byte for each char in string + */ + public static byte[] toBytes(String string) { + try { + return string.getBytes("ISO-8859-1"); + } catch(UnsupportedEncodingException uee) { + // This JVM is whacked, it doesn't even have iso-8859-1 + throw Py.SystemError("Java couldn't find the ISO-8859-1 encoding"); + } + } + + /** + * Return a new String with chars corresponding to buf from off to + * off + len. + * + * @param buf an array of bytes + * @param off the initial offset + * @param len the length + * @return a new String corresponding to the bytes in buf + */ + public static String fromBytes(byte[] buf, int off, int len) { + // Yes, I known the method is deprecated, but it is the fastest + // way of converting between between byte[] and String + return new String(buf, 0, off, len); + } + + /** + * Return a new String with chars corresponding to buf. + * + * @param buf an array of bytes + * @return a new String corresponding to the bytes in buf + */ + public static String fromBytes(byte[] buf) { + return fromBytes(buf, 0, buf.length); + } + + /** + * Return a new String with chars corresponding to buf. + * + * @param buf a ByteBuffer of bytes + * @return a new String corresponding to the bytes in buf + */ + public static String fromBytes(ByteBuffer buf) { + return fromBytes(buf.array(), buf.arrayOffset() + buf.position(), + buf.arrayOffset() + buf.limit()); + } +} Modified: trunk/jython/src/org/python/modules/SHA1.java =================================================================== --- trunk/jython/src/org/python/modules/SHA1.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/modules/SHA1.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -45,6 +45,7 @@ import java.io.UnsupportedEncodingException; import org.python.core.*; +import org.python.core.util.StringUtil; /** * This class implements the SHA-1 message digest algorithm. @@ -492,7 +493,7 @@ ); public String digest() { - return PyString.from_bytes(engineDigest()); + return StringUtil.fromBytes(engineDigest()); } // XXX should become PyObject and use Py.idstr? Modified: trunk/jython/src/org/python/modules/binascii.java =================================================================== --- trunk/jython/src/org/python/modules/binascii.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/modules/binascii.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -18,6 +18,7 @@ import org.python.core.PyString; import org.python.core.PyStringMap; import org.python.core.PyTuple; +import org.python.core.util.StringUtil; /** * The <tt>binascii.java</tt> module contains a number of methods to convert @@ -203,7 +204,7 @@ }; private static byte[] table_b2a_hqx = - PyString.to_bytes("!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr"); + StringUtil.toBytes("!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr"); @@ -225,7 +226,7 @@ private static int BASE64_MAXBIN = 57; private static byte[] table_b2a_base64 = - PyString.to_bytes("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); + StringUtil.toBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); Modified: trunk/jython/src/org/python/modules/sha.java =================================================================== --- trunk/jython/src/org/python/modules/sha.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/modules/sha.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -3,6 +3,7 @@ package org.python.modules; import org.python.core.*; +import org.python.core.util.StringUtil; public class sha implements ClassDictInit { public static String __doc__ = @@ -43,7 +44,7 @@ String cp = ap.getString(0, null); SHA1 n = new SHA1(); if(cp != null) { - n.update(PyString.to_bytes(cp)); + n.update(StringUtil.toBytes(cp)); } return n; } Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2007-11-20 04:13:54 UTC (rev 3707) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2007-11-20 20:03:46 UTC (rev 3708) @@ -27,6 +27,7 @@ import org.python.core.PyString; import org.python.core.PyTuple; import org.python.core.PyType; +import org.python.core.util.StringUtil; import java.util.Date; import java.util.Enumeration; @@ -493,7 +494,7 @@ // continue } } - return PyString.from_bytes(data); + return StringUtil.fromBytes(data); } public boolean is_package(String fullname) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-11-25 22:20:11
|
Revision: 3725 http://jython.svn.sourceforge.net/jython/?rev=3725&view=rev Author: pjenvey Date: 2007-11-25 14:20:10 -0800 (Sun, 25 Nov 2007) Log Message: ----------- kill the file expose hack by customizing file's new via expose_new_immutable Modified Paths: -------------- trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/templates/file.expose trunk/jython/src/templates/mappings Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2007-11-25 20:59:51 UTC (rev 3724) +++ trunk/jython/src/org/python/core/PyFile.java 2007-11-25 22:20:10 UTC (rev 3725) @@ -490,33 +490,7 @@ dict.__setitem__("__new__",new PyNewWrapper(PyFile.class,"__new__",-1,-1) { public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { - PyFile newobj; - if (for_type == subtype) { - newobj = null; - if (init) { - if (args.length == 0) { - newobj = new PyFile(); - newobj.file_init(args, keywords); - } else if (args[0] instanceof PyString || - (args[0] instanceof PyJavaInstance && - ((PyJavaInstance) args[0]).javaProxy == String.class)) { - // If first arg is a PyString or String, assume its being - // called as a builtin. - newobj = new PyFile(); - newobj.file_init(args, keywords); - newobj.closer = new Closer(newobj.file); - } else { - // assume it's being called as a java class - PyJavaClass pjc = new PyJavaClass(PyFile.class); - newobj = (PyFile) pjc.__call__(args, keywords); - } - } else { - newobj = new PyFile(); - } - } else { - newobj = new PyFileDerived(subtype); - } - return newobj; + return file_new(this,init,subtype,args,keywords); } }); @@ -642,6 +616,36 @@ file_init(new FileIO(name, parseMode(mode)), name, mode, bufsize); } + final static PyObject file_new(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[]args, String[]keywords) { + PyFile newFile; + if (new_.for_type == subtype) { + if (init) { + if (args.length == 0) { + newFile = new PyFile(); + newFile.file_init(args, keywords); + } else if (args[0] instanceof PyString || + (args[0] instanceof PyJavaInstance && + ((PyJavaInstance)args[0]).javaProxy == String.class)) { + // If first arg is a PyString or String, assume + // its being called as a builtin. + newFile = new PyFile(); + newFile.file_init(args, keywords); + newFile.closer = new Closer(newFile.file); + } else { + // assume it's being called as a java class + PyJavaClass pjc = new PyJavaClass(PyFile.class); + newFile = (PyFile)pjc.__call__(args, keywords); + } + } else { + newFile = new PyFile(); + } + } else { + newFile = new PyFileDerived(subtype); + } + return newFile; + } + final void file_init(PyObject[] args,String[] kwds) { ArgParser ap = new ArgParser("file", args, kwds, new String[] { "name", "mode", "bufsize" }, 1); Modified: trunk/jython/src/templates/file.expose =================================================================== --- trunk/jython/src/templates/file.expose 2007-11-25 20:59:51 UTC (rev 3724) +++ trunk/jython/src/templates/file.expose 2007-11-25 22:20:10 UTC (rev 3725) @@ -36,4 +36,6 @@ expose_wide_meth: __init__ -1 -1 `vdeleg`(init); `void; -expose_new_mutable: +# PyFile is mutable, its new is marked as 'immutable' for the sake of +# being customized +expose_new_immutable: Modified: trunk/jython/src/templates/mappings =================================================================== --- trunk/jython/src/templates/mappings 2007-11-25 20:59:51 UTC (rev 3724) +++ trunk/jython/src/templates/mappings 2007-11-25 22:20:10 UTC (rev 3725) @@ -19,8 +19,7 @@ dict.expose:org.python.core.PyDictionary enumerate.expose:org.python.core.PyEnumerate file.derived:org.python.core.PyFileDerived -#PyFile has evil hand edited code in new_impl -#file.expose:org.python.core.PyFile +file.expose:org.python.core.PyFile float.derived:org.python.core.PyFloatDerived float.expose:org.python.core.PyFloat #function.expose:org.python.core.PyFunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2007-12-16 00:26:19
|
Revision: 3811 http://jython.svn.sourceforge.net/jython/?rev=3811&view=rev Author: cgroves Date: 2007-12-15 16:26:15 -0800 (Sat, 15 Dec 2007) Log Message: ----------- Mark Strings coming in as class constants or through *Derived classes' __findattr__ as already interned when making PyStrings out of them. This means they won't be reinterned which is a significant speedup for class attr lookups on subclasses of newstyle classes Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyArrayDerived.java trunk/jython/src/org/python/core/PyBooleanDerived.java trunk/jython/src/org/python/core/PyClassMethodDerived.java trunk/jython/src/org/python/core/PyComplexDerived.java trunk/jython/src/org/python/core/PyDictionaryDerived.java trunk/jython/src/org/python/core/PyFileDerived.java trunk/jython/src/org/python/core/PyFloatDerived.java trunk/jython/src/org/python/core/PyIntegerDerived.java trunk/jython/src/org/python/core/PyListDerived.java trunk/jython/src/org/python/core/PyLongDerived.java trunk/jython/src/org/python/core/PyModuleDerived.java trunk/jython/src/org/python/core/PyObjectDerived.java trunk/jython/src/org/python/core/PyPropertyDerived.java trunk/jython/src/org/python/core/PySliceDerived.java trunk/jython/src/org/python/core/PyString.java trunk/jython/src/org/python/core/PyStringDerived.java trunk/jython/src/org/python/core/PySuperDerived.java trunk/jython/src/org/python/core/PyTupleDerived.java trunk/jython/src/org/python/core/PyTypeDerived.java trunk/jython/src/org/python/core/PyUnicode.java trunk/jython/src/org/python/core/PyUnicodeDerived.java trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java trunk/jython/src/templates/object.derived Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/compiler/Module.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -128,10 +128,8 @@ public void put(Code c) throws IOException { module.classfile.addField(name, $pyStr, access); c.ldc(value); - int mref_newString = c.pool.Methodref( - "org/python/core/Py", - "newString", - "(" + $str + ")" + $pyStr); + int mref_newString = c.pool.Methodref("org/python/core/PyString", "fromInterned", "(" + + $str + ")" + $pyStr); c.invokestatic(mref_newString); c.putstatic(module.classfile.name, name, $pyStr); } @@ -163,11 +161,9 @@ public void put(Code c) throws IOException { module.classfile.addField(name, $pyUnicode, access); c.ldc(value); - int mref_newString = c.pool.Methodref( - "org/python/core/Py", - "newUnicode", - "(" + $str + ")" + $pyUnicode); - c.invokestatic(mref_newString); + int mref_newUni = c.pool.Methodref("org/python/core/PyUnicode", "fromInterned", "(" + + $str + ")" + $pyUnicode); + c.invokestatic(mref_newUni); c.putstatic(module.classfile.name, name, $pyUnicode); } Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/Py.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -554,7 +554,7 @@ public static PyString newString(String s) { return new PyString(s); } - + public static PyUnicode newUnicode(char c) { return (PyUnicode)makeCharacter(c, true); } Modified: trunk/jython/src/org/python/core/PyArrayDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyArrayDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyArrayDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyBooleanDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyBooleanDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyBooleanDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyClassMethodDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyClassMethodDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyClassMethodDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyComplexDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyComplexDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyComplexDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyDictionaryDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionaryDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyDictionaryDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyFileDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyFileDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyFileDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyFloatDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyFloatDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyFloatDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyIntegerDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyIntegerDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyIntegerDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyListDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyListDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyListDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyLongDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyLongDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyLongDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyModuleDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyModuleDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyModuleDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -845,7 +845,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -854,7 +854,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -869,7 +869,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -879,7 +879,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyObjectDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyObjectDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyObjectDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyPropertyDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyPropertyDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyPropertyDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PySliceDerived.java =================================================================== --- trunk/jython/src/org/python/core/PySliceDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PySliceDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyString.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -1565,7 +1565,7 @@ protected String string; private transient int cached_hashcode=0; - private transient boolean interned=false; + protected transient boolean interned=false; // for PyJavaClass.init() public PyString() { @@ -1589,6 +1589,16 @@ this(STRTYPE,String.valueOf(c)); } + /** + * Creates a PyString from an already interned String. Just means it won't + * be reinterned if used in a place that requires interned Strings. + */ + public static PyString fromInterned(String interned) { + PyString str = new PyString(STRTYPE, interned); + str.interned = true; + return str; + } + final static PyObject str_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("str", args, keywords, new String[] { "object" }, 0); Modified: trunk/jython/src/org/python/core/PyStringDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyStringDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyStringDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PySuperDerived.java =================================================================== --- trunk/jython/src/org/python/core/PySuperDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PySuperDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyTupleDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyTupleDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyTupleDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyTypeDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyTypeDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyTypeDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -845,7 +845,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -854,7 +854,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -869,7 +869,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -879,7 +879,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/core/PyUnicode.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicode.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyUnicode.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -1490,6 +1490,16 @@ this(UNICODETYPE,String.valueOf(c)); } + /** + * Creates a PyUnicode from an already interned String. Just means it won't + * be reinterned if used in a place that requires interned Strings. + */ + public static PyUnicode fromInterned(String interned) { + PyUnicode uni = new PyUnicode(UNICODETYPE, interned); + uni.interned = true; + return uni; + } + final static PyObject unicode_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("unicode", Modified: trunk/jython/src/org/python/core/PyUnicodeDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicodeDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/core/PyUnicodeDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -869,7 +869,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -878,7 +878,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -893,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -903,7 +903,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java 2007-12-16 00:26:15 UTC (rev 3811) @@ -1,18 +1,11 @@ package org.python.modules.zipimport; -import java.util.Iterator; - import org.python.core.Py; -import org.python.core.PyBuiltinFunction; -import org.python.core.PyBuiltinMethod; -import org.python.core.PyBuiltinMethodNarrow; import org.python.core.PyComplex; import org.python.core.PyException; -import org.python.core.PyInteger; import org.python.core.PyFloat; +import org.python.core.PyInteger; import org.python.core.PyLong; -import org.python.core.PyMethodDescr; -import org.python.core.PyNewWrapper; import org.python.core.PyObject; import org.python.core.PySequenceIter; import org.python.core.PyString; @@ -866,7 +859,7 @@ PyString py_name=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -875,7 +868,7 @@ PyObject getattr=self_type.lookup("__getattr__"); if (getattr!=null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); } catch (PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; @@ -890,7 +883,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__setattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -900,7 +893,7 @@ PyType self_type=getType(); PyObject impl=self_type.lookup("__delattr__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); Modified: trunk/jython/src/templates/object.derived =================================================================== --- trunk/jython/src/templates/object.derived 2007-12-16 00:02:14 UTC (rev 3810) +++ trunk/jython/src/templates/object.derived 2007-12-16 00:26:15 UTC (rev 3811) @@ -235,7 +235,7 @@ PyString py_name = null; try { if (getattribute != null) { - return getattribute.__get__(this,self_type).__call__(py_name = new PyString(name)); + return getattribute.__get__(this,self_type).__call__(py_name = PyString.fromInterned(name)); } else { return super.__findattr__(name); } @@ -244,7 +244,7 @@ PyObject getattr = self_type.lookup("__getattr__"); if (getattr != null) try { - return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:new PyString(name)); + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name: PyString.fromInterned(name)); } catch(PyException e1) { if (!Py.matchException(e1,Py.AttributeError)) throw e1; } @@ -258,7 +258,7 @@ PyType self_type = getType(); PyObject impl = self_type.lookup("__setattr__"); if (impl != null) { - impl.__get__(this,self_type).__call__(new PyString(name),value); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); return; } super.__setattr__(name,value); @@ -268,7 +268,7 @@ PyType self_type = getType(); PyObject impl = self_type.lookup("__delattr__"); if (impl != null) { - impl.__get__(this,self_type).__call__(new PyString(name)); + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); return; } super.__delattr__(name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-01-01 01:23:19
|
Revision: 3924 http://jython.svn.sourceforge.net/jython/?rev=3924&view=rev Author: pjenvey Date: 2007-12-31 17:23:18 -0800 (Mon, 31 Dec 2007) Log Message: ----------- expose_binary is actually shorthand for how we want these exposed Modified Paths: -------------- trunk/jython/src/org/python/modules/collections/PyDeque.java trunk/jython/src/templates/deque.expose Modified: trunk/jython/src/org/python/modules/collections/PyDeque.java =================================================================== --- trunk/jython/src/org/python/modules/collections/PyDeque.java 2008-01-01 01:12:29 UTC (rev 3923) +++ trunk/jython/src/org/python/modules/collections/PyDeque.java 2008-01-01 01:23:18 UTC (rev 3924) @@ -45,6 +45,120 @@ public static final String exposed_name="deque"; public static void typeSetup(PyObject dict,PyType.Newstyle marker) { + class exposed___eq__ extends PyBuiltinMethodNarrow { + + exposed___eq__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___eq__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDeque)self).deque___eq__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyDeque.class,1,1,new exposed___eq__(null,null))); + class exposed___ne__ extends PyBuiltinMethodNarrow { + + exposed___ne__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___ne__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDeque)self).deque___ne__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ne__",new PyMethodDescr("__ne__",PyDeque.class,1,1,new exposed___ne__(null,null))); + class exposed___lt__ extends PyBuiltinMethodNarrow { + + exposed___lt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___lt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDeque)self).deque___lt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__lt__",new PyMethodDescr("__lt__",PyDeque.class,1,1,new exposed___lt__(null,null))); + class exposed___le__ extends PyBuiltinMethodNarrow { + + exposed___le__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___le__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDeque)self).deque___le__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__le__",new PyMethodDescr("__le__",PyDeque.class,1,1,new exposed___le__(null,null))); + class exposed___gt__ extends PyBuiltinMethodNarrow { + + exposed___gt__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___gt__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDeque)self).deque___gt__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__gt__",new PyMethodDescr("__gt__",PyDeque.class,1,1,new exposed___gt__(null,null))); + class exposed___ge__ extends PyBuiltinMethodNarrow { + + exposed___ge__(PyObject self,PyBuiltinFunction.Info info) { + super(self,info); + } + + public PyBuiltinFunction bind(PyObject self) { + return new exposed___ge__(self,info); + } + + public PyObject __call__(PyObject arg0) { + PyObject ret=((PyDeque)self).deque___ge__(arg0); + if (ret==null) + return Py.NotImplemented; + return ret; + } + + } + dict.__setitem__("__ge__",new PyMethodDescr("__ge__",PyDeque.class,1,1,new exposed___ge__(null,null))); class exposed_append extends PyBuiltinMethodNarrow { exposed_append(PyObject self,PyBuiltinFunction.Info info) { @@ -299,120 +413,6 @@ } dict.__setitem__("__iter__",new PyMethodDescr("__iter__",PyDeque.class,0,0,new exposed___iter__(null,null))); - class exposed___eq__ extends PyBuiltinMethodNarrow { - - exposed___eq__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___eq__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyDeque)self).deque___eq__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyDeque.class,1,1,new exposed___eq__(null,null))); - class exposed___ne__ extends PyBuiltinMethodNarrow { - - exposed___ne__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___ne__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyDeque)self).deque___ne__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__ne__",new PyMethodDescr("__ne__",PyDeque.class,1,1,new exposed___ne__(null,null))); - class exposed___lt__ extends PyBuiltinMethodNarrow { - - exposed___lt__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___lt__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyDeque)self).deque___lt__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__lt__",new PyMethodDescr("__lt__",PyDeque.class,1,1,new exposed___lt__(null,null))); - class exposed___le__ extends PyBuiltinMethodNarrow { - - exposed___le__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___le__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyDeque)self).deque___le__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__le__",new PyMethodDescr("__le__",PyDeque.class,1,1,new exposed___le__(null,null))); - class exposed___gt__ extends PyBuiltinMethodNarrow { - - exposed___gt__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___gt__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyDeque)self).deque___gt__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__gt__",new PyMethodDescr("__gt__",PyDeque.class,1,1,new exposed___gt__(null,null))); - class exposed___ge__ extends PyBuiltinMethodNarrow { - - exposed___ge__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___ge__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyDeque)self).deque___ge__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__ge__",new PyMethodDescr("__ge__",PyDeque.class,1,1,new exposed___ge__(null,null))); class exposed___hash__ extends PyBuiltinMethodNarrow { exposed___hash__(PyObject self,PyBuiltinFunction.Info info) { Modified: trunk/jython/src/templates/deque.expose =================================================================== --- trunk/jython/src/templates/deque.expose 2008-01-01 01:12:29 UTC (rev 3923) +++ trunk/jython/src/templates/deque.expose 2008-01-01 01:23:18 UTC (rev 3924) @@ -18,36 +18,7 @@ expose_meth: __repr__ return new PyString(((`typ)self).deque_toString()); expose_meth: __iter__ -expose_meth: __eq__ o - PyObject ret = ((`typ)self).deque___eq__(`arg0); - if (ret == null) - return Py.NotImplemented; - return ret; -expose_meth: __ne__ o - PyObject ret = ((`typ)self).deque___ne__(`arg0); - if (ret == null) - return Py.NotImplemented; - return ret; -expose_meth: __lt__ o - PyObject ret = ((`typ)self).deque___lt__(`arg0); - if (ret == null) - return Py.NotImplemented; - return ret; -expose_meth: __le__ o - PyObject ret = ((`typ)self).deque___le__(`arg0); - if (ret == null) - return Py.NotImplemented; - return ret; -expose_meth: __gt__ o - PyObject ret = ((`typ)self).deque___gt__(`arg0); - if (ret == null) - return Py.NotImplemented; - return ret; -expose_meth: __ge__ o - PyObject ret = ((`typ)self).deque___ge__(`arg0); - if (ret == null) - return Py.NotImplemented; - return ret; +expose_binary: __eq__ __ne__ __lt__ __le__ __gt__ __ge__ expose_meth: __hash__ return new PyInteger(((`typ)self).deque_hashCode()); expose_meth: __reduce__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-02-10 08:17:37
|
Revision: 4123 http://jython.svn.sourceforge.net/jython/?rev=4123&view=rev Author: cgroves Date: 2008-02-10 00:17:36 -0800 (Sun, 10 Feb 2008) Log Message: ----------- Convert remaining types in mappings to annotations Modified Paths: -------------- trunk/jython/src/org/python/core/PyInteger.java trunk/jython/src/org/python/core/PyLong.java trunk/jython/src/org/python/core/PyNewWrapper.java trunk/jython/src/org/python/core/PyProperty.java trunk/jython/src/org/python/core/PySlice.java trunk/jython/src/org/python/core/PySuper.java trunk/jython/src/org/python/core/PyTuple.java trunk/jython/src/org/python/core/__builtin__.java trunk/jython/src/org/python/modules/PyLocal.java trunk/jython/src/org/python/modules/sets/PyImmutableSet.java trunk/jython/src/org/python/modules/sets/PySet.java trunk/jython/src/org/python/modules/sets/Sets.java trunk/jython/src/org/python/modules/thread.java trunk/jython/src/templates/mappings Removed Paths: ------------- trunk/jython/src/templates/baseset.expose trunk/jython/src/templates/immutableset.expose trunk/jython/src/templates/local.expose trunk/jython/src/templates/long.expose trunk/jython/src/templates/property.expose trunk/jython/src/templates/sequence.expose trunk/jython/src/templates/set.expose trunk/jython/src/templates/slice.expose trunk/jython/src/templates/super.expose trunk/jython/src/templates/test.expose trunk/jython/src/templates/tuple.expose Modified: trunk/jython/src/org/python/core/PyInteger.java =================================================================== --- trunk/jython/src/org/python/core/PyInteger.java 2008-02-10 08:16:48 UTC (rev 4122) +++ trunk/jython/src/org/python/core/PyInteger.java 2008-02-10 08:17:36 UTC (rev 4123) @@ -448,7 +448,7 @@ return _pow(coerce(left), getValue(), modulo, left, this); } - @ExposedMethod(type = MethodType.BINARY, defaults = {"null"}) + @ExposedMethod(type = MethodType.BINARY) final PyObject int___rpow__(PyObject left){ return __rpow__(left, null); } Modified: trunk/jython/src/org/python/core/PyLong.java =================================================================== --- trunk/jython/src/org/python/core/PyLong.java 2008-02-10 08:16:48 UTC (rev 4122) +++ trunk/jython/src/org/python/core/PyLong.java 2008-02-10 08:17:36 UTC (rev 4123) @@ -1,16 +1,23 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.math.BigInteger; import java.io.Serializable; +import java.math.BigInteger; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedType; +import org.python.expose.MethodType; + /** * A builtin python long. This is implemented as a * java.math.BigInteger. */ +@ExposedType(name = "long") +public class PyLong extends PyObject { -public class PyLong extends PyObject -{ + public static final PyType TYPE = PyType.fromClass(PyLong.class); + public static final BigInteger minLong = BigInteger.valueOf(Long.MIN_VALUE); public static final BigInteger maxLong = @@ -18,812 +25,13 @@ public static final BigInteger maxULong = BigInteger.valueOf(1).shiftLeft(64).subtract(BigInteger.valueOf(1)); - //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py - /* type info */ - - public static final String exposed_name="long"; - - public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - class exposed___abs__ extends PyBuiltinMethodNarrow { - - exposed___abs__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___abs__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___abs__(); - } - - } - dict.__setitem__("__abs__",new PyMethodDescr("__abs__",PyLong.class,0,0,new exposed___abs__(null,null))); - class exposed___float__ extends PyBuiltinMethodNarrow { - - exposed___float__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___float__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___float__(); - } - - } - dict.__setitem__("__float__",new PyMethodDescr("__float__",PyLong.class,0,0,new exposed___float__(null,null))); - class exposed___hex__ extends PyBuiltinMethodNarrow { - - exposed___hex__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___hex__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___hex__(); - } - - } - dict.__setitem__("__hex__",new PyMethodDescr("__hex__",PyLong.class,0,0,new exposed___hex__(null,null))); - class exposed___int__ extends PyBuiltinMethodNarrow { - - exposed___int__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___int__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___int__(); - } - - } - dict.__setitem__("__int__",new PyMethodDescr("__int__",PyLong.class,0,0,new exposed___int__(null,null))); - class exposed___invert__ extends PyBuiltinMethodNarrow { - - exposed___invert__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___invert__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___invert__(); - } - - } - dict.__setitem__("__invert__",new PyMethodDescr("__invert__",PyLong.class,0,0,new exposed___invert__(null,null))); - class exposed___long__ extends PyBuiltinMethodNarrow { - - exposed___long__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___long__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___long__(); - } - - } - dict.__setitem__("__long__",new PyMethodDescr("__long__",PyLong.class,0,0,new exposed___long__(null,null))); - class exposed___neg__ extends PyBuiltinMethodNarrow { - - exposed___neg__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___neg__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___neg__(); - } - - } - dict.__setitem__("__neg__",new PyMethodDescr("__neg__",PyLong.class,0,0,new exposed___neg__(null,null))); - class exposed___oct__ extends PyBuiltinMethodNarrow { - - exposed___oct__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___oct__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___oct__(); - } - - } - dict.__setitem__("__oct__",new PyMethodDescr("__oct__",PyLong.class,0,0,new exposed___oct__(null,null))); - class exposed___pos__ extends PyBuiltinMethodNarrow { - - exposed___pos__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___pos__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___pos__(); - } - - } - dict.__setitem__("__pos__",new PyMethodDescr("__pos__",PyLong.class,0,0,new exposed___pos__(null,null))); - class exposed___add__ extends PyBuiltinMethodNarrow { - - exposed___add__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___add__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___add__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__add__",new PyMethodDescr("__add__",PyLong.class,1,1,new exposed___add__(null,null))); - class exposed___and__ extends PyBuiltinMethodNarrow { - - exposed___and__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___and__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___and__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__and__",new PyMethodDescr("__and__",PyLong.class,1,1,new exposed___and__(null,null))); - class exposed___div__ extends PyBuiltinMethodNarrow { - - exposed___div__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___div__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___div__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__div__",new PyMethodDescr("__div__",PyLong.class,1,1,new exposed___div__(null,null))); - class exposed___divmod__ extends PyBuiltinMethodNarrow { - - exposed___divmod__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___divmod__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___divmod__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__divmod__",new PyMethodDescr("__divmod__",PyLong.class,1,1,new exposed___divmod__(null,null))); - class exposed___floordiv__ extends PyBuiltinMethodNarrow { - - exposed___floordiv__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___floordiv__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___floordiv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__floordiv__",new PyMethodDescr("__floordiv__",PyLong.class,1,1,new exposed___floordiv__(null,null))); - class exposed___lshift__ extends PyBuiltinMethodNarrow { - - exposed___lshift__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___lshift__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___lshift__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__lshift__",new PyMethodDescr("__lshift__",PyLong.class,1,1,new exposed___lshift__(null,null))); - class exposed___mod__ extends PyBuiltinMethodNarrow { - - exposed___mod__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___mod__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___mod__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__mod__",new PyMethodDescr("__mod__",PyLong.class,1,1,new exposed___mod__(null,null))); - class exposed___mul__ extends PyBuiltinMethodNarrow { - - exposed___mul__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___mul__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___mul__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__mul__",new PyMethodDescr("__mul__",PyLong.class,1,1,new exposed___mul__(null,null))); - class exposed___or__ extends PyBuiltinMethodNarrow { - - exposed___or__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___or__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___or__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__or__",new PyMethodDescr("__or__",PyLong.class,1,1,new exposed___or__(null,null))); - class exposed___radd__ extends PyBuiltinMethodNarrow { - - exposed___radd__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___radd__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___radd__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__radd__",new PyMethodDescr("__radd__",PyLong.class,1,1,new exposed___radd__(null,null))); - class exposed___rdiv__ extends PyBuiltinMethodNarrow { - - exposed___rdiv__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rdiv__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rdiv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rdiv__",new PyMethodDescr("__rdiv__",PyLong.class,1,1,new exposed___rdiv__(null,null))); - class exposed___rfloordiv__ extends PyBuiltinMethodNarrow { - - exposed___rfloordiv__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rfloordiv__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rfloordiv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rfloordiv__",new PyMethodDescr("__rfloordiv__",PyLong.class,1,1,new exposed___rfloordiv__(null,null))); - class exposed___rmod__ extends PyBuiltinMethodNarrow { - - exposed___rmod__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rmod__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rmod__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rmod__",new PyMethodDescr("__rmod__",PyLong.class,1,1,new exposed___rmod__(null,null))); - class exposed___rmul__ extends PyBuiltinMethodNarrow { - - exposed___rmul__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rmul__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rmul__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rmul__",new PyMethodDescr("__rmul__",PyLong.class,1,1,new exposed___rmul__(null,null))); - class exposed___rshift__ extends PyBuiltinMethodNarrow { - - exposed___rshift__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rshift__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rshift__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rshift__",new PyMethodDescr("__rshift__",PyLong.class,1,1,new exposed___rshift__(null,null))); - class exposed___rsub__ extends PyBuiltinMethodNarrow { - - exposed___rsub__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rsub__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rsub__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rsub__",new PyMethodDescr("__rsub__",PyLong.class,1,1,new exposed___rsub__(null,null))); - class exposed___rtruediv__ extends PyBuiltinMethodNarrow { - - exposed___rtruediv__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rtruediv__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rtruediv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rtruediv__",new PyMethodDescr("__rtruediv__",PyLong.class,1,1,new exposed___rtruediv__(null,null))); - class exposed___sub__ extends PyBuiltinMethodNarrow { - - exposed___sub__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___sub__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___sub__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__sub__",new PyMethodDescr("__sub__",PyLong.class,1,1,new exposed___sub__(null,null))); - class exposed___truediv__ extends PyBuiltinMethodNarrow { - - exposed___truediv__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___truediv__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___truediv__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__truediv__",new PyMethodDescr("__truediv__",PyLong.class,1,1,new exposed___truediv__(null,null))); - class exposed___xor__ extends PyBuiltinMethodNarrow { - - exposed___xor__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___xor__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___xor__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__xor__",new PyMethodDescr("__xor__",PyLong.class,1,1,new exposed___xor__(null,null))); - class exposed___rxor__ extends PyBuiltinMethodNarrow { - - exposed___rxor__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rxor__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rxor__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rxor__",new PyMethodDescr("__rxor__",PyLong.class,1,1,new exposed___rxor__(null,null))); - class exposed___rrshift__ extends PyBuiltinMethodNarrow { - - exposed___rrshift__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rrshift__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rrshift__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rrshift__",new PyMethodDescr("__rrshift__",PyLong.class,1,1,new exposed___rrshift__(null,null))); - class exposed___ror__ extends PyBuiltinMethodNarrow { - - exposed___ror__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___ror__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___ror__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__ror__",new PyMethodDescr("__ror__",PyLong.class,1,1,new exposed___ror__(null,null))); - class exposed___rand__ extends PyBuiltinMethodNarrow { - - exposed___rand__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rand__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rand__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rand__",new PyMethodDescr("__rand__",PyLong.class,1,1,new exposed___rand__(null,null))); - class exposed___rpow__ extends PyBuiltinMethodNarrow { - - exposed___rpow__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rpow__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rpow__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rpow__",new PyMethodDescr("__rpow__",PyLong.class,1,1,new exposed___rpow__(null,null))); - class exposed___rlshift__ extends PyBuiltinMethodNarrow { - - exposed___rlshift__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rlshift__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rlshift__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rlshift__",new PyMethodDescr("__rlshift__",PyLong.class,1,1,new exposed___rlshift__(null,null))); - class exposed___rdivmod__ extends PyBuiltinMethodNarrow { - - exposed___rdivmod__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___rdivmod__(self,info); - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___rdivmod__(arg0); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__rdivmod__",new PyMethodDescr("__rdivmod__",PyLong.class,1,1,new exposed___rdivmod__(null,null))); - class exposed___cmp__ extends PyBuiltinMethodNarrow { - - exposed___cmp__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___cmp__(self,info); - } - - public PyObject __call__(PyObject arg0) { - int ret=((PyLong)self).long___cmp__(arg0); - if (ret==-2) { - throw Py.TypeError("long"+".__cmp__(x,y) requires y to be '"+"long"+"', not a '"+(arg0).getType().fastGetName()+"'"); - } - return Py.newInteger(ret); - } - - } - dict.__setitem__("__cmp__",new PyMethodDescr("__cmp__",PyLong.class,1,1,new exposed___cmp__(null,null))); - class exposed___pow__ extends PyBuiltinMethodNarrow { - - exposed___pow__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___pow__(self,info); - } - - public PyObject __call__(PyObject arg0,PyObject arg1) { - PyObject ret=((PyLong)self).long___pow__(arg0,arg1); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - public PyObject __call__(PyObject arg0) { - PyObject ret=((PyLong)self).long___pow__(arg0,null); - if (ret==null) - return Py.NotImplemented; - return ret; - } - - } - dict.__setitem__("__pow__",new PyMethodDescr("__pow__",PyLong.class,1,2,new exposed___pow__(null,null))); - class exposed___nonzero__ extends PyBuiltinMethodNarrow { - - exposed___nonzero__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___nonzero__(self,info); - } - - public PyObject __call__() { - return Py.newBoolean(((PyLong)self).long___nonzero__()); - } - - } - dict.__setitem__("__nonzero__",new PyMethodDescr("__nonzero__",PyLong.class,0,0,new exposed___nonzero__(null,null))); - class exposed___repr__ extends PyBuiltinMethodNarrow { - - exposed___repr__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___repr__(self,info); - } - - public PyObject __call__() { - return new PyString(((PyLong)self).long_toString()); - } - - } - dict.__setitem__("__repr__",new PyMethodDescr("__repr__",PyLong.class,0,0,new exposed___repr__(null,null))); - class exposed___str__ extends PyBuiltinMethodNarrow { - - exposed___str__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___str__(self,info); - } - - public PyObject __call__() { - return new PyString(((PyLong)self).long_toString()); - } - - } - dict.__setitem__("__str__",new PyMethodDescr("__str__",PyLong.class,0,0,new exposed___str__(null,null))); - class exposed___getnewargs__ extends PyBuiltinMethodNarrow { - - exposed___getnewargs__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___getnewargs__(self,info); - } - - public PyObject __call__() { - return((PyLong)self).long___getnewargs__(); - } - - } - dict.__setitem__("__getnewargs__",new PyMethodDescr("__getnewargs__",PyLong.class,0,0,new exposed___getnewargs__(null,null))); - class exposed___hash__ extends PyBuiltinMethodNarrow { - - exposed___hash__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___hash__(self,info); - } - - public PyObject __call__() { - return Py.newInteger(((PyLong)self).long_hashCode()); - } - - } - dict.__setitem__("__hash__",new PyMethodDescr("__hash__",PyLong.class,0,0,new exposed___hash__(null,null))); - dict.__setitem__("__new__",new PyNewWrapper(PyLong.class,"__new__",-1,-1) { - - public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { - return long_new(this,init,subtype,args,keywords); - } - - }); - } - //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py - private BigInteger value; + @ExposedNew public static PyObject long_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { - ArgParser ap = new ArgParser(exposed_name, args, keywords, - new String[] { "x", "base" }, 0); + ArgParser ap = new ArgParser("long", args, keywords, new String[] {"x", "base"}, 0); PyObject x = ap.getPyObject(0, null); int base = ap.getInt(1, -909); @@ -865,16 +73,14 @@ return new PyLongDerived(subtype, (((PyString) x).atol(base)).getValue()); } - } // xxx + } - private static final PyType LONGTYPE = PyType.fromClass(PyLong.class); - public PyLong(PyType subType, BigInteger v) { super(subType); value = v; } public PyLong(BigInteger v) { - this(LONGTYPE, v); + this(TYPE, v); } public PyLong(double v) { @@ -895,16 +101,17 @@ return long_toString(); } + @ExposedMethod(names = {"__str__", "__repr__"}) final String long_toString() { return value.toString()+"L"; } public int hashCode() { - return long_hashCode(); + return long___hash__(); } - final int long_hashCode() { - // Probably won't work well for some classes of keys... + @ExposedMethod + final int long___hash__() { return value.intValue(); } @@ -912,6 +119,7 @@ return !value.equals(BigInteger.valueOf(0)); } + @ExposedMethod public boolean long___nonzero__() { return __nonzero__(); } @@ -1017,6 +225,7 @@ return long___cmp__(other); } + @ExposedMethod(type = MethodType.CMP) final int long___cmp__(PyObject other) { if (!canCoerce(other)) return -2; @@ -1052,6 +261,7 @@ return long___add__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___add__(PyObject right) { if (!canCoerce(right)) return null; @@ -1062,6 +272,7 @@ return long___radd__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___radd__(PyObject left) { return __add__(left); } @@ -1070,6 +281,7 @@ return long___sub__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___sub__(PyObject right) { if (!canCoerce(right)) return null; @@ -1080,6 +292,7 @@ return long___rsub__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rsub__(PyObject left) { return Py.newLong(coerce(left).subtract(value)); } @@ -1088,6 +301,7 @@ return long___mul__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___mul__(PyObject right) { if (right instanceof PySequence) return ((PySequence) right).repeat(coerceInt(this)); @@ -1101,6 +315,7 @@ return long___rmul__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rmul__(PyObject left) { if (left instanceof PySequence) return ((PySequence) left).repeat(coerceInt(this)); @@ -1131,6 +346,7 @@ return long___div__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___div__(PyObject right) { if (!canCoerce(right)) return null; @@ -1143,6 +359,7 @@ return long___rdiv__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rdiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -1155,6 +372,7 @@ return long___floordiv__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___floordiv__(PyObject right) { if (!canCoerce(right)) return null; @@ -1165,6 +383,7 @@ return long___rfloordiv__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rfloordiv__(PyObject left) { if (!canCoerce(left)) return null; @@ -1203,6 +422,7 @@ return long___truediv__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___truediv__(PyObject right) { if (!canCoerce(right)) return null; @@ -1213,6 +433,7 @@ return long___rtruediv__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rtruediv__(PyObject left) { if (!canCoerce(left)) return null; @@ -1227,6 +448,7 @@ return long___mod__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___mod__(PyObject right) { if (!canCoerce(right)) return null; @@ -1238,6 +460,7 @@ return long___rmod__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rmod__(PyObject left) { if (!canCoerce(left)) return null; @@ -1249,6 +472,7 @@ return long___divmod__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___divmod__(PyObject right) { if (!canCoerce(right)) return null; @@ -1262,6 +486,7 @@ return long___rdivmod__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rdivmod__(PyObject left) { if (!canCoerce(left)) return null; @@ -1274,6 +499,8 @@ public PyObject __pow__(PyObject right, PyObject modulo) { return long___pow__(right, modulo); } + + @ExposedMethod(type = MethodType.BINARY, defaults = {"null"}) final PyObject long___pow__(PyObject right, PyObject modulo) { if (!canCoerce(right)) return null; @@ -1287,6 +514,7 @@ return long___rpow__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rpow__(PyObject left) { if (!canCoerce(left)) return null; @@ -1352,6 +580,7 @@ return long___lshift__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___lshift__(PyObject right) { if (!canCoerce(right)) return null; @@ -1361,6 +590,7 @@ return Py.newLong(value.shiftLeft(rightv)); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rlshift__(PyObject left) { if (!canCoerce(left)) return null; @@ -1373,6 +603,7 @@ return long___rshift__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rshift__(PyObject right) { if (!canCoerce(right)) return null; @@ -1382,6 +613,7 @@ return Py.newLong(value.shiftRight(rightv)); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rrshift__(PyObject left) { if (!canCoerce(left)) return null; @@ -1394,6 +626,7 @@ return long___and__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___and__(PyObject right) { if (!canCoerce(right)) return null; @@ -1404,6 +637,7 @@ return long___rand__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rand__(PyObject left) { if (!canCoerce(left)) return null; @@ -1414,6 +648,7 @@ return long___xor__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___xor__(PyObject right) { if (!canCoerce(right)) return null; @@ -1424,6 +659,7 @@ return long___rxor__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___rxor__(PyObject left) { if (!canCoerce(left)) return null; @@ -1434,6 +670,7 @@ return long___or__(right); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___or__(PyObject right) { if (!canCoerce(right)) return null; @@ -1444,6 +681,7 @@ return long___ror__(left); } + @ExposedMethod(type = MethodType.BINARY) final PyObject long___ror__(PyObject left) { if (!canCoerce(left)) return null; @@ -1454,6 +692,7 @@ return long___neg__(); } + @ExposedMethod final PyObject long___neg__() { return Py.newLong(value.negate()); } @@ -1462,6 +701,7 @@ return long___pos__(); } + @ExposedMethod final PyObject long___pos__() { return Py.newLong(value); } @@ -1469,6 +709,8 @@ public PyObject __abs__() { return long___abs__(); } + + @ExposedMethod final PyObject long___abs__() { return Py.newLong(value.abs()); } @@ -1477,6 +719,7 @@ return long___invert__(); } + @ExposedMethod final PyObject long___invert__() { return Py.newLong(value.not()); } @@ -1485,6 +728,7 @@ return long___int__(); } + @ExposedMethod final PyObject long___int__() { long v = value.longValue(); if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) { @@ -1499,6 +743,7 @@ return long___long__(); } + @ExposedMethod final PyLong long___long__() { return Py.newLong(value); } @@ -1507,6 +752,7 @@ return long___float__(); } + @ExposedMethod final PyFloat long___float__() { return new PyFloat(doubleValue()); } @@ -1523,6 +769,7 @@ return long___oct__(); } + @ExposedMethod final PyString long___oct__() { String s = value.toString(8); if (s.startsWith("-")) @@ -1538,6 +785,7 @@ return long___hex__(); } + @ExposedMethod final PyString long___hex__() { String s = value.toString(16).toUpperCase(); if (s.startsWith("-")) @@ -1554,6 +802,7 @@ return new PyUnicode(value.toString()); } + @ExposedMethod final PyTuple long___getnewargs__() { return new PyTuple(new PyLong(this.getValue())); } Modified: trunk/jython/src/org/python/core/PyNewWrapper.java =================================================================== --- trunk/jython/src/org/python/core/PyNewWrapper.java 2008-02-10 08:16:48 UTC (rev 4122) +++ trunk/jython/src/org/python/core/PyNewWrapper.java 2008-02-10 08:17:36 UTC (rev 4123) @@ -23,6 +23,10 @@ throw Py.SystemError("__new__ wrappers are already bound"); } + public PyType getWrappedType() { + return for_type; + } + public void setWrappedType(PyType type) { self = type; for_type = type; Modified: trunk/jython/src/org/python/core/PyProperty.java =================================================================== --- trunk/jython/src/org/python/core/PyProperty.java 2008-02-10 08:16:48 UTC (rev 4122) +++ trunk/jython/src/org/python/core/PyProperty.java 2008-02-10 08:17:36 UTC (rev 4123) @@ -1,138 +1,45 @@ package org.python.core; -public class PyProperty extends PyObject implements PyType.Newstyle { - //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py - /* type info */ +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; - public static final String exposed_name="property"; +@ExposedType(name = "property") +public class PyProperty extends PyObject { - public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - dict.__setitem__("fget",new PyGetSetDescr("fget",PyProperty.class,"getFget","setFget",null)); - dict.__setitem__("fset",new PyGetSetDescr("fset",PyProperty.class,"getFset","setFset",null)); - dict.__setitem__("fdel",new PyGetSetDescr("fdel",PyProperty.class,"getFdel","setFdel",null)); - dict.__setitem__("__doc__",new PyGetSetDescr("__doc__",PyProperty.class,"getDoc","setDoc",null)); - class exposed___get__ extends PyBuiltinMethodNarrow { + public static final PyType TYPE = PyType.fromClass(PyProperty.class); - exposed___get__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___get__(self,info); - } - - public PyObject __call__(PyObject arg0,PyObject arg1) { - PyObject obj=(arg0==Py.None)?null:arg0; - PyObject type=(arg1==null)?obj:arg1; - return((PyProperty)self).property___get__(obj,type); - } - - public PyObject __call__(PyObject arg0) { - PyObject obj=(arg0==Py.None)?null:arg0; - PyObject type=((null)==null)?obj:(null); - return((PyProperty)self).property___get__(obj,type); - } - - } - dict.__setitem__("__get__",new PyMethodDescr("__get__",PyProperty.class,1,2,new exposed___get__(null,null))); - class exposed___set__ extends PyBuiltinMethodNarrow { - - exposed___set__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___set__(self,info); - } - - public PyObject __call__(PyObject arg0,PyObject arg1) { - ((PyProperty)self).property___set__(arg0,arg1); - return Py.None; - } - - } - dict.__setitem__("__set__",new PyMethodDescr("__set__",PyProperty.class,2,2,new exposed___set__(null,null))); - class exposed___delete__ extends PyBuiltinMethodNarrow { - - exposed___delete__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___delete__(self,info); - } - - public PyObject __call__(PyObject arg0) { - ((PyProperty)self).property___delete__(arg0); - return Py.None; - } - - } - dict.__setitem__("__delete__",new PyMethodDescr("__delete__",PyProperty.class,1,1,new exposed___delete__(null,null))); - class exposed___init__ extends PyBuiltinMethod { - - exposed___init__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___init__(self,info); - } - - public PyObject __call__(PyObject[]args) { - return __call__(args,Py.NoKeywords); - } - - public PyObject __call__(PyObject[]args,String[]keywords) { - ((PyProperty)self).property_init(args,keywords); - return Py.None; - } - - } - dict.__setitem__("__init__",new PyMethodDescr("__init__",PyProperty.class,-1,-1,new exposed___init__(null,null))); - dict.__setitem__("__new__",new PyNewWrapper(PyProperty.class,"__new__",-1,-1) { - - public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { - PyProperty newobj; - if (for_type==subtype) { - newobj=new PyProperty(); - if (init) - newobj.property_init(args,keywords); - } else { - newobj=new PyPropertyDerived(subtype); - } - return newobj; - } - - }); - } - //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py - - private static final PyType PROPERTYTYPE = PyType.fromClass(PyProperty.class); - protected PyObject fget; protected PyObject fset; protected PyObject fdel; protected PyObject doc; public PyProperty() { - this(PROPERTYTYPE); + this(TYPE); } public PyProperty(PyType subType) { super(subType); } + @ExposedGet(name = "__doc__") public PyObject getDoc() { return doc; } + + @ExposedGet(name = "fdel") public PyObject getFdel() { return fdel; } + + @ExposedGet(name = "fset") public PyObject getFset() { return fset; } + @ExposedGet(name = "fget") public PyObject getFget() { return fget; } @@ -140,23 +47,29 @@ // However I believe that this should be fixed through // PyGetSetDescr.java instead // Carlos Quiroz: 19.11.2005 + @ExposedSet(name = "fget") public void setFget(PyObject py) { throw Py.TypeError("readonly attribute"); } - + + @ExposedSet(name = "fset") public void setFset(PyObject py) { throw Py.TypeError("readonly attribute"); } - + + @ExposedSet(name = "fdel") public void setFdel(PyObject py) { throw Py.TypeError("readonly attribute"); } - + + @ExposedSet(name = "__doc__") public void setDoc(PyObject py) { throw Py.TypeError("readonly attribute"); } - public void property_init(PyObject[] args, String[] keywords) { + @ExposedNew + @ExposedMethod + public void property___init__(PyObject[] args, String[] keywords) { ArgParser argparse = new ArgParser("property",args, keywords, new String[] {"fget","fset","fdel","doc"}, 0); fget = argparse.getPyObject(0, null); @@ -176,8 +89,9 @@ return property___get__(obj,type); } + @ExposedMethod(defaults = "null") final PyObject property___get__(PyObject obj, PyObject type) { - if (obj == null || null == Py.None) + if (obj == null || obj == Py.None) return this; if (fget == null) throw Py.AttributeError("unreadable attribute"); @@ -188,6 +102,7 @@ property___set__(obj,value); } + @ExposedMethod final void property___set__(PyObject obj, PyObject value) { if (fset == null) throw Py.AttributeError("can't set attribute"); @@ -198,6 +113,7 @@ property___delete__(obj); } + @ExposedMethod final void property___delete__(PyObject obj) { if (fdel == null) throw Py.AttributeError("can't delete attribute"); Modified: trunk/jython/src/org/python/core/PySlice.java =================================================================== --- trunk/jython/src/org/python/core/PySlice.java 2008-02-10 08:16:48 UTC (rev 4122) +++ trunk/jython/src/org/python/core/PySlice.java 2008-02-10 08:17:36 UTC (rev 4123) @@ -1,95 +1,23 @@ //Copyright (c) Corporation for National Research Initiatives package org.python.core; -import org.python.core.PyObject.ConversionException; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedType; /** * A python slice object. */ +@ExposedType(name = "slice") public class PySlice extends PyObject { - - //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py - /* type info */ - - public static final String exposed_name="slice"; - - public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - dict.__setitem__("start",new PyGetSetDescr("start",PySlice.class,"getStart",null,null)); - dict.__setitem__("stop",new PyGetSetDescr("stop",PySlice.class,"getStop",null,null)); - dict.__setitem__("step",new PyGetSetDescr("step",PySlice.class,"getStep",null,null)); - class exposed_indices extends PyBuiltinMethodNarrow { - - exposed_indices(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed_indices(self,info); - } - - public PyObject __call__(PyObject arg0) { - return((PySlice)self).slice_indices(arg0); - } - - } - dict.__setitem__("indices",new PyMethodDescr("indices",PySlice.class,1,1,new exposed_indices(null,null))); - class exposed___hash__ extends PyBuiltinMethodNarrow { - - exposed___hash__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___hash__(self,info); - } - - public PyObject __call__() { - throw Py.TypeError("unhashable type"); - } - - } - dict.__setitem__("__hash__",new PyMethodDescr("__hash__",PySlice.class,0,0,new exposed___hash__(null,null))); - class exposed___init__ extends PyBuiltinMethod { - - exposed___init__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___init__(self,info); - } - - public PyObject __call__(PyObject[]args) { - return __call__(args,Py.NoKeywords); - } - - public PyObject __call__(PyObject[]args,String[]keywords) { - ((PySlice)self).slice_init(args,keywords); - return Py.None; - } - - } - dict.__setitem__("__init__",new PyMethodDescr("__init__",PySlice.class,-1,-1,new exposed___init__(null,null))); - dict.__setitem__("__new__",new PyNewWrapper(PySlice.class,"__new__",-1,-1) { - - public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { - PySlice newobj; - if (for_type==subtype) { - newobj=new PySlice(); - if (init) - newobj.slice_init(args,keywords); - } else { - newobj=new PySliceDerived(subtype); - } - return newobj; - } - - }); - } - //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py - - final void slice_init(PyObject[] args, String[] keywords) { + + public static final PyType TYPE = PyType.fromClass(PySlice.class); + + @ExposedNew + @ExposedMethod + final void slice___init__(PyObject[] args, String[] keywords) { if(args.length == 0) { throw Py.TypeError("slice expected at least 1 arguments, got " + args.length); } else if(args.length > 3) { @@ -108,10 +36,8 @@ } } - private static final PyType SLICE_TYPE = PyType.fromClass(PySlice.class); - public PySlice(PyObject start, PyObject stop, PyObject step) { - this(SLICE_TYPE); + this(TYPE); if(start != null) { this.start = start; } @@ -128,7 +54,7 @@ } public PySlice() { - this(SLICE_TYPE); + this(TYPE); } public final PyObject getStart() { @@ -144,10 +70,11 @@ } public int hashCode() { - return slice_hashCode(); + return slice___hash__(); } - final int slice_hashCode() { + @ExposedMethod + final int slice___hash__() { throw Py.TypeError("unhashable type"); } @@ -185,6 +112,7 @@ return __eq__(o).__not__(); } + @ExposedMethod public PyObject slice_indices(PyObject len) { int ilen; try { @@ -269,9 +197,12 @@ } private static final int START = 0, STOP = 1, STEP = 2; + @ExposedGet public PyObject start = Py.None; + @ExposedGet public PyObject stop = Py.None; + @ExposedGet public PyObject step = Py.None; } Modified: trunk/jython/src/org/python/core/PySuper.java =================================================================== --- trunk/jython/src/org/python/core/PySuper.java 2008-02-10 08:16:48 UTC (rev 4122) +++ trunk/jython/src/org/python/core/PySuper.java 2008-02-10 08:17:36 UTC (rev 4123) @@ -1,114 +1,20 @@ package org.python.core; -public class PySuper extends PyObject implements PyType.Newstyle { - //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py - /* type info */ +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedType; - public static final String exposed_name="super"; +@ExposedType(name = "super") +public class PySuper extends PyObject { - public static void typeSetup(PyObject dict,PyType.Newstyle marker) { - dict.__setitem__("__thisclass__",new PyGetSetDescr("__thisclass__",PySuper.class,"getThisClass",null,null)); - dict.__setitem__("__self__",new PyGetSetDescr("__self__",PySuper.class,"getSelf",null,null)); - dict.__setitem__("__self_class__",new PyGetSetDescr("__self_class__",PySuper.class,"getSelfClass",null,null)); - class exposed___getattribute__ extends PyBuiltinMethodNarrow { - - exposed___getattribute__(PyObject self,PyBuiltinFunction.Info info) { - super(self,info); - } - - public PyBuiltinFunction bind(PyObject self) { - return new exposed___getattribute__(self,info); - } - - public PyObject __call__(PyObject arg0) { - try { - String name=(arg0.asName(0)); - PyObject ret=((PySuper)self).super___findattr__(name); - if (ret==null) - ((PySupe... [truncated message content] |
From: <cg...@us...> - 2008-03-17 22:17:07
|
Revision: 4216 http://jython.svn.sourceforge.net/jython/?rev=4216&view=rev Author: cgroves Date: 2008-03-17 15:17:05 -0700 (Mon, 17 Mar 2008) Log Message: ----------- Rip out all the old school 'public static PyClass __class__' optimizations. They haven't been enabled since forever and new style types set their type explicitly and don't need the optimization Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/DBApiType.java trunk/jython/src/com/ziclix/python/sql/PyConnection.java trunk/jython/src/com/ziclix/python/sql/PyCursor.java trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java trunk/jython/src/com/ziclix/python/sql/PyStatement.java trunk/jython/src/com/ziclix/python/sql/connect/Connect.java trunk/jython/src/com/ziclix/python/sql/connect/Connectx.java trunk/jython/src/com/ziclix/python/sql/connect/Lookup.java trunk/jython/src/com/ziclix/python/sql/util/BCP.java trunk/jython/src/com/ziclix/python/sql/zxJDBC.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyClass.java trunk/jython/src/org/python/core/PyJavaClass.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/com/ziclix/python/sql/DBApiType.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/DBApiType.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/DBApiType.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -23,11 +23,6 @@ public final class DBApiType extends PyInteger { /** - * Field __class__ - */ - public static PyClass __class__; - - /** * Constructor DBApiType * * @param type @@ -44,13 +39,4 @@ public DBApiType(Integer type) { super(type.intValue()); } - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } } Modified: trunk/jython/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -59,20 +59,6 @@ private Set statements; /** - * Field __class__ - */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } - - /** * Field __members__ */ protected static PyList __members__; Modified: trunk/jython/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -128,19 +128,6 @@ this.rsConcur = rsConcur; } - /** Field __class__ */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - * - */ - protected PyClass getPyClass() { - return __class__; - } - /** Field __methods__ */ protected static PyList __methods__; Modified: trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/PyExtendedCursor.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -27,22 +27,7 @@ * @version $Revision$ */ public class PyExtendedCursor extends PyCursor { - /** - * Field __class__ - */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } - - /** * Field __members__ */ protected static PyList __members__; Modified: trunk/jython/src/com/ziclix/python/sql/PyStatement.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyStatement.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/PyStatement.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -9,7 +9,6 @@ package com.ziclix.python.sql; import org.python.core.Py; -import org.python.core.PyClass; import org.python.core.PyException; import org.python.core.PyInteger; import org.python.core.PyList; @@ -90,20 +89,6 @@ } /** - * Field __class__ - */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } - - /** * Field __methods__ */ protected static PyList __methods__; Modified: trunk/jython/src/com/ziclix/python/sql/connect/Connect.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/connect/Connect.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/connect/Connect.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -117,20 +117,4 @@ public String toString() { return "<connect object instance at " + Py.id(this) + ">"; } - - // __class__ boilerplate -- see PyObject for details - - /** - * Field __class__ - */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } } Modified: trunk/jython/src/com/ziclix/python/sql/connect/Connectx.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/connect/Connectx.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/connect/Connectx.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -18,7 +18,6 @@ import javax.sql.DataSource; import org.python.core.Py; -import org.python.core.PyClass; import org.python.core.PyObject; import org.python.core.PyString; @@ -198,20 +197,4 @@ return method; } - - // __class__ boilerplate -- see PyObject for details - - /** - * Field __class__ - */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } } Modified: trunk/jython/src/com/ziclix/python/sql/connect/Lookup.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/connect/Lookup.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/connect/Lookup.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -147,20 +147,4 @@ public String toString() { return "<lookup object instance at " + Py.id(this) + ">"; } - - // __class__ boilerplate -- see PyObject for details - - /** - * Field __class__ - */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } } Modified: trunk/jython/src/com/ziclix/python/sql/util/BCP.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/util/BCP.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/util/BCP.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -66,24 +66,8 @@ this.batchsize = batchsize; this.queuesize = 0; } - - // __class__ boilerplate -- see PyObject for details - + /** - * Field __class__ - */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } - - /** * Field __methods__ */ protected static PyList __methods__; Modified: trunk/jython/src/com/ziclix/python/sql/zxJDBC.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/zxJDBC.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/com/ziclix/python/sql/zxJDBC.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -150,20 +150,6 @@ } /** - * Field __class__ - */ - public static PyClass __class__; - - /** - * Method getPyClass - * - * @return PyClass - */ - protected PyClass getPyClass() { - return __class__; - } - - /** * Add the types from java.sql.Types * * @param dict Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/org/python/core/Py.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -1280,7 +1280,6 @@ "a separate value"); } else { type = type.fastGetClass(); - //return new PyException(type.__class__, type); } } @@ -1647,7 +1646,7 @@ PyObject dict = code.call(Py.EmptyObjects, Py.NoKeywords, globals, Py.EmptyObjects, new PyTuple(closure_cells)); - if (doc != null) { + if (doc != null && dict.__finditem__("__doc__") == null) { dict.__setitem__("__doc__", doc); } Modified: trunk/jython/src/org/python/core/PyClass.java =================================================================== --- trunk/jython/src/org/python/core/PyClass.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/org/python/core/PyClass.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -300,15 +300,6 @@ } inst.__init__(args, keywords); - // xxx this cannot happen anymore - /* - * if (proxyClass != null && - * PyObject.class.isAssignableFrom(proxyClass)) { // It would be better - * if we didn't have to create a PyInstance // in the first place. - * ((PyObject)inst.javaProxy).__class__ = this; return - * (PyObject)inst.javaProxy; } - */ - return inst; } Modified: trunk/jython/src/org/python/core/PyJavaClass.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaClass.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/org/python/core/PyJavaClass.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -163,23 +163,6 @@ setMethods(proxyClass, methods); } catch(SecurityException se) {} } - - private synchronized void init__class__(Class c) { - /* xxx disable opt, will need similar opt for types - if (!PyObject.class.isAssignableFrom(c)) - return; - try { - Field field = c.getField("__class__"); - if (Modifier.isStatic(field.getModifiers()) && - field.getType().isAssignableFrom(PyJavaClass.class) && - field.getDeclaringClass() == c) - { - field.set(null, this); - } - } - catch (NoSuchFieldException exc) {} - catch (IllegalAccessException exc1) {} */ - } private synchronized void init__bases__(Class c) { if (__bases__ != null) return; @@ -225,7 +208,6 @@ private void init(Class c) { - init__class__(c); proxyClass = c; __name__ = c.getName(); } @@ -881,14 +863,6 @@ PyInstance inst = new PyJavaInstance(this); inst.__init__(args, keywords); - /*if (proxyClass != null && - PyObject.class.isAssignableFrom(proxyClass)) { - // It would be better if we didn't have to create a PyInstance - // in the first place. - ((PyObject)inst.javaProxy).__class__ = this; - return (PyObject)inst.javaProxy; - }*/ - return inst; } Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/org/python/core/PyObject.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -79,37 +79,13 @@ /** * The standard constructor for a <code>PyObject</code>. It will set - * the <code>__class__</code> field to correspond to the specific + * the <code>objtype</code> field to correspond to the specific * subclass of <code>PyObject</code> being instantiated. **/ public PyObject() { - // xxx for now no such caching - // PyClass c = getPyClass(); - // if (c == null) - // c = PyJavaClass.lookup(getClass()); objtype = PyType.fromClass(getClass()); } - /* xxx will be replaced. - * This method is provided to efficiently initialize the __class__ - * attribute. If the following boilerplate is added to a subclass of - * PyObject, the instantiation time for the object will be greatly - * reduced. - * - * <blockquote><pre> - * // __class__ boilerplate -- see PyObject for details - * public static PyClass __class__; - * protected PyClass getPyClass() { return __class__; } - * </pre></blockquote> - * - * With PyIntegers this leads to a 50% faster instantiation time. - * This replaces the PyObject(PyClass c) constructor which is now - * deprecated. - * - protected PyClass getPyClass() { - return null; - } */ - /** * Dispatch __init__ behavior */ @@ -766,16 +742,7 @@ * * @see #__findattr__(PyString) **/ - public PyObject __findattr__(String name) { // xxx accelerators/ expose - /*if (getType() == null) - return null; - if (name == "__class__") - return getType();*/ - /*PyObject ret = getType().lookup(name, false); - if (ret != null) - return ret._doget(this); - return null;*/ - + public PyObject __findattr__(String name) { return object___findattr__(name); } Modified: trunk/jython/src/org/python/core/PyReflectedFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedFunction.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/org/python/core/PyReflectedFunction.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -155,21 +155,6 @@ } } } - /* xxx this way it is slow! - Method super_method = null; - try { - super_method = cself.getClass().getMethod(mname,m.getParameterTypes()); - } catch(NoSuchMethodException e) { // ??? more stuff to ignore? - } - if (super_method != null) { - m = super_method; - }*/ - /* xxx original - PyJavaClass jc = PyJavaClass.lookup(iself.__class__.proxyClass); - PyObject super__ = jc.__findattr__(mname.intern()); - if (super__ != null) { - return super__.__call__(self, args, keywords); - }*/ } } try { Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-03-17 21:48:47 UTC (rev 4215) +++ trunk/jython/src/org/python/core/PyType.java 2008-03-17 22:17:05 UTC (rev 4216) @@ -898,28 +898,23 @@ String fldname = field.getName(); int fldmods = field.getModifiers(); Class fldtype = field.getType(); - if(Modifier.isStatic(fldmods)) { - // ignore static PyClass __class__ - if(fldname.equals("__class__") && fldtype == PyClass.class) { - continue; - } else if(fldname.startsWith("__doc__") - && fldname.length() > 7 + 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) { + if (memb != null && memb instanceof PyReflectedFunction) { PyString doc = null; try { doc = (PyString)field.get(null); - } catch(IllegalAccessException e) { + } catch (IllegalAccessException e) { throw error(e); } ((PyReflectedFunction)memb).__doc__ = doc; } } } - dict.__setitem__(normalize_name(fldname), - new PyReflectedField(field)); + dict.__setitem__(normalize_name(fldname), new PyReflectedField(field)); } } for(Iterator iter = propnames.keySet().iterator(); iter.hasNext();) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-04-15 00:07:45
|
Revision: 4345 http://jython.svn.sourceforge.net/jython/?rev=4345&view=rev Author: pjenvey Date: 2008-04-14 17:07:42 -0700 (Mon, 14 Apr 2008) Log Message: ----------- o automatically define toString() in derived classes (instead of including it from object.derived) but allow disabling of it. for PyString/UnicodeDerived; they need toString() to pass through instead of calling __repr__ as that breaks the expectation that PyString.toString() returns the real string this means PyObject.toString() from java code always returns __repr__ *except* for PyString/Unicode, which return the actual string (thanks Mehendran) o update the "should return a <type>" message in derived class descriptors to match CPython 2.5's o from the full gderived.py run: removed a useless constructor from PyUnicodeDerived and updated the collections derives' getattr/setattr to use interned strings Modified Paths: -------------- trunk/jython/src/org/python/core/PyArrayDerived.java trunk/jython/src/org/python/core/PyBooleanDerived.java trunk/jython/src/org/python/core/PyClassMethodDerived.java trunk/jython/src/org/python/core/PyComplexDerived.java trunk/jython/src/org/python/core/PyDictionaryDerived.java trunk/jython/src/org/python/core/PyFileDerived.java trunk/jython/src/org/python/core/PyFloatDerived.java trunk/jython/src/org/python/core/PyIntegerDerived.java trunk/jython/src/org/python/core/PyListDerived.java trunk/jython/src/org/python/core/PyLongDerived.java trunk/jython/src/org/python/core/PyModuleDerived.java trunk/jython/src/org/python/core/PyObjectDerived.java trunk/jython/src/org/python/core/PyPropertyDerived.java trunk/jython/src/org/python/core/PySliceDerived.java trunk/jython/src/org/python/core/PyStringDerived.java trunk/jython/src/org/python/core/PySuperDerived.java trunk/jython/src/org/python/core/PyTupleDerived.java trunk/jython/src/org/python/core/PyTypeDerived.java trunk/jython/src/org/python/core/PyUnicodeDerived.java trunk/jython/src/org/python/modules/collections/PyDefaultDictDerived.java trunk/jython/src/org/python/modules/collections/PyDequeDerived.java trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java trunk/jython/src/templates/gderived-defs trunk/jython/src/templates/gderived.py trunk/jython/src/templates/object.derived trunk/jython/src/templates/str.derived trunk/jython/src/templates/unicode.derived Modified: trunk/jython/src/org/python/core/PyArrayDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyArrayDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyArrayDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyBooleanDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyBooleanDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyBooleanDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyClassMethodDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyClassMethodDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyClassMethodDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyComplexDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyComplexDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyComplexDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyDictionaryDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionaryDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyDictionaryDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyFileDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyFileDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyFileDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyFloatDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyFloatDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyFloatDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyIntegerDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyIntegerDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyIntegerDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyListDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyListDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyListDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyLongDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyLongDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyLongDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyModuleDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyModuleDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyModuleDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -24,7 +24,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -36,7 +36,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -665,18 +665,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -927,4 +915,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyObjectDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyObjectDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyObjectDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PyPropertyDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyPropertyDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PyPropertyDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); } return super.__long__(); } @@ -120,7 +120,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyComplex) return(PyComplex)res; - throw Py.TypeError("__complex__"+" should return a "+"complex"); + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); } return super.__complex__(); } @@ -689,18 +689,6 @@ return super.__int__(); } - public String toString() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (!(res instanceof PyString)) - throw Py.TypeError("__repr__ should return a string"); - return((PyString)res).toString(); - } - return super.toString(); - } - public int hashCode() { PyType self_type=getType(); PyObject impl=self_type.lookup("__hash__"); @@ -951,4 +939,16 @@ } } + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + } Modified: trunk/jython/src/org/python/core/PySliceDerived.java =================================================================== --- trunk/jython/src/org/python/core/PySliceDerived.java 2008-04-14 14:59:19 UTC (rev 4344) +++ trunk/jython/src/org/python/core/PySliceDerived.java 2008-04-15 00:07:42 UTC (rev 4345) @@ -48,7 +48,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__str__"+" should return a "+"string"); + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); } @@ -60,7 +60,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__repr__"+" should return a "+"string"); + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__repr__(); } @@ -72,7 +72,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__hex__"+" should return a "+"string"); + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__hex__(); } @@ -84,7 +84,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; - throw Py.TypeError("__oct__"+" should return a "+"string"); + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__oct__(); } @@ -96,7 +96,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyFloat) return(PyFloat)res; - throw Py.TypeError("__float__"+" should return a "+"float"); + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); } return super.__float__(); } @@ -108,7 +108,7 @@ PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyLong) return(PyLong)res; - throw Py.TypeError("__long__"+" should return a "+"long"); + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "... [truncated message content] |
From: Samuele P. <ped...@op...> - 2008-04-17 07:07:56
|
pj...@us... wrote: > Revision: 4345 > http://jython.svn.sourceforge.net/jython/?rev=4345&view=rev > Author: pjenvey > Date: 2008-04-14 17:07:42 -0700 (Mon, 14 Apr 2008) > > Log Message: > ----------- > o automatically define toString() in derived classes (instead of including it > from object.derived) but allow disabling of it. for PyString/UnicodeDerived; > they need toString() to pass through instead of calling __repr__ as that breaks > the expectation that PyString.toString() returns the real string > > this means PyObject.toString() from java code always returns __repr__ *except* > for PyString/Unicode, which return the actual string > (thanks Mehendran) > wouldn't it make more sense for toString to correspond to __str__ and to __repr__ only if the first is not defined, notice that this would remove the need of special casing. Also I think __str__ is really the conceptual correspondent to toString, indeed both Python str.__str__ and java String.toString are nops. > o update the "should return a <type>" message in derived class descriptors to > match CPython 2.5's > o from the full gderived.py run: removed a useless constructor from > PyUnicodeDerived and updated the collections derives' getattr/setattr to use > interned strings > > Modified Paths: > -------------- > trunk/jython/src/org/python/core/PyArrayDerived.java > trunk/jython/src/org/python/core/PyBooleanDerived.java > trunk/jython/src/org/python/core/PyClassMethodDerived.java > trunk/jython/src/org/python/core/PyComplexDerived.java > trunk/jython/src/org/python/core/PyDictionaryDerived.java > trunk/jython/src/org/python/core/PyFileDerived.java > trunk/jython/src/org/python/core/PyFloatDerived.java > trunk/jython/src/org/python/core/PyIntegerDerived.java > trunk/jython/src/org/python/core/PyListDerived.java > trunk/jython/src/org/python/core/PyLongDerived.java > trunk/jython/src/org/python/core/PyModuleDerived.java > trunk/jython/src/org/python/core/PyObjectDerived.java > trunk/jython/src/org/python/core/PyPropertyDerived.java > trunk/jython/src/org/python/core/PySliceDerived.java > trunk/jython/src/org/python/core/PyStringDerived.java > trunk/jython/src/org/python/core/PySuperDerived.java > trunk/jython/src/org/python/core/PyTupleDerived.java > trunk/jython/src/org/python/core/PyTypeDerived.java > trunk/jython/src/org/python/core/PyUnicodeDerived.java > trunk/jython/src/org/python/modules/collections/PyDefaultDictDerived.java > trunk/jython/src/org/python/modules/collections/PyDequeDerived.java > trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java > trunk/jython/src/templates/gderived-defs > trunk/jython/src/templates/gderived.py > trunk/jython/src/templates/object.derived > trunk/jython/src/templates/str.derived > trunk/jython/src/templates/unicode.derived > > Modified: trunk/jython/src/org/python/core/PyArrayDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyArrayDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyArrayDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyBooleanDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyBooleanDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyBooleanDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyClassMethodDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyClassMethodDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyClassMethodDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyComplexDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyComplexDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyComplexDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyDictionaryDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyDictionaryDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyDictionaryDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyFileDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyFileDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyFileDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyFloatDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyFloatDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyFloatDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyIntegerDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyIntegerDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyIntegerDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyListDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyListDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyListDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyLongDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyLongDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyLongDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyModuleDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyModuleDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyModuleDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -24,7 +24,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -36,7 +36,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -665,18 +665,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -927,4 +915,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyObjectDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyObjectDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyObjectDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > } > } > > + public String toString() { > + PyType self_type=getType(); > + PyObject impl=self_type.lookup("__repr__"); > + if (impl!=null) { > + PyObject res=impl.__get__(this,self_type).__call__(); > + if (!(res instanceof PyString)) > + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); > + return((PyString)res).toString(); > + } > + return super.toString(); > + } > + > } > > Modified: trunk/jython/src/org/python/core/PyPropertyDerived.java > =================================================================== > --- trunk/jython/src/org/python/core/PyPropertyDerived.java 2008-04-14 14:59:19 UTC (rev 4344) > +++ trunk/jython/src/org/python/core/PyPropertyDerived.java 2008-04-15 00:07:42 UTC (rev 4345) > @@ -48,7 +48,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__str__"+" should return a "+"string"); > + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__str__(); > } > @@ -60,7 +60,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__repr__"+" should return a "+"string"); > + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__repr__(); > } > @@ -72,7 +72,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__hex__"+" should return a "+"string"); > + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__hex__(); > } > @@ -84,7 +84,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyString) > return(PyString)res; > - throw Py.TypeError("__oct__"+" should return a "+"string"); > + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); > } > return super.__oct__(); > } > @@ -96,7 +96,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyFloat) > return(PyFloat)res; > - throw Py.TypeError("__float__"+" should return a "+"float"); > + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); > } > return super.__float__(); > } > @@ -108,7 +108,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyLong) > return(PyLong)res; > - throw Py.TypeError("__long__"+" should return a "+"long"); > + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); > } > return super.__long__(); > } > @@ -120,7 +120,7 @@ > PyObject res=impl.__get__(this,self_type).__call__(); > if (res instanceof PyComplex) > return(PyComplex)res; > - throw Py.TypeError("__complex__"+" should return a "+"complex"); > + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); > } > return super.__complex__(); > } > @@ -689,18 +689,6 @@ > return super.__int__(); > } > > - public String toString() { > - PyType self_type=getType(); > - PyObject impl=self_type.lookup("__repr__"); > - if (impl!=null) { > - PyObject res=impl.__get__(this,self_type).__call__(); > - if (!(res instanceof PyString)) > - throw Py.TypeError("__repr__ should return a string"); > - return((PyString)res).toString(); > - } > - return super.toString(); > - } > - > public int hashCode() { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__hash__"); > @@ -951,4 +939,16 @@ > }... [truncated message content] |