From: <fwi...@us...> - 2008-10-27 13:19:34
|
Revision: 5517 http://jython.svn.sourceforge.net/jython/?rev=5517&view=rev Author: fwierzbicki Date: 2008-10-27 13:19:32 +0000 (Mon, 27 Oct 2008) Log Message: ----------- Fix for bug http://bugs.jython.org/issue1158, where the __builtin__ compile function does not recognize when it is passed an AST as the first argument. Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-10-27 03:09:47 UTC (rev 5516) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-10-27 13:19:32 UTC (rev 5517) @@ -274,7 +274,10 @@ if (args.length > 4) { dont_inherit = Py.py2boolean(args[4]); } - + modType ast = py2node(args[0]); + if (ast != null) { + return __builtin__.compile(ast, args[1].toString(), args[2].toString(), flags, dont_inherit); + } if (args[0] instanceof PyUnicode) { flags += PyTableCode.PyCF_SOURCE_IS_UTF8; } @@ -291,6 +294,21 @@ public PyObject getModule() { return module; } + + /** + * @returns modType if obj is a wrapper around an AST modType + * + * XXX: Reaches deep into implementation details -- needs to be reviewed if + * PyInstance is significantly changed. + */ + private static modType py2node(PyObject obj) { + if (obj != null && obj instanceof PyInstance && ((PyInstance)obj).javaProxy + instanceof modType) { + return (modType)((PyInstance)obj).javaProxy; + } + return null; + } + } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-10-27 14:54:43
|
Revision: 5518 http://jython.svn.sourceforge.net/jython/?rev=5518&view=rev Author: fwierzbicki Date: 2008-10-27 14:54:38 +0000 (Mon, 27 Oct 2008) Log Message: ----------- Simplifying the fix for http://bugs.jython.org/issue1158 based on the java integration changes in r5516. Mainly, javaProxy now lives directly in PyObject, so there is no need to check for a PyInstance first. Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-10-27 13:19:32 UTC (rev 5517) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-10-27 14:54:38 UTC (rev 5518) @@ -296,15 +296,15 @@ } /** - * @returns modType if obj is a wrapper around an AST modType + * @returns modType if obj is a wrapper around an AST modType else returns + * null * - * XXX: Reaches deep into implementation details -- needs to be reviewed if - * PyInstance is significantly changed. + * XXX: Reaches into implementation details -- needs to be reviewed if our + * java integration changes. */ private static modType py2node(PyObject obj) { - if (obj != null && obj instanceof PyInstance && ((PyInstance)obj).javaProxy - instanceof modType) { - return (modType)((PyInstance)obj).javaProxy; + if (obj != null && obj.javaProxy instanceof modType) { + return (modType)obj.javaProxy; } return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-10-27 21:15:27
|
Revision: 5522 http://jython.svn.sourceforge.net/jython/?rev=5522&view=rev Author: fwierzbicki Date: 2008-10-27 21:15:22 +0000 (Mon, 27 Oct 2008) Log Message: ----------- Another change to checking for AST as the first arg to __builtins__.compile(). Using the reasonably forward-compatible __tojava__ now instead of the more implementation dependent javaProxy field. Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-10-27 17:35:45 UTC (rev 5521) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-10-27 21:15:22 UTC (rev 5522) @@ -303,10 +303,11 @@ * java integration changes. */ private static modType py2node(PyObject obj) { - if (obj != null && obj.javaProxy instanceof modType) { - return (modType)obj.javaProxy; + Object node = obj.__tojava__(modType.class); + if (node == Py.NoConversion) { + return null; } - return null; + return (modType)node; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-05 07:21:05
|
Revision: 6297 http://jython.svn.sourceforge.net/jython/?rev=6297&view=rev Author: pjenvey Date: 2009-05-05 07:20:51 +0000 (Tue, 05 May 2009) Log Message: ----------- refactor filter{string,unicode} into filterBaseString Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2009-05-05 07:19:13 UTC (rev 6296) +++ trunk/jython/src/org/python/core/__builtin__.java 2009-05-05 07:20:51 UTC (rev 6297) @@ -548,13 +548,11 @@ public static PyObject filter(PyObject func, PyObject seq) { if (seq instanceof PyString) { - if (seq instanceof PyUnicode) { - return filterunicode(func, (PyUnicode)seq); - } - return filterstring(func, (PyString)seq); + return filterBaseString(func, (PyString)seq, + seq instanceof PyUnicode ? PyUnicode.TYPE : PyString.TYPE); } if (seq instanceof PyTuple) { - return filtertuple(func, (PyTuple)seq); + return filterTuple(func, (PyTuple)seq); } PyList list = new PyList(); @@ -571,8 +569,8 @@ return list; } - public static PyObject filterstring(PyObject func, PyString seq) { - if (func == Py.None && seq.getType() == PyString.TYPE) { + public static PyObject filterBaseString(PyObject func, PyBaseString seq, PyType stringType) { + if (func == Py.None && seq.getType() == stringType) { // If it's a real string we can return the original, as no character is ever // false and __getitem__ does return this character. If it's a subclass we // must go through the __getitem__ loop @@ -591,51 +589,24 @@ ok = true; } if (ok) { - if (!(item instanceof PyString) || item instanceof PyUnicode) { - throw Py.TypeError("can't filter str to str: __getitem__ returned different " - + "type"); + if (!Py.isInstance(item, stringType)) { + String name = stringType.fastGetName(); + throw Py.TypeError(String.format("can't filter %s to %s: __getitem__ returned " + + "different type", name, name)); } builder.append(item.toString()); } } - return new PyString(builder.toString()); - } - public static PyObject filterunicode(PyObject func, PyUnicode seq) { - if (func == Py.None && seq.getType() == PyUnicode.TYPE) { - // If it's a real string we can return the original, as no character is ever - // false and __getitem__ does return this character. If it's a subclass we - // must go through the __getitem__ loop - return seq; - } - - StringBuilder builder = new StringBuilder(); - boolean ok; - for (PyObject item : seq.asIterable()) { - ok = false; - if (func == Py.None) { - if (item.__nonzero__()) { - ok = true; - } - } else if (func.__call__(item).__nonzero__()) { - ok = true; - } - if (ok) { - if (!(item instanceof PyUnicode)) { - throw Py.TypeError("can't filter unicode to unicode: __getitem__ returned " - + "different type"); - } - builder.append(item.toString()); - } - } - return new PyUnicode(builder.toString()); + String result = builder.toString(); + return stringType == PyString.TYPE ? new PyString(result) : new PyUnicode(result); } - public static PyObject filtertuple(PyObject func, PyTuple seq) { - int len = seq.__len__(); + public static PyObject filterTuple(PyObject func, PyTuple seq) { + int len = seq.size(); if (len == 0) { if (seq.getType() != PyTuple.TYPE) { - seq = new PyTuple(); + return Py.EmptyTuple; } return seq; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-07-07 04:49:26
|
Revision: 6518 http://jython.svn.sourceforge.net/jython/?rev=6518&view=rev Author: pjenvey Date: 2009-07-07 04:49:12 +0000 (Tue, 07 Jul 2009) Log Message: ----------- unused method Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2009-07-07 03:41:42 UTC (rev 6517) +++ trunk/jython/src/org/python/core/__builtin__.java 2009-07-07 04:49:12 UTC (rev 6518) @@ -465,10 +465,6 @@ return x._divmod(y); } - public static PyEnumerate enumerate(PyObject seq) { - return new PyEnumerate(seq); - } - private static boolean PyMapping_check(PyObject o, boolean rw) { return o == null || o == Py.None || This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-07-11 22:38:53
|
Revision: 6528 http://jython.svn.sourceforge.net/jython/?rev=6528&view=rev Author: pjenvey Date: 2009-07-11 22:38:33 +0000 (Sat, 11 Jul 2009) Log Message: ----------- small refactor Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2009-07-11 06:47:49 UTC (rev 6527) +++ trunk/jython/src/org/python/core/__builtin__.java 2009-07-11 22:38:33 UTC (rev 6528) @@ -21,6 +21,7 @@ super(name, index, minargs, maxargs); } + @Override public PyObject __call__() { switch (this.index) { case 4: @@ -42,6 +43,7 @@ } } + @Override public PyObject __call__(PyObject arg1) { switch (this.index) { case 0: @@ -121,6 +123,7 @@ } } + @Override public PyObject __call__(PyObject arg1, PyObject arg2) { switch (this.index) { case 2: @@ -176,6 +179,7 @@ } } + @Override public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { switch (this.index) { case 2: @@ -244,6 +248,7 @@ } } + @Override public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4) { switch (this.index) { case 44: @@ -261,6 +266,7 @@ } } + @Override public PyObject fancyCall(PyObject[] args) { switch (this.index) { case 29: @@ -272,6 +278,7 @@ } } + @Override public PyObject getModule() { return module; } @@ -574,24 +581,20 @@ } StringBuilder builder = new StringBuilder(); - boolean ok; for (PyObject item : seq.asIterable()) { - ok = false; if (func == Py.None) { - if (item.__nonzero__()) { - ok = true; + if (!item.__nonzero__()) { + continue; } - } else if (func.__call__(item).__nonzero__()) { - ok = true; + } else if (!func.__call__(item).__nonzero__()) { + continue; } - if (ok) { - if (!Py.isInstance(item, stringType)) { - String name = stringType.fastGetName(); - throw Py.TypeError(String.format("can't filter %s to %s: __getitem__ returned " - + "different type", name, name)); - } - builder.append(item.toString()); + if (!Py.isInstance(item, stringType)) { + String name = stringType.fastGetName(); + throw Py.TypeError(String.format("can't filter %s to %s: __getitem__ returned " + + "different type", name, name)); } + builder.append(item.toString()); } String result = builder.toString(); @@ -609,20 +612,16 @@ PyList list = new PyList(); PyObject item; - boolean ok; for (int i = 0; i < len; i++) { - ok = false; item = seq.__finditem__(i); if (func == Py.None) { - if (item.__nonzero__()) { - ok = true; + if (!item.__nonzero__()) { + continue; } - } else if (func.__call__(item).__nonzero__()) { - ok = true; + } else if (!func.__call__(item).__nonzero__()) { + continue; } - if (ok) { - list.append(item); - } + list.append(item); } return PyTuple.fromIterable(list); } @@ -1221,6 +1220,7 @@ "is the number of parent directories to search relative to the current module."); } + @Override public PyObject __call__(PyObject args[], String keywords[]) { ArgParser ap = new ArgParser("__import__", args, keywords, new String[]{"name", "globals", "locals", "fromlist", "level"}, @@ -1436,6 +1436,7 @@ "This always returns a floating point number. Precision may be negative."); } + @Override public PyObject __call__(PyObject args[], String kwds[]) { ArgParser ap = new ArgParser("round", args, kwds, new String[] {"number", "ndigits"}, 0); PyObject number = ap.getPyObject(0); @@ -1474,6 +1475,7 @@ + "in addition to any features explicitly specified."); } + @Override public PyObject __call__(PyObject args[], String kwds[]) { ArgParser ap = new ArgParser("compile", args, kwds, new String[] {"source", "filename", "mode", "flags", @@ -1556,6 +1558,7 @@ "Passing an Input/OutputStream to open is deprecated, use " + "org.python.core.util.FileUtil.wrap(stream[, bufsize]) instead."; + @Override public PyObject __call__(PyObject args[], String kwds[]) { ArgParser ap = new ArgParser("file", args, kwds, new String[] {"name", "mode", "bufsize"}, 1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-27 02:54:29
|
Revision: 6910 http://jython.svn.sourceforge.net/jython/?rev=6910&view=rev Author: pjenvey Date: 2009-10-27 02:54:10 +0000 (Tue, 27 Oct 2009) Log Message: ----------- speedup get/hasattr, use __findattr__ and intern the PyString itself, that way we don't have to do it again later if called with the same string Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2009-10-26 21:15:12 UTC (rev 6909) +++ trunk/jython/src/org/python/core/__builtin__.java 2009-10-27 02:54:10 UTC (rev 6910) @@ -633,24 +633,23 @@ public static PyObject getattr(PyObject obj, PyObject name, PyObject def) { String nameStr; if (name instanceof PyUnicode) { - nameStr = ((PyUnicode)name).encode(); + nameStr = ((PyUnicode)name).encode().intern(); } else if (name instanceof PyString) { - nameStr = name.asString(); + nameStr = ((PyString)name).internedString(); } else { throw Py.TypeError("getattr(): attribute name must be string"); } - PyObject result; - try { - result = obj.__getattr__(nameStr.intern()); - } catch (PyException pye) { - if (pye.match(Py.AttributeError) && def != null) { - result = def; - } else { - throw pye; - } + PyObject result = obj.__findattr__(nameStr.intern()); + if (result != null) { + return result; } - return result; + if (def != null) { + return def; + } + // throws AttributeError + obj.noAttributeError(nameStr); + return null; } public static PyObject globals() { @@ -662,13 +661,13 @@ if (name instanceof PyUnicode) { nameStr = ((PyUnicode)name).encode().intern(); } else if (name instanceof PyString) { - nameStr = name.asString(); + nameStr = ((PyString)name).internedString(); } else { throw Py.TypeError("hasattr(): attribute name must be string"); } try { - return obj.__findattr__(nameStr.intern()) != null; + return obj.__findattr__(nameStr) != null; } catch (PyException pye) { // swallow } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-27 02:56:47
|
Revision: 6911 http://jython.svn.sourceforge.net/jython/?rev=6911&view=rev Author: pjenvey Date: 2009-10-27 02:56:41 +0000 (Tue, 27 Oct 2009) Log Message: ----------- er, don't intern twice Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2009-10-27 02:54:10 UTC (rev 6910) +++ trunk/jython/src/org/python/core/__builtin__.java 2009-10-27 02:56:41 UTC (rev 6911) @@ -640,7 +640,7 @@ throw Py.TypeError("getattr(): attribute name must be string"); } - PyObject result = obj.__findattr__(nameStr.intern()); + PyObject result = obj.__findattr__(nameStr); if (result != null) { return result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-27 22:09:34
|
Revision: 6916 http://jython.svn.sourceforge.net/jython/?rev=6916&view=rev Author: pjenvey Date: 2009-10-27 22:09:16 +0000 (Tue, 27 Oct 2009) Log Message: ----------- coding standards/cleanup, avoid a potential ClassCastException in apply Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2009-10-27 21:30:30 UTC (rev 6915) +++ trunk/jython/src/org/python/core/__builtin__.java 2009-10-27 22:09:16 UTC (rev 6916) @@ -1,6 +1,12 @@ -// Copyright (c) Corporation for National Research Initiatives +/* + * Copyright (c) Corporation for National Research Initiatives + * Copyright (c) Jython Developers + */ package org.python.core; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Iterator; @@ -47,20 +53,24 @@ public PyObject __call__(PyObject arg1) { switch (this.index) { case 0: - return Py.newString(__builtin__.chr(Py.py2int(arg1, "chr(): 1st arg can't be coerced to int"))); + return Py.newString(__builtin__.chr(Py.py2int(arg1, + "chr(): 1st arg can't be coerced to " + + "int"))); case 1: return Py.newInteger(__builtin__.len(arg1)); case 2: return __builtin__.range(arg1); case 3: if (!(arg1 instanceof PyString)) { - throw Py.TypeError("ord() expected string of length 1, but " + arg1.getType().fastGetName() + " found"); + throw Py.TypeError("ord() expected string of length 1, but " + + arg1.getType().fastGetName() + " found"); } return Py.newInteger(__builtin__.ord(arg1)); case 5: return __builtin__.hash(arg1); case 6: - return Py.newUnicode(__builtin__.unichr(Py.py2int(arg1, "unichr(): 1st arg can't be coerced to int"))); + return Py.newUnicode(__builtin__.unichr(Py.py2int(arg1, "unichr(): 1st arg can't " + + "be coerced to int"))); case 7: return __builtin__.abs(arg1); case 9: @@ -111,11 +121,11 @@ case 41: return __builtin__.vars(arg1); case 30: - return fancyCall(new PyObject[]{arg1}); + return fancyCall(new PyObject[] {arg1}); case 31: - return fancyCall(new PyObject[]{arg1}); + return fancyCall(new PyObject[] {arg1}); case 43: - return fancyCall(new PyObject[]{arg1}); + return fancyCall(new PyObject[] {arg1}); case 45: return __builtin__.reversed(arg1); default: @@ -139,7 +149,8 @@ case 13: return __builtin__.coerce(arg1, arg2); case 15: - __builtin__.delattr(arg1, asString(arg2, "delattr(): attribute name must be string")); + __builtin__.delattr(arg1, asString(arg2, + "delattr(): attribute name must be string")); return Py.None; case 17: return __builtin__.divmod(arg1, arg2); @@ -167,13 +178,13 @@ case 35: return __builtin__.reduce(arg1, arg2); case 29: - return fancyCall(new PyObject[]{arg1, arg2}); + return fancyCall(new PyObject[] {arg1, arg2}); case 30: - return fancyCall(new PyObject[]{arg1, arg2}); + return fancyCall(new PyObject[] {arg1, arg2}); case 31: - return fancyCall(new PyObject[]{arg1, arg2}); + return fancyCall(new PyObject[] {arg1, arg2}); case 43: - return fancyCall(new PyObject[]{arg1, arg2}); + return fancyCall(new PyObject[] {arg1, arg2}); default: throw info.unexpectedCall(2, false); } @@ -197,12 +208,14 @@ PyDictionary d = (PyDictionary) arg3; return __builtin__.apply(arg1, arg2, d); } catch (ClassCastException e) { - throw Py.TypeError("apply() 3rd argument must be a " + "dictionary with string keys"); + throw Py.TypeError("apply() 3rd argument must be a " + + "dictionary with string keys"); } case 18: return __builtin__.eval(arg1, arg2, arg3); case 19: - __builtin__.execfile(asString(arg1, "execfile's first argument must be str", false), arg2, arg3); + __builtin__.execfile(asString(arg1, "execfile's first argument must be str", + false), arg2, arg3); return Py.None; case 21: return __builtin__.getattr(arg1, arg2, arg3); @@ -211,25 +224,28 @@ case 35: return __builtin__.reduce(arg1, arg2, arg3); case 39: - __builtin__.setattr(arg1, asString(arg2, "setattr(): attribute name must be string"), arg3); + __builtin__.setattr(arg1, asString(arg2, + "setattr(): attribute name must be string"), + arg3); return Py.None; case 44: - return fancyCall(new PyObject[]{arg1, arg2, arg3}); + return fancyCall(new PyObject[] {arg1, arg2, arg3}); case 29: - return fancyCall(new PyObject[]{arg1, arg2, arg3}); + return fancyCall(new PyObject[] {arg1, arg2, arg3}); case 30: - return fancyCall(new PyObject[]{arg1, arg2, arg3}); + return fancyCall(new PyObject[] {arg1, arg2, arg3}); case 31: - return fancyCall(new PyObject[]{arg1, arg2, arg3}); + return fancyCall(new PyObject[] {arg1, arg2, arg3}); case 43: - return fancyCall(new PyObject[]{arg1, arg2, arg3}); + return fancyCall(new PyObject[] {arg1, arg2, arg3}); default: throw info.unexpectedCall(3, false); } } /** - * @return arg as an interned String, or throws TypeError with mesage if asString throws a ConversionException + * @return arg as an interned String, or throws TypeError with mesage if asString + * throws a ConversionException */ private String asString(PyObject arg, String message) { return asString(arg, message, true); @@ -237,7 +253,8 @@ /** * @param intern - should the resulting string be interned - * @return arg as a String, or throws TypeError with message if asString throws a ConversionException. + * @return arg as a String, or throws TypeError with message if asString throws a + * ConversionException. */ private String asString(PyObject arg, String message, boolean intern) { @@ -252,15 +269,15 @@ public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4) { switch (this.index) { case 44: - return fancyCall(new PyObject[]{arg1, arg2, arg3, arg4}); + return fancyCall(new PyObject[] {arg1, arg2, arg3, arg4}); case 29: - return fancyCall(new PyObject[]{arg1, arg2, arg3, arg4}); + return fancyCall(new PyObject[] {arg1, arg2, arg3, arg4}); case 30: - return fancyCall(new PyObject[]{arg1, arg2, arg3, arg4}); + return fancyCall(new PyObject[] {arg1, arg2, arg3, arg4}); case 31: - return fancyCall(new PyObject[]{arg1, arg2, arg3, arg4}); + return fancyCall(new PyObject[] {arg1, arg2, arg3, arg4}); case 43: - return fancyCall(new PyObject[]{arg1, arg2, arg3, arg4}); + return fancyCall(new PyObject[] {arg1, arg2, arg3, arg4}); default: throw info.unexpectedCall(4, false); } @@ -289,6 +306,8 @@ */ public class __builtin__ { + private static final PyStringMap internedStrings = new PyStringMap(); + public static void fillWithBuiltins(PyObject dict) { /* newstyle */ dict.__setitem__("object", PyObject.TYPE); @@ -304,7 +323,6 @@ dict.__setitem__("tuple", PyTuple.TYPE); dict.__setitem__("set", PySet.TYPE); dict.__setitem__("frozenset", PyFrozenSet.TYPE); - dict.__setitem__("property", PyProperty.TYPE); dict.__setitem__("staticmethod", PyStaticMethod.TYPE); dict.__setitem__("classmethod", PyClassMethod.TYPE); @@ -316,8 +334,6 @@ dict.__setitem__("slice", PySlice.TYPE); dict.__setitem__("xrange", PyXRange.TYPE); - /* - */ - dict.__setitem__("None", Py.None); dict.__setitem__("NotImplemented", Py.NotImplemented); dict.__setitem__("Ellipsis", Py.Ellipsis); @@ -394,10 +410,10 @@ public static PyObject apply(PyObject o, PyObject args, PyDictionary kws) { PyObject[] a; String[] kw; - Map table = kws.table; + Map<PyObject, PyObject> table = kws.table; if (table.size() > 0) { - Iterator ik = table.keySet().iterator(); - Iterator iv = table.values().iterator(); + Iterator<PyObject> ik = table.keySet().iterator(); + Iterator<PyObject> iv = table.values().iterator(); int n = table.size(); kw = new String[n]; PyObject[] aargs = Py.make_array(args); @@ -406,8 +422,12 @@ int offset = aargs.length; for (int i = 0; i < n; i++) { - kw[i] = ((PyString) ik.next()).internedString(); - a[i + offset] = (PyObject) iv.next(); + PyObject name = ik.next(); + if (name.getClass() != PyString.class) { + throw Py.TypeError(String.format("keywords must be strings")); + } + kw[i] = ((PyString)name).internedString(); + a[i + offset] = iv.next(); } return o.__call__(a, kw); } else { @@ -462,7 +482,8 @@ try { ret = (PyList) retObj; } catch (ClassCastException e) { - throw Py.TypeError("Expected keys() to be a list, not '" + retObj.getType().fastGetName() + "'"); + throw Py.TypeError(String.format("Expected keys() to be a list, not '%s'", + retObj.getType().fastGetName())); } ret.sort(); return ret; @@ -519,12 +540,13 @@ execfile_flags(name, globals, locals, Py.getCompilerFlags()); } - public static void execfile_flags(String name, PyObject globals, PyObject locals, CompilerFlags cflags) { + public static void execfile_flags(String name, PyObject globals, PyObject locals, + CompilerFlags cflags) { verify_mappings(globals, locals, true); - java.io.FileInputStream file; + FileInputStream file; try { - file = new java.io.FileInputStream(new RelativeFile(name)); - } catch (java.io.FileNotFoundException e) { + file = new FileInputStream(new RelativeFile(name)); + } catch (FileNotFoundException e) { throw Py.IOError(e); } PyCode code; @@ -534,7 +556,7 @@ } finally { try { file.close(); - } catch (java.io.IOException e) { + } catch (IOException e) { throw Py.IOError(e); } } @@ -694,7 +716,6 @@ public static PyObject input() { return input(new PyString("")); } - private static final PyStringMap internedStrings = new PyStringMap(); public static PyString intern(PyObject obj) { if (!(obj instanceof PyString) || obj instanceof PyUnicode) { @@ -705,11 +726,6 @@ throw Py.TypeError("can't intern subclass of string"); } PyString s = (PyString)obj; - - // XXX: for some reason, not seeing this as an instance of PyStringDerived when derived - if (s instanceof PyStringDerived) { - throw Py.TypeError("can't intern subclass of string"); - } String istring = s.internedString(); PyObject ret = internedStrings.__finditem__(istring); if (ret != null) { @@ -773,7 +789,8 @@ PyObject[] iters = new PyObject[n]; for (int j = 0; j < n; j++) { - iters[j] = Py.iter(argstar[j + 1], "argument " + (j + 1) + " to map() must support iteration"); + iters[j] = Py.iter(argstar[j + 1], "argument " + (j + 1) + + " to map() must support iteration"); } while (true) { @@ -821,7 +838,7 @@ } } throw Py.TypeError("ord() expected a character, but string of length " + - length + " found"); + length + " found"); } public static PyObject pow(PyObject x, PyObject y) { @@ -1068,7 +1085,7 @@ } public static PyObject reload(PySystemState o) { - // reinitialize methods + // reinitialize methods o.reload(); return o; } @@ -1123,7 +1140,11 @@ } } - public static PyString __doc__zip = new PyString("zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]\n" + "\n" + "Return a list of tuples, where each tuple contains the i-th element\n" + "from each of the argument sequences. The returned list is\n" + "truncated in length to the length of the shortest argument sequence."); + public static PyString __doc__zip = new PyString( + "zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]\n\n" + + "Return a list of tuples, where each tuple contains the i-th element\n" + + "from each of the argument sequences. The returned list is\n" + + "truncated in length to the length of the shortest argument sequence."); public static PyObject zip() { return new PyList(); @@ -1180,11 +1201,13 @@ return __import__(name, globals, locals, null, imp.DEFAULT_LEVEL); } - public static PyObject __import__(String name, PyObject globals, PyObject locals, PyObject fromlist) { + public static PyObject __import__(String name, PyObject globals, PyObject locals, + PyObject fromlist) { return __import__(name, globals, locals, fromlist, imp.DEFAULT_LEVEL); } - public static PyObject __import__(String name, PyObject globals, PyObject locals, PyObject fromlist, int level) { + public static PyObject __import__(String name, PyObject globals, PyObject locals, + PyObject fromlist, int level) { PyFrame frame = Py.getFrame(); PyObject builtins; if (frame != null && frame.f_builtins != null) { @@ -1198,7 +1221,8 @@ return null; } - PyObject module = __import__.__call__(new PyObject[]{Py.newString(name), globals, locals, fromlist, Py.newInteger(level)}); + PyObject module = __import__.__call__(new PyObject[] {Py.newString(name), globals, locals, + fromlist, Py.newInteger(level)}); return module; } } @@ -1222,14 +1246,15 @@ @Override public PyObject __call__(PyObject args[], String keywords[]) { ArgParser ap = new ArgParser("__import__", args, keywords, - new String[]{"name", "globals", "locals", "fromlist", "level"}, + new String[] {"name", "globals", "locals", "fromlist", + "level"}, 1); String module = ap.getString(0); PyObject globals = ap.getPyObject(1, null); PyObject fromlist = ap.getPyObject(3, Py.EmptyTuple); int level = ap.getInt(4, imp.DEFAULT_LEVEL); return imp.importName(module.intern(), fromlist == Py.None || fromlist.__len__() == 0, - globals, fromlist, level); + globals, fromlist, level); } } @@ -1241,13 +1266,15 @@ @Override public PyObject __call__(PyObject args[], String kwds[]) { if (args.length == 0) { - throw Py.TypeError(" sorted() takes at least 1 argument (0 given)"); + throw Py.TypeError("sorted() takes at least 1 argument (0 given)"); } else if (args.length > 4) { - throw Py.TypeError(" sorted() takes at most 4 arguments (" + args.length + " given)"); + throw Py.TypeError(String.format("sorted() takes at most 4 arguments (%s given)", + args.length)); } else { PyObject iter = args[0].__iter__(); if (iter == null) { - throw Py.TypeError("'" + args[0].getType().fastGetName() + "' object is not iterable"); + throw Py.TypeError(String.format("'%s' object is not iterable", + args[0].getType().fastGetName())); } } @@ -1255,8 +1282,8 @@ PyObject newargs[] = new PyObject[args.length - 1]; System.arraycopy(args, 1, newargs, 0, args.length - 1); - ArgParser ap = new ArgParser("sorted", newargs, kwds, new String[]{"cmp", "key", "reverse"}, 0); - + ArgParser ap = new ArgParser("sorted", newargs, kwds, + new String[] {"cmp", "key", "reverse"}, 0); PyObject cmp = ap.getPyObject(0, Py.None); PyObject key = ap.getPyObject(1, Py.None); PyObject reverse = ap.getPyObject(2, Py.None); @@ -1291,7 +1318,8 @@ class AnyFunction extends PyBuiltinFunctionNarrow { AnyFunction() { super("any", 1, 1, - "any(iterable) -> bool\n\nReturn True if bool(x) is True for any x in the iterable."); + "any(iterable) -> bool\n\n" + + "Return True if bool(x) is True for any x in the iterable."); } @Override @@ -1312,7 +1340,8 @@ class MaxFunction extends PyBuiltinFunction { MaxFunction() { super("max", - "max(iterable[, key=func]) -> value\nmax(a, b, c, ...[, key=func]) -> value\n\n" + + "max(iterable[, key=func]) -> value\n" + + "max(a, b, c, ...[, key=func]) -> value\n\n" + "With a single iterable argument, return its largest item.\n" + "With two or more arguments, return the largest argument."); } @@ -1331,16 +1360,14 @@ PyObject newargs[] = new PyObject[argslen - 1]; System.arraycopy(args, 0, newargs, 0, argslen - 1); args = newargs; - } - else { + } else { throw Py.TypeError("max() got an unexpected keyword argument"); } } if (args.length > 1) { return max(new PyTuple(args), key); - } - else { + } else { return max(args[0], key); } } @@ -1352,8 +1379,7 @@ PyObject itemKey; if (key == null) { itemKey = item; - } - else { + } else { itemKey = key.__call__(item); } if (maxKey == null || itemKey._gt(maxKey).__nonzero__()) { @@ -1372,7 +1398,8 @@ class MinFunction extends PyBuiltinFunction { MinFunction() { super("min", - "min(iterable[, key=func]) -> value\nmin(a, b, c, ...[, key=func]) -> value\n\n" + + "min(iterable[, key=func]) -> value\n" + + "min(a, b, c, ...[, key=func]) -> value\n\n" + "With a single iterable argument, return its smallest item.\n" + "With two or more arguments, return the smallest argument.'"); } @@ -1383,7 +1410,7 @@ PyObject key = null; if (args.length - kwds.length == 0) { - throw Py.TypeError(" min() expected 1 arguments, got 0"); + throw Py.TypeError("min() expected 1 arguments, got 0"); } if (kwds.length > 0) { if (kwds[0].equals("key")) { @@ -1391,16 +1418,14 @@ PyObject newargs[] = new PyObject[argslen - 1]; System.arraycopy(args, 0, newargs, 0, argslen - 1); args = newargs; - } - else { + } else { throw Py.TypeError("min() got an unexpected keyword argument"); } } if (args.length > 1) { return min(new PyTuple(args), key); - } - else { + } else { return min(args[0], key); } } @@ -1412,8 +1437,7 @@ PyObject itemKey; if (key == null) { itemKey = item; - } - else { + } else { itemKey = key.__call__(item); } if (minKey == null || itemKey._lt(minKey).__nonzero__()) { @@ -1500,19 +1524,19 @@ return compile(source, filename, kind, cflags, dont_inherit); } - public static PyObject compile(PyObject source, String filename, CompileMode kind, CompilerFlags cflags, - boolean dont_inherit) { + public static PyObject compile(PyObject source, String filename, CompileMode kind, + CompilerFlags cflags, boolean dont_inherit) { cflags = Py.getCompilerFlags(cflags, dont_inherit); - + mod ast = py2node(source); if (ast == null) { if (!(source instanceof PyString)) { throw Py.TypeError("expected a readable buffer object"); } cflags.source_is_utf8 = source instanceof PyUnicode; - + String data = source.toString(); - + if (data.contains("\0")) { throw Py.TypeError("compile() expected string without null bytes"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-18 21:45:57
|
Revision: 7041 http://jython.svn.sourceforge.net/jython/?rev=7041&view=rev Author: pjenvey Date: 2010-04-18 21:45:51 +0000 (Sun, 18 Apr 2010) Log Message: ----------- this doesn't need to grab the javaProxy field directly Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2010-04-18 18:06:07 UTC (rev 7040) +++ trunk/jython/src/org/python/core/__builtin__.java 2010-04-18 21:45:51 UTC (rev 7041) @@ -1544,12 +1544,13 @@ PyObject obj = ap.getPyObject(0); if (obj.getJavaProxy() != null) { int bufsize = ap.getInt(2, -1); - if (obj.javaProxy instanceof InputStream) { + Object javaProxy = obj.getJavaProxy(); + if (javaProxy instanceof InputStream) { Py.warning(Py.DeprecationWarning, warning); - return new PyFile((InputStream)obj.javaProxy, bufsize); - } else if (obj.javaProxy instanceof OutputStream) { + return new PyFile((InputStream) javaProxy, bufsize); + } else if (javaProxy instanceof OutputStream) { Py.warning(Py.DeprecationWarning, warning); - return new PyFile((OutputStream)obj.javaProxy, bufsize); + return new PyFile((OutputStream) javaProxy, bufsize); } } return PyFile.TYPE.__call__(args, kwds); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |