From: <cg...@us...> - 2007-12-30 23:01:22
|
Revision: 3914 http://jython.svn.sourceforge.net/jython/?rev=3914&view=rev Author: cgroves Date: 2007-12-30 15:01:18 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Merged revisions 3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3862,3864,3866,3871-3875,3879,3881,3883-3885,3890,3892,3895-3896,3898-3900,3904,3912-3913 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r3742 | cgroves | 2007-11-30 12:53:42 -0800 (Fri, 30 Nov 2007) | 1 line Applying patch #1814683 from markacy to fix bugs #1796425, 1796415 and 1814678 ........ r3743 | cgroves | 2007-11-30 13:21:59 -0800 (Fri, 30 Nov 2007) | 1 line Check that f_back isn't null when throwing an exception in case it's rethrown. Fixes bug #1812122 ........ r3751 | cgroves | 2007-12-02 00:36:39 -0800 (Sun, 02 Dec 2007) | 1 line patch #1830916 from byronf to attach the initially thrown Java exception to PyException so the exception chain isn't broken ........ r3753 | cgroves | 2007-12-02 11:20:58 -0800 (Sun, 02 Dec 2007) | 1 line Fix for bug #1816134 from boisgerault. Remove equals from PyString to allow PyObject's equals to be used which respects Python's __eq__ semantics. PyString's implementation was just a little optimization which actually didn't do much: it checked for interned which String.equals does already. See the added test case for the brokeness this was causing. Also have PySequenceList.equals call PyObject.equals, but leave it overriding so it can handle equality with Java List types. ........ r3754 | cgroves | 2007-12-02 12:13:08 -0800 (Sun, 02 Dec 2007) | 1 line Fix for bug #1839871. CPython's dict uses an internal setitem method to initialize itself rather than __setitem__ which can go through to its subclasses. Now Jython does as well. ........ r3755 | cgroves | 2007-12-02 14:03:30 -0800 (Sun, 02 Dec 2007) | 7 lines Fix for bug #1841445. PythonInterpreter.get(String name) would return the local value of name or null if it wasn't bound. PythonInterpreter.get(String name, Class javaclass) would return the local value as an instance of the given javaclass or throw a NullPointerException if it wasn't bound. Now the second form returns null as well when the name isn't bound. ........ r3913 | cgroves | 2007-12-30 14:54:48 -0800 (Sun, 30 Dec 2007) | 1 line Added everything I'm about to pull over to Release_2_2maint ........ Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/javaos.py branches/Release_2_2maint/jython/NEWS branches/Release_2_2maint/jython/src/org/python/core/Py.java branches/Release_2_2maint/jython/src/org/python/core/PyDictionary.java branches/Release_2_2maint/jython/src/org/python/core/PyObject.java branches/Release_2_2maint/jython/src/org/python/core/PySequenceList.java branches/Release_2_2maint/jython/src/org/python/core/PyString.java branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java Added Paths: ----------- branches/Release_2_2maint/jython/Lib/test/test_dict_jy.py branches/Release_2_2maint/jython/Lib/test/test_str_jy.py Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3745,3747-3748,3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3882,3891 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913 Modified: branches/Release_2_2maint/jython/Lib/javaos.py =================================================================== --- branches/Release_2_2maint/jython/Lib/javaos.py 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/Lib/javaos.py 2007-12-30 23:01:18 UTC (rev 3914) @@ -20,11 +20,11 @@ (e.g., split and join). """ -__all__ = ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep", - "defpath", "name", - "system", "environ", "putenv", "getenv", - "popen", "popen2", "popen3", "popen4", "getlogin" - ] +__all__ = ["altsep", "chdir", "curdir", "defpath", "environ", "getcwd", + "getenv", "getlogin", "linesep", "listdir", "mkdir", "name", + "pardir", "pathsep", "popen", "popen2", "popen3", "popen4", + "putenv","remove", "rename", "rmdir", "sep", "stat", "system", + "unlink", "utime"] from java.io import File import java.lang.System @@ -165,6 +165,8 @@ if not File(path).delete(): raise OSError(0, "couldn't delete file", path) +unlink = remove + def rename(path, newpath): """rename(old, new) @@ -173,6 +175,33 @@ if not File(path).renameTo(File(newpath)): raise OSError(0, "couldn't rename file", path) +#XXX: copied from CPython 2.5.1 +def renames(old, new): + """renames(old, new) + + Super-rename; create directories as necessary and delete any left + empty. Works like rename, except creation of any intermediate + directories needed to make the new pathname good is attempted + first. After the rename, directories corresponding to rightmost + path segments of the old name will be pruned way until either the + whole path is consumed or a nonempty directory is found. + + Note: this function can fail with the new directory structure made + if you lack permissions needed to unlink the leaf directory or + file. + + """ + head, tail = path.split(new) + if head and tail and not path.exists(head): + makedirs(head) + rename(old, new) + head, tail = path.split(old) + if head and tail: + try: + removedirs(head) + except error: + pass + def rmdir(path): """rmdir(path) @@ -180,8 +209,31 @@ if not File(path).delete(): raise OSError(0, "couldn't delete directory", path) -unlink = remove +#XXX: copied from CPython 2.5.1 +def removedirs(name): + """removedirs(path) + Super-rmdir; remove a leaf directory and empty all intermediate + ones. Works like rmdir except that, if the leaf directory is + successfully removed, directories corresponding to rightmost path + segments will be pruned away until either the whole path is + consumed or an error occurs. Errors during this latter phase are + ignored -- they generally mean that a directory was not empty. + + """ + rmdir(name) + head, tail = path.split(name) + if not tail: + head, tail = path.split(head) + while head and tail: + try: + rmdir(head) + except error: + break + head, tail = path.split(head) + +__all__.extend(['makedirs', 'renames', 'removedirs']) + def stat(path): """stat(path) -> stat result Copied: branches/Release_2_2maint/jython/Lib/test/test_dict_jy.py (from rev 3755, trunk/jython/Lib/test/test_dict_jy.py) =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_dict_jy.py (rev 0) +++ branches/Release_2_2maint/jython/Lib/test/test_dict_jy.py 2007-12-30 23:01:18 UTC (rev 3914) @@ -0,0 +1,30 @@ +import test_support +import unittest + +class DictInitTest(unittest.TestCase): + def testInternalSetitemInInit(self): + '''Test for http://jython.org/bugs/1816134 + + CPython's dict uses an internal setitem method to initialize itself + rather than the one on its subclasses, and this tests that Jython does + as well. + ''' + class Subdict(dict): + def __init__(self): + super(Subdict, self).__init__([('a',1)]) + self.createdInInit = 1 + + def __setitem__(self, key, value): + super(Subdict, self).__setitem__(key, value) + assert hasattr(self, 'createdInInit') + self.createdInInit = value + + s = Subdict() + s[7] = 'called' + self.assertEquals('called', s.createdInInit) + +def test_main(): + test_support.run_unittest(DictInitTest) + +if __name__ == '__main__': + test_main() Copied: branches/Release_2_2maint/jython/Lib/test/test_str_jy.py (from rev 3755, trunk/jython/Lib/test/test_str_jy.py) =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_str_jy.py (rev 0) +++ branches/Release_2_2maint/jython/Lib/test/test_str_jy.py 2007-12-30 23:01:18 UTC (rev 3914) @@ -0,0 +1,28 @@ +import test_support +import unittest + +class WrappedStrCmpTest(unittest.TestCase): + def testWrappedWorksAsKey(self): + '''Test for http://jython.org/bugs/1816134 + + PyString's equal used to check for str explicitly, so Wrapper's __cmp__ wasn't used + and a KeyError would be raised by the lookup on ABC. + ''' + class Wrapper(object): + def __init__(self, content): + self.content = content + def __hash__(self): + return hash(self.content) + def __cmp__(self, other): + if isinstance(other, Wrapper): + return cmp(self.content, other.content) + return cmp(self.content, other) + d = {'ABC' : 1} + ABC = Wrapper('ABC') + self.assertEquals(1, d[ABC]) + +def test_main(): + test_support.run_unittest(WrappedStrCmpTest) + +if __name__ == '__main__': + test_main() Modified: branches/Release_2_2maint/jython/NEWS =================================================================== --- branches/Release_2_2maint/jython/NEWS 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/NEWS 2007-12-30 23:01:18 UTC (rev 3914) @@ -7,6 +7,15 @@ - [ 1831710 ] PyFileCloser throws NullPointerException on shutdown - [ 1817908 ] Broken link for corner icon in html documentation - [ 1850722 ] socket.py - ClientCookie and ClientForm (and urllib2) + - [ 1841445 ] PythonInterpreter.get(String name, Class javaclass) throws + an NPE if name isn't defined + - [ 1839871 ] dict calls __setitem__ on subclasses in initialization + - [ 1816134 ] str uses its own __eq__ instead of deferring to subclasses + - [ 1796425 ] os.renames missing + - [ 1796415 ] os.removedirs missing + - [ 1814678 ] os.__all__ missing many functions + - [ 1812122 ] NullPointerException when rethrowing an exception + - [ 1830916 ] PyException doesn't store causal Java exception Jython 2.2.1 Identical to 2.2.1 rc2 Modified: branches/Release_2_2maint/jython/src/org/python/core/Py.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/Py.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/Py.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -365,7 +365,11 @@ memory_error((OutOfMemoryError)t); } PyJavaInstance exc = new PyJavaInstance(t); - return new PyException(exc.instclass, exc); + PyException pyex = new PyException(exc.instclass, exc); + // Set the cause to the original throwable to preserve + // the exception chain. + pyex.initCause(t); + return pyex; } // Don't allow any constructors. Class only provides static methods. @@ -1088,7 +1092,7 @@ PyException e = Py.JavaError(t); //Add another traceback object to the exception if needed - if (e.traceback.tb_frame != frame) { + if (e.traceback.tb_frame != frame && e.traceback.tb_frame.f_back != null) { e.traceback = new PyTraceback(e.traceback); } } @@ -1099,7 +1103,7 @@ pye.instantiate(); // attach catching frame - if (frame != null && pye.traceback.tb_frame != frame) { + if (frame != null && pye.traceback.tb_frame != frame && pye.traceback.tb_frame.f_back != null) { pye.traceback = new PyTraceback(pye.traceback); } Modified: branches/Release_2_2maint/jython/src/org/python/core/PyDictionary.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyDictionary.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/PyDictionary.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -651,12 +651,12 @@ throw Py.ValueError("dictionary update sequence element #"+cnt+ " has length "+n+"; 2 is required"); } - this.__setitem__(pair.__getitem__(0),pair.__getitem__(1)); + dict___setitem__(pair.__getitem__(0), pair.__getitem__(1)); } } } - for (int i=0; i < kwds.length; i++) { - this.__setitem__(kwds[i],args[nargs+i]); + for(int i = 0; i < kwds.length; i++) { + dict___setitem__(Py.newString(kwds[i]), args[nargs + i]); } } public static PyObject fromkeys(PyObject keys) { Modified: branches/Release_2_2maint/jython/src/org/python/core/PyObject.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyObject.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/PyObject.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -381,15 +381,16 @@ * <code>a.equals(b) == true</code> iff <code>cmp(a,b) == 0</code> **/ public boolean equals(Object ob_other) { - return (ob_other instanceof PyObject) - && _eq((PyObject) ob_other).__nonzero__(); + if(ob_other == this) { + return true; + } + return (ob_other instanceof PyObject) && _eq((PyObject)ob_other).__nonzero__(); } /** - * Equivalent to the standard Python __nonzero__ method. - * Returns whether of not a given <code>PyObject</code> is - * considered true. - **/ + * Equivalent to the standard Python __nonzero__ method. Returns whether of + * not a given <code>PyObject</code> is considered true. + */ public boolean __nonzero__() { return true; } Modified: branches/Release_2_2maint/jython/src/org/python/core/PySequenceList.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PySequenceList.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/PySequenceList.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -138,9 +138,11 @@ public boolean equals(Object o) { if(o instanceof PySequenceList) { return list.equals(((PySequenceList)o).list); - } else if (o instanceof List) { + } else if(o instanceof List) { return o.equals(this); - } else return false; + } else { + return super.equals(o); + } } public int hashCode() { Modified: branches/Release_2_2maint/jython/src/org/python/core/PyString.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/core/PyString.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/core/PyString.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -1910,17 +1910,6 @@ return v.toString(); } - public boolean equals(Object other) { - if (!(other instanceof PyString)) - return false; - - PyString o = (PyString)other; - if (interned && o.interned) - return string == o.string; - - return string.equals(o.string); - } - public int __cmp__(PyObject other) { return str___cmp__(other); } Modified: branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java =================================================================== --- branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java 2007-12-30 22:54:48 UTC (rev 3913) +++ branches/Release_2_2maint/jython/src/org/python/util/PythonInterpreter.java 2007-12-30 23:01:18 UTC (rev 3914) @@ -195,27 +195,36 @@ locals.__setitem__(name.intern(), value); } - /** * Get the value of a variable in the local namespace - * - * @param name the name of the variable + * + * @param name + * the name of the variable + * @return the value of the variable, or null if that name isn't assigned */ public PyObject get(String name) { return locals.__finditem__(name.intern()); } /** - * Get the value of a variable in the local namespace Value will be - * returned as an instance of the given Java class. + * Get the value of a variable in the local namespace Value will be returned + * as an instance of the given Java class. * <code>interp.get("foo", Object.class)</code> will return the most * appropriate generic Java object. - * - * @param name the name of the variable - * @param javaclass the class of object to return + * + * @param name + * the name of the variable + * @param javaclass + * the class of object to return + * @return the value of the variable as the given class, or null if that + * name isn't assigned */ public Object get(String name, Class javaclass) { - return Py.tojava(locals.__finditem__(name.intern()), javaclass); + PyObject val = locals.__finditem__(name.intern()); + if(val == null) { + return null; + } + return Py.tojava(val, javaclass); } public void cleanup() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |