From: <fwi...@us...> - 2008-09-10 03:59:24
|
Revision: 5310 http://jython.svn.sourceforge.net/jython/?rev=5310&view=rev Author: fwierzbicki Date: 2008-09-10 03:59:17 +0000 (Wed, 10 Sep 2008) Log Message: ----------- Merged revisions 5300-5308 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r5300 | fwierzbicki | 2008-09-06 19:20:46 -0400 (Sat, 06 Sep 2008) | 2 lines Add alpha2 link and remove jeps directory. ........ r5301 | fwierzbicki | 2008-09-07 01:57:26 -0400 (Sun, 07 Sep 2008) | 2 lines Committing Nicholas Riley's patch after getting test_ast.py to work. See http://bugs.jython.org/issue1758279. ........ r5302 | otmarhumbel | 2008-09-08 10:41:41 -0400 (Mon, 08 Sep 2008) | 9 lines Fix for issue #1123: Weird "unexpected at this time" error. The tests if environment variables JAVA_HOME or JYTHON_HOME are set did not work: - if the path contained a space - if the variable really was not set The passed (manual, so far) tests can be found in: http://bugs.jython.org/msg3489 ........ r5303 | leosoto | 2008-09-08 13:48:28 -0400 (Mon, 08 Sep 2008) | 1 line SystemRandom implementation taken from CPython. It depends on urandom(), which seems supported now through jna-posix ........ r5304 | fwierzbicki | 2008-09-09 14:42:57 -0400 (Tue, 09 Sep 2008) | 2 lines Fix some offset problems in DEDENT, INDENT, and EOF. ........ r5305 | fwierzbicki | 2008-09-09 15:06:17 -0400 (Tue, 09 Sep 2008) | 3 lines from: http://svn.python.org/projects/python/branches/release25-maint/Lib@66318 ........ r5306 | otmarhumbel | 2008-09-09 16:35:30 -0400 (Tue, 09 Sep 2008) | 2 lines enable compilation for full-build (-A is still broken) ........ r5307 | fwierzbicki | 2008-09-09 17:15:54 -0400 (Tue, 09 Sep 2008) | 2 lines Disable refcount test with is_jython check. ........ r5308 | otmarhumbel | 2008-09-09 18:34:55 -0400 (Tue, 09 Sep 2008) | 1 line applied leosoto's patch from http://bugs.jython.org/issue1077 to avoid duplicate entries in jython-complete.jar ........ Modified Paths: -------------- branches/Release_2_5maint/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java branches/Release_2_5maint/jython/Lib/random.py branches/Release_2_5maint/jython/Lib/test/test_ast.py branches/Release_2_5maint/jython/Lib/test/test_class_jy.py branches/Release_2_5maint/jython/build.xml branches/Release_2_5maint/jython/src/org/python/antlr/PythonTokenSource.java branches/Release_2_5maint/jython/src/org/python/core/PyJavaClass.java branches/Release_2_5maint/jython/src/shell/jython.bat branches/Release_2_5maint/website/Project/index.txt Added Paths: ----------- branches/Release_2_5maint/jython/Lib/test/test_os.py Removed Paths: ------------- branches/Release_2_5maint/website/jeps/ Property Changed: ---------------- branches/Release_2_5maint/ Property changes on: branches/Release_2_5maint ___________________________________________________________________ Modified: svnmerge-integrated - /trunk:1-5297 + /trunk:1-5309 Modified: branches/Release_2_5maint/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java =================================================================== --- branches/Release_2_5maint/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/installer/test/java/org/python/util/install/StartScriptGeneratorTest.java 2008-09-10 03:59:17 UTC (rev 5310) @@ -44,8 +44,8 @@ buf.append("# Created on " + AT_DATE + " by " + System.getProperty("user.name") + "\n"); buf.append("\n"); buf.append("\"C:\\target/jython\" \"C:\\target/Tools/jythonc/jythonc.py\" \"$@\"\n"); - assertEquals(buf.toString().replaceAll(AT_DATE, new Date().toString()), _generator - .getJythoncScript(StartScriptGenerator.UNIX_FLAVOUR)); +// assertEquals(buf.toString().replaceAll(AT_DATE, new Date().toString()), _generator +// .getJythoncScript(StartScriptGenerator.UNIX_FLAVOUR)); } public void testWindows() throws IOException { @@ -75,8 +75,8 @@ buf = new StringBuffer(100); buf.append(winBuf); buf.append("\"C:\\target\\jython.bat\" \"C:\\target\\Tools\\jythonc\\jythonc.py\" %ARGS%"+WIN_CR_LF); - assertEquals(buf.toString().replaceAll(AT_DATE, new Date().toString()), _generator - .getJythoncScript(StartScriptGenerator.WINDOWS_FLAVOUR)); +// assertEquals(buf.toString().replaceAll(AT_DATE, new Date().toString()), _generator +// .getJythoncScript(StartScriptGenerator.WINDOWS_FLAVOUR)); } public void testFlavour() { Modified: branches/Release_2_5maint/jython/Lib/random.py =================================================================== --- branches/Release_2_5maint/jython/Lib/random.py 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/jython/Lib/random.py 2008-09-10 03:59:17 UTC (rev 5310) @@ -43,7 +43,10 @@ from math import log as _log, exp as _exp, pi as _pi, e as _e from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin from math import floor as _floor +from os import urandom as _urandom +from binascii import hexlify as _hexlify + __all__ = ["Random","seed","random","uniform","randint","choice","sample", "randrange","shuffle","normalvariate","lognormvariate", "cunifvariate","expovariate","vonmisesvariate","gammavariate", @@ -55,6 +58,7 @@ LOG4 = _log(4.0) SG_MAGICCONST = 1.0 + _log(4.5) BPF = 53 # Number of bits in a float +RECIP_BPF = 2**-BPF # Translated by Guido van Rossum from C source provided by # Adrian Baddeley. Adapted by Raymond Hettinger for use with @@ -768,24 +772,37 @@ ## --------------- Operating System Random Source ------------------ class SystemRandom(Random): + """Alternate random number generator using sources provided + by the operating system (such as /dev/urandom on Unix or + CryptGenRandom on Windows). + + Not available on all systems (see os.urandom() for details). """ - XXX: throw NotImplementedError for any attemt to use this for now. - """ def random(self): - self._notimplemented() + """Get the next random number in the range [0.0, 1.0).""" + return (long(_hexlify(_urandom(7)), 16) >> 3) * RECIP_BPF def getrandbits(self, k): - self._notimplemented() + """getrandbits(k) -> x. Generates a long int with k random bits.""" + if k <= 0: + raise ValueError('number of bits must be greater than zero') + if k != int(k): + raise TypeError('number of bits should be an integer') + bytes = (k + 7) // 8 # bits / 8 and rounded up + x = long(_hexlify(_urandom(bytes)), 16) + return x >> (bytes * 8 - k) # trim excess bits def _stub(self, *args, **kwds): - self._notimplemented() + "Stub method. Not used for a system random number generator." + return None + seed = jumpahead = _stub def _notimplemented(self, *args, **kwds): - raise NotImplementedError('SystemRandom not implemented on Jython.') + "Method should not be called for a system random number generator." + raise NotImplementedError('System entropy source does not have state.') getstate = setstate = _notimplemented - ## -------------------- test program -------------------- def _test_generator(n, funccall): Modified: branches/Release_2_5maint/jython/Lib/test/test_ast.py =================================================================== --- branches/Release_2_5maint/jython/Lib/test/test_ast.py 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/jython/Lib/test/test_ast.py 2008-09-10 03:59:17 UTC (rev 5310) @@ -5,12 +5,12 @@ def get_class_name(t): result = t.__class__.__name__ if os.name.startswith('java'): - if result in ("org.python.antlr.ast.expr_contextType", - "org.python.antlr.ast.boolopType", - "org.python.antlr.ast.unaryopType", - "org.python.antlr.ast.cmpopType", - "org.python.antlr.ast.operatorType"): - result = str(t) + if result in ("expr_contextType", + "boolopType", + "unaryopType", + "cmpopType", + "operatorType"): + result = t.name() else: result = result.split(".")[-1] if result.endswith("Type"): Modified: branches/Release_2_5maint/jython/Lib/test/test_class_jy.py =================================================================== --- branches/Release_2_5maint/jython/Lib/test/test_class_jy.py 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/jython/Lib/test/test_class_jy.py 2008-09-10 03:59:17 UTC (rev 5310) @@ -273,12 +273,29 @@ self.assert_(isinstance(retro, OldStyle)) +class JavaClassNamingTestCase(unittest.TestCase): + """ + Tests for PyJavaClass naming. + """ + + def test_java_class_name(self): + """ + The __name__ and __module__ attributes of Java classes should be set + according to the same convention that Python uses. + """ + from java.lang import String + self.assertEqual(String.__name__, "String") + self.assertEqual(String.__module__, "java.lang") + + + def test_main(): test_support.run_unittest(ClassGeneralTestCase, ClassNamelessModuleTestCase, BrokenNameTestCase, ClassLocalsTestCase, - IsDescendentTestCase) + IsDescendentTestCase, + JavaClassNamingTestCase) if __name__ == "__main__": Copied: branches/Release_2_5maint/jython/Lib/test/test_os.py (from rev 5308, trunk/jython/Lib/test/test_os.py) =================================================================== --- branches/Release_2_5maint/jython/Lib/test/test_os.py (rev 0) +++ branches/Release_2_5maint/jython/Lib/test/test_os.py 2008-09-10 03:59:17 UTC (rev 5310) @@ -0,0 +1,494 @@ +# As a test suite for the os module, this is woefully inadequate, but this +# does add tests for a few functions which have been determined to be more +# portable than they had been thought to be. + +import os +import unittest +import warnings +import sys +from test import test_support + +warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__) +warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__) + +# Tests creating TESTFN +class FileTests(unittest.TestCase): + def setUp(self): + if os.path.exists(test_support.TESTFN): + os.unlink(test_support.TESTFN) + tearDown = setUp + + def test_access(self): + f = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR) + os.close(f) + self.assert_(os.access(test_support.TESTFN, os.W_OK)) + + def test_rename(self): + path = unicode(test_support.TESTFN) + if not test_support.is_jython: + old = sys.getrefcount(path) + self.assertRaises(TypeError, os.rename, path, 0) + if not test_support.is_jython: + new = sys.getrefcount(path) + self.assertEqual(old, new) + + +class TemporaryFileTests(unittest.TestCase): + def setUp(self): + self.files = [] + os.mkdir(test_support.TESTFN) + + def tearDown(self): + for name in self.files: + os.unlink(name) + os.rmdir(test_support.TESTFN) + + def check_tempfile(self, name): + # make sure it doesn't already exist: + self.failIf(os.path.exists(name), + "file already exists for temporary file") + # make sure we can create the file + open(name, "w") + self.files.append(name) + + def test_tempnam(self): + if not hasattr(os, "tempnam"): + return + warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, + r"test_os$") + self.check_tempfile(os.tempnam()) + + name = os.tempnam(test_support.TESTFN) + self.check_tempfile(name) + + name = os.tempnam(test_support.TESTFN, "pfx") + self.assert_(os.path.basename(name)[:3] == "pfx") + self.check_tempfile(name) + + def test_tmpfile(self): + if not hasattr(os, "tmpfile"): + return + # As with test_tmpnam() below, the Windows implementation of tmpfile() + # attempts to create a file in the root directory of the current drive. + # On Vista and Server 2008, this test will always fail for normal users + # as writing to the root directory requires elevated privileges. With + # XP and below, the semantics of tmpfile() are the same, but the user + # running the test is more likely to have administrative privileges on + # their account already. If that's the case, then os.tmpfile() should + # work. In order to make this test as useful as possible, rather than + # trying to detect Windows versions or whether or not the user has the + # right permissions, just try and create a file in the root directory + # and see if it raises a 'Permission denied' OSError. If it does, then + # test that a subsequent call to os.tmpfile() raises the same error. If + # it doesn't, assume we're on XP or below and the user running the test + # has administrative privileges, and proceed with the test as normal. + if sys.platform == 'win32': + name = '\\python_test_os_test_tmpfile.txt' + if os.path.exists(name): + os.remove(name) + try: + fp = open(name, 'w') + except IOError, first: + # open() failed, assert tmpfile() fails in the same way. + # Although open() raises an IOError and os.tmpfile() raises an + # OSError(), 'args' will be (13, 'Permission denied') in both + # cases. + try: + fp = os.tmpfile() + except OSError, second: + self.assertEqual(first.args, second.args) + else: + self.fail("expected os.tmpfile() to raise OSError") + return + else: + # open() worked, therefore, tmpfile() should work. Close our + # dummy file and proceed with the test as normal. + fp.close() + os.remove(name) + + fp = os.tmpfile() + fp.write("foobar") + fp.seek(0,0) + s = fp.read() + fp.close() + self.assert_(s == "foobar") + + def test_tmpnam(self): + import sys + if not hasattr(os, "tmpnam"): + return + warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, + r"test_os$") + name = os.tmpnam() + if sys.platform in ("win32",): + # The Windows tmpnam() seems useless. From the MS docs: + # + # The character string that tmpnam creates consists of + # the path prefix, defined by the entry P_tmpdir in the + # file STDIO.H, followed by a sequence consisting of the + # digit characters '0' through '9'; the numerical value + # of this string is in the range 1 - 65,535. Changing the + # definitions of L_tmpnam or P_tmpdir in STDIO.H does not + # change the operation of tmpnam. + # + # The really bizarre part is that, at least under MSVC6, + # P_tmpdir is "\\". That is, the path returned refers to + # the root of the current drive. That's a terrible place to + # put temp files, and, depending on privileges, the user + # may not even be able to open a file in the root directory. + self.failIf(os.path.exists(name), + "file already exists for temporary file") + else: + self.check_tempfile(name) + +# Test attributes on return values from os.*stat* family. +class StatAttributeTests(unittest.TestCase): + def setUp(self): + os.mkdir(test_support.TESTFN) + self.fname = os.path.join(test_support.TESTFN, "f1") + f = open(self.fname, 'wb') + f.write("ABC") + f.close() + + def tearDown(self): + os.unlink(self.fname) + os.rmdir(test_support.TESTFN) + + def test_stat_attributes(self): + if not hasattr(os, "stat"): + return + + import stat + result = os.stat(self.fname) + + # Make sure direct access works + self.assertEquals(result[stat.ST_SIZE], 3) + self.assertEquals(result.st_size, 3) + + import sys + + # Make sure all the attributes are there + members = dir(result) + for name in dir(stat): + if name[:3] == 'ST_': + attr = name.lower() + if name.endswith("TIME"): + def trunc(x): return int(x) + else: + def trunc(x): return x + self.assertEquals(trunc(getattr(result, attr)), + result[getattr(stat, name)]) + self.assert_(attr in members) + + try: + result[200] + self.fail("No exception thrown") + except IndexError: + pass + + # Make sure that assignment fails + try: + result.st_mode = 1 + self.fail("No exception thrown") + except TypeError: + pass + + try: + result.st_rdev = 1 + self.fail("No exception thrown") + except (AttributeError, TypeError): + pass + + try: + result.parrot = 1 + self.fail("No exception thrown") + except AttributeError: + pass + + # Use the stat_result constructor with a too-short tuple. + try: + result2 = os.stat_result((10,)) + self.fail("No exception thrown") + except TypeError: + pass + + # Use the constructr with a too-long tuple. + try: + result2 = os.stat_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) + except TypeError: + pass + + + def test_statvfs_attributes(self): + if not hasattr(os, "statvfs"): + return + + import statvfs + try: + result = os.statvfs(self.fname) + except OSError, e: + # On AtheOS, glibc always returns ENOSYS + import errno + if e.errno == errno.ENOSYS: + return + + # Make sure direct access works + self.assertEquals(result.f_bfree, result[statvfs.F_BFREE]) + + # Make sure all the attributes are there + members = dir(result) + for name in dir(statvfs): + if name[:2] == 'F_': + attr = name.lower() + self.assertEquals(getattr(result, attr), + result[getattr(statvfs, name)]) + self.assert_(attr in members) + + # Make sure that assignment really fails + try: + result.f_bfree = 1 + self.fail("No exception thrown") + except TypeError: + pass + + try: + result.parrot = 1 + self.fail("No exception thrown") + except AttributeError: + pass + + # Use the constructor with a too-short tuple. + try: + result2 = os.statvfs_result((10,)) + self.fail("No exception thrown") + except TypeError: + pass + + # Use the constructr with a too-long tuple. + try: + result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) + except TypeError: + pass + + # Restrict test to Win32, since there is no guarantee other + # systems support centiseconds + if sys.platform == 'win32': + def get_file_system(path): + root = os.path.splitdrive(os.path.abspath(path))[0] + '\\' + import ctypes + kernel32 = ctypes.windll.kernel32 + buf = ctypes.create_string_buffer("", 100) + if kernel32.GetVolumeInformationA(root, None, 0, None, None, None, buf, len(buf)): + return buf.value + + if get_file_system(test_support.TESTFN) == "NTFS": + def test_1565150(self): + t1 = 1159195039.25 + os.utime(self.fname, (t1, t1)) + self.assertEquals(os.stat(self.fname).st_mtime, t1) + + def test_1686475(self): + # Verify that an open file can be stat'ed + try: + os.stat(r"c:\pagefile.sys") + except WindowsError, e: + if e == 2: # file does not exist; cannot run test + return + self.fail("Could not stat pagefile.sys") + +from test import mapping_tests + +class EnvironTests(mapping_tests.BasicTestMappingProtocol): + """check that os.environ object conform to mapping protocol""" + type2test = None + def _reference(self): + return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"} + def _empty_mapping(self): + os.environ.clear() + return os.environ + def setUp(self): + self.__save = dict(os.environ) + os.environ.clear() + def tearDown(self): + os.environ.clear() + os.environ.update(self.__save) + + # Bug 1110478 + def test_update2(self): + if os.path.exists("/bin/sh"): + os.environ.update(HELLO="World") + value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip() + self.assertEquals(value, "World") + +class WalkTests(unittest.TestCase): + """Tests for os.walk().""" + + def test_traversal(self): + import os + from os.path import join + + # Build: + # TESTFN/ a file kid and two directory kids + # tmp1 + # SUB1/ a file kid and a directory kid + # tmp2 + # SUB11/ no kids + # SUB2/ just a file kid + # tmp3 + sub1_path = join(test_support.TESTFN, "SUB1") + sub11_path = join(sub1_path, "SUB11") + sub2_path = join(test_support.TESTFN, "SUB2") + tmp1_path = join(test_support.TESTFN, "tmp1") + tmp2_path = join(sub1_path, "tmp2") + tmp3_path = join(sub2_path, "tmp3") + + # Create stuff. + os.makedirs(sub11_path) + os.makedirs(sub2_path) + for path in tmp1_path, tmp2_path, tmp3_path: + f = file(path, "w") + f.write("I'm " + path + " and proud of it. Blame test_os.\n") + f.close() + + # Walk top-down. + all = list(os.walk(test_support.TESTFN)) + self.assertEqual(len(all), 4) + # We can't know which order SUB1 and SUB2 will appear in. + # Not flipped: TESTFN, SUB1, SUB11, SUB2 + # flipped: TESTFN, SUB2, SUB1, SUB11 + flipped = all[0][1][0] != "SUB1" + all[0][1].sort() + self.assertEqual(all[0], (test_support.TESTFN, ["SUB1", "SUB2"], ["tmp1"])) + self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"])) + self.assertEqual(all[2 + flipped], (sub11_path, [], [])) + self.assertEqual(all[3 - 2 * flipped], (sub2_path, [], ["tmp3"])) + + # Prune the search. + all = [] + for root, dirs, files in os.walk(test_support.TESTFN): + all.append((root, dirs, files)) + # Don't descend into SUB1. + if 'SUB1' in dirs: + # Note that this also mutates the dirs we appended to all! + dirs.remove('SUB1') + self.assertEqual(len(all), 2) + self.assertEqual(all[0], (test_support.TESTFN, ["SUB2"], ["tmp1"])) + self.assertEqual(all[1], (sub2_path, [], ["tmp3"])) + + # Walk bottom-up. + all = list(os.walk(test_support.TESTFN, topdown=False)) + self.assertEqual(len(all), 4) + # We can't know which order SUB1 and SUB2 will appear in. + # Not flipped: SUB11, SUB1, SUB2, TESTFN + # flipped: SUB2, SUB11, SUB1, TESTFN + flipped = all[3][1][0] != "SUB1" + all[3][1].sort() + self.assertEqual(all[3], (test_support.TESTFN, ["SUB1", "SUB2"], ["tmp1"])) + self.assertEqual(all[flipped], (sub11_path, [], [])) + self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"])) + self.assertEqual(all[2 - 2 * flipped], (sub2_path, [], ["tmp3"])) + + # Tear everything down. This is a decent use for bottom-up on + # Windows, which doesn't have a recursive delete command. The + # (not so) subtlety is that rmdir will fail unless the dir's + # kids are removed first, so bottom up is essential. + for root, dirs, files in os.walk(test_support.TESTFN, topdown=False): + for name in files: + os.remove(join(root, name)) + for name in dirs: + os.rmdir(join(root, name)) + os.rmdir(test_support.TESTFN) + +class MakedirTests (unittest.TestCase): + def setUp(self): + os.mkdir(test_support.TESTFN) + + def test_makedir(self): + base = test_support.TESTFN + path = os.path.join(base, 'dir1', 'dir2', 'dir3') + os.makedirs(path) # Should work + path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4') + os.makedirs(path) + + # Try paths with a '.' in them + self.failUnlessRaises(OSError, os.makedirs, os.curdir) + path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir) + os.makedirs(path) + path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4', + 'dir5', 'dir6') + os.makedirs(path) + + + + + def tearDown(self): + path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3', + 'dir4', 'dir5', 'dir6') + # If the tests failed, the bottom-most directory ('../dir6') + # may not have been created, so we look for the outermost directory + # that exists. + while not os.path.exists(path) and path != test_support.TESTFN: + path = os.path.dirname(path) + + os.removedirs(path) + +class DevNullTests (unittest.TestCase): + def test_devnull(self): + f = file(os.devnull, 'w') + f.write('hello') + f.close() + f = file(os.devnull, 'r') + self.assertEqual(f.read(), '') + f.close() + +class URandomTests (unittest.TestCase): + def test_urandom(self): + try: + self.assertEqual(len(os.urandom(1)), 1) + self.assertEqual(len(os.urandom(10)), 10) + self.assertEqual(len(os.urandom(100)), 100) + self.assertEqual(len(os.urandom(1000)), 1000) + except NotImplementedError: + pass + +class Win32ErrorTests(unittest.TestCase): + def test_rename(self): + self.assertRaises(WindowsError, os.rename, test_support.TESTFN, test_support.TESTFN+".bak") + + def test_remove(self): + self.assertRaises(WindowsError, os.remove, test_support.TESTFN) + + def test_chdir(self): + self.assertRaises(WindowsError, os.chdir, test_support.TESTFN) + + def test_mkdir(self): + self.assertRaises(WindowsError, os.chdir, test_support.TESTFN) + + def test_utime(self): + self.assertRaises(WindowsError, os.utime, test_support.TESTFN, None) + + def test_access(self): + self.assertRaises(WindowsError, os.utime, test_support.TESTFN, 0) + + def test_chmod(self): + self.assertRaises(WindowsError, os.utime, test_support.TESTFN, 0) + +if sys.platform != 'win32': + class Win32ErrorTests(unittest.TestCase): + pass + +def test_main(): + test_support.run_unittest( + FileTests, + TemporaryFileTests, + StatAttributeTests, + EnvironTests, + WalkTests, + MakedirTests, + DevNullTests, + URandomTests, + Win32ErrorTests + ) + +if __name__ == "__main__": + test_main() Modified: branches/Release_2_5maint/jython/build.xml =================================================================== --- branches/Release_2_5maint/jython/build.xml 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/jython/build.xml 2008-09-10 03:59:17 UTC (rev 5310) @@ -533,9 +533,9 @@ </target> <target name="jar-complete" depends="compile,expose,jarjar"> - <jar destfile="${dist.dir}/jython-complete.jar"> + <jar destfile="${dist.dir}/jython-complete.jar" duplicate="preserve"> + <fileset dir="${exposed.dir}"/> <fileset dir="${compile.dir}"/> - <fileset dir="${exposed.dir}"/> <fileset dir="${jarjar.dir}"> </fileset> <manifest> @@ -557,9 +557,9 @@ </target> <target name="jar" depends="compile,expose,jarjar"> - <jar destfile="${dist.dir}/jython.jar"> + <jar destfile="${dist.dir}/jython.jar" duplicate="preserve"> + <fileset dir="${exposed.dir}"/> <fileset dir="${compile.dir}"/> - <fileset dir="${exposed.dir}"/> <fileset dir="${jarjar.dir}"> <include name="org/python/objectweb/asm/ClassReader.class" /> </fileset> Modified: branches/Release_2_5maint/jython/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/Release_2_5maint/jython/src/org/python/antlr/PythonTokenSource.java 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/jython/src/org/python/antlr/PythonTokenSource.java 2008-09-10 03:59:17 UTC (rev 5310) @@ -154,6 +154,7 @@ private void handleEOF(CommonToken eof, CommonToken prev) { if (prev != null) { + eof.setStartIndex(prev.getStopIndex()); eof.setStopIndex(prev.getStopIndex()); } } @@ -258,9 +259,11 @@ private void handleIndents(int cpos, CommonToken t) { push(cpos); //System.out.println("push("+cpos+"): "+stackString()); - Token indent = new CommonToken(PythonParser.INDENT,""); + CommonToken indent = new CommonToken(PythonParser.INDENT,""); indent.setCharPositionInLine(t.getCharPositionInLine()); indent.setLine(t.getLine()); + indent.setStartIndex(t.getStartIndex() - 1); + indent.setStopIndex(t.getStartIndex() - 1); tokens.addElement(indent); } @@ -274,9 +277,8 @@ dedent.setCharPositionInLine(t.getCharPositionInLine()); dedent.setLine(t.getLine()); - //XXX: this will get messed up by comments. - dedent.setStartIndex(t.getStartIndex()); - dedent.setStopIndex(t.getStopIndex()); + dedent.setStartIndex(t.getStartIndex() - 1); + dedent.setStopIndex(t.getStartIndex() - 1); tokens.addElement(dedent); } Modified: branches/Release_2_5maint/jython/src/org/python/core/PyJavaClass.java =================================================================== --- branches/Release_2_5maint/jython/src/org/python/core/PyJavaClass.java 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/jython/src/org/python/core/PyJavaClass.java 2008-09-10 03:59:17 UTC (rev 5310) @@ -75,8 +75,30 @@ init(c); } - protected PyJavaClass(String name,PackageManager mgr) { - __name__ = name; + public String __module__; + /** + * Set the full name of this class. + */ + private void setName(String name) { + int dotIndex = name.lastIndexOf("."); + if (dotIndex == -1) { + __name__ = name; + __module__ = ""; + } else { + __name__ = name.substring(name.lastIndexOf(".")+1, name.length()); + __module__ = name.substring(0, name.lastIndexOf(".")); + } + } + + private String fullName() { + if (__module__ == "") + return __name__; + else + return __module__ + "." + __name__; + } + + protected PyJavaClass(String name, PackageManager mgr) { + setName(name); this.__mgr__ = mgr; } @@ -97,7 +119,7 @@ } private static final void initLazy(PyJavaClass jc) { - Class c = jc.__mgr__.findClass(null,jc.__name__,"lazy java class"); + Class c = jc.__mgr__.findClass(null,jc.fullName(),"lazy java class"); check_lazy_allowed(c); // xxx jc.init(c); tbl.putCanonical(jc.proxyClass,jc); @@ -209,7 +231,7 @@ private void init(Class c) { proxyClass = c; - __name__ = c.getName(); + setName(c.getName()); } /** @@ -761,6 +783,8 @@ } if (name == "__name__") return new PyString(__name__); + if (name == "__module__") + return new PyString(__module__); if (name == "__bases__") { if (__bases__ == null) initialize(); @@ -851,11 +875,11 @@ if (PyObject.class.isAssignableFrom(proxyClass)) { if (Modifier.isAbstract(proxyClass.getModifiers())) { throw Py.TypeError("can't instantiate abstract class ("+ - __name__+")"); + fullName()+")"); } if (__init__ == null) { throw Py.TypeError("no public constructors for "+ - __name__); + fullName()); } return __init__.make(args,keywords); } @@ -871,7 +895,19 @@ return super.__tojava__(c); } + public int __cmp__(PyObject other) { + if (!(other instanceof PyJavaClass)) { + return -2; + } + int c = fullName().compareTo(((PyJavaClass) other).fullName()); + return c < 0 ? -1 : c > 0 ? 1 : 0; + } + + public PyString __str__() { + return new PyString(fullName()); + } + public String toString() { - return "<jclass "+__name__+" "+Py.idstr(this)+">"; + return "<jclass "+fullName()+" "+Py.idstr(this)+">"; } } Modified: branches/Release_2_5maint/jython/src/shell/jython.bat =================================================================== --- branches/Release_2_5maint/jython/src/shell/jython.bat 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/jython/src/shell/jython.bat 2008-09-10 03:59:17 UTC (rev 5310) @@ -17,12 +17,12 @@ rem ----- Verify and set required environment variables ----------------------- set _JAVA_CMD=java -if not "%JAVA_HOME%" == "" ( +if not [%JAVA_HOME%] == [] ( set _JAVA_CMD="%JAVA_HOME:"=%\bin\java" ) set _JYTHON_HOME=%JYTHON_HOME% -if not "%JYTHON_HOME%" == "" goto gotHome +if not [%JYTHON_HOME%] == [] goto gotHome pushd "%~dp0%\.." set _JYTHON_HOME="%CD%" popd @@ -84,7 +84,7 @@ if ["%_CMP%"] == ["--"] goto argsDone if ["%_CMP%"] == ["--jdb"] ( - if "%JAVA_HOME%" == "" ( + if [%JAVA_HOME%] == [] ( set _JAVA_CMD=jdb ) else ( set _JAVA_CMD="%_JAVA_HOME:"=%\bin\jdb" Modified: branches/Release_2_5maint/website/Project/index.txt =================================================================== --- branches/Release_2_5maint/website/Project/index.txt 2008-09-10 03:43:18 UTC (rev 5309) +++ branches/Release_2_5maint/website/Project/index.txt 2008-09-10 03:59:17 UTC (rev 5310) @@ -11,8 +11,12 @@ .. admonition:: Latest News - The Jython development team is proud to announce a new release: Jython 2.2.1! + The Jython development team is proud to announce a new alpha release: Jython 2.5a2! + * `Test the alpha <http://downloads.sourceforge.net/jython/jython_installer-2.5a2.jar>`__ + + For production use please continue to use Jython 2.2.1 + * `Download location`_ * `Installation instructions <installation.html>`__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |