From: <fwi...@us...> - 2009-10-01 01:16:50
|
Revision: 6817 http://jython.svn.sourceforge.net/jython/?rev=6817&view=rev Author: fwierzbicki Date: 2009-10-01 01:16:13 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Merged revisions 6762-6763,6766-6785,6788-6789,6795-6797,6800,6807-6808,6812,6814 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r6762 | zyasoft | 2009-09-07 16:41:45 -0400 (Mon, 07 Sep 2009) | 4 lines Fixed regression where threading._Lock, _RLock were no longer available as synonyms to Lock and RLock respectively, which Twisted needs. Added a test case to prevent recurrence. This resolves #1079. ........ r6763 | zyasoft | 2009-09-07 17:48:20 -0400 (Mon, 07 Sep 2009) | 5 lines CodeCompiler#visitAssert now looks up the AssertionError by using PyFrame#getglobal, so user code can redefine the behavior of assert. Fixes #1461 Bumped bytecode magic. ........ r6766 | pjenvey | 2009-09-08 22:58:36 -0400 (Tue, 08 Sep 2009) | 4 lines don't assume posix fixes #1425 thanks Matthew L Daniel ........ r6767 | pjenvey | 2009-09-08 23:06:20 -0400 (Tue, 08 Sep 2009) | 3 lines fix os.popen*/popen2 to only invoke a shell if cmd is a string refs http://bugs.python.org/issue5329 ........ r6768 | pjenvey | 2009-09-08 23:24:04 -0400 (Tue, 08 Sep 2009) | 3 lines fix array.to/fromfile on files in + mode fixes #1457 ........ r6769 | pjenvey | 2009-09-08 23:45:43 -0400 (Tue, 08 Sep 2009) | 4 lines fix __cmp__ specifying the wrong array type to lookup_where triggering an ArrayStoreException in some cases fixes #1382 ........ r6770 | pjenvey | 2009-09-08 23:47:22 -0400 (Tue, 08 Sep 2009) | 2 lines regen per r6769 ........ r6771 | pjenvey | 2009-09-09 00:16:49 -0400 (Wed, 09 Sep 2009) | 3 lines allow hashlib updating from arrays fixes #1443 ........ r6772 | pjenvey | 2009-09-09 00:59:15 -0400 (Wed, 09 Sep 2009) | 3 lines allow zlib input from arrays fixes #1444 ........ r6773 | pjenvey | 2009-09-09 01:47:17 -0400 (Wed, 09 Sep 2009) | 1 line whitespace ........ r6774 | fwierzbicki | 2009-09-09 08:11:47 -0400 (Wed, 09 Sep 2009) | 2 lines tab -> spaces. ........ r6775 | fwierzbicki | 2009-09-09 12:59:20 -0400 (Wed, 09 Sep 2009) | 2 lines Cleanup. ........ r6776 | fwierzbicki | 2009-09-09 13:28:32 -0400 (Wed, 09 Sep 2009) | 3 lines Add PyList testing for http://bugs.jython.org/issue1419, but it will also be a good place for testing the Java List interface of PyList in the future. ........ r6777 | fwierzbicki | 2009-09-09 13:35:38 -0400 (Wed, 09 Sep 2009) | 3 lines Test PyTuple for http://bugs.jython.org/issue1419 "Bug in PyTuple.indexOf and PyList.indexOf". ........ r6778 | fwierzbicki | 2009-09-09 13:47:39 -0400 (Wed, 09 Sep 2009) | 2 lines Give tests non-stupid names. ........ r6779 | fwierzbicki | 2009-09-09 13:59:05 -0400 (Wed, 09 Sep 2009) | 2 lines Also test the toArray() bugs fixed by Andrea's patch applied by Tobias. ........ r6780 | pjenvey | 2009-09-10 23:35:35 -0400 (Thu, 10 Sep 2009) | 4 lines support multiple ResultSets via cursor.nextset. to accommodate this staticFetch Statements are no longer immediately closed after execute (unless an exception was thrown), like dynamicFetch ........ r6781 | cgroves | 2009-09-11 01:22:00 -0400 (Fri, 11 Sep 2009) | 1 line Widening, standards ........ r6782 | pjenvey | 2009-09-11 01:34:56 -0400 (Fri, 11 Sep 2009) | 4 lines o fix PyTuple/List.equals not trying rich comparison (_eq) to all other PyObjects like PyObject.equals does o no need to synchronize all of PyList.equals ........ r6783 | pjenvey | 2009-09-11 01:52:44 -0400 (Fri, 11 Sep 2009) | 1 line cleanup ........ r6784 | zyasoft | 2009-09-11 02:44:19 -0400 (Fri, 11 Sep 2009) | 4 lines Added with-statement support to zxJDBC: * PyConnection - commit if no exception, otherwise rollback * PyCursor - always close this resource ........ r6785 | cgroves | 2009-09-11 02:55:34 -0400 (Fri, 11 Sep 2009) | 3 lines Use the builtin codecs when nothing is found in the registry. Fixes issue 1458. ........ r6788 | zyasoft | 2009-09-11 22:24:31 -0400 (Fri, 11 Sep 2009) | 1 line Updated NEWS re zxJDBC support of with-statement ........ r6789 | fwierzbicki | 2009-09-12 14:14:14 -0400 (Sat, 12 Sep 2009) | 2 lines Update versions. ........ r6795 | pjenvey | 2009-09-13 19:30:43 -0400 (Sun, 13 Sep 2009) | 1 line add @Overrides ........ r6796 | pjenvey | 2009-09-13 21:05:23 -0400 (Sun, 13 Sep 2009) | 4 lines force real O_APPEND for files' 'a' mode by going through FileOutputStream, otherwise emulate it with a performance hit for 'a+' mode fixes #1466 ........ r6797 | pjenvey | 2009-09-13 21:49:05 -0400 (Sun, 13 Sep 2009) | 1 line actually test 'a+' ........ r6800 | fwierzbicki | 2009-09-17 00:14:04 -0400 (Thu, 17 Sep 2009) | 2 lines Remove modules that now have modified versions living in our Lib/ ........ r6807 | fwierzbicki | 2009-09-23 20:16:35 -0400 (Wed, 23 Sep 2009) | 2 lines Update README for rc3. ........ r6808 | fwierzbicki | 2009-09-23 20:17:16 -0400 (Wed, 23 Sep 2009) | 2 lines Finish updating README for rc3. ........ r6812 | fwierzbicki | 2009-09-26 12:14:48 -0400 (Sat, 26 Sep 2009) | 2 lines Update README and version numbering. ........ r6814 | fwierzbicki | 2009-09-26 21:34:11 -0400 (Sat, 26 Sep 2009) | 2 lines Removed unused import from thread.java, expanded javadoc package scan. ........ Modified Paths: -------------- branches/indy/CPythonLib.includes branches/indy/Lib/distutils/util.py branches/indy/Lib/popen2.py branches/indy/Lib/test/test_array_jy.py branches/indy/Lib/test/test_cmp_jy.py branches/indy/Lib/test/test_hashlib_jy.py branches/indy/Lib/test/test_seq_jy.py branches/indy/Lib/test/test_threading_jy.py branches/indy/Lib/threading.py branches/indy/Lib/zlib.py branches/indy/NEWS branches/indy/README.txt branches/indy/build.xml branches/indy/src/com/ziclix/python/sql/PyConnection.java branches/indy/src/com/ziclix/python/sql/PyCursor.java branches/indy/src/org/python/antlr/PythonTree.java branches/indy/src/org/python/antlr/ast/AssertDerived.java branches/indy/src/org/python/antlr/ast/AssignDerived.java branches/indy/src/org/python/antlr/ast/AttributeDerived.java branches/indy/src/org/python/antlr/ast/AugAssignDerived.java branches/indy/src/org/python/antlr/ast/BinOpDerived.java branches/indy/src/org/python/antlr/ast/BoolOpDerived.java branches/indy/src/org/python/antlr/ast/BreakDerived.java branches/indy/src/org/python/antlr/ast/CallDerived.java branches/indy/src/org/python/antlr/ast/ClassDefDerived.java branches/indy/src/org/python/antlr/ast/CompareDerived.java branches/indy/src/org/python/antlr/ast/ContinueDerived.java branches/indy/src/org/python/antlr/ast/DeleteDerived.java branches/indy/src/org/python/antlr/ast/DictDerived.java branches/indy/src/org/python/antlr/ast/EllipsisDerived.java branches/indy/src/org/python/antlr/ast/ExceptHandlerDerived.java branches/indy/src/org/python/antlr/ast/ExecDerived.java branches/indy/src/org/python/antlr/ast/ExprDerived.java branches/indy/src/org/python/antlr/ast/ExpressionDerived.java branches/indy/src/org/python/antlr/ast/ExtSliceDerived.java branches/indy/src/org/python/antlr/ast/ForDerived.java branches/indy/src/org/python/antlr/ast/FunctionDefDerived.java branches/indy/src/org/python/antlr/ast/GeneratorExpDerived.java branches/indy/src/org/python/antlr/ast/GlobalDerived.java branches/indy/src/org/python/antlr/ast/IfDerived.java branches/indy/src/org/python/antlr/ast/IfExpDerived.java branches/indy/src/org/python/antlr/ast/ImportDerived.java branches/indy/src/org/python/antlr/ast/ImportFromDerived.java branches/indy/src/org/python/antlr/ast/IndexDerived.java branches/indy/src/org/python/antlr/ast/InteractiveDerived.java branches/indy/src/org/python/antlr/ast/LambdaDerived.java branches/indy/src/org/python/antlr/ast/ListCompDerived.java branches/indy/src/org/python/antlr/ast/ListDerived.java branches/indy/src/org/python/antlr/ast/ModuleDerived.java branches/indy/src/org/python/antlr/ast/NameDerived.java branches/indy/src/org/python/antlr/ast/NumDerived.java branches/indy/src/org/python/antlr/ast/PassDerived.java branches/indy/src/org/python/antlr/ast/PrintDerived.java branches/indy/src/org/python/antlr/ast/RaiseDerived.java branches/indy/src/org/python/antlr/ast/ReprDerived.java branches/indy/src/org/python/antlr/ast/ReturnDerived.java branches/indy/src/org/python/antlr/ast/SliceDerived.java branches/indy/src/org/python/antlr/ast/StrDerived.java branches/indy/src/org/python/antlr/ast/SubscriptDerived.java branches/indy/src/org/python/antlr/ast/SuiteDerived.java branches/indy/src/org/python/antlr/ast/TryExceptDerived.java branches/indy/src/org/python/antlr/ast/TryFinallyDerived.java branches/indy/src/org/python/antlr/ast/TupleDerived.java branches/indy/src/org/python/antlr/ast/UnaryOpDerived.java branches/indy/src/org/python/antlr/ast/WhileDerived.java branches/indy/src/org/python/antlr/ast/WithDerived.java branches/indy/src/org/python/antlr/ast/YieldDerived.java branches/indy/src/org/python/antlr/ast/aliasDerived.java branches/indy/src/org/python/antlr/ast/argumentsDerived.java branches/indy/src/org/python/antlr/ast/comprehensionDerived.java branches/indy/src/org/python/antlr/ast/keywordDerived.java branches/indy/src/org/python/antlr/op/AddDerived.java branches/indy/src/org/python/antlr/op/AndDerived.java branches/indy/src/org/python/antlr/op/AugLoadDerived.java branches/indy/src/org/python/antlr/op/AugStoreDerived.java branches/indy/src/org/python/antlr/op/BitAndDerived.java branches/indy/src/org/python/antlr/op/BitOrDerived.java branches/indy/src/org/python/antlr/op/BitXorDerived.java branches/indy/src/org/python/antlr/op/DelDerived.java branches/indy/src/org/python/antlr/op/DivDerived.java branches/indy/src/org/python/antlr/op/EqDerived.java branches/indy/src/org/python/antlr/op/FloorDivDerived.java branches/indy/src/org/python/antlr/op/GtDerived.java branches/indy/src/org/python/antlr/op/GtEDerived.java branches/indy/src/org/python/antlr/op/InDerived.java branches/indy/src/org/python/antlr/op/InvertDerived.java branches/indy/src/org/python/antlr/op/IsDerived.java branches/indy/src/org/python/antlr/op/IsNotDerived.java branches/indy/src/org/python/antlr/op/LShiftDerived.java branches/indy/src/org/python/antlr/op/LoadDerived.java branches/indy/src/org/python/antlr/op/LtDerived.java branches/indy/src/org/python/antlr/op/LtEDerived.java branches/indy/src/org/python/antlr/op/ModDerived.java branches/indy/src/org/python/antlr/op/MultDerived.java branches/indy/src/org/python/antlr/op/NotDerived.java branches/indy/src/org/python/antlr/op/NotEqDerived.java branches/indy/src/org/python/antlr/op/NotInDerived.java branches/indy/src/org/python/antlr/op/OrDerived.java branches/indy/src/org/python/antlr/op/ParamDerived.java branches/indy/src/org/python/antlr/op/PowDerived.java branches/indy/src/org/python/antlr/op/RShiftDerived.java branches/indy/src/org/python/antlr/op/StoreDerived.java branches/indy/src/org/python/antlr/op/SubDerived.java branches/indy/src/org/python/antlr/op/UAddDerived.java branches/indy/src/org/python/antlr/op/USubDerived.java branches/indy/src/org/python/compiler/CodeCompiler.java branches/indy/src/org/python/core/ClasspathPyImporterDerived.java branches/indy/src/org/python/core/PyArray.java branches/indy/src/org/python/core/PyArrayDerived.java branches/indy/src/org/python/core/PyBaseExceptionDerived.java branches/indy/src/org/python/core/PyBooleanDerived.java branches/indy/src/org/python/core/PyClassMethodDerived.java branches/indy/src/org/python/core/PyComplexDerived.java branches/indy/src/org/python/core/PyDictionaryDerived.java branches/indy/src/org/python/core/PyEnumerateDerived.java branches/indy/src/org/python/core/PyFileDerived.java branches/indy/src/org/python/core/PyFloatDerived.java branches/indy/src/org/python/core/PyFrozenSetDerived.java branches/indy/src/org/python/core/PyIntegerDerived.java branches/indy/src/org/python/core/PyList.java branches/indy/src/org/python/core/PyListDerived.java branches/indy/src/org/python/core/PyLongDerived.java branches/indy/src/org/python/core/PyModuleDerived.java branches/indy/src/org/python/core/PyObjectDerived.java branches/indy/src/org/python/core/PyPropertyDerived.java branches/indy/src/org/python/core/PySetDerived.java branches/indy/src/org/python/core/PySliceDerived.java branches/indy/src/org/python/core/PyStringDerived.java branches/indy/src/org/python/core/PySuperDerived.java branches/indy/src/org/python/core/PyTuple.java branches/indy/src/org/python/core/PyTupleDerived.java branches/indy/src/org/python/core/PyTypeDerived.java branches/indy/src/org/python/core/PyUnicodeDerived.java branches/indy/src/org/python/core/codecs.java branches/indy/src/org/python/core/imp.java branches/indy/src/org/python/core/io/FileIO.java branches/indy/src/org/python/modules/_collections/PyDefaultDictDerived.java branches/indy/src/org/python/modules/_collections/PyDequeDerived.java branches/indy/src/org/python/modules/_csv/PyDialectDerived.java branches/indy/src/org/python/modules/_functools/PyPartialDerived.java branches/indy/src/org/python/modules/_hashlib.java branches/indy/src/org/python/modules/_threading/_threading.java branches/indy/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/indy/src/org/python/modules/random/PyRandomDerived.java branches/indy/src/org/python/modules/thread/PyLocalDerived.java branches/indy/src/org/python/modules/thread/thread.java branches/indy/src/org/python/modules/zipimport/zipimporterDerived.java branches/indy/src/templates/object.derived Added Paths: ----------- branches/indy/Lib/test/print_sans_lib.py branches/indy/Lib/test/test_codecs_jy.py branches/indy/Lib/test/test_file_jy.py branches/indy/Lib/test/test_zlib_jy.py branches/indy/tests/java/org/python/core/PyListTest.java branches/indy/tests/java/org/python/core/PyTupleTest.java Property Changed: ---------------- branches/indy/ branches/indy/extlibs/xercesImpl-2.9.1.jar branches/indy/tests/java/org/python/tests/RedundantInterfaceDeclarations.java Property changes on: branches/indy ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-6751 + /trunk/jython:1-6814 Modified: svn:mergeinfo - /branches/jsr223:6285-6565 /branches/newstyle-java-types:5564-5663,5666-5729 /trunk/jython:6662-6741 + /branches/jsr223:6285-6565 /branches/newstyle-java-types:5564-5663,5666-5729 /trunk/jython:6662-6741,6762-6814 Modified: branches/indy/CPythonLib.includes =================================================================== --- branches/indy/CPythonLib.includes 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/CPythonLib.includes 2009-10-01 01:16:13 UTC (rev 6817) @@ -55,17 +55,14 @@ dummy_thread.py dummy_threading.py exceptions.py -fileinput.py fnmatch.py formatter.py fpformat.py ftplib.py functools.py getopt.py -gettext.py glob.py gopherlib.py -gzip.py hashlib.py heapq.py hmac.py @@ -76,13 +73,11 @@ ihooks.py imaplib.py imghdr.py -inspect.py keyword.py linecache.py locale.py macpath.py macurl2path.py -mailbox.py mailcap.py markupbase.py md5.py @@ -94,9 +89,7 @@ modulefinder.py multifile.py mutex.py -netrc.py nntplib.py -ntpath.py nturl2path.py opcode.py optparse.py @@ -104,15 +97,12 @@ pickle.py pickletools.py pipes.py -pkgutil.py -platform.py poplib.py posixfile.py pprint.py profile.py pstats.py pyclbr.py -pydoc.py Queue.py quopri.py random.py @@ -130,9 +120,7 @@ shelve.py shlex.py shutil.py -SimpleHTTPServer.py SimpleXMLRPCServer.py -site.py site-packages/README smtpd.py smtplib.py @@ -145,26 +133,20 @@ symbol.py tabnanny.py this.py -threading.py textwrap.py -timeit.py token.py tokenize.py trace.py traceback.py tzparse.py unittest.py -urllib.py urllib2.py urlparse.py user.py UserDict.py UserList.py UserString.py -uu.py uuid.py -warnings.py -weakref.py whichdb.py whrandom.py wsgiref.egg-info @@ -172,4 +154,3 @@ xdrlib.py xmllib.py xmlrpclib.py -zipfile.py Modified: branches/indy/Lib/distutils/util.py =================================================================== --- branches/indy/Lib/distutils/util.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/distutils/util.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -155,25 +155,26 @@ Otherwise, it requires making 'pathname' relative and then joining the two, which is tricky on DOS/Windows and Mac OS. """ - if os.name == 'posix' or os.name == 'java': + os_name = os._name if sys.platform.startswith('java') else os.name + if os_name == 'posix': if not os.path.isabs(pathname): return os.path.join(new_root, pathname) else: return os.path.join(new_root, pathname[1:]) - elif os.name == 'nt': + elif os_name == 'nt': (drive, path) = os.path.splitdrive(pathname) if path[0] == '\\': path = path[1:] return os.path.join(new_root, path) - elif os.name == 'os2': + elif os_name == 'os2': (drive, path) = os.path.splitdrive(pathname) if path[0] == os.sep: path = path[1:] return os.path.join(new_root, path) - elif os.name == 'mac': + elif os_name == 'mac': if not os.path.isabs(pathname): return os.path.join(new_root, pathname) else: @@ -184,7 +185,7 @@ else: raise DistutilsPlatformError, \ - "nothing known about platform '%s'" % os.name + "nothing known about platform '%s'" % os_name _environ_checked = 0 Modified: branches/indy/Lib/popen2.py =================================================================== --- branches/indy/Lib/popen2.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/popen2.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -34,7 +34,8 @@ process.""" stderr = subprocess.PIPE if capturestderr else None PIPE = subprocess.PIPE - self._popen = subprocess.Popen(cmd, bufsize=bufsize, shell=True, + self._popen = subprocess.Popen(cmd, bufsize=bufsize, + shell=isinstance(cmd, basestring), stdin=PIPE, stdout=PIPE, stderr=stderr) self._setup(cmd) @@ -73,7 +74,8 @@ def __init__(self, cmd, bufsize=-1): PIPE = subprocess.PIPE - self._popen = subprocess.Popen(cmd, bufsize=bufsize, shell=True, + self._popen = subprocess.Popen(cmd, bufsize=bufsize, + shell=isinstance(cmd, basestring), stdin=PIPE, stdout=PIPE, stderr=subprocess.STDOUT) self._setup(cmd) Copied: branches/indy/Lib/test/print_sans_lib.py (from rev 6814, trunk/jython/Lib/test/print_sans_lib.py) =================================================================== --- branches/indy/Lib/test/print_sans_lib.py (rev 0) +++ branches/indy/Lib/test/print_sans_lib.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -0,0 +1,4 @@ +import sys +sys.path = [path for path in sys.path if not path.startswith('/')] +encoded = u'hi'.encode("utf-8") +encoded.decode('utf-8') Modified: branches/indy/Lib/test/test_array_jy.py =================================================================== --- branches/indy/Lib/test/test_array_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_array_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -1,6 +1,7 @@ # The jarray module is being phased out, with all functionality # now available in the array module. - +from __future__ import with_statement +import os import unittest from test import test_support from array import array, zeros @@ -11,7 +12,6 @@ class ArrayJyTestCase(unittest.TestCase): def test_jarray(self): # until it is fully formally removed - # While jarray is still being phased out, just flex the initializers. # The rest of the test for array will catch all the big problems. import jarray @@ -44,8 +44,34 @@ Color.RGBtoHSB(0, 255, 255, hsb1) self.assertEqual(hsb, hsb1, "hsb float arrays were not equal") + +class ToFromfileTestCase(unittest.TestCase): + + def tearDown(self): + if os.path.exists(test_support.TESTFN): + os.remove(test_support.TESTFN) + + def test_tofromfile(self): + # http://bugs.jython.org/issue1457 + x = array('i', range(5)) + with open(test_support.TESTFN, 'wb') as f: + x.tofile(f) + + x = array('i', []) + with open(test_support.TESTFN, 'r+b') as f: + x.fromfile(f, 5) + x *= 2 + x.tofile(f) + + with open(test_support.TESTFN, 'rb') as f: + x.fromfile(f, 10) + self.assertEqual(x, array('i', range(5) * 4)) + + def test_main(): - test_support.run_unittest(ArrayJyTestCase) + test_support.run_unittest(ArrayJyTestCase, + ToFromfileTestCase) + if __name__ == "__main__": test_main() Modified: branches/indy/Lib/test/test_cmp_jy.py =================================================================== --- branches/indy/Lib/test/test_cmp_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_cmp_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -1,7 +1,18 @@ "Tests for cmp() compatibility with CPython" +import UserDict import unittest from test import test_support +class CmpGeneralTestCase(unittest.TestCase): + + def test_type_crash(self): + # Used to throw ArrayStoreException: + # http://bugs.jython.org/issue1382 + class Configuration(object, UserDict.DictMixin): + pass + self.assertNotEqual(Configuration(), None) + + class UnicodeDerivedCmp(unittest.TestCase): "Test for http://bugs.jython.org/issue1889394" def testCompareWithString(self): @@ -14,6 +25,7 @@ class B(unicode): pass self.assertEqual(A(), B()) + class LongDerivedCmp(unittest.TestCase): def testCompareWithString(self): class Test(long): @@ -21,6 +33,7 @@ self.assertNotEqual(Test(0), 'foo') self.assertTrue('foo' in [Test(12), 'foo']) + class IntStrCmp(unittest.TestCase): def testIntStrCompares(self): assert not (-1 > 'a') @@ -31,6 +44,7 @@ assert (-2 < 'a') assert not (-1 == 'a') + class CustomCmp(unittest.TestCase): def test___cmp___returns(self): class Foo(object): @@ -63,13 +77,16 @@ __eq__ = lambda self, other: True self.assertEqual(cmp(Foo(), Bar()), 1) + def test_main(): test_support.run_unittest( + CmpGeneralTestCase, UnicodeDerivedCmp, LongDerivedCmp, IntStrCmp, CustomCmp ) + if __name__ == '__main__': test_main() Copied: branches/indy/Lib/test/test_codecs_jy.py (from rev 6814, trunk/jython/Lib/test/test_codecs_jy.py) =================================================================== --- branches/indy/Lib/test/test_codecs_jy.py (rev 0) +++ branches/indy/Lib/test/test_codecs_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -0,0 +1,19 @@ +import subprocess +import sys +import test_support +import unittest + +class AccessBuiltinCodecs(unittest.TestCase): + def test_print_sans_lib(self): + '''Encodes and decodes using utf-8 after in an environment without the standard library + + Checks that the builtin utf-8 codec is always available: http://bugs.jython.org/issue1458''' + subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", + "-J-Dpython.security.respectJavaAccessibility=false", + test_support.findfile('print_sans_lib.py')]) + +def test_main(): + test_support.run_unittest(AccessBuiltinCodecs) + +if __name__ == "__main__": + test_main() Copied: branches/indy/Lib/test/test_file_jy.py (from rev 6814, trunk/jython/Lib/test/test_file_jy.py) =================================================================== --- branches/indy/Lib/test/test_file_jy.py (rev 0) +++ branches/indy/Lib/test/test_file_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -0,0 +1,39 @@ +"""Misc file tests. + +Made for Jython. +""" +from __future__ import with_statement +import os +import unittest +from test import test_support + +class FileTestCase(unittest.TestCase): + + def tearDown(self): + if os.path.exists(test_support.TESTFN): + os.remove(test_support.TESTFN) + + def test_append(self): + self._test_append('ab') + + def test_appendplus(self): + self._test_append('a+') + + def _test_append(self, mode): + # http://bugs.jython.org/issue1466 + fp1 = open(test_support.TESTFN, mode) + fp1.write('test1\n') + fp2 = open(test_support.TESTFN, mode) + fp2.write('test2\n') + fp1.close() + fp2.close() + with open(test_support.TESTFN) as fp: + self.assertEqual('test1\ntest2\n', fp.read()) + + +def test_main(): + test_support.run_unittest(FileTestCase) + + +if __name__ == '__main__': + test_main() Modified: branches/indy/Lib/test/test_hashlib_jy.py =================================================================== --- branches/indy/Lib/test/test_hashlib_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_hashlib_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -5,6 +5,7 @@ """ import hashlib import unittest +from array import array from test import test_support class HashlibTestCase(unittest.TestCase): @@ -14,7 +15,14 @@ 'acbd18db4cc2f85cedef654fccc4a4d8') self.assertRaises(UnicodeEncodeError, hashlib.md5, u'Gráin amháiñ') + def test_array(self): + self.assertEqual(hashlib.sha1(array('c', 'hovercraft')).hexdigest(), + '496df4d8de2c71973d7e917c4fbe57e6ad46d738') + intarray = array('i', range(5)) + self.assertEqual(hashlib.sha1(intarray).hexdigest(), + hashlib.sha1(intarray.tostring()).hexdigest()) + def test_main(): test_support.run_unittest(HashlibTestCase) Modified: branches/indy/Lib/test/test_seq_jy.py =================================================================== --- branches/indy/Lib/test/test_seq_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_seq_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -27,6 +27,14 @@ self.assertTrue(foo in seq1) self.assertFalse(eq_called) + def test_seq_equality(self): + class Foo(object): + def __eq__(self, other): + return True + foo = [Foo()] + for type2test in self.types2test: + self.assertTrue(type2test() in foo) + def test_seq_subclass_equality(self): # Various combinations of PyObject._eq, overriden Object.equals, # and cmp implementations Modified: branches/indy/Lib/test/test_threading_jy.py =================================================================== --- branches/indy/Lib/test/test_threading_jy.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/test/test_threading_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -36,8 +36,14 @@ time.sleep(random.random()) +class TwistedTestCase(unittest.TestCase): + + def test_needs_underscored_versions(self): + self.assertEqual(threading.Lock, threading._Lock) + self.assertEqual(threading.RLock, threading._RLock) + def test_main(): - test_support.run_unittest(ThreadingTestCase) + test_support.run_unittest(ThreadingTestCase, TwistedTestCase) if __name__ == "__main__": Copied: branches/indy/Lib/test/test_zlib_jy.py (from rev 6814, trunk/jython/Lib/test/test_zlib_jy.py) =================================================================== --- branches/indy/Lib/test/test_zlib_jy.py (rev 0) +++ branches/indy/Lib/test/test_zlib_jy.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -0,0 +1,37 @@ +"""Misc zlib tests + +Made for Jython. +""" +import unittest +import zlib +from array import array +from test import test_support + +class ArrayTestCase(unittest.TestCase): + + def test_array(self): + self._test_array(zlib.compress, zlib.decompress) + + def test_array_compressobj(self): + def compress(value): + co = zlib.compressobj() + return co.compress(value) + co.flush() + def decompress(value): + dco = zlib.decompressobj() + return dco.decompress(value) + dco.flush() + self._test_array(compress, decompress) + + def _test_array(self, compress, decompress): + self.assertEqual(compress(array('c', 'jython')), compress('jython')) + intarray = array('i', range(5)) + self.assertEqual(compress(intarray), compress(intarray.tostring())) + compressed = array('c', compress('jython')) + self.assertEqual('jython', decompress(compressed)) + + +def test_main(): + test_support.run_unittest(ArrayTestCase) + + +if __name__ == '__main__': + test_main() Modified: branches/indy/Lib/threading.py =================================================================== --- branches/indy/Lib/threading.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/threading.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -5,7 +5,7 @@ from org.python.util import jython from thread import _newFunctionThread from thread import _local as local -from _threading import Lock, RLock, Condition +from _threading import Lock, RLock, Condition, _Lock, _RLock import java.lang.Thread import weakref Modified: branches/indy/Lib/zlib.py =================================================================== --- branches/indy/Lib/zlib.py 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/Lib/zlib.py 2009-10-01 01:16:13 UTC (rev 6817) @@ -13,7 +13,9 @@ Compressor objects support compress() and flush() methods; decompressor objects support decompress() and flush(). """ -import jarray, binascii +import array +import binascii +import jarray from java.util.zip import Adler32, Deflater, Inflater, DataFormatException from java.lang import Long, String @@ -59,13 +61,14 @@ if level < Z_BEST_SPEED or level > Z_BEST_COMPRESSION: raise error, "Bad compression level" deflater = Deflater(level, 0) + string = _to_input(string) deflater.setInput(string, 0, len(string)) deflater.finish() return _get_deflate_data(deflater) def decompress(string, wbits=0, bufsize=16384): inflater = Inflater(wbits < 0) - inflater.setInput(string) + inflater.setInput(_to_input(string)) return _get_inflate_data(inflater) @@ -84,6 +87,7 @@ def compress(self, string): if self._ended: raise error("compressobj may not be used after flush(Z_FINISH)") + string = _to_input(string) self.deflater.setInput(string, 0, len(string)) return _get_deflate_data(self.deflater) @@ -123,6 +127,7 @@ if max_length < 0: raise ValueError("max_length must be a positive integer") + string = _to_input(string) self.inflater.setInput(string) inflated = _get_inflate_data(self.inflater, max_length) @@ -146,6 +151,8 @@ self.inflater.end() return last +def _to_input(string): + return string.tostring() if isinstance(string, array.array) else string def _get_deflate_data(deflater): buf = jarray.zeros(1024, 'b') Modified: branches/indy/NEWS =================================================================== --- branches/indy/NEWS 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/NEWS 2009-10-01 01:16:13 UTC (rev 6817) @@ -1,5 +1,22 @@ Jython NEWS +Jython 2.5.1rc3 + Bugs Fixed + - [ 1466 ] wrong handling of append only files + +Jython 2.5.1rc2 + New Features + - zxJDBC supports the with-statement: connections are committed or rollbacked; cursors are closed + Bugs Fixed + - [ 1079 ] fixed regression on issue: twisted.python.threadable module: missing attribute '_RLock' + - [ 1461 ] assert statement should lookup AssertionError using getglobal + - [ 1425 ] distutils/util.py assumes too much posix + - [ 1457 ] Cannot write an array in a file opened in r+b mode. + - [ 1382 ] __cmp__ on certain types raises ArrayStoreException + - [ 1443 ] Can't update() hashlib.sha1() with array.array('c') + - [ 1444 ] Can't zlib.compress() with array.array('c') + - [ 1458 ] Builtin codecs aren't available without standard lib + Jython 2.5.1rc1 New Features - Upgraded to ANTLR 3.1.3 Modified: branches/indy/README.txt =================================================================== --- branches/indy/README.txt 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/README.txt 2009-10-01 01:16:13 UTC (rev 6817) @@ -1,10 +1,10 @@ -Welcome to Jython 2.5.1rc1 -========================== +Welcome to Jython 2.5.1 Final +============================= -This is the first release candidate of the 2.5.1 version of Jython. This -release fixes a number of bugs, including some major errors when using -coroutines and when using relative imports. Please see the NEWS file for -detailed release notes. +This is the final release of the 2.5.1 version of Jython. This release fixes a +number of bugs, including some major errors when using coroutines and when +using relative imports, as well as a potential data loss bug when writing to +files in append mode. Please see the NEWS file for detailed release notes. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. Modified: branches/indy/build.xml =================================================================== --- branches/indy/build.xml 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/build.xml 2009-10-01 01:16:13 UTC (rev 6817) @@ -129,8 +129,8 @@ <property name="jython.major_version" value="2"/> <property name="jython.minor_version" value="5"/> <property name="jython.micro_version" value="1"/> - <property name="jython.release_level" value="${PY_RELEASE_LEVEL_GAMMA}"/> - <property name="jython.release_serial" value="1"/> + <property name="jython.release_level" value="${PY_RELEASE_LEVEL_FINAL}"/> + <property name="jython.release_serial" value="0"/> <condition property="do.snapshot.build"> <isset property="snapshot.revision" /> @@ -679,7 +679,7 @@ source="${jdk.source.version}" public="true" breakiterator="yes" - packagenames="org.python.core, org.python.util, com.ziclix.python.sql" + packagenames="org.python.core.*, org.python.util.*, org.python.modules.*, com.ziclix.python.sql, com.xhaus.modjy" windowtitle="Jython API documentation" bottom="<a href='http://www.jython.org' target='_top'>Jython homepage</a>" > Property changes on: branches/indy/extlibs/xercesImpl-2.9.1.jar ___________________________________________________________________ Modified: svn:mergeinfo - /branches/newstyle-java-types/extlibs/xercesImpl.jar:5564-5663,5666-5729 /trunk/jython/extlibs/xercesImpl-2.9.1.jar:6662-6741 + /branches/newstyle-java-types/extlibs/xercesImpl.jar:5564-5663,5666-5729 /trunk/jython/extlibs/xercesImpl-2.9.1.jar:6662-6741,6762-6814 Modified: branches/indy/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- branches/indy/src/com/ziclix/python/sql/PyConnection.java 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/src/com/ziclix/python/sql/PyConnection.java 2009-10-01 01:16:13 UTC (rev 6817) @@ -17,6 +17,7 @@ import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyBuiltinMethodSet; +import org.python.core.PyException; import org.python.core.PyInteger; import org.python.core.PyList; import org.python.core.PyObject; @@ -24,7 +25,10 @@ import org.python.core.PyUnicode; import com.ziclix.python.sql.util.PyArgParser; +import org.python.core.ContextManager; +import org.python.core.ThreadState; + /** * A connection to the database. * @@ -32,7 +36,7 @@ * @author last revised by $Author$ * @version $Revision$ */ -public class PyConnection extends PyObject implements ClassDictInit { +public class PyConnection extends PyObject implements ClassDictInit, ContextManager { /** True if closed. */ protected boolean closed; @@ -40,6 +44,9 @@ /** Whether transactions are supported. */ protected boolean supportsTransactions; + /** Whether multiple ResultSets are supported. */ + protected boolean supportsMultipleResultSets; + /** The underlying java.sql.Connection. */ protected Connection connection; @@ -90,6 +97,8 @@ this.connection = connection; this.statements = new HashSet<PyStatement>(); this.supportsTransactions = this.connection.getMetaData().supportsTransactions(); + this.supportsMultipleResultSets = + this.connection.getMetaData().supportsMultipleResultSets(); if (this.supportsTransactions) { this.connection.setAutoCommit(false); @@ -132,6 +141,8 @@ zxJDBC.getString("rollback"))); dict.__setitem__("nativesql", new ConnectionFunc("nativesql", 4, 1, 1, zxJDBC.getString("nativesql"))); + dict.__setitem__("__enter__", new ConnectionFunc("__enter__", 5, 0, 0, "__enter__")); + dict.__setitem__("__exit__", new ConnectionFunc("__exit__", 6, 3, 3, "__exit__")); // hide from python dict.__setitem__("initModule", null); @@ -416,6 +427,33 @@ } return this.statements.contains(statement); } + + public PyObject __enter__(ThreadState ts) { + return this; + } + + public PyObject __enter__() { + return this; + } + + public boolean __exit__(ThreadState ts, PyException exception) { + if (exception == null) { + commit(); + } else { + rollback(); + } + return false; + } + + public boolean __exit__(PyObject type, PyObject value, PyObject traceback) { + if (type == null || type == Py.None) { + commit(); + } else { + rollback(); + } + return false; + } + } class ConnectionFunc extends PyBuiltinMethodSet { @@ -439,6 +477,8 @@ case 3: c.rollback(); return Py.None; + case 5: + return c.__enter__(); default: throw info.unexpectedCall(0, false); } @@ -463,6 +503,8 @@ switch (index) { case 2: return c.cursor(arg1.__nonzero__(), arg2, arg3); + case 6: + return Py.newBoolean(c.__exit__(arg1, arg2, arg3)); default: throw info.unexpectedCall(3, false); } Modified: branches/indy/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- branches/indy/src/com/ziclix/python/sql/PyCursor.java 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/src/com/ziclix/python/sql/PyCursor.java 2009-10-01 01:16:13 UTC (rev 6817) @@ -26,7 +26,10 @@ import org.python.core.PyUnicode; import com.ziclix.python.sql.util.PyArgParser; +import org.python.core.ContextManager; +import org.python.core.ThreadState; + /** * These objects represent a database cursor, which is used to manage the * context of a fetch operation. @@ -35,7 +38,7 @@ * @author last revised by $Author$ * @version $Revision$ */ -public class PyCursor extends PyObject implements ClassDictInit, WarningListener { +public class PyCursor extends PyObject implements ClassDictInit, WarningListener, ContextManager { /** Field fetch */ protected Fetch fetch; @@ -260,6 +263,8 @@ dict.__setitem__("scroll", new CursorFunc("scroll", 10, 1, 2, "scroll the cursor in the result set to a new position according to mode")); dict.__setitem__("write", new CursorFunc("write", 11, 1, "execute the sql written to this file-like object")); dict.__setitem__("prepare", new CursorFunc("prepare", 12, 1, "prepare the sql statement for later execution")); + dict.__setitem__("__enter__", new CursorFunc("__enter__", 13, 0, 0, "__enter__")); + dict.__setitem__("__exit__", new CursorFunc("__exit__", 14, 3, 3, "__exit__")); // hide from python dict.__setitem__("classDictInit", null); @@ -482,15 +487,11 @@ throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); } - } catch (PyException e) { - throw e; - } catch (Throwable e) { - throw zxJDBC.makeException(e); - } finally { - if (this.statement != null) { - // close what we opened - this.statement.close(); + } catch (Throwable t) { + if (statement != null) { + statement.close(); } + throw zxJDBC.makeException(t); } } @@ -584,17 +585,12 @@ this.execute(Py.None, Py.None); } } - } catch (PyException e) { - throw e; - } catch (Throwable e) { - throw zxJDBC.makeException(zxJDBC.Error, e, rowIndex); - } finally { - if (this.statement != null) { + } catch (Throwable t) { + if (statement != null && !(sql instanceof PyStatement)) { // only close static, single-use statements - if (!(sql instanceof PyStatement) && !this.dynamicFetch) { - this.statement.close(); - } + statement.close(); } + throw zxJDBC.makeException(zxJDBC.Error, t, rowIndex); } } @@ -605,18 +601,12 @@ protected void execute(PyObject params, PyObject bindings) { try { Statement stmt = this.statement.statement; - this.datahandler.preExecute(stmt); // this performs the SQL execution and fetch per the Statement type this.statement.execute(this, params, bindings); - this.lastrowid = this.datahandler.getRowId(stmt); - - int uc = stmt.getUpdateCount(); - - this.updatecount = uc < 0 ? Py.None : Py.newInteger(uc); - + this.updateAttributes(stmt.getUpdateCount()); warning(new WarningEvent(this, stmt.getWarnings())); this.datahandler.postExecute(stmt); } catch (PyException e) { @@ -627,6 +617,17 @@ } /** + * Update the cursor's lastrowid and updatecount. + * + * @param updateCount The int value of updatecount + * @throws SQLException + */ + private void updateAttributes(int updateCount) throws SQLException { + lastrowid = datahandler.getRowId(statement.statement); + updatecount = updateCount < 0 ? Py.None : Py.newInteger(updateCount); + } + + /** * Fetch the next row of a query result set, returning a single sequence, * or None when no more data is available. * @@ -691,7 +692,28 @@ */ public PyObject nextset() { ensureOpen(); - return this.fetch.nextset(); + PyObject nextset = fetch.nextset(); + + // If the fetch is exhausted and multiple ResultSets are supported, try addding a + // next ResultSet. XXX: DynamicFetch currently isn't so tailored for this + if (!nextset.__nonzero__() && connection.supportsMultipleResultSets && !dynamicFetch) { + Statement stmt = statement.statement; + try { + boolean hasMoreResults; + int updateCount = -1; + if ((hasMoreResults = stmt.getMoreResults()) + || (updateCount = stmt.getUpdateCount()) != -1) { + // Only call getUpdateCount once, per its docs + updateAttributes(!hasMoreResults ? updateCount : stmt.getUpdateCount()); + fetch.add(stmt.getResultSet()); + nextset = Py.One; + } + } catch (SQLException sqle) { + throw zxJDBC.makeException(sqle); + } + } + + return nextset; } /** @@ -784,12 +806,9 @@ } if (this.statement != null) { - // we can't close a dynamic fetch statement until everything has been - // consumed so the only time we can clean up is now - // but if this is a previously prepared statement we don't want to close - // it underneath someone; we can check this by looking in the set + // Finally done with the Statement: only close it if we created it try { - if (this.dynamicFetch && !this.connection.contains(this.statement)) { + if (!this.connection.contains(this.statement)) { this.statement.close(); } } finally { @@ -870,6 +889,24 @@ throw zxJDBC.makeException(zxJDBC.ProgrammingError, "cursor is closed"); } } + + public PyObject __enter__(ThreadState ts) { + return this; + } + + public PyObject __enter__() { + return this; + } + + public boolean __exit__(ThreadState ts, PyException exception) { + close(); + return false; + } + + public boolean __exit__(PyObject type, PyObject value, PyObject traceback) { + close(); + return false; + } } class CursorFunc extends PyBuiltinMethodSet { @@ -897,6 +934,8 @@ return cursor.fetchone(); case 4 : return cursor.nextset(); + case 13 : + return cursor.__enter__(); default : throw info.unexpectedCall(0, false); } @@ -969,6 +1008,8 @@ case 9 : cursor.executemany(arga, argb, argc, Py.None); return Py.None; + case 14 : + return Py.newBoolean(cursor.__exit__(arga, argc, argc)); default : throw info.unexpectedCall(3, false); } Modified: branches/indy/src/org/python/antlr/PythonTree.java =================================================================== --- branches/indy/src/org/python/antlr/PythonTree.java 2009-10-01 01:13:04 UTC (rev 6816) +++ branches/indy/src/org/python/antlr/PythonTree.java 2009-10-01 01:16:13 UTC (rev 6817) @@ -16,22 +16,10 @@ private int charStartIndex = -1; private int charStopIndex = -1; private CommonTree node; + + /** Who is the parent node of this node; if null, implies node is root */ private PythonTree parent; - /** A single token is the payload */ - //private Token token; - - /** What token indexes bracket all tokens associated with this node - * and below? - */ - //protected int startIndex=-1, stopIndex=-1; - - /** Who is the parent node of this node; if null, implies node is root */ - //private PythonTree parent; - - /** What index is this node in the child list? Range: 0..n-1 */ - //private int childIndex = -1; - public PythonTree() { node = new CommonTree(); } @@ -60,73 +48,73 @@ charStartIndex = tree.getCharStartIndex(); charStopIndex = tree.getCharStopIndex(); } - + public CommonTree getNode() { return node; } - public Token getToken() { - return node.getToken(); - } + public Token getToken() { + return node.getToken(); + } - public PythonTree dupNode() { - return new PythonTree(this); - } + public PythonTree dupNode() { + return new PythonTree(this); + } - public boolean isNil() { - return node.isNil(); - } + public boolean isNil() { + return node.isNil(); + } - public int getAntlrType() { - return node.getType(); - } + public int getAntlrType() { + return node.getType(); + } - public String getText() { - return node.getText(); - } + public String getText() { + return node.getText(); + } - public int getLine() { - if (node.getToken()==null || node.getToken().getLine()==0) { - if ( getChildCount()>0 ) { - return getChild(0).getLine(); - } - return 1; - } - return node.getToken().getLine(); - } + public int getLine() { + if (node.getToken()==null || node.getToken().getLine()==0) { + if ( getChildCount()>0 ) { + return getChild(0).getLine(); + } + return 1; + } + return node.getToken().getLine(); + } - public int getCharPositionInLine() { + public int getCharPositionInLine() { Token token = node.getToken(); - if (token==null || token.getCharPositionInLine()==-1) { - if (getChildCount()>0) { - return getChild(0).getCharPositionInLine(); - } - return 0; - } else if (token != null && token.getCharPositionInLine() == -2) { + if (token==null || token.getCharPositionInLine()==-1) { + if (getChildCount()>0) { + return getChild(0).getCharPositionInLine(); + } + return 0; + } else if (token != null && token.getCharPositionInLine() == -2) { //XXX: yucky fix because CPython's ast uses -1 as a real value // for char pos in certain circumstances (for example, the // char pos of multi-line strings. I would just use -1, // but ANTLR is using -1 in special ways also. return -1; } - return token.getCharPositionInLine(); - } + return token.getCharPositionInLine(); + } - public int getTokenStartIndex() { + public int getTokenStartIndex() { return node.getTokenStartIndex(); - } + } - public void setTokenStartIndex(int index) { - node.setTokenStartIndex(index); - } + public void setTokenStartIndex(int index) { + node.setTokenStartIndex(index); + } - public int getTokenStopIndex() { + public int getTokenStopIndex() { return node.getTokenStopIndex(); - } + } - public void setTokenStopIndex(int index) { - node.setTokenStopIndex(index); - } + public void setTokenStopIndex(int index) { + node.setTokenStopIndex(index); + } public int getCharStartIndex() { if (charStartIndex == -1 && node.getToken() != null) { @@ -160,33 +148,33 @@ charStopIndex = index; } - public int getChildIndex() { - return node.getChildIndex(); - } + public int getChildIndex() { + return node.getChildIndex(); + } - public PythonTree getParent() { - return parent; - } + public PythonTree getParent() { + return parent; + } - public void setParent(PythonTree t) { - this.parent = t; - } + public void setParent(PythonTree t) { + this.parent = t; + } - public void setChildIndex(int index) { - node.setChildIndex(index); - } + public void setChildIndex(int index) { + node.setChildIndex(index); + } @Override public String toString() { if (isNil()) { return "None"; } - if ( getAntlrType()==Token.INVALID_TOKEN_TYPE ) { - return "<errornode>"; - } - if ( node.getToken()==null ) { - return null; - } + if ( getAntlrType()==Token.INVALID_TOKEN_TYPE ) { + return "<errornode>"; + } + if ( node.getToken()==null ) { + return null; + } return node.getToken().getText() + "(" + this.getLine() + "," + this.getCharPositionInLine() + ")"; } @@ -251,203 +239,194 @@ } //XXX: From here down copied from org.antlr.runtime.tree.BaseTree - protected List<PythonTree> children; + protected List<PythonTree> children; - public PythonTree getChild(int i) { - if ( children==null || i>=children.size() ) { - return null; - } - return children.get(i); - } + public PythonTree getChild(int i) { + if ( children==null || i>=children.size() ) { + return null; + } + return children.get(i); + } - /** Get the children internal List; note that if you directly mess with - * the list, do so at your own risk. - */ - public List<PythonTree> getChildren() { - return children; - } + /** Get the children internal List; note that if you directly mess with + * the list, do so at your own risk. + */ + public List<PythonTree> getChildren() { + return children; + } - public PythonTree getFirstChildWithType(int type) { - for (int i = 0; children!=null && i < children.size(); i++) { - PythonTree t = children.get(i); - if ( t.getAntlrType()==type ) { - return t; - } - } - return null; - } + public PythonTree getFirstChildWithType(int type) { + for (int i = 0; children!=null && i < children.size(); i++) { + PythonTree t = children.get(i); + if ( t.getAntlrType()==type ) { + return t; + } + } + return null; + } - public int getChildCount() { - if ( children==null ) { - return 0; - } - return children.size(); - } + public int getChildCount() { + if ( children==null ) { + return 0; + } + return children.size(); + } - /** Add t as child of this node. - * - * Warning: if t has no children, but child does - * and child isNil then this routine moves children to t via - * t.children = child.children; i.e., without copying the array. - */ - public void addChild(PythonTree t) { - //System.out.println("add child "+t.toStringTree()+" "+this.toStringTree()); - //System.out.println("existing children: "+children); - if ( t==null ) { - return; // do nothing upon addChild(null) - } - PythonTree childTree = t; - if ( childTree.isNil() ) { // t is an empty node possibly with children - if ( this.children!=null && this.children == childTree.children ) { - throw new RuntimeException("attempt to add child list to itself"); - } - // just add all of childTree's children to this - if ( childTree.children!=null ) { - if ( this.children!=null ) { // must copy, this has children already - int n = childTree.children.size(); - for (int i = 0; i < n; i++) { - PythonTree c = childTree.children.get(i); - this.children.add(c); - // handle double-link stuff for each child of nil root - c.setParent(this); - c.setChildIndex(children.size()-1); - } - } - else { - // no children for this but t has children; just set pointer - // call general freshener routine - this.children = childTree.children; - this.freshenParentAndChildIndexes(); - } - } - } - else { // child is not nil (don't care about children) - if ( children==null ) { - children = createChildrenList(); // create children list on demand - } - children.add(t); - childTree.setParent(this); - childTree.setChildIndex(children.size()-1); - } - // System.out.println("now children are: "+children); - } + /** Add t as child of this node. + * + * Warning: if t has no children, but child does + * and child isNil then this routine moves children to t via + * t.children = child.children; i.e., without copying the array. + */ + public void addChild(PythonTree t) { + if ( t==null ) { + return; // do nothing upon addChild(null) + } + PythonTree childTree = t; + if ( childTree.isNil() ) { // t is an empty node possibly with children + if ( this.children!=null && this.children == childTree.children ) { + throw new RuntimeException("attempt to add child list to itself"); + } + // just add all of childTree's children to this + if ( childTree.children!=null ) { + if ( this.children!=null ) { // must copy, this has children already + int n = childTree.children.size(); + for (int i = 0; i < n; i++) { + PythonTree c = childTree.children.get(i); + this.children.add(c); + // handle double-link stuff for each child of nil root + c.setParent(this); + c.setChildIndex(children.size()-1); + } + } + else { + // no children for this but t has children; just set pointer + // call general freshener routine + this.children = childTree.children; + this.freshenParentAndChildIndexes(); + } + } + } + else { // child is not nil (don't care about children) + if ( children==null ) { + children = createChildrenList(); // create children list on demand + } + children.add(t); + childTree.setParent(this); + childTree.setChildIndex(children.size()-1); + } + } - /** Add all elements of kids list as children of this node */ - public void addChildren(List<PythonTree> kids) { - for (int i = 0; i < kids.size(); i++) { - PythonTree t = kids.get(i); - addChild(t); - } - } + /** Add all elements of kids list as children of this node */ + public void addChildren(List<PythonTree> kids) { + for (int i = 0; i < kids.size(); i++) { + PythonTree t = kids.get(i); + addChild(t); + } + } - public void setChild(int i, PythonTree t) { - if ( t==null ) { - return; - } - if ( t.isNil() ) { - throw new IllegalArgumentException("Can't set single child to a list"); - } - if ( children==null ) { - children = createChildrenList(); - } - children.set(i, t); - t.setParent(this); - t.setChildIndex(i); - } - - public Object deleteChild(int i) { - if ( children==null ) { - return null; - } - PythonTree killed = children.remove(i); - // walk rest and decrement their child indexes - this.freshenParentAndChildIndexes(i); - return killed; - } + public void setChild(int i, PythonTree t) { + if ( t==null ) { + return; + } + if ( t.isNil() ) { + throw new IllegalArgumentException("Can't set single child to a list"); + } + if ( children==null ) { + children = createChildrenList(); + } + children.set(i, t); + t.setParent(this); + t.setChildIndex(i); + } + + public Object deleteChild(int i) { + if ( children==null ) { + return null; + } + PythonTree killed = children.remove(i); + // walk rest and decrement their child indexes + this.freshenParentAndChildIndexes(i); + return killed; + } - /** Delete children from start to stop and replace with t even if t is - * a list (nil-root tree). num of children can increase or decrease. - * For huge child lists, inserting children can force walking rest of - * children to set their childindex; could be slow. - */ - public void replaceChildren(int startChildIndex, int stopChildIndex, Object t) { - /* - System.out.println("replaceChildren "+startChildIndex+", "+stopChildIndex+ - " with "+((PythonTree)t).toStringTree()); - System.out.println("in="+toStringTree()); - */ - if ( children==null ) { - throw new IllegalArgumentException("indexes invalid; no children in list"); - } - int replacingHowMany = stopChildIndex - startChildIndex + 1; - int replacingWithHowMany; - PythonTree newTree = (PythonTree)t; - List<PythonTree> newChildren = null; - // normalize to a list of c... [truncated message content] |