From: <fwi...@us...> - 2008-05-30 03:28:43
|
Revision: 4487 http://jython.svn.sourceforge.net/jython/?rev=4487&view=rev Author: fwierzbicki Date: 2008-05-29 20:28:32 -0700 (Thu, 29 May 2008) Log Message: ----------- Merged revisions 4473,4475-4486 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r4473 | pjenvey | 2008-05-29 15:24:41 -0400 (Thu, 29 May 2008) | 1 line don't consider tests skipped due to ResourceDenied as unexpected ........ r4475 | pjenvey | 2008-05-29 17:37:07 -0400 (Thu, 29 May 2008) | 6 lines fix intermittent failures in test_select_new: o allow socket.connect_ex to be called multiple times o since we're using connect_ex for an asynchronous connects, don't assume it's immediately ready in finish_connect o same idea for server accept: don't assume it's immediately acceptable ........ r4476 | pjenvey | 2008-05-29 18:39:00 -0400 (Thu, 29 May 2008) | 1 line revert part of r4409: Java 6 disallows the exposed method access to the private base ........ r4477 | pjenvey | 2008-05-29 18:51:31 -0400 (Thu, 29 May 2008) | 1 line use String.format ........ r4478 | pjenvey | 2008-05-29 18:52:21 -0400 (Thu, 29 May 2008) | 1 line be more efficient with memory in the generic readall ........ r4479 | pjenvey | 2008-05-29 18:56:22 -0400 (Thu, 29 May 2008) | 1 line expect test_ast to fail for now, until we actually include antlr-runtime ........ r4480 | pjenvey | 2008-05-29 20:34:42 -0400 (Thu, 29 May 2008) | 3 lines UserString.py from http://svn.python.org/projects/python/branches/release25-maint/Lib/UserString.py@46876 ........ r4481 | pjenvey | 2008-05-29 20:35:40 -0400 (Thu, 29 May 2008) | 4 lines add str/unicode partition/rpartition fixes #1796272, 1797751 thanks ukeshav ........ r4482 | nriley | 2008-05-29 22:47:57 -0400 (Thu, 29 May 2008) | 1 line clean up start script, add test script, tested on Mac OS X/Linux/Solaris/Cygwin ........ r4483 | nriley | 2008-05-29 22:52:24 -0400 (Thu, 29 May 2008) | 1 line remove debugging, interferes with help ........ r4484 | nriley | 2008-05-29 22:56:23 -0400 (Thu, 29 May 2008) | 1 line fix help sort order ........ r4485 | fwierzbicki | 2008-05-29 23:13:31 -0400 (Thu, 29 May 2008) | 2 lines Added line numbers and column to ast display. ........ r4486 | fwierzbicki | 2008-05-29 23:21:14 -0400 (Thu, 29 May 2008) | 2 lines Fix lineno/col for yield. ........ Modified Paths: -------------- branches/asm/Lib/socket.py branches/asm/Lib/test/regrtest.py branches/asm/Lib/test/string_tests.py branches/asm/Lib/test/test_select_new.py branches/asm/Lib/test/test_set.py branches/asm/ast/astview.py branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g branches/asm/src/org/python/core/PyString.java branches/asm/src/org/python/core/PyType.java branches/asm/src/org/python/core/PyUnicode.java branches/asm/src/org/python/core/io/IOBase.java branches/asm/src/org/python/core/io/RawIOBase.java branches/asm/src/shell/jython Added Paths: ----------- branches/asm/Lib/UserString.py branches/asm/tests/shell/ branches/asm/tests/shell/test-jython.sh Removed Paths: ------------- branches/asm/tests/shell/test-jython.sh Property Changed: ---------------- branches/asm/ Property changes on: branches/asm ___________________________________________________________________ Name: svnmerge-integrated - /trunk/jython:1-4471 + /trunk/jython:1-4486 Copied: branches/asm/Lib/UserString.py (from rev 4486, trunk/jython/Lib/UserString.py) =================================================================== --- branches/asm/Lib/UserString.py (rev 0) +++ branches/asm/Lib/UserString.py 2008-05-30 03:28:32 UTC (rev 4487) @@ -0,0 +1,194 @@ +#!/usr/bin/env python +## vim:ts=4:et:nowrap +"""A user-defined wrapper around string objects + +Note: string objects have grown methods in Python 1.6 +This module requires Python 1.6 or later. +""" +import sys + +__all__ = ["UserString","MutableString"] + +class UserString: + def __init__(self, seq): + if isinstance(seq, basestring): + self.data = seq + elif isinstance(seq, UserString): + self.data = seq.data[:] + else: + self.data = str(seq) + def __str__(self): return str(self.data) + def __repr__(self): return repr(self.data) + def __int__(self): return int(self.data) + def __long__(self): return long(self.data) + def __float__(self): return float(self.data) + def __complex__(self): return complex(self.data) + def __hash__(self): return hash(self.data) + + def __cmp__(self, string): + if isinstance(string, UserString): + return cmp(self.data, string.data) + else: + return cmp(self.data, string) + def __contains__(self, char): + return char in self.data + + def __len__(self): return len(self.data) + def __getitem__(self, index): return self.__class__(self.data[index]) + def __getslice__(self, start, end): + start = max(start, 0); end = max(end, 0) + return self.__class__(self.data[start:end]) + + def __add__(self, other): + if isinstance(other, UserString): + return self.__class__(self.data + other.data) + elif isinstance(other, basestring): + return self.__class__(self.data + other) + else: + return self.__class__(self.data + str(other)) + def __radd__(self, other): + if isinstance(other, basestring): + return self.__class__(other + self.data) + else: + return self.__class__(str(other) + self.data) + def __mul__(self, n): + return self.__class__(self.data*n) + __rmul__ = __mul__ + def __mod__(self, args): + return self.__class__(self.data % args) + + # the following methods are defined in alphabetical order: + def capitalize(self): return self.__class__(self.data.capitalize()) + def center(self, width, *args): + return self.__class__(self.data.center(width, *args)) + def count(self, sub, start=0, end=sys.maxint): + return self.data.count(sub, start, end) + def decode(self, encoding=None, errors=None): # XXX improve this? + if encoding: + if errors: + return self.__class__(self.data.decode(encoding, errors)) + else: + return self.__class__(self.data.decode(encoding)) + else: + return self.__class__(self.data.decode()) + def encode(self, encoding=None, errors=None): # XXX improve this? + if encoding: + if errors: + return self.__class__(self.data.encode(encoding, errors)) + else: + return self.__class__(self.data.encode(encoding)) + else: + return self.__class__(self.data.encode()) + def endswith(self, suffix, start=0, end=sys.maxint): + return self.data.endswith(suffix, start, end) + def expandtabs(self, tabsize=8): + return self.__class__(self.data.expandtabs(tabsize)) + def find(self, sub, start=0, end=sys.maxint): + return self.data.find(sub, start, end) + def index(self, sub, start=0, end=sys.maxint): + return self.data.index(sub, start, end) + def isalpha(self): return self.data.isalpha() + def isalnum(self): return self.data.isalnum() + def isdecimal(self): return self.data.isdecimal() + def isdigit(self): return self.data.isdigit() + def islower(self): return self.data.islower() + def isnumeric(self): return self.data.isnumeric() + def isspace(self): return self.data.isspace() + def istitle(self): return self.data.istitle() + def isupper(self): return self.data.isupper() + def join(self, seq): return self.data.join(seq) + def ljust(self, width, *args): + return self.__class__(self.data.ljust(width, *args)) + def lower(self): return self.__class__(self.data.lower()) + def lstrip(self, chars=None): return self.__class__(self.data.lstrip(chars)) + def partition(self, sep): + return self.data.partition(sep) + def replace(self, old, new, maxsplit=-1): + return self.__class__(self.data.replace(old, new, maxsplit)) + def rfind(self, sub, start=0, end=sys.maxint): + return self.data.rfind(sub, start, end) + def rindex(self, sub, start=0, end=sys.maxint): + return self.data.rindex(sub, start, end) + def rjust(self, width, *args): + return self.__class__(self.data.rjust(width, *args)) + def rpartition(self, sep): + return self.data.rpartition(sep) + def rstrip(self, chars=None): return self.__class__(self.data.rstrip(chars)) + def split(self, sep=None, maxsplit=-1): + return self.data.split(sep, maxsplit) + def rsplit(self, sep=None, maxsplit=-1): + return self.data.rsplit(sep, maxsplit) + def splitlines(self, keepends=0): return self.data.splitlines(keepends) + def startswith(self, prefix, start=0, end=sys.maxint): + return self.data.startswith(prefix, start, end) + def strip(self, chars=None): return self.__class__(self.data.strip(chars)) + def swapcase(self): return self.__class__(self.data.swapcase()) + def title(self): return self.__class__(self.data.title()) + def translate(self, *args): + return self.__class__(self.data.translate(*args)) + def upper(self): return self.__class__(self.data.upper()) + def zfill(self, width): return self.__class__(self.data.zfill(width)) + +class MutableString(UserString): + """mutable string objects + + Python strings are immutable objects. This has the advantage, that + strings may be used as dictionary keys. If this property isn't needed + and you insist on changing string values in place instead, you may cheat + and use MutableString. + + But the purpose of this class is an educational one: to prevent + people from inventing their own mutable string class derived + from UserString and than forget thereby to remove (override) the + __hash__ method inherited from UserString. This would lead to + errors that would be very hard to track down. + + A faster and better solution is to rewrite your program using lists.""" + def __init__(self, string=""): + self.data = string + def __hash__(self): + raise TypeError, "unhashable type (it is mutable)" + def __setitem__(self, index, sub): + if index < 0: + index += len(self.data) + if index < 0 or index >= len(self.data): raise IndexError + self.data = self.data[:index] + sub + self.data[index+1:] + def __delitem__(self, index): + if index < 0: + index += len(self.data) + if index < 0 or index >= len(self.data): raise IndexError + self.data = self.data[:index] + self.data[index+1:] + def __setslice__(self, start, end, sub): + start = max(start, 0); end = max(end, 0) + if isinstance(sub, UserString): + self.data = self.data[:start]+sub.data+self.data[end:] + elif isinstance(sub, basestring): + self.data = self.data[:start]+sub+self.data[end:] + else: + self.data = self.data[:start]+str(sub)+self.data[end:] + def __delslice__(self, start, end): + start = max(start, 0); end = max(end, 0) + self.data = self.data[:start] + self.data[end:] + def immutable(self): + return UserString(self.data) + def __iadd__(self, other): + if isinstance(other, UserString): + self.data += other.data + elif isinstance(other, basestring): + self.data += other + else: + self.data += str(other) + return self + def __imul__(self, n): + self.data *= n + return self + +if __name__ == "__main__": + # execute the regression test to stdout, if called as a script: + import os + called_in_dir, called_as = os.path.split(sys.argv[0]) + called_as, py = os.path.splitext(called_as) + if '-q' in sys.argv: + from test import test_support + test_support.verbose = 0 + __import__('test.test_' + called_as.lower()) Modified: branches/asm/Lib/socket.py =================================================================== --- branches/asm/Lib/socket.py 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/Lib/socket.py 2008-05-30 03:28:32 UTC (rev 4487) @@ -624,7 +624,8 @@ def connect_ex(self, addr): "This signifies a client socket" - self._do_connect(addr) + if not self.sock_impl: + self._do_connect(addr) if self.sock_impl.finish_connect(): self._setup() return 0 Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/Lib/test/regrtest.py 2008-05-30 03:28:32 UTC (rev 4487) @@ -293,6 +293,7 @@ good = [] bad = [] skipped = [] + resource_denieds = [] if findleaks: try: @@ -367,6 +368,8 @@ bad.append(test) else: skipped.append(test) + if ok == -2: + resource_denieds.append(test) if findleaks: gc.collect() if gc.garbage: @@ -397,10 +400,10 @@ surprises = 0 if skipped and not quiet: print count(len(skipped), "test"), "skipped:" - surprises += countsurprises(skips, skipped, 'skip', 'ran', allran) + surprises += countsurprises(skips, skipped, 'skip', 'ran', allran, resource_denieds) if bad: print count(len(bad), "test"), "failed:" - surprises += countsurprises(failures, bad, 'fail', 'passed', allran) + surprises += countsurprises(failures, bad, 'fail', 'passed', allran, resource_denieds) if memo: savememo(memo,good,bad,skipped) @@ -472,6 +475,11 @@ indirect_test() finally: sys.stdout = save_stdout + except test_support.ResourceDenied, msg: + if not quiet: + print test, "skipped --", msg + sys.stdout.flush() + return -2 except (ImportError, test_support.TestSkipped), msg: if not quiet: print test, "skipped --", msg @@ -604,7 +612,7 @@ if len(line) > indent: print line -def countsurprises(expected, actual, action, antiaction, allran): +def countsurprises(expected, actual, action, antiaction, allran, resource_denieds): """returns the number of items in actual that aren't in expected.""" printlist(actual) if not expected.isvalid(): @@ -615,7 +623,7 @@ if allran and good_surprise: print count(len(good_surprise), 'test'), antiaction, 'unexpectedly:' printlist(good_surprise) - bad_surprise = set(actual) - expected.getexpected() + bad_surprise = set(actual) - expected.getexpected() - set(resource_denieds) if bad_surprise: print count(len(bad_surprise), action), "unexpected:" printlist(bad_surprise) @@ -1018,6 +1026,7 @@ _failures = { 'java': ''' + test_ast test_class test_copy test_dis Modified: branches/asm/Lib/test/string_tests.py =================================================================== --- branches/asm/Lib/test/string_tests.py 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/Lib/test/string_tests.py 2008-05-30 03:28:32 UTC (rev 4487) @@ -590,6 +590,34 @@ else: self.checkcall(format, "__mod__", value) + def test_partition(self): + self.checkequal(('this is the par', 'ti', 'tion method'), + 'this is the partition method', 'partition', 'ti') + + # from raymond's original specification + S = 'http://www.python.org' + self.checkequal(('http', '://', 'www.python.org'), S, 'partition', '://') + self.checkequal(('http://www.python.org', '', ''), S, 'partition', '?') + self.checkequal(('', 'http://', 'www.python.org'), S, 'partition', 'http://') + self.checkequal(('http://www.python.', 'org', ''), S, 'partition', 'org') + + self.checkraises(ValueError, S, 'partition', '') + self.checkraises(TypeError, S, 'partition', None) + + def test_rpartition(self): + self.checkequal(('this is the rparti', 'ti', 'on method'), + 'this is the rpartition method', 'rpartition', 'ti') + + # from raymond's original specification + S = 'http://www.python.org' + self.checkequal(('http', '://', 'www.python.org'), S, 'rpartition', '://') + self.checkequal(('', '', 'http://www.python.org'), S, 'rpartition', '?') + self.checkequal(('', 'http://', 'www.python.org'), S, 'rpartition', 'http://') + self.checkequal(('http://www.python.', 'org', ''), S, 'rpartition', 'org') + + self.checkraises(ValueError, S, 'rpartition', '') + self.checkraises(TypeError, S, 'rpartition', None) + class MixinStrStringUserStringTest: # Additional tests for 8bit strings, i.e. str, UserString and # the string module Modified: branches/asm/Lib/test/test_select_new.py =================================================================== --- branches/asm/Lib/test/test_select_new.py 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/Lib/test/test_select_new.py 2008-05-30 03:28:32 UTC (rev 4487) @@ -2,6 +2,7 @@ AMAK: 20050515: This module is a brand new test_select module, which gives much wider coverage. """ +import errno import time import test_support import unittest @@ -46,7 +47,13 @@ return select.select([self.server_socket], [self.server_socket], [], SELECT_TIMEOUT)[0] def verify_acceptable(self): - assert self.select_acceptable(), "Server socket should be acceptable" + start = time.time() + while True: + if self.select_acceptable(): + return + elif (time.time() - start) > READ_TIMEOUT: + raise Exception('Server socket did not accept in time') + time.sleep(0.1) def verify_not_acceptable(self): assert not self.select_acceptable(), "Server socket should not be acceptable" @@ -143,10 +150,21 @@ result = self.socket.connect_ex(SERVER_ADDRESS) if result == 0: self.connected = 1 + else: + assert result == errno.EINPROGRESS def finish_connect(self): if self.connected: return + start = time.time() + while True: + self.start_connect() + if self.connected: + break + elif (time.time() - start) > READ_TIMEOUT: + raise Exception('Client socket incomplete connect') + time.sleep(0.1) + rfds, wfds, xfds = select.select([], [self.socket], [], SELECT_TIMEOUT) assert self.socket in wfds, "Client socket incomplete connect" Modified: branches/asm/Lib/test/test_set.py =================================================================== --- branches/asm/Lib/test/test_set.py 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/Lib/test/test_set.py 2008-05-30 03:28:32 UTC (rev 4487) @@ -261,10 +261,7 @@ w = ReprWrapper() s = self.thetype([w]) w.value = s - # XXX: Jython doesn't have str.partition yet - #name = repr(s).partition('(')[0] # strip class name from repr string - srepr = repr(s) - name = srepr[0:srepr.find('(')] + name = repr(s).partition('(')[0] # strip class name from repr string self.assertEqual(repr(s), '%s([%s(...)])' % (name, name)) def test_cyclical_print(self): Modified: branches/asm/ast/astview.py =================================================================== --- branches/asm/ast/astview.py 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/ast/astview.py 2008-05-30 03:28:32 UTC (rev 4487) @@ -37,11 +37,16 @@ get_symbol_key = type get_class_name = lambda node: node.__class__.__name__ +get_lines_and_cols = True + def lispify_ast(node): return tuple(lispify_ast2(node)) def lispify_ast2(node): - yield get_class_name(node) + result = get_class_name(node) + if get_lines_and_cols and hasattr(node, 'lineno') and hasattr(node, 'col_offset'): + result = "%s (%s,%s)" % (result, node.lineno, node.col_offset) + yield result#get_class_name(node)#result try: for field in node._fields: yield tuple(lispify_field(field, getattr(node, field))) Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/grammar/Python.g 2008-05-30 03:28:32 UTC (rev 4487) @@ -870,7 +870,7 @@ //yield_expr: 'yield' [testlist] yield_expr : 'yield' testlist? - -> ^(Yield ^(Value testlist)?) + -> ^(Yield 'yield' ^(Value testlist)?) ; //XXX: Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/grammar/PythonWalker.g 2008-05-30 03:28:32 UTC (rev 4487) @@ -686,12 +686,12 @@ ; yield_expr returns [exprType etype] - : ^(Yield (^(Value test[expr_contextType.Load]))?) { + : ^(Yield tok='yield' (^(Value test[expr_contextType.Load]))?) { exprType v = null; if ($Value != null) { v = $test.etype; } - $etype = new Yield($Yield, v); + $etype = new Yield($tok, v); } ; Modified: branches/asm/src/org/python/core/PyString.java =================================================================== --- branches/asm/src/org/python/core/PyString.java 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/src/org/python/core/PyString.java 2008-05-30 03:28:32 UTC (rev 4487) @@ -1063,6 +1063,108 @@ return list; } + public PyTuple partition(PyObject sepObj) { + return str_partition(sepObj); + } + + @ExposedMethod + final PyTuple str_partition(PyObject sepObj) { + String sep; + + if (sepObj instanceof PyUnicode) { + return unicodePartition(sepObj); + } else if (sepObj instanceof PyString) { + sep = ((PyString)sepObj).string; + } else { + throw Py.TypeError("expected a character buffer object"); + } + + if (sep.length() == 0) { + throw Py.ValueError("empty separator"); + } + + int index = string.indexOf(sep); + if (index != -1) { + return new PyTuple(fromSubstring(0, index), sepObj, + fromSubstring(index + sep.length(), string.length())); + } else { + return new PyTuple(this, Py.EmptyString, Py.EmptyString); + } + } + + final PyTuple unicodePartition(PyObject sepObj) { + PyUnicode strObj = __unicode__(); + String str = strObj.string; + + // Will throw a TypeError if not a basestring + String sep = sepObj.asString(); + sepObj = sepObj.__unicode__(); + + if (sep.length() == 0) { + throw Py.ValueError("empty separator"); + } + + int index = str.indexOf(sep); + if (index != -1) { + return new PyTuple(strObj.fromSubstring(0, index), sepObj, + strObj.fromSubstring(index + sep.length(), str.length())); + } else { + PyUnicode emptyUnicode = Py.newUnicode(""); + return new PyTuple(this, emptyUnicode, emptyUnicode); + } + } + + public PyTuple rpartition(PyObject sepObj) { + return str_rpartition(sepObj); + } + + @ExposedMethod + final PyTuple str_rpartition(PyObject sepObj) { + String sep; + + if (sepObj instanceof PyUnicode) { + return unicodePartition(sepObj); + } else if (sepObj instanceof PyString) { + sep = ((PyString)sepObj).string; + } else { + throw Py.TypeError("expected a character buffer object"); + } + + if (sep.length() == 0) { + throw Py.ValueError("empty separator"); + } + + int index = string.lastIndexOf(sep); + if (index != -1) { + return new PyTuple(fromSubstring(0, index), sepObj, + fromSubstring(index + sep.length(), string.length())); + } else { + return new PyTuple(Py.EmptyString, Py.EmptyString, this); + } + } + + final PyTuple unicodeRpartition(PyObject sepObj) { + PyUnicode strObj = __unicode__(); + String str = strObj.string; + + // Will throw a TypeError if not a basestring + String sep = sepObj.asString(); + sepObj = sepObj.__unicode__(); + + if (sep.length() == 0) { + throw Py.ValueError("empty separator"); + } + + int index = str.lastIndexOf(sep); + if (index != -1) { + return new PyTuple(strObj.fromSubstring(0, index), sepObj, + strObj.fromSubstring(index + sep.length(), str.length())); + } else { + PyUnicode emptyUnicode = Py.newUnicode(""); + return new PyTuple(emptyUnicode, emptyUnicode, this); + } + } + private PyList splitfields(String sep, int maxsplit) { PyList list = new PyList(); Modified: branches/asm/src/org/python/core/PyType.java =================================================================== --- branches/asm/src/org/python/core/PyType.java 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/src/org/python/core/PyType.java 2008-05-30 03:28:32 UTC (rev 4487) @@ -38,7 +38,6 @@ private String name; /** __base__, the direct base type or null. */ - @ExposedGet(name = "__base__") private PyType base; /** __bases__, the base classes. */ @@ -478,6 +477,13 @@ return base.getLayout(); } + @ExposedGet(name = "__base__") + public PyObject getBase() { + if (base == null) + return Py.None; + return base; + } + @ExposedGet(name = "__bases__") public PyObject getBases() { return new PyTuple(bases); Modified: branches/asm/src/org/python/core/PyUnicode.java =================================================================== --- branches/asm/src/org/python/core/PyUnicode.java 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/src/org/python/core/PyUnicode.java 2008-05-30 03:28:32 UTC (rev 4487) @@ -206,7 +206,16 @@ return new PyUnicode(str_rstrip(sep)); } + @ExposedMethod + final PyTuple unicode_partition(PyObject sep) { + return unicodePartition(sep); + } + @ExposedMethod + final PyTuple unicode_rpartition(PyObject sep) { + return unicodeRpartition(sep); + } + @ExposedMethod(defaults = {"null", "-1"}) final PyList unicode_split(String sep, int maxsplit) { return str_split(sep, maxsplit); Modified: branches/asm/src/org/python/core/io/IOBase.java =================================================================== --- branches/asm/src/org/python/core/io/IOBase.java 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/src/org/python/core/io/IOBase.java 2008-05-30 03:28:32 UTC (rev 4487) @@ -8,8 +8,8 @@ /** * Base class for all I/O classes. * - * IOBase and its descendents in org.python.core.io are loosely based - * off of Python 3000's new io module (PEP 3116). + * IOBase and its descendents in org.python.core.io are based off + * Python 3's new io module (PEP 3116). * * This does not define read(), readinto() and write(), nor readline() * and friends, since their signatures vary per layer. @@ -210,6 +210,6 @@ protected void unsupported(String methodName) { String qualifiedName = getClass().getName(); String className = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); - throw Py.TypeError(className + "." + methodName + "() not supported"); + throw Py.TypeError(String.format("%s.%s() not supported", className, methodName)); } } Modified: branches/asm/src/org/python/core/io/RawIOBase.java =================================================================== --- branches/asm/src/org/python/core/io/RawIOBase.java 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/src/org/python/core/io/RawIOBase.java 2008-05-30 03:28:32 UTC (rev 4487) @@ -3,9 +3,6 @@ import java.nio.ByteBuffer; import java.nio.channels.Channel; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import org.python.core.Py; @@ -58,27 +55,28 @@ * @return a ByteBuffer containing the bytes read */ public ByteBuffer readall() { - long count = 0; - List<ByteBuffer> chunks = new ArrayList<ByteBuffer>(); - while (true) { - ByteBuffer chunk = read(DEFAULT_BUFFER_SIZE); - int chunkSize = chunk.remaining(); - if (chunkSize == 0) { - break; + long allCount = 0; + int readCount = 0; + ByteBuffer all = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE); + ByteBuffer readBuffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE); + while ((readCount = readinto(readBuffer)) > 0) { + if (all.remaining() < readCount) { + ByteBuffer old = all; + all = ByteBuffer.allocate(Math.max(old.capacity() * 2, + old.position() + readCount)); + old.flip(); + all.put(old); } - chunks.add(chunk); - count += chunkSize; + readBuffer.flip(); + all.put(readBuffer); + readBuffer.clear(); } - if (count > Integer.MAX_VALUE) { + if (allCount > Integer.MAX_VALUE) { throw Py.OverflowError("requested number of bytes is more than a Python string can " + "hold"); } - ByteBuffer all = ByteBuffer.allocate((int)count); - for (ByteBuffer chunk : chunks) { - all.put(chunk); - } all.flip(); return all; } Modified: branches/asm/src/shell/jython =================================================================== --- branches/asm/src/shell/jython 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/src/shell/jython 2008-05-30 03:28:32 UTC (rev 4487) @@ -1,14 +1,14 @@ -#!/bin/bash +#!/bin/sh # ----------------------------------------------------------------------------- -# jython.sh - Start Script for the Jython +# jython.sh - start script for Jython (adapted from jruby.sh) # -# Adapted from jruby.sh +# Environment variables (optional) # -# Environment Variable Prequisites +# JAVA_HOME Java installation directory # -# JYTHON_OPTS (Optional) Default Jython command line args +# JYTHON_HOME Jython installation directory # -# JAVA_HOME Must point at your Java Development Kit installation. +# JYTHON_OPTS Default Jython command line arguments # # ----------------------------------------------------------------------------- @@ -16,27 +16,28 @@ # ----- Identify OS we are running under -------------------------------------- case "`uname`" in -CYGWIN*) cygwin=true + CYGWIN*) cygwin=true esac -# ----- Verify and Set Required Environment Variables ------------------------- +# ----- Verify and set required environment variables ------------------------- -## resolve links - $0 may be a link to home +## resolve links - $0 may be a link to home PRG=$0 -progname=`basename "$0"` while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '.*/.*' > /dev/null; then - PRG="$link" + PRG="$link" else - PRG="`dirname $PRG`/$link" + PRG="`dirname $PRG`/$link" fi done -JYTHON_HOME_1=`dirname "$PRG"` # the ./bin dir -JYTHON_HOME=`dirname "$JYTHON_HOME_1"` # the . dir +if [ -z "$JYTHON_HOME" ] ; then + JYTHON_HOME_1=`dirname "$PRG"` # the ./bin dir + JYTHON_HOME=`dirname "$JYTHON_HOME_1"` # the . dir +fi if [ -z "$JYTHON_OPTS" ] ; then JYTHON_OPTS="" @@ -51,71 +52,99 @@ JAVA_CMD="$JAVA_HOME/bin/java" fi -CP_DELIMETER=":" +CP_DELIMITER=":" CP=$JYTHON_HOME/jython.jar +if [ ! -f "$CP" ]; then + echo "$0: '$CP' does not exist." >&2 + echo "Try running this script from the 'bin' directory of an installed Jython or " >&2 + echo 'setting $JYTHON_HOME.' >&2 + exit 1 +fi + # add necessary jars for command-line execution for j in "$JYTHON_HOME"/javalib/*.jar; do - if [ "$CP" ]; then - CP="$CP$CP_DELIMETER$j" - else - CP="$j" - fi + if [ "$CP" ]; then + CP="$CP$CP_DELIMITER$j" + else + CP="$j" + fi done if $cygwin; then - CP=`cygpath -p -w "$CP"` + CP=`cygpath -wp "$CP"` + PRG=`cygpath -w "$PRG"` fi -# ----- Execute The Requested Command ----------------------------------------- +# ----- Execute the requested command ----------------------------------------- -JAVA_MEM=-Xmx378m -JAVA_STACK=-Xss1024k +JAVA_STACK=-Xss512k # minimum requirement for test_cpickle # Split out any -J argument for passing to the JVM. # Scanning for args is aborted by '--'. -declare -a java_args -declare -a python_args - while [ $# -gt 0 ] -do - case "$1" in +while [ $# -gt 0 ] ; do + case "$1" in # Stuff after '-J' in this argument goes to JVM -J*) - val=${1:2} - if [ "${val:0:4}" = "-Xmx" ]; then - JAVA_MEM=$val - elif [ "${val:0:4}" = "-Xss" ]; then - JAVA_STACK=$val - else - java_args=("${java_args[@]}" "${1:2}") - fi - ;; - # Match switches that take an argument - -c|-D|-C|-jar|-Q|-W) python_args=("${python_args[@]}" "$1" "$2"); shift ;; - # Match -Dprop=val type args - -D*) python_args=("${python_args[@]}" "$1" ) ;; - # Run with the instrumented profiler: http://jiprof.sourceforge.net/ - --profile) PROFILE_ARGS="-javaagent:$JYTHON_HOME/javalib/profile.jar -Dprofile.properties=$JYTHON_HOME/javalib/profile.properties" ;; - # Run under JDB - --jdb) - if [ -z "$JAVA_HOME" ] ; then - JAVA_CMD='jdb' - else - if $cygwin; then - JAVA_HOME=`cygpath -u "$JAVA_HOME"` - fi - JAVA_CMD="$JAVA_HOME/bin/jdb" - fi ;; - --help) python_args=("${python_args[@]}" "$1") ;; - # Abort processing on the double dash - --) break ;; - # Other opts go to python - -*) python_args=("${python_args[@]}" "$1") ;; - # Abort processing on first non-opt arg - *) break ;; - esac - shift + val=${1:2} + if [ "${val:0:4}" = "-Xss" ] ; then + JAVA_STACK=$val + else + java_args=("${java_args[@]}" "${1:2}") + fi + ;; + # Match switches that take an argument + -c|-C|-jar|-Q|-W) + python_args=("${python_args[@]}" "$1" "$2") + shift + ;; + # Match -Dprop=val type args + -D*) + python_args=("${python_args[@]}" "$1") + ;; + # Run with the instrumented profiler: http://jiprof.sourceforge.net/ + --profile) + rm -f profile.txt # XXX do this? + profile_requested=true + agent_path="$JYTHON_HOME/javalib/profile.jar" + props_path="$JYTHON_HOME/javalib/profile.properties" + if $cygwin; then + agent_path=`cygpath -w "$agent_path"` + props_path=`cygpath -w "$props_path"` + fi + java_args=("${java_args[@]}" -javaagent:"$agent_path" + -Dprofile.properties="$props_path") + ;; + # Run under JDB + --jdb) + if [ -z "$JAVA_HOME" ] ; then + JAVA_CMD='jdb' + else + if $cygwin; then + JAVA_HOME=`cygpath -u "$JAVA_HOME"` + fi + JAVA_CMD="$JAVA_HOME/bin/jdb" + fi + ;; + -h|--help) + help_requested=true + python_args=("${python_args[@]}" "$1") + ;; + # Abort processing on a double dash + --) + break + ;; + # Other opts go to Jython + -*) + python_args=("${python_args[@]}" "$1") + ;; + # Abort processing on first non-opt arg + *) + break + ;; + esac + shift done # Append the rest of the arguments @@ -124,7 +153,7 @@ # Put the python_args back into the position arguments $1, $2 etc set -- "${python_args[@]}" -JAVA_OPTS="$JAVA_OPTS $JAVA_MEM $JAVA_STACK" +JAVA_OPTS="$JAVA_OPTS $JAVA_STACK" if $cygwin; then JAVA_HOME=`cygpath --mixed "$JAVA_HOME"` @@ -138,24 +167,33 @@ fi fi -if [ "$PROFILE_ARGS" != "" ]; then +if [ -n "$profile_requested" ] ; then echo "Running with instrumented profiler" + alias runjava="$JAVA_CMD" + java_args=("${java_args[@]}" -classpath "$CP$CP_SEPARATOR$CLASSPATH") +else + if [ -z $help_requested ] ; then + alias runjava="exec $JAVA_CMD" + else + alias runjava="$JAVA_CMD" + fi + java_args=("${java_args[@]}" -Xbootclasspath/a:"$CP" -classpath "$CLASSPATH") +fi - $JAVA_CMD $PROFILE_ARGS $JAVA_OPTS "${java_args[@]}" -classpath "$CP$CP_SEPARATOR$CLASSPATH" \ - "-Dpython.home=$JYTHON_HOME" \ - org.python.util.jython $JYTHON_OPTS "$@" +runjava $JAVA_OPTS "${java_args[@]}" -Dpython.home="$JYTHON_HOME" \ + -Dpython.executable="$PRG" org.python.util.jython $JYTHON_OPTS "$@" +if [ -n "$profile_requested" ] ; then echo "Profiling results:" - cat profile.txt - -else - echo "$JAVA_CMD" $JAVA_OPTS "${java_args[@]}" -Xbootclasspath/a:"$CP" -classpath "$CLASSPATH" \ - "-Dpython.home=$JYTHON_HOME" \ - org.python.util.jython $JYTHON_OPTS "$@" - - exec "$JAVA_CMD" $JAVA_OPTS "${java_args[@]}" -Xbootclasspath/a:"$CP" -classpath "$CLASSPATH" \ - "-Dpython.home=$JYTHON_HOME" \ - org.python.util.jython $JYTHON_OPTS "$@" - +elif [ -n "$help_requested" ] ; then + echo "Jython launcher options:" >&2 + echo "-Jarg : pass argument through to Java VM (e.g. -J-Xmx512m)" >&2 + echo "--jdb : run under JDB" >&2 + echo "--profile: run with the Java Interactive Profiler (http://jiprof.sf.net)" >&2 + echo "-- : pass remaining arguments through to Jython" >&2 + echo "Jython launcher environment variables:" >&2 + echo "JAVA_HOME : Java installation directory" >&2 + echo "JYTHON_HOME: Jython installation directory" >&2 + echo "JYTHON_OPTS: default command line arguments" >&2 fi Copied: branches/asm/tests/shell (from rev 4486, trunk/jython/tests/shell) Deleted: branches/asm/tests/shell/test-jython.sh =================================================================== --- trunk/jython/tests/shell/test-jython.sh 2008-05-30 03:21:14 UTC (rev 4486) +++ branches/asm/tests/shell/test-jython.sh 2008-05-30 03:28:32 UTC (rev 4487) @@ -1,57 +0,0 @@ -#!/bin/sh - -# test script for bin/jython - -if [ -z "$1" ] ; then - echo "$0: usage: test-jython.sh <Jython home>" >&2 - exit 99 -fi - -TEST_DIR="`mktemp -dt test-jython.XXXXXX`" -SPACE_DIR="$TEST_DIR/directory with spaces" - -cp -Rp "$1" "$SPACE_DIR" - -for JYTHON_HOME in "$SPACE_DIR" "$1" ; do - JYTHON="$JYTHON_HOME/bin/jython" - export JYTHON_HOME - set -ex - - # -J passthrough - "$JYTHON" -J-version 2>&1 | [ `egrep -c "^java version "` == 1 ] - - # Jython reports version - "$JYTHON" --version 2>&1 | [ `egrep -c "^Jython "` == 1 ] - - # $JYTHON_OPTS - JYTHON_OPTS="--version" "$JYTHON" 2>&1 | [ `egrep -c "^Jython "` == 1 ] - - # Jython help - "$JYTHON" --help 2>&1 | [ `egrep -c "^usage: "` == 1 ] - - # Jython launcher help - "$JYTHON" --help 2>&1 | [ `egrep -c "^Jython launcher options:"` == 1 ] - - # Jython exit status - set +e - "$JYTHON" -c 'import sys; sys.exit(5)' - [ $? == 5 ] || exit 1 - set -e - - # Jython executable (don't include newline in case it's \r\n) - [ `"$JYTHON" -c 'import sys; print sys.executable is not None,'` == True ] - - # JDB - echo run | "$JYTHON" --jdb -c "print '\ntest'" | [ `egrep -c "^test"` == 1 ] - - # Jython profiling - "$JYTHON" --profile -c pass 2>&1 | \ - [ `egrep -c "^\| Thread depth limit:"` == 1 ] - [ -f profile.txt ] && rm profile.txt - - set +ex -done - -rm -rf "$TEST_DIR" - -echo "Test successful." Copied: branches/asm/tests/shell/test-jython.sh (from rev 4486, trunk/jython/tests/shell/test-jython.sh) =================================================================== --- branches/asm/tests/shell/test-jython.sh (rev 0) +++ branches/asm/tests/shell/test-jython.sh 2008-05-30 03:28:32 UTC (rev 4487) @@ -0,0 +1,57 @@ +#!/bin/sh + +# test script for bin/jython + +if [ -z "$1" ] ; then + echo "$0: usage: test-jython.sh <Jython home>" >&2 + exit 99 +fi + +TEST_DIR="`mktemp -dt test-jython.XXXXXX`" +SPACE_DIR="$TEST_DIR/directory with spaces" + +cp -Rp "$1" "$SPACE_DIR" + +for JYTHON_HOME in "$SPACE_DIR" "$1" ; do + JYTHON="$JYTHON_HOME/bin/jython" + export JYTHON_HOME + set -ex + + # -J passthrough + "$JYTHON" -J-version 2>&1 | [ `egrep -c "^java version "` == 1 ] + + # Jython reports version + "$JYTHON" --version 2>&1 | [ `egrep -c "^Jython "` == 1 ] + + # $JYTHON_OPTS + JYTHON_OPTS="--version" "$JYTHON" 2>&1 | [ `egrep -c "^Jython "` == 1 ] + + # Jython help + "$JYTHON" --help 2>&1 | [ `egrep -c "^usage: "` == 1 ] + + # Jython launcher help + "$JYTHON" --help 2>&1 | [ `egrep -c "^Jython launcher options:"` == 1 ] + + # Jython exit status + set +e + "$JYTHON" -c 'import sys; sys.exit(5)' + [ $? == 5 ] || exit 1 + set -e + + # Jython executable (don't include newline in case it's \r\n) + [ `"$JYTHON" -c 'import sys; print sys.executable is not None,'` == True ] + + # JDB + echo run | "$JYTHON" --jdb -c "print '\ntest'" | [ `egrep -c "^test"` == 1 ] + + # Jython profiling + "$JYTHON" --profile -c pass 2>&1 | \ + [ `egrep -c "^\| Thread depth limit:"` == 1 ] + [ -f profile.txt ] && rm profile.txt + + set +ex +done + +rm -rf "$TEST_DIR" + +echo "Test successful." This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |