From: <pj...@us...> - 2008-07-17 03:29:22
|
Revision: 4962 http://jython.svn.sourceforge.net/jython/?rev=4962&view=rev Author: pjenvey Date: 2008-07-17 03:29:17 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Merged revisions 4931-4961 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r4948 | amak | 2008-07-15 14:24:55 -0700 (Tue, 15 Jul 2008) | 1 line Merging forward IPv6 and UDP <broadcast> changes from Release 22 maint. ........ r4953 | pjenvey | 2008-07-15 18:15:46 -0700 (Tue, 15 Jul 2008) | 1 line restore proto=0 as _realsocket asserts it so ........ r4954 | pjenvey | 2008-07-15 18:18:14 -0700 (Tue, 15 Jul 2008) | 1 line don't attempt a traceback line for a bogus lineno ........ r4955 | pjenvey | 2008-07-15 19:11:48 -0700 (Tue, 15 Jul 2008) | 1 line use getClass here incase class becomes a permanent keyword in 2.5 ........ r4957 | pjenvey | 2008-07-16 17:29:54 -0700 (Wed, 16 Jul 2008) | 1 line allow passing unicode hostnames to socket.connect ........ r4958 | pjenvey | 2008-07-16 17:37:53 -0700 (Wed, 16 Jul 2008) | 1 line make the r4954 fix resemble asm's version ........ r4960 | pjenvey | 2008-07-16 18:43:59 -0700 (Wed, 16 Jul 2008) | 1 line use the full path of sys.prefix ........ Modified Paths: -------------- branches/asm/Lib/socket.py branches/asm/Lib/test/test_socket.py branches/asm/src/org/python/core/PySystemState.java branches/asm/src/org/python/core/PyTraceback.java Property Changed: ---------------- branches/asm/ Property changes on: branches/asm ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-4930 + /trunk/jython:1-4961 Modified: branches/asm/Lib/socket.py =================================================================== --- branches/asm/Lib/socket.py 2008-07-17 03:21:35 UTC (rev 4961) +++ branches/asm/Lib/socket.py 2008-07-17 03:29:17 UTC (rev 4962) @@ -147,8 +147,8 @@ SHUT_WR = 1 SHUT_RDWR = 2 -__all__ = [ 'AF_INET', 'SOCK_DGRAM', 'SOCK_RAW', - 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', +__all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', + 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', 'SO_BROADCAST', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', 'SO_RCVBUF', 'SO_REUSEADDR', 'SO_SNDBUF', 'SO_TIMEOUT', 'TCP_NODELAY', 'SocketType', 'error', 'herror', 'gaierror', 'timeout', @@ -158,8 +158,12 @@ 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', ] +AF_UNSPEC = 0 AF_INET = 2 +AF_INET6 = 23 +AI_PASSIVE=1 + SOCK_DGRAM = 1 SOCK_STREAM = 2 SOCK_RAW = 3 # not supported @@ -372,8 +376,7 @@ bytes_sent = self.jchannel.send(byte_buf, socket_address) return bytes_sent - def sendto(self, byte_array, address, flags): - host, port = _unpack_address_tuple(address) + def sendto(self, byte_array, host, port, flags): socket_address = java.net.InetSocketAddress(host, port) if self.mode == MODE_TIMEOUT: return self._do_send_net(byte_array, socket_address, flags) @@ -430,6 +433,10 @@ else: return self._do_receive_nio(0, num_bytes, flags) +# Name and address functions + +has_ipv6 = 1 + def _gethostbyaddr(name): # This is as close as I can get; at least the types are correct... addresses = java.net.InetAddress.getAllByName(gethostbyname(name)) @@ -495,11 +502,29 @@ else: return _udpsocket() -def getaddrinfo(host, port, family=0, socktype=SOCK_STREAM, proto=0, flags=0): - return ( (AF_INET, socktype, 0, "", (gethostbyname(host), port)), ) +def getaddrinfo(host, port, family=None, socktype=None, proto=0, flags=None): + try: + if not family in [AF_INET, AF_INET6, AF_UNSPEC]: + raise NotSupportedError() + filter_fns = [] + filter_fns.append({ + AF_INET: lambda x: isinstance(x, java.net.Inet4Address), + AF_INET6: lambda x: isinstance(x, java.net.Inet6Address), + AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress), + }[family]) + # Cant see a way to support AI_PASSIVE right now. + # if flags and flags & AI_PASSIVE: + # pass + results = [] + for a in java.net.InetAddress.getAllByName(host): + if len([f for f in filter_fns if f(a)]): + family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()] + # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses + results.append( (family, socktype, proto, a.getCanonicalHostName(), (a.getHostAddress(), port)) ) + return results + except java.lang.Exception, jlx: + raise _map_exception(jlx) -has_ipv6 = 1 - def getnameinfo(sock_addr, flags): raise NotImplementedError("getnameinfo not yet supported on jython.") @@ -609,13 +634,28 @@ def _get_jsocket(self): return self.sock_impl.jsocket -def _unpack_address_tuple(address_tuple): +def _unpack_address_tuple(address_tuple, for_tx=False): + # TODO: Upgrade to support the 4-tuples used for IPv6 addresses + # which include flowinfo and scope_id. + # To be upgraded in synch with getaddrinfo error_message = "Address must be a tuple of (hostname, port)" - if type(address_tuple) is not type( () ) \ - or type(address_tuple[0]) is not type("") \ - or type(address_tuple[1]) is not type(0): + if not isinstance(address_tuple, tuple) or \ + not isinstance(address_tuple[0], basestring) or \ + not isinstance(address_tuple[1], (int, long)): raise TypeError(error_message) - return address_tuple[0], address_tuple[1] + hostname = address_tuple[0] + if isinstance(hostname, unicode): + # XXX: Should be encode('idna') (See CPython + # socketmodule::getsockaddrarg), but Jython's idna support is + # currently broken + hostname = hostname.encode() + hostname = hostname.strip() + if hostname == "<broadcast>": + if for_tx: + hostname = "255.255.255.255" + else: + hostname = "0.0.0.0" + return hostname, address_tuple[1] class _tcpsocket(_nonblocking_api_mixin): @@ -632,7 +672,7 @@ assert not self.sock_impl assert not self.local_addr # Do the address format check - host, port = _unpack_address_tuple(addr) + _unpack_address_tuple(addr) self.local_addr = addr def listen(self, backlog=50): @@ -641,7 +681,7 @@ assert not self.sock_impl self.server = 1 if self.local_addr: - host, port = self.local_addr + host, port = _unpack_address_tuple(self.local_addr) else: host, port = "", 0 self.sock_impl = _server_socket_impl(host, port, backlog, self.pending_options[SO_REUSEADDR]) @@ -678,7 +718,7 @@ host, port = self._get_host_port(addr) self.sock_impl = _client_socket_impl() if self.local_addr: # Has the socket been bound to a local address? - bind_host, bind_port = self.local_addr + bind_host, bind_port = _unpack_address_tuple(self.local_addr) self.sock_impl.bind(bind_host, bind_port, self.pending_options[SO_REUSEADDR]) self._config() # Configure timeouts, etc, now that the socket exists self.sock_impl.connect(host, port) @@ -836,8 +876,9 @@ if not self.sock_impl: self.sock_impl = _datagram_socket_impl() self._config() + host, port = _unpack_address_tuple(addr, True) byte_array = java.lang.String(data).getBytes('iso-8859-1') - result = self.sock_impl.sendto(byte_array, addr, flags) + result = self.sock_impl.sendto(byte_array, host, port, flags) return result except java.lang.Exception, jlx: raise _map_exception(jlx) Modified: branches/asm/Lib/test/test_socket.py =================================================================== --- branches/asm/Lib/test/test_socket.py 2008-07-17 03:21:35 UTC (rev 4961) +++ branches/asm/Lib/test/test_socket.py 2008-07-17 03:29:17 UTC (rev 4962) @@ -801,6 +801,21 @@ self.cli.settimeout(10) self.cli.sendto(EIGHT_BIT_MSG, 0, (HOST, PORT)) +class UDPBroadcastTest(ThreadedUDPSocketTest): + + def setUp(self): + self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + def testBroadcast(self): + self.serv.bind( ("<broadcast>", PORT) ) + msg = self.serv.recv(len(EIGHT_BIT_MSG)) + self.assertEqual(msg, EIGHT_BIT_MSG) + + def _testBroadcast(self): + self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + self.cli.sendto(EIGHT_BIT_MSG, ("<broadcast>", PORT) ) + class BasicSocketPairTest(SocketPairTest): def __init__(self, methodName='runTest'): @@ -1421,6 +1436,14 @@ def setUp(self): self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +class UnicodeTest(ThreadedTCPSocketTest): + + def testUnicodeHostname(self): + pass + + def _testUnicodeHostname(self): + self.cli.connect((unicode(HOST), PORT)) + def test_main(): tests = [ GeneralModuleTests, @@ -1442,13 +1465,18 @@ PrivateFileObjectTestCase, UnbufferedFileObjectClassTestCase, LineBufferedFileObjectClassTestCase, - SmallBufferedFileObjectClassTestCase + SmallBufferedFileObjectClassTestCase, + UnicodeTest ] if hasattr(socket, "socketpair"): tests.append(BasicSocketPairTest) if sys.platform[:4] == 'java': tests.append(TestJythonTCPExceptions) tests.append(TestJythonUDPExceptions) + # TODO: Broadcast requires permission, and is blocked by some firewalls + # Need some way to discover the network setup on the test machine + if False: + tests.append(UDPBroadcastTest) suites = [unittest.makeSuite(klass, 'test') for klass in tests] test_support.run_suite(unittest.TestSuite(suites)) Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-07-17 03:21:35 UTC (rev 4961) +++ branches/asm/src/org/python/core/PySystemState.java 2008-07-17 03:29:17 UTC (rev 4962) @@ -383,6 +383,14 @@ } } } + if (root != null) { + File rootFile = new File(root); + try { + root = rootFile.getCanonicalPath(); + } catch (IOException ioe) { + root = rootFile.getAbsolutePath(); + } + } return root; } Modified: branches/asm/src/org/python/core/PyTraceback.java =================================================================== --- branches/asm/src/org/python/core/PyTraceback.java 2008-07-17 03:21:35 UTC (rev 4961) +++ branches/asm/src/org/python/core/PyTraceback.java 2008-07-17 03:29:17 UTC (rev 4962) @@ -80,7 +80,7 @@ // Continue, we may have the line } - if (i == tb_lineno && line != null) {//FJW: XXX: added null check just to avoid NPE. + if (line != null && i == tb_lineno) { i = 0; while (i < line.length()) { char c = line.charAt(i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-17 21:20:18
|
Revision: 4965 http://jython.svn.sourceforge.net/jython/?rev=4965&view=rev Author: fwierzbicki Date: 2008-07-17 21:19:56 +0000 (Thu, 17 Jul 2008) Log Message: ----------- added custom toStringTree to each node. Modified Paths: -------------- branches/asm/ast/asdl_antlr.py branches/asm/src/org/python/antlr/ast/Assert.java branches/asm/src/org/python/antlr/ast/Assign.java branches/asm/src/org/python/antlr/ast/Attribute.java branches/asm/src/org/python/antlr/ast/AugAssign.java branches/asm/src/org/python/antlr/ast/BinOp.java branches/asm/src/org/python/antlr/ast/BoolOp.java branches/asm/src/org/python/antlr/ast/Break.java branches/asm/src/org/python/antlr/ast/Call.java branches/asm/src/org/python/antlr/ast/ClassDef.java branches/asm/src/org/python/antlr/ast/Compare.java branches/asm/src/org/python/antlr/ast/Continue.java branches/asm/src/org/python/antlr/ast/Delete.java branches/asm/src/org/python/antlr/ast/Dict.java branches/asm/src/org/python/antlr/ast/Ellipsis.java branches/asm/src/org/python/antlr/ast/Exec.java branches/asm/src/org/python/antlr/ast/Expr.java branches/asm/src/org/python/antlr/ast/Expression.java branches/asm/src/org/python/antlr/ast/ExtSlice.java branches/asm/src/org/python/antlr/ast/For.java branches/asm/src/org/python/antlr/ast/FunctionDef.java branches/asm/src/org/python/antlr/ast/GeneratorExp.java branches/asm/src/org/python/antlr/ast/Global.java branches/asm/src/org/python/antlr/ast/If.java branches/asm/src/org/python/antlr/ast/IfExp.java branches/asm/src/org/python/antlr/ast/Import.java branches/asm/src/org/python/antlr/ast/ImportFrom.java branches/asm/src/org/python/antlr/ast/Index.java branches/asm/src/org/python/antlr/ast/Interactive.java branches/asm/src/org/python/antlr/ast/Lambda.java branches/asm/src/org/python/antlr/ast/List.java branches/asm/src/org/python/antlr/ast/ListComp.java branches/asm/src/org/python/antlr/ast/Module.java branches/asm/src/org/python/antlr/ast/Name.java branches/asm/src/org/python/antlr/ast/Num.java branches/asm/src/org/python/antlr/ast/Pass.java branches/asm/src/org/python/antlr/ast/Print.java branches/asm/src/org/python/antlr/ast/Raise.java branches/asm/src/org/python/antlr/ast/Repr.java branches/asm/src/org/python/antlr/ast/Return.java branches/asm/src/org/python/antlr/ast/Slice.java branches/asm/src/org/python/antlr/ast/Str.java branches/asm/src/org/python/antlr/ast/Subscript.java branches/asm/src/org/python/antlr/ast/Suite.java branches/asm/src/org/python/antlr/ast/TryExcept.java branches/asm/src/org/python/antlr/ast/TryFinally.java branches/asm/src/org/python/antlr/ast/Tuple.java branches/asm/src/org/python/antlr/ast/UnaryOp.java branches/asm/src/org/python/antlr/ast/Unicode.java branches/asm/src/org/python/antlr/ast/While.java branches/asm/src/org/python/antlr/ast/With.java branches/asm/src/org/python/antlr/ast/Yield.java branches/asm/src/org/python/antlr/ast/aliasType.java branches/asm/src/org/python/antlr/ast/argumentsType.java branches/asm/src/org/python/antlr/ast/comprehensionType.java branches/asm/src/org/python/antlr/ast/excepthandlerType.java branches/asm/src/org/python/antlr/ast/keywordType.java Modified: branches/asm/ast/asdl_antlr.py =================================================================== --- branches/asm/ast/asdl_antlr.py 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/ast/asdl_antlr.py 2008-07-17 21:19:56 UTC (rev 4965) @@ -306,6 +306,18 @@ self.emit("}", depth) self.emit("", 0) + # The toStringTree() method + self.emit("public String toStringTree() {", depth) + self.emit('StringBuffer sb = new StringBuffer("%s[");' % clsname, + depth+1) + for f in fields: + self.emit('sb.append("%s=");' % f.name, depth+1) + self.emit("sb.append(this.%s);" % f.name, depth+1) + self.emit('sb.append("]");', depth+1) + self.emit("return sb.toString();", depth+1) + self.emit("}", depth) + self.emit("", 0) + # The pickle() method #self.emit("public void pickle(DataOutputStream ostream) throws IOException {", depth) #self.emit("pickleThis(%s, ostream);" % type.index, depth+1); Modified: branches/asm/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Assert.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Assert.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "Assert"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Assert["); + sb.append("test="); + sb.append(this.test); + sb.append("msg="); + sb.append(this.msg); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitAssert(this); } Modified: branches/asm/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Assign.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Assign.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -49,6 +49,16 @@ return "Assign"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Assign["); + sb.append("targets="); + sb.append(this.targets); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitAssign(this); } Modified: branches/asm/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Attribute.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Attribute.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "Attribute"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Attribute["); + sb.append("value="); + sb.append(this.value); + sb.append("attr="); + sb.append(this.attr); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitAttribute(this); } Modified: branches/asm/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/asm/src/org/python/antlr/ast/AugAssign.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/AugAssign.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "AugAssign"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("AugAssign["); + sb.append("target="); + sb.append(this.target); + sb.append("op="); + sb.append(this.op); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitAugAssign(this); } Modified: branches/asm/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/BinOp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/BinOp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -40,6 +40,18 @@ return "BinOp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("BinOp["); + sb.append("left="); + sb.append(this.left); + sb.append("op="); + sb.append(this.op); + sb.append("right="); + sb.append(this.right); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitBinOp(this); } Modified: branches/asm/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/BoolOp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/BoolOp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -49,6 +49,16 @@ return "BoolOp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("BoolOp["); + sb.append("op="); + sb.append(this.op); + sb.append("values="); + sb.append(this.values); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitBoolOp(this); } Modified: branches/asm/src/org/python/antlr/ast/Break.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Break.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Break.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -26,6 +26,12 @@ return "Break"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Break["); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitBreak(this); } Modified: branches/asm/src/org/python/antlr/ast/Call.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Call.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Call.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -80,6 +80,22 @@ return "Call"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Call["); + sb.append("func="); + sb.append(this.func); + sb.append("args="); + sb.append(this.args); + sb.append("keywords="); + sb.append(this.keywords); + sb.append("starargs="); + sb.append(this.starargs); + sb.append("kwargs="); + sb.append(this.kwargs); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitCall(this); } Modified: branches/asm/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ClassDef.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/ClassDef.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -71,6 +71,18 @@ return "ClassDef"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("ClassDef["); + sb.append("name="); + sb.append(this.name); + sb.append("bases="); + sb.append(this.bases); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitClassDef(this); } Modified: branches/asm/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Compare.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Compare.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -60,6 +60,18 @@ return "Compare"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Compare["); + sb.append("left="); + sb.append(this.left); + sb.append("ops="); + sb.append(this.ops); + sb.append("comparators="); + sb.append(this.comparators); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitCompare(this); } Modified: branches/asm/src/org/python/antlr/ast/Continue.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Continue.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Continue.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -26,6 +26,12 @@ return "Continue"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Continue["); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitContinue(this); } Modified: branches/asm/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Delete.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Delete.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Delete"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Delete["); + sb.append("targets="); + sb.append(this.targets); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitDelete(this); } Modified: branches/asm/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Dict.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Dict.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -64,6 +64,16 @@ return "Dict"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Dict["); + sb.append("keys="); + sb.append(this.keys); + sb.append("values="); + sb.append(this.values); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitDict(this); } Modified: branches/asm/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Ellipsis.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Ellipsis.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -26,6 +26,12 @@ return "Ellipsis"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Ellipsis["); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitEllipsis(this); } Modified: branches/asm/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Exec.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Exec.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "Exec"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Exec["); + sb.append("body="); + sb.append(this.body); + sb.append("globals="); + sb.append(this.globals); + sb.append("locals="); + sb.append(this.locals); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitExec(this); } Modified: branches/asm/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Expr.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Expr.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Expr"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Expr["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitExpr(this); } Modified: branches/asm/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Expression.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Expression.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Expression"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Expression["); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitExpression(this); } Modified: branches/asm/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ExtSlice.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/ExtSlice.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "ExtSlice"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("ExtSlice["); + sb.append("dims="); + sb.append(this.dims); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitExtSlice(this); } Modified: branches/asm/src/org/python/antlr/ast/For.java =================================================================== --- branches/asm/src/org/python/antlr/ast/For.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/For.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -76,6 +76,20 @@ return "For"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("For["); + sb.append("target="); + sb.append(this.target); + sb.append("iter="); + sb.append(this.iter); + sb.append("body="); + sb.append(this.body); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitFor(this); } Modified: branches/asm/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/asm/src/org/python/antlr/ast/FunctionDef.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/FunctionDef.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -76,6 +76,20 @@ return "FunctionDef"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("FunctionDef["); + sb.append("name="); + sb.append(this.name); + sb.append("args="); + sb.append(this.args); + sb.append("body="); + sb.append(this.body); + sb.append("decorators="); + sb.append(this.decorators); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitFunctionDef(this); } Modified: branches/asm/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/GeneratorExp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/GeneratorExp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -52,6 +52,16 @@ return "GeneratorExp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("GeneratorExp["); + sb.append("elt="); + sb.append(this.elt); + sb.append("generators="); + sb.append(this.generators); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitGeneratorExp(this); } Modified: branches/asm/src/org/python/antlr/ast/Global.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Global.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Global.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Global"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Global["); + sb.append("names="); + sb.append(this.names); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitGlobal(this); } Modified: branches/asm/src/org/python/antlr/ast/If.java =================================================================== --- branches/asm/src/org/python/antlr/ast/If.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/If.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -71,6 +71,18 @@ return "If"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("If["); + sb.append("test="); + sb.append(this.test); + sb.append("body="); + sb.append(this.body); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitIf(this); } Modified: branches/asm/src/org/python/antlr/ast/IfExp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/IfExp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/IfExp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "IfExp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("IfExp["); + sb.append("test="); + sb.append(this.test); + sb.append("body="); + sb.append(this.body); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitIfExp(this); } Modified: branches/asm/src/org/python/antlr/ast/Import.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Import.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Import.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Import"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Import["); + sb.append("names="); + sb.append(this.names); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitImport(this); } Modified: branches/asm/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ImportFrom.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/ImportFrom.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -57,6 +57,18 @@ return "ImportFrom"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("ImportFrom["); + sb.append("module="); + sb.append(this.module); + sb.append("names="); + sb.append(this.names); + sb.append("level="); + sb.append(this.level); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitImportFrom(this); } Modified: branches/asm/src/org/python/antlr/ast/Index.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Index.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Index.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Index"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Index["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitIndex(this); } Modified: branches/asm/src/org/python/antlr/ast/Interactive.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Interactive.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Interactive.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Interactive"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Interactive["); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitInteractive(this); } Modified: branches/asm/src/org/python/antlr/ast/Lambda.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Lambda.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Lambda.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "Lambda"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Lambda["); + sb.append("args="); + sb.append(this.args); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitLambda(this); } Modified: branches/asm/src/org/python/antlr/ast/List.java =================================================================== --- branches/asm/src/org/python/antlr/ast/List.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/List.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -49,6 +49,16 @@ return "List"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("List["); + sb.append("elts="); + sb.append(this.elts); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitList(this); } Modified: branches/asm/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ListComp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/ListComp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -51,6 +51,16 @@ return "ListComp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("ListComp["); + sb.append("elt="); + sb.append(this.elt); + sb.append("generators="); + sb.append(this.generators); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitListComp(this); } Modified: branches/asm/src/org/python/antlr/ast/Module.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Module.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Module.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Module"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Module["); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitModule(this); } Modified: branches/asm/src/org/python/antlr/ast/Name.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Name.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Name.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "Name"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Name["); + sb.append("id="); + sb.append(this.id); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitName(this); } Modified: branches/asm/src/org/python/antlr/ast/Num.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Num.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Num.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Num"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Num["); + sb.append("n="); + sb.append(this.n); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitNum(this); } Modified: branches/asm/src/org/python/antlr/ast/Pass.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Pass.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Pass.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -26,6 +26,12 @@ return "Pass"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Pass["); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitPass(this); } Modified: branches/asm/src/org/python/antlr/ast/Print.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Print.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Print.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -55,6 +55,18 @@ return "Print"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Print["); + sb.append("dest="); + sb.append(this.dest); + sb.append("values="); + sb.append(this.values); + sb.append("nl="); + sb.append(this.nl); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitPrint(this); } Modified: branches/asm/src/org/python/antlr/ast/Raise.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Raise.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Raise.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -40,6 +40,18 @@ return "Raise"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Raise["); + sb.append("type="); + sb.append(this.type); + sb.append("inst="); + sb.append(this.inst); + sb.append("tback="); + sb.append(this.tback); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitRaise(this); } Modified: branches/asm/src/org/python/antlr/ast/Repr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Repr.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Repr.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Repr"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Repr["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitRepr(this); } Modified: branches/asm/src/org/python/antlr/ast/Return.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Return.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Return.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Return"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Return["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitReturn(this); } Modified: branches/asm/src/org/python/antlr/ast/Slice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Slice.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Slice.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "Slice"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Slice["); + sb.append("lower="); + sb.append(this.lower); + sb.append("upper="); + sb.append(this.upper); + sb.append("step="); + sb.append(this.step); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitSlice(this); } Modified: branches/asm/src/org/python/antlr/ast/Str.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Str.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Str.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Str"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Str["); + sb.append("s="); + sb.append(this.s); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitStr(this); } Modified: branches/asm/src/org/python/antlr/ast/Subscript.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Subscript.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Subscript.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "Subscript"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Subscript["); + sb.append("value="); + sb.append(this.value); + sb.append("slice="); + sb.append(this.slice); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitSubscript(this); } Modified: branches/asm/src/org/python/antlr/ast/Suite.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Suite.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Suite.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Suite"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Suite["); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitSuite(this); } Modified: branches/asm/src/org/python/antlr/ast/TryExcept.java =================================================================== --- branches/asm/src/org/python/antlr/ast/TryExcept.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/TryExcept.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -87,6 +87,18 @@ return "TryExcept"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("TryExcept["); + sb.append("body="); + sb.append(this.body); + sb.append("handlers="); + sb.append(this.handlers); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitTryExcept(this); } Modified: branches/asm/src/org/python/antlr/ast/TryFinally.java =================================================================== --- branches/asm/src/org/python/antlr/ast/TryFinally.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/TryFinally.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -65,6 +65,16 @@ return "TryFinally"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("TryFinally["); + sb.append("body="); + sb.append(this.body); + sb.append("finalbody="); + sb.append(this.finalbody); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitTryFinally(this); } Modified: branches/asm/src/org/python/antlr/ast/Tuple.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Tuple.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Tuple.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -50,6 +50,16 @@ return "Tuple"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Tuple["); + sb.append("elts="); + sb.append(this.elts); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitTuple(this); } Modified: branches/asm/src/org/python/antlr/ast/UnaryOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/UnaryOp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/UnaryOp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "UnaryOp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("UnaryOp["); + sb.append("op="); + sb.append(this.op); + sb.append("operand="); + sb.append(this.operand); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitUnaryOp(this); } Modified: branches/asm/src/org/python/antlr/ast/Unicode.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Unicode.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Unicode.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Unicode"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Unicode["); + sb.append("s="); + sb.append(this.s); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitUnicode(this); } Modified: branches/asm/src/org/python/antlr/ast/While.java =================================================================== --- branches/asm/src/org/python/antlr/ast/While.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/While.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -72,6 +72,18 @@ return "While"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("While["); + sb.append("test="); + sb.append(this.test); + sb.append("body="); + sb.append(this.body); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitWhile(this); } Modified: branches/asm/src/org/python/antlr/ast/With.java =================================================================== --- branches/asm/src/org/python/antlr/ast/With.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/With.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -57,6 +57,18 @@ return "With"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("With["); + sb.append("context_expr="); + sb.append(this.context_expr); + sb.append("optional_vars="); + sb.append(this.optional_vars); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitWith(this); } Modified: branches/asm/src/org/python/antlr/ast/Yield.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Yield.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Yield.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Yield"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Yield["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitYield(this); } Modified: branches/asm/src/org/python/antlr/ast/aliasType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/aliasType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/aliasType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "alias"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("alias["); + sb.append("name="); + sb.append(this.name); + sb.append("asname="); + sb.append(this.asname); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; Modified: branches/asm/src/org/python/antlr/ast/argumentsType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/argumentsType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/argumentsType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -76,6 +76,20 @@ return "arguments"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("arguments["); + sb.append("args="); + sb.append(this.args); + sb.append("vararg="); + sb.append(this.vararg); + sb.append("kwarg="); + sb.append(this.kwarg); + sb.append("defaults="); + sb.append(this.defaults); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; Modified: branches/asm/src/org/python/antlr/ast/comprehensionType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/comprehensionType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/comprehensionType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -56,6 +56,18 @@ return "comprehension"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("comprehension["); + sb.append("target="); + sb.append(this.target); + sb.append("iter="); + sb.append(this.iter); + sb.append("ifs="); + sb.append(this.ifs); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; Modified: branches/asm/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/excepthandlerType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/excepthandlerType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -65,6 +65,22 @@ return "excepthandler"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("excepthandler["); + sb.append("type="); + sb.append(this.type); + sb.append("name="); + sb.append(this.name); + sb.append("body="); + sb.append(this.body); + sb.append("lineno="); + sb.append(this.lineno); + sb.append("col_offset="); + sb.append(this.col_offset); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; Modified: branches/asm/src/org/python/antlr/ast/keywordType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/keywordType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/keywordType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "keyword"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("keyword["); + sb.append("arg="); + sb.append(this.arg); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-19 22:55:51
|
Revision: 4974 http://jython.svn.sourceforge.net/jython/?rev=4974&view=rev Author: fwierzbicki Date: 2008-07-19 22:48:21 +0000 (Sat, 19 Jul 2008) Log Message: ----------- Make PythonTree's toStringTree more easily comparable with ast/astview.py output. This will help with the walkerless Python.g, as it doesn't quite parse ast/astview.py yet. Modified Paths: -------------- branches/asm/ast/asdl_antlr.py branches/asm/src/org/python/antlr/PythonTree.java branches/asm/src/org/python/antlr/ast/Assert.java branches/asm/src/org/python/antlr/ast/Assign.java branches/asm/src/org/python/antlr/ast/Attribute.java branches/asm/src/org/python/antlr/ast/AugAssign.java branches/asm/src/org/python/antlr/ast/BinOp.java branches/asm/src/org/python/antlr/ast/BoolOp.java branches/asm/src/org/python/antlr/ast/Break.java branches/asm/src/org/python/antlr/ast/Call.java branches/asm/src/org/python/antlr/ast/ClassDef.java branches/asm/src/org/python/antlr/ast/Compare.java branches/asm/src/org/python/antlr/ast/Continue.java branches/asm/src/org/python/antlr/ast/Delete.java branches/asm/src/org/python/antlr/ast/Dict.java branches/asm/src/org/python/antlr/ast/Ellipsis.java branches/asm/src/org/python/antlr/ast/Exec.java branches/asm/src/org/python/antlr/ast/Expr.java branches/asm/src/org/python/antlr/ast/Expression.java branches/asm/src/org/python/antlr/ast/ExtSlice.java branches/asm/src/org/python/antlr/ast/For.java branches/asm/src/org/python/antlr/ast/FunctionDef.java branches/asm/src/org/python/antlr/ast/GeneratorExp.java branches/asm/src/org/python/antlr/ast/Global.java branches/asm/src/org/python/antlr/ast/If.java branches/asm/src/org/python/antlr/ast/IfExp.java branches/asm/src/org/python/antlr/ast/Import.java branches/asm/src/org/python/antlr/ast/ImportFrom.java branches/asm/src/org/python/antlr/ast/Index.java branches/asm/src/org/python/antlr/ast/Interactive.java branches/asm/src/org/python/antlr/ast/Lambda.java branches/asm/src/org/python/antlr/ast/List.java branches/asm/src/org/python/antlr/ast/ListComp.java branches/asm/src/org/python/antlr/ast/Module.java branches/asm/src/org/python/antlr/ast/Name.java branches/asm/src/org/python/antlr/ast/Num.java branches/asm/src/org/python/antlr/ast/Pass.java branches/asm/src/org/python/antlr/ast/Print.java branches/asm/src/org/python/antlr/ast/Raise.java branches/asm/src/org/python/antlr/ast/Repr.java branches/asm/src/org/python/antlr/ast/Return.java branches/asm/src/org/python/antlr/ast/Slice.java branches/asm/src/org/python/antlr/ast/Str.java branches/asm/src/org/python/antlr/ast/Subscript.java branches/asm/src/org/python/antlr/ast/Suite.java branches/asm/src/org/python/antlr/ast/TryExcept.java branches/asm/src/org/python/antlr/ast/TryFinally.java branches/asm/src/org/python/antlr/ast/Tuple.java branches/asm/src/org/python/antlr/ast/UnaryOp.java branches/asm/src/org/python/antlr/ast/Unicode.java branches/asm/src/org/python/antlr/ast/While.java branches/asm/src/org/python/antlr/ast/With.java branches/asm/src/org/python/antlr/ast/Yield.java branches/asm/src/org/python/antlr/ast/aliasType.java branches/asm/src/org/python/antlr/ast/argumentsType.java branches/asm/src/org/python/antlr/ast/comprehensionType.java branches/asm/src/org/python/antlr/ast/excepthandlerType.java branches/asm/src/org/python/antlr/ast/keywordType.java Modified: branches/asm/ast/asdl_antlr.py =================================================================== --- branches/asm/ast/asdl_antlr.py 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/ast/asdl_antlr.py 2008-07-19 22:48:21 UTC (rev 4974) @@ -308,12 +308,13 @@ # The toStringTree() method self.emit("public String toStringTree() {", depth) - self.emit('StringBuffer sb = new StringBuffer("%s[");' % clsname, + self.emit('StringBuffer sb = new StringBuffer("%s(");' % clsname, depth+1) for f in fields: self.emit('sb.append("%s=");' % f.name, depth+1) - self.emit("sb.append(this.%s);" % f.name, depth+1) - self.emit('sb.append("]");', depth+1) + self.emit("sb.append(dumpThis(%s));" % f.name, depth+1) + self.emit('sb.append(",");', depth+1) + self.emit('sb.append(")");', depth+1) self.emit("return sb.toString();", depth+1) self.emit("}", depth) self.emit("", 0) Modified: branches/asm/src/org/python/antlr/PythonTree.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTree.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/PythonTree.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -83,13 +83,12 @@ public String toStringTree() { if (children == null || children.size() == 0) { - // System.out.println("Where are my children? -- asks " + token.getText()); - return this.toString() + "[" + this.info() + "]"; + return this.toString();// + "[" + this.info() + "]"; } StringBuffer buf = new StringBuffer(); if (!isNil()) { buf.append("("); - buf.append(this.toString() + "[" + this.info() + "]"); + buf.append(this.toString());// + "[" + this.info() + "]"); buf.append(' '); } for (int i = 0; children != null && i < children.size(); i++) { @@ -105,6 +104,34 @@ return buf.toString(); } + protected String dumpThis(String s) { + return s; + } + + protected String dumpThis(Object o) { + if (o instanceof PythonTree) { + return ((PythonTree)o).toStringTree(); + } + return String.valueOf(o); + } + + protected String dumpThis(Object[] s) { + StringBuffer sb = new StringBuffer(); + if (s == null) { + sb.append("null"); + } else { + sb.append("("); + for (int i = 0; i < s.length; i++) { + if (i > 0) + sb.append(", "); + sb.append(dumpThis(s[i])); + } + sb.append(")"); + } + + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { throw new RuntimeException("Unexpected node: " + this); } Modified: branches/asm/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Assert.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Assert.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Assert["); + StringBuffer sb = new StringBuffer("Assert("); sb.append("test="); - sb.append(this.test); + sb.append(dumpThis(test)); + sb.append(","); sb.append("msg="); - sb.append(this.msg); - sb.append("]"); + sb.append(dumpThis(msg)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Assign.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Assign.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -50,12 +50,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Assign["); + StringBuffer sb = new StringBuffer("Assign("); sb.append("targets="); - sb.append(this.targets); + sb.append(dumpThis(targets)); + sb.append(","); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Attribute.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Attribute.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Attribute["); + StringBuffer sb = new StringBuffer("Attribute("); sb.append("value="); - sb.append(this.value); + sb.append(dumpThis(value)); + sb.append(","); sb.append("attr="); - sb.append(this.attr); + sb.append(dumpThis(attr)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/asm/src/org/python/antlr/ast/AugAssign.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/AugAssign.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("AugAssign["); + StringBuffer sb = new StringBuffer("AugAssign("); sb.append("target="); - sb.append(this.target); + sb.append(dumpThis(target)); + sb.append(","); sb.append("op="); - sb.append(this.op); + sb.append(dumpThis(op)); + sb.append(","); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/BinOp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/BinOp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -41,14 +41,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("BinOp["); + StringBuffer sb = new StringBuffer("BinOp("); sb.append("left="); - sb.append(this.left); + sb.append(dumpThis(left)); + sb.append(","); sb.append("op="); - sb.append(this.op); + sb.append(dumpThis(op)); + sb.append(","); sb.append("right="); - sb.append(this.right); - sb.append("]"); + sb.append(dumpThis(right)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/BoolOp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/BoolOp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -50,12 +50,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("BoolOp["); + StringBuffer sb = new StringBuffer("BoolOp("); sb.append("op="); - sb.append(this.op); + sb.append(dumpThis(op)); + sb.append(","); sb.append("values="); - sb.append(this.values); - sb.append("]"); + sb.append(dumpThis(values)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Break.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Break.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Break.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -27,8 +27,8 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Break["); - sb.append("]"); + StringBuffer sb = new StringBuffer("Break("); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Call.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Call.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Call.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -81,18 +81,23 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Call["); + StringBuffer sb = new StringBuffer("Call("); sb.append("func="); - sb.append(this.func); + sb.append(dumpThis(func)); + sb.append(","); sb.append("args="); - sb.append(this.args); + sb.append(dumpThis(args)); + sb.append(","); sb.append("keywords="); - sb.append(this.keywords); + sb.append(dumpThis(keywords)); + sb.append(","); sb.append("starargs="); - sb.append(this.starargs); + sb.append(dumpThis(starargs)); + sb.append(","); sb.append("kwargs="); - sb.append(this.kwargs); - sb.append("]"); + sb.append(dumpThis(kwargs)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ClassDef.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/ClassDef.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -72,14 +72,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("ClassDef["); + StringBuffer sb = new StringBuffer("ClassDef("); sb.append("name="); - sb.append(this.name); + sb.append(dumpThis(name)); + sb.append(","); sb.append("bases="); - sb.append(this.bases); + sb.append(dumpThis(bases)); + sb.append(","); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Compare.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Compare.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -61,14 +61,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Compare["); + StringBuffer sb = new StringBuffer("Compare("); sb.append("left="); - sb.append(this.left); + sb.append(dumpThis(left)); + sb.append(","); sb.append("ops="); - sb.append(this.ops); + sb.append(dumpThis(ops)); + sb.append(","); sb.append("comparators="); - sb.append(this.comparators); - sb.append("]"); + sb.append(dumpThis(comparators)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Continue.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Continue.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Continue.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -27,8 +27,8 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Continue["); - sb.append("]"); + StringBuffer sb = new StringBuffer("Continue("); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Delete.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Delete.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Delete["); + StringBuffer sb = new StringBuffer("Delete("); sb.append("targets="); - sb.append(this.targets); - sb.append("]"); + sb.append(dumpThis(targets)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Dict.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Dict.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -65,12 +65,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Dict["); + StringBuffer sb = new StringBuffer("Dict("); sb.append("keys="); - sb.append(this.keys); + sb.append(dumpThis(keys)); + sb.append(","); sb.append("values="); - sb.append(this.values); - sb.append("]"); + sb.append(dumpThis(values)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Ellipsis.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Ellipsis.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -27,8 +27,8 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Ellipsis["); - sb.append("]"); + StringBuffer sb = new StringBuffer("Ellipsis("); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Exec.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Exec.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Exec["); + StringBuffer sb = new StringBuffer("Exec("); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("globals="); - sb.append(this.globals); + sb.append(dumpThis(globals)); + sb.append(","); sb.append("locals="); - sb.append(this.locals); - sb.append("]"); + sb.append(dumpThis(locals)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Expr.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Expr.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Expr["); + StringBuffer sb = new StringBuffer("Expr("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Expression.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Expression.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Expression["); + StringBuffer sb = new StringBuffer("Expression("); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ExtSlice.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/ExtSlice.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("ExtSlice["); + StringBuffer sb = new StringBuffer("ExtSlice("); sb.append("dims="); - sb.append(this.dims); - sb.append("]"); + sb.append(dumpThis(dims)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/For.java =================================================================== --- branches/asm/src/org/python/antlr/ast/For.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/For.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -77,16 +77,20 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("For["); + StringBuffer sb = new StringBuffer("For("); sb.append("target="); - sb.append(this.target); + sb.append(dumpThis(target)); + sb.append(","); sb.append("iter="); - sb.append(this.iter); + sb.append(dumpThis(iter)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/asm/src/org/python/antlr/ast/FunctionDef.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/FunctionDef.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -77,16 +77,20 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("FunctionDef["); + StringBuffer sb = new StringBuffer("FunctionDef("); sb.append("name="); - sb.append(this.name); + sb.append(dumpThis(name)); + sb.append(","); sb.append("args="); - sb.append(this.args); + sb.append(dumpThis(args)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("decorators="); - sb.append(this.decorators); - sb.append("]"); + sb.append(dumpThis(decorators)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/GeneratorExp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/GeneratorExp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -53,12 +53,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("GeneratorExp["); + StringBuffer sb = new StringBuffer("GeneratorExp("); sb.append("elt="); - sb.append(this.elt); + sb.append(dumpThis(elt)); + sb.append(","); sb.append("generators="); - sb.append(this.generators); - sb.append("]"); + sb.append(dumpThis(generators)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Global.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Global.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Global.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Global["); + StringBuffer sb = new StringBuffer("Global("); sb.append("names="); - sb.append(this.names); - sb.append("]"); + sb.append(dumpThis(names)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/If.java =================================================================== --- branches/asm/src/org/python/antlr/ast/If.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/If.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -72,14 +72,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("If["); + StringBuffer sb = new StringBuffer("If("); sb.append("test="); - sb.append(this.test); + sb.append(dumpThis(test)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/IfExp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/IfExp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/IfExp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("IfExp["); + StringBuffer sb = new StringBuffer("IfExp("); sb.append("test="); - sb.append(this.test); + sb.append(dumpThis(test)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Import.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Import.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Import.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Import["); + StringBuffer sb = new StringBuffer("Import("); sb.append("names="); - sb.append(this.names); - sb.append("]"); + sb.append(dumpThis(names)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ImportFrom.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/ImportFrom.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -58,14 +58,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("ImportFrom["); + StringBuffer sb = new StringBuffer("ImportFrom("); sb.append("module="); - sb.append(this.module); + sb.append(dumpThis(module)); + sb.append(","); sb.append("names="); - sb.append(this.names); + sb.append(dumpThis(names)); + sb.append(","); sb.append("level="); - sb.append(this.level); - sb.append("]"); + sb.append(dumpThis(level)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Index.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Index.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Index.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Index["); + StringBuffer sb = new StringBuffer("Index("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Interactive.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Interactive.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Interactive.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Interactive["); + StringBuffer sb = new StringBuffer("Interactive("); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Lambda.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Lambda.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Lambda.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Lambda["); + StringBuffer sb = new StringBuffer("Lambda("); sb.append("args="); - sb.append(this.args); + sb.append(dumpThis(args)); + sb.append(","); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/List.java =================================================================== --- branches/asm/src/org/python/antlr/ast/List.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/List.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -50,12 +50,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("List["); + StringBuffer sb = new StringBuffer("List("); sb.append("elts="); - sb.append(this.elts); + sb.append(dumpThis(elts)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ListComp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/ListComp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -52,12 +52,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("ListComp["); + StringBuffer sb = new StringBuffer("ListComp("); sb.append("elt="); - sb.append(this.elt); + sb.append(dumpThis(elt)); + sb.append(","); sb.append("generators="); - sb.append(this.generators); - sb.append("]"); + sb.append(dumpThis(generators)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Module.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Module.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Module.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Module["); + StringBuffer sb = new StringBuffer("Module("); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Name.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Name.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Name.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Name["); + StringBuffer sb = new StringBuffer("Name("); sb.append("id="); - sb.append(this.id); + sb.append(dumpThis(id)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Num.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Num.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Num.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Num["); + StringBuffer sb = new StringBuffer("Num("); sb.append("n="); - sb.append(this.n); - sb.append("]"); + sb.append(dumpThis(n)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Pass.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Pass.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Pass.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -27,8 +27,8 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Pass["); - sb.append("]"); + StringBuffer sb = new StringBuffer("Pass("); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Print.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Print.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Print.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -56,14 +56,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Print["); + StringBuffer sb = new StringBuffer("Print("); sb.append("dest="); - sb.append(this.dest); + sb.append(dumpThis(dest)); + sb.append(","); sb.append("values="); - sb.append(this.values); + sb.append(dumpThis(values)); + sb.append(","); sb.append("nl="); - sb.append(this.nl); - sb.append("]"); + sb.append(dumpThis(nl)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Raise.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Raise.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Raise.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -41,14 +41,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Raise["); + StringBuffer sb = new StringBuffer("Raise("); sb.append("type="); - sb.append(this.type); + sb.append(dumpThis(type)); + sb.append(","); sb.append("inst="); - sb.append(this.inst); + sb.append(dumpThis(inst)); + sb.append(","); sb.append("tback="); - sb.append(this.tback); - sb.append("]"); + sb.append(dumpThis(tback)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Repr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Repr.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Repr.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Repr["); + StringBuffer sb = new StringBuffer("Repr("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Return.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Return.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Return.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Return["); + StringBuffer sb = new StringBuffer("Return("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Slice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Slice.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Slice.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Slice["); + StringBuffer sb = new StringBuffer("Slice("); sb.append("lower="); - sb.append(this.lower); + sb.append(dumpThis(lower)); + sb.append(","); sb.append("upper="); - sb.append(this.upper); + sb.append(dumpThis(upper)); + sb.append(","); sb.append("step="); - sb.append(this.step); - sb.append("]"); + sb.append(dumpThis(step)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Str.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Str.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Str.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Str["); + StringBuffer sb = new StringBuffer("Str("); sb.append("s="); - sb.append(this.s); - sb.append("]"); + sb.append(dumpThis(s)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Subscript.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Subscript.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Subscript.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Subscript["); + StringBuffer sb = new StringBuffer("Subscript("); sb.append("value="); - sb.append(this.value); + sb.append(dumpThis(value)); + sb.append(","); sb.append("slice="); - sb.append(this.slice); + sb.append(dumpThis(slice)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Suite.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Suite.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Suite.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Suite["); + StringBuffer sb = new StringBuffer("Suite("); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/TryExcept.java =================================================================== --- branches/asm/src/org/python/antlr/ast/TryExcept.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/TryExcept.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -88,14 +88,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("TryExcept["); + StringBuffer sb = new StringBuffer("TryExcept("); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("handlers="); - sb.append(this.handlers); + sb.append(dumpThis(handlers)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/TryFinally.java =================================================================== --- branches/asm/src/org/python/antlr/ast/TryFinally.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/TryFinally.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -66,12 +66,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("TryFinally["); + StringBuffer sb = new StringBuffer("TryFinally("); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("finalbody="); - sb.append(this.finalbody); - sb.append("]"); + sb.append(dumpThis(finalbody)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Tuple.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Tuple.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Tuple.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -51,12 +51,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Tuple["); + StringBuffer sb = new StringBuffer("Tuple("); sb.append("elts="); - sb.append(this.elts); + sb.append(dumpThis(elts)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/UnaryOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/UnaryOp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/UnaryOp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("UnaryOp["); + StringBuffer sb = new StringBuffer("UnaryOp("); sb.append("op="); - sb.append(this.op); + sb.append(dumpThis(op)); + sb.append(","); sb.append("operand="); - sb.append(this.operand); - sb.append("]"); + sb.append(dumpThis(operand)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Unicode.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Unicode.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Unicode.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Unicode["); + StringBuffer sb = new StringBuffer("Unicode("); sb.append("s="); - sb.append(this.s); - sb.append("]"); + sb.append(dumpThis(s)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/While.java =================================================================== --- branches/asm/src/org/python/antlr/ast/While.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/While.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -73,14 +73,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("While["); + StringBuffer sb = new StringBuffer("While("); sb.append("test="); - sb.append(this.test); + sb.append(dumpThis(test)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/With.java =================================================================== --- branches/asm/src/org/python/antlr/ast/With.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/With.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -58,14 +58,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("With["); + StringBuffer sb = new StringBuffer("With("); sb.append("context_expr="); - sb.append(this.context_expr); + sb.append(dumpThis(context_expr)); + sb.append(","); sb.append("optional_vars="); - sb.append(this.optional_vars); + sb.append(dumpThis(optional_vars)); + sb.append(","); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Yield.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Yield.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Yield.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Yield["); + StringBuffer sb = new StringBuffer("Yield("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/aliasType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/aliasType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/aliasType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("alias["); + StringBuffer sb = new StringBuffer("alias("); sb.append("name="); - sb.append(this.name); + sb.append(dumpThis(name)); + sb.append(","); sb.append("asname="); - sb.append(this.asname); - sb.append("]"); + sb.append(dumpThis(asname)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/argumentsType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/argumentsType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/argumentsType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -77,16 +77,20 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("arguments["); + StringBuffer sb = new StringBuffer("arguments("); sb.append("args="); - sb.append(this.args); + sb.append(dumpThis(args)); + sb.append(","); sb.append("vararg="); - sb.append(this.vararg); + sb.append(dumpThis(vararg)); + sb.append(","); sb.append("kwarg="); - sb.append(this.kwarg); + sb.append(dumpThis(kwarg)); + sb.append(","); sb.append("defaults="); - sb.append(this.defaults); - sb.append("]"); + sb.append(dumpThis(defaults)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/comprehensionType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/comprehensionType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/comprehensionType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -57,14 +57,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("comprehension["); + StringBuffer sb = new StringBuffer("comprehension("); sb.append("target="); - sb.append(this.target); + sb.append(dumpThis(target)); + sb.append(","); sb.append("iter="); - sb.append(this.iter); + sb.append(dumpThis(iter)); + sb.append(","); sb.append("ifs="); - sb.append(this.ifs); - sb.append("]"); + sb.append(dumpThis(ifs)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/excepthandlerType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/excepthandlerType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -66,18 +66,23 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("excepthandler["); + StringBuffer sb = new StringBuffer("excepthandler("); sb.append("type="); - sb.append(this.type); + sb.append(dumpThis(type)); + sb.append(","); sb.append("name="); - sb.append(this.name); + sb.append(dumpThis(name)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("lineno="); - sb.append(this.lineno); + sb.append(dumpThis(lineno)); + sb.append(","); sb.append("col_offset="); - sb.append(this.col_offset); - sb.append("]"); + sb.append(dumpThis(col_offset)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/keywordType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/keywordType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/keywordType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("keyword["); + StringBuffer sb = new StringBuffer("keyword("); sb.append("arg="); - sb.append(this.arg); + sb.append(dumpThis(arg)); + sb.append(","); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 04:59:19
|
Revision: 4979 http://jython.svn.sourceforge.net/jython/?rev=4979&view=rev Author: pjenvey Date: 2008-07-21 04:59:03 +0000 (Mon, 21 Jul 2008) Log Message: ----------- Merged revisions 4962-4978 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r4966 | pjenvey | 2008-07-17 14:25:44 -0700 (Thu, 17 Jul 2008) | 3 lines fix loading of 0L in cPickle proto 2 and match cPickle's dumps(0L, 2) to pickle's ........ r4975 | pjenvey | 2008-07-19 16:23:25 -0700 (Sat, 19 Jul 2008) | 1 line reintegrate r3069: don't abspath __classpath__ in sys.path ........ r4976 | pjenvey | 2008-07-20 18:38:17 -0700 (Sun, 20 Jul 2008) | 1 line small cleanup ........ r4977 | pjenvey | 2008-07-20 18:43:14 -0700 (Sun, 20 Jul 2008) | 4 lines add PyFastSequenceIter (for list and tuple) which calls final seq___finditem__. whereas PySequenceIter calls __finditem__ which may be overridden by subclasses ........ r4978 | pjenvey | 2008-07-20 18:59:47 -0700 (Sun, 20 Jul 2008) | 3 lines fix __finditem__(int) not trying subclasses' __getitem__ if the parent overrode it (like PySequence does) ........ Modified Paths: -------------- branches/asm/Lib/site.py branches/asm/src/org/python/core/PyArrayDerived.java branches/asm/src/org/python/core/PyBooleanDerived.java branches/asm/src/org/python/core/PyClassMethodDerived.java branches/asm/src/org/python/core/PyComplexDerived.java branches/asm/src/org/python/core/PyDictionaryDerived.java branches/asm/src/org/python/core/PyEnumerateDerived.java branches/asm/src/org/python/core/PyFileDerived.java branches/asm/src/org/python/core/PyFloatDerived.java branches/asm/src/org/python/core/PyFrozenSetDerived.java branches/asm/src/org/python/core/PyIntegerDerived.java branches/asm/src/org/python/core/PyList.java branches/asm/src/org/python/core/PyListDerived.java branches/asm/src/org/python/core/PyLongDerived.java branches/asm/src/org/python/core/PyModuleDerived.java branches/asm/src/org/python/core/PyObjectDerived.java branches/asm/src/org/python/core/PyPropertyDerived.java branches/asm/src/org/python/core/PySequence.java branches/asm/src/org/python/core/PySequenceIter.java branches/asm/src/org/python/core/PySetDerived.java branches/asm/src/org/python/core/PySliceDerived.java branches/asm/src/org/python/core/PyStringDerived.java branches/asm/src/org/python/core/PySuperDerived.java branches/asm/src/org/python/core/PyTuple.java branches/asm/src/org/python/core/PyTupleDerived.java branches/asm/src/org/python/core/PyTypeDerived.java branches/asm/src/org/python/core/PyUnicodeDerived.java branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/asm/src/org/python/modules/cPickle.java branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java branches/asm/src/org/python/modules/collections/PyDequeDerived.java branches/asm/src/org/python/modules/random/PyRandomDerived.java branches/asm/src/org/python/modules/thread/PyLocalDerived.java branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java branches/asm/src/templates/object.derived Added Paths: ----------- branches/asm/Lib/test/test_cpickle_jy.py branches/asm/Lib/test/test_iter_jy.py branches/asm/src/org/python/core/PyFastSequenceIter.java Property Changed: ---------------- branches/asm/ Property changes on: branches/asm ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-4961 + /trunk/jython:1-4978 Modified: branches/asm/Lib/site.py =================================================================== --- branches/asm/Lib/site.py 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/Lib/site.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -64,7 +64,10 @@ def makepath(*paths): - dir = os.path.abspath(os.path.join(*paths)) + dir = os.path.join(*paths) + if dir == '__classpath__': + return dir, dir + dir = os.path.abspath(dir) return dir, os.path.normcase(dir) def abs__file__(): Copied: branches/asm/Lib/test/test_cpickle_jy.py (from rev 4978, trunk/jython/Lib/test/test_cpickle_jy.py) =================================================================== --- branches/asm/Lib/test/test_cpickle_jy.py (rev 0) +++ branches/asm/Lib/test/test_cpickle_jy.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -0,0 +1,22 @@ +"""Misc cPickle tests. + +Made for Jython. +""" +import cPickle +import pickle +import unittest +from test import test_support + +class CPickleTestCase(unittest.TestCase): + + def test_zero_long(self): + self.assertEqual(cPickle.loads(cPickle.dumps(0L, 2)), 0L) + self.assertEqual(cPickle.dumps(0L, 2), pickle.dumps(0L, 2)) + + +def test_main(): + test_support.run_unittest(CPickleTestCase) + + +if __name__ == '__main__': + test_main() Copied: branches/asm/Lib/test/test_iter_jy.py (from rev 4978, trunk/jython/Lib/test/test_iter_jy.py) =================================================================== --- branches/asm/Lib/test/test_iter_jy.py (rev 0) +++ branches/asm/Lib/test/test_iter_jy.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -0,0 +1,32 @@ +"""Misc iterator tests. + +Made for Jython. +""" +import test_support +import unittest + +class IterTestCase(unittest.TestCase): + + def test_fastiter(self): + class MyList(list): + def __getitem__(self, index): + return str(index) + '!' + class MyTuple(tuple): + def __getitem__(self, index): + return str(index) + '!' + self.assertEqual(iter(MyList(['a', 'b'])).next(), 'a') + self.assertEqual(iter(MyTuple(['a', 'b'])).next(), 'a') + + def test_slowiter(self): + class MyStr(str): + def __getitem__(self, index): + return str(index) + '!' + self.assertEqual(iter(MyStr('ab')).next(), '0!') + + +def test_main(): + test_support.run_unittest(IterTestCase) + + +if __name__ == '__main__': + test_main() Modified: branches/asm/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Copied: branches/asm/src/org/python/core/PyFastSequenceIter.java (from rev 4978, trunk/jython/src/org/python/core/PyFastSequenceIter.java) =================================================================== --- branches/asm/src/org/python/core/PyFastSequenceIter.java (rev 0) +++ branches/asm/src/org/python/core/PyFastSequenceIter.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -0,0 +1,27 @@ +/* Copyright (c) Jython Developers */ +package org.python.core; + +/** + * Sequence iterator specialized for accessing the underlying sequence directly. + */ +public class PyFastSequenceIter extends PyIterator { + + private PySequence seq; + + private int index = 0; + + public PyFastSequenceIter(PySequence seq) { + this.seq = seq; + } + + public PyObject __iternext__() { + try { + return seq.seq___finditem__(index++); + } catch (PyException exc) { + if (Py.matchException(exc, Py.StopIteration)) { + return null; + } + throw exc; + } + } +} Modified: branches/asm/src/org/python/core/PyFileDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFileDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFileDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyList.java =================================================================== --- branches/asm/src/org/python/core/PyList.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyList.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -380,9 +380,13 @@ return seq___nonzero__(); } + public PyObject __iter__() { + return list___iter__(); + } + @ExposedMethod public PyObject list___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") Modified: branches/asm/src/org/python/core/PyListDerived.java =================================================================== --- branches/asm/src/org/python/core/PyListDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyListDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyLongDerived.java =================================================================== --- branches/asm/src/org/python/core/PyLongDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyLongDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -830,6 +830,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySequence.java =================================================================== --- branches/asm/src/org/python/core/PySequence.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySequence.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -256,7 +256,11 @@ } } - public synchronized PyObject __finditem__(int index) { + public PyObject __finditem__(int index) { + return seq___finditem__(index); + } + + final synchronized PyObject seq___finditem__(int index) { index = fixindex(index); if(index == -1) { return null; @@ -271,7 +275,7 @@ final PyObject seq___finditem__(PyObject index) { if(index instanceof PyInteger || index instanceof PyLong) { - return __finditem__(index.asInt()); + return seq___finditem__(index.asInt()); } else if(index instanceof PySlice) { PySlice s = (PySlice)index; return __getslice__(s.start, s.stop, s.step); Modified: branches/asm/src/org/python/core/PySequenceIter.java =================================================================== --- branches/asm/src/org/python/core/PySequenceIter.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySequenceIter.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -1,12 +1,17 @@ +/* Copyright (c) Jython Developers */ package org.python.core; +/** + * General sequence iterator. + */ public class PySequenceIter extends PyIterator { + private PyObject seq; - private int idx; + private int index = 0; + public PySequenceIter(PyObject seq) { this.seq = seq; - this.idx = 0; } public PyObject __iternext__() { @@ -16,7 +21,7 @@ PyObject result; try { - result = seq.__finditem__(idx++); + result = seq.__finditem__(index++); } catch (PyException exc) { if (Py.matchException(exc, Py.StopIteration)) { seq = null; @@ -30,4 +35,3 @@ return result; } } - Modified: branches/asm/src/org/python/core/PySetDerived.java =================================================================== --- branches/asm/src/org/python/core/PySetDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySetDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySliceDerived.java =================================================================== --- branches/asm/src/org/python/core/PySliceDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySliceDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyStringDerived.java =================================================================== --- branches/asm/src/org/python/core/PyStringDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyStringDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySuperDerived.java =================================================================== --- branches/asm/src/org/python/core/PySuperDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySuperDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyTuple.java =================================================================== --- branches/asm/src/org/python/core/PyTuple.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTuple.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -191,9 +191,13 @@ return repeat(count); } + public PyObject __iter__() { + return tuple___iter__(); + } + @ExposedMethod public PyObject tuple___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") Modified: branches/asm/src/org/python/core/PyTupleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTupleDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTupleDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyTypeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTypeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTypeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -830,6 +830,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyUnicodeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/cPickle.java =================================================================== --- branches/asm/src/org/python/modules/cPickle.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/cPickle.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -1130,9 +1130,17 @@ private void save_long(PyObject object) { if(protocol >= 2) { BigInteger integer = ((PyLong)object).getValue(); + + if (integer.compareTo(BigInteger.ZERO) == 0) { + // It's 0 -- an empty bytestring. + file.write(LONG1); + file.write((char)0); + return; + } + byte[] bytes = integer.toByteArray(); int l = bytes.length; - if(l < 256) { + if (l < 256) { file.write(LONG1); file.write((char)l); } else { @@ -1905,6 +1913,10 @@ private void load_bin_long(int length) { int longLength = read_binint(length); + if (longLength == 0) { + push(new PyLong(BigInteger.ZERO)); + return; + } String s = file.read(longLength); byte[] bytes = new byte[s.length()]; // Write to the byte array in reverse order: pickle orders Modified: branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/collections/PyDequeDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -832,6 +832,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -832,6 +832,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/templates/object.derived =================================================================== --- branches/asm/src/templates/object.derived 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/templates/object.derived 2008-07-21 04:59:03 UTC (rev 4979) @@ -188,6 +188,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type = getType(); + PyObject impl = self_type.lookup("__getitem__"); + if (impl != null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc, Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-23 01:21:35
|
Revision: 4987 http://jython.svn.sourceforge.net/jython/?rev=4987&view=rev Author: pjenvey Date: 2008-07-23 01:21:32 +0000 (Wed, 23 Jul 2008) Log Message: ----------- many various PyArray fixes for 2.5 test_array Modified Paths: -------------- branches/asm/Lib/test/test_array.py branches/asm/src/org/python/core/PyArray.java Modified: branches/asm/Lib/test/test_array.py =================================================================== --- branches/asm/Lib/test/test_array.py 2008-07-23 01:19:34 UTC (rev 4986) +++ branches/asm/Lib/test/test_array.py 2008-07-23 01:21:32 UTC (rev 4987) @@ -9,6 +9,10 @@ import array, cStringIO, math from cPickle import loads, dumps +if test_support.is_jython: + import operator + from test_weakref import extra_collect + class ArraySubclass(array.array): pass @@ -308,7 +312,10 @@ array.array(self.typecode) ) - self.assertRaises(TypeError, a.__mul__, "bad") + if test_support.is_jython: + self.assertRaises(TypeError, operator.mul, a, "bad") + else: + self.assertRaises(TypeError, a.__mul__, "bad") def test_imul(self): a = array.array(self.typecode, self.example) @@ -337,7 +344,10 @@ a *= -1 self.assertEqual(a, array.array(self.typecode)) - self.assertRaises(TypeError, a.__imul__, "bad") + if test_support.is_jython: + self.assertRaises(TypeError, operator.imul, a, "bad") + else: + self.assertRaises(TypeError, a.__imul__, "bad") def test_getitem(self): a = array.array(self.typecode, self.example) @@ -690,6 +700,8 @@ p = proxy(s) self.assertEqual(p.tostring(), s.tostring()) s = None + if test_support.is_jython: + extra_collect() self.assertRaises(ReferenceError, len, p) def test_bug_782369(self): @@ -898,7 +910,13 @@ def test_overflow(self): a = array.array(self.typecode) lower = 0 - upper = long(pow(2, a.itemsize * 8)) - 1L + itemsize = a.itemsize + if test_support.is_jython: + # XXX: unsigned itemsizes are larger than would be expected + # in CPython + itemsize /= 2 + #upper = long(pow(2, a.itemsize * 8)) - 1L + upper = long(pow(2, itemsize * 8)) - 1L self.check_overflow(lower, upper) @@ -980,6 +998,13 @@ def test_main(verbose=None): import sys + if test_support.is_jython: + # CPython specific; returns a memory address + del BaseTest.test_buffer_info + + # No buffers in Jython + del BaseTest.test_buffer + test_support.run_unittest(*tests) # verify reference counting Modified: branches/asm/src/org/python/core/PyArray.java =================================================================== --- branches/asm/src/org/python/core/PyArray.java 2008-07-23 01:19:34 UTC (rev 4986) +++ branches/asm/src/org/python/core/PyArray.java 2008-07-23 01:21:32 UTC (rev 4987) @@ -27,88 +27,104 @@ * <p> * See also the jarray module. */ -@ExposedType(name = "array", base = PyObject.class) +@ExposedType(name = "array.array", base = PyObject.class) public class PyArray extends PySequence implements Cloneable { public static final PyType TYPE = PyType.fromClass(PyArray.class); - + + /** The underlying Java array. */ private Object data; + /** The Java array class. */ private Class type; + /** The Python style typecode of the array. */ private String typecode; private ArrayDelegate delegate; - // PyArray can't extend anymore, so delegate - private class ArrayDelegate extends AbstractArray { + public PyArray(PyType type) { + super(type); + } + public PyArray(Class type, Object data) { + this(TYPE); + setup(type, data); + } - private ArrayDelegate() { - super(data == null ? 0 : Array.getLength(data)); - } - - protected Object getArray() { - return data; - } - - protected void setArray(Object array) { - data = array; - } - - @Override - protected Object createArray(int size) { - Class baseType = data.getClass().getComponentType(); - return Array.newInstance(baseType, size); - } + public PyArray(Class type, int n) { + this(type, Array.newInstance(type, n)); } - - public PyArray(PyType type){ - super(type); - } public PyArray(PyArray toCopy) { - data = toCopy.delegate.copyArray(); - delegate = new ArrayDelegate(); - type = toCopy.type; + this(toCopy.type, toCopy.delegate.copyArray()); + typecode = toCopy.typecode; } - public PyArray(Class type, Object data) { + private void setup(Class type, Object data) { this.type = type; - this.data = data; + typecode = class2char(type); + if (data == null) { + this.data = Array.newInstance(type, 0); + } else { + this.data = data; + } delegate = new ArrayDelegate(); } - public PyArray(Class type, int n) { - this(type, Array.newInstance(type, n)); - } - - @ExposedMethod @ExposedNew - final void array_init(PyObject[] args, String[] kwds) { - ArgParser ap = new ArgParser("array", args, kwds, new String[] {"typecode", "seq"}, 1); + static final PyObject array_new(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { + if (new_.for_type != subtype && keywords.length > 0) { + int argc = args.length - keywords.length; + PyObject[] justArgs = new PyObject[argc]; + System.arraycopy(args, 0, justArgs, 0, argc); + args = justArgs; + } + ArgParser ap = new ArgParser("array", args, Py.NoKeywords, new String[] {"typecode", "initializer"}, + 1); + ap.noKeywords(); PyObject obj = ap.getPyObject(0); - if (obj instanceof PyString) { - String code = obj.toString(); - if (code.length() != 1) { + PyObject initial = ap.getPyObject(1, null); + + Class type; + String typecode; + if (obj instanceof PyString && !(obj instanceof PyUnicode)) { + if (obj.__len__() != 1) { throw Py.TypeError("array() argument 1 must be char, not str"); } - type = char2class(code.charAt(0)); - typecode = code; + typecode = obj.toString(); + type = char2class(typecode.charAt(0)); } else if (obj instanceof PyJavaClass) { type = ((PyJavaClass)obj).proxyClass; typecode = type.getName(); } else { - throw Py.TypeError("array() argument 1 must be char, not " + - obj.getType().fastGetName()); + throw Py.TypeError("array() argument 1 must be char, not " + obj.getType().fastGetName()); } - data = Array.newInstance(type, 0); - delegate = new ArrayDelegate(); - PyObject seq = ap.getPyObject(1, null); - if (seq == null) { - return; + + PyArray self; + if (new_.for_type == subtype) { + self = new PyArray(subtype); + } else { + self = new PyArrayDerived(subtype); } - extendInternal(seq); + // Initialize the typecode (and validate type) before creating the backing Array + class2char(type); + self.setup(type, Array.newInstance(type, 0)); + self.typecode = typecode; + if (initial == null) { + return self; + } + if (initial instanceof PyList) { + self.fromlist(initial); + } else if (initial instanceof PyString && !(initial instanceof PyUnicode)) { + self.fromstring(initial.toString()); + } else if (initial instanceof PyUnicode && "u".equals(typecode)) { + self.fromunicode(initial.toString()); + } else { + self.extendInternal(initial); + } + return self; } public static PyArray zeros(int n, char typecode) { @@ -230,6 +246,74 @@ seq___delslice__(start, stop, step); } + public PyObject __imul__(PyObject o) { + return array___imul__(o); + } + + @ExposedMethod(type = MethodType.BINARY) + final PyObject array___imul__(PyObject o) { + if(!(o instanceof PyInteger || o instanceof PyLong)) { + return null; + } + if (delegate.getSize() > 0) { + int count = o.asInt(); + if (count <= 0) { + delegate.clear(); + return this; + } + Object copy = delegate.copyArray(); + delegate.ensureCapacity(delegate.getSize() * count); + for (int i = 1; i < count; i++) { + delegate.appendArray(copy); + } + } + return this; + } + + public PyObject __mul__(PyObject o) { + return array___mul__(o); + } + + @ExposedMethod(type = MethodType.BINARY) + final PyObject array___mul__(PyObject o) { + if(!(o instanceof PyInteger || o instanceof PyLong)) { + return null; + } + return repeat(o.asInt()); + } + + public PyObject __rmul__(PyObject o) { + return array___rmul__(o); + } + + @ExposedMethod(type = MethodType.BINARY) + final PyObject array___rmul__(PyObject o) { + if(!(o instanceof PyInteger || o instanceof PyLong)) { + return null; + } + return repeat(o.asInt()); + } + + public PyObject __iadd__(PyObject other) { + return array___iadd__(other); + } + + @ExposedMethod + final PyObject array___iadd__(PyObject other) { + PyArray otherArr = null; + if (!(other instanceof PyArray)) { + throw Py.TypeError(String.format("can only append array (not \"%.200s\") to array", + other.getType().fastGetName())); + } + otherArr = (PyArray)other; + if (!otherArr.typecode.equals(this.typecode)) { + throw Py.TypeError("can only append arrays of the same type, " + + "expected '" + this.type + ", found " + otherArr.type); + } + delegate.appendArray(otherArr.delegate.copyArray()); + return this; + } + public PyObject __add__(PyObject other) { return array___add__(other); } @@ -248,7 +332,7 @@ throw Py.TypeError("can only append another array to an array"); } otherArr = (PyArray)other; - if(!otherArr.type.equals(this.type)) { + if(!otherArr.typecode.equals(this.typecode)) { throw Py.TypeError("can only append arrays of the same type, " + "expected '" + this.type + ", found " + otherArr.type); } @@ -266,25 +350,38 @@ return delegate.getSize(); } - /** - * String representation of PyArray - * - * @return string representation of PyArray - */ - public PyString __repr__() { - StringBuffer buf = new StringBuffer(128); - buf.append("array(").append(class2char(type)).append(",["); - for(int i = 0; i < __len__() - 1; i++) { - buf.append(pyget(i).__repr__().toString()); - buf.append(", "); + public PyObject __reduce__() { + return array___reduce__(); + } + + @ExposedMethod + final PyObject array___reduce__() { + PyObject dict = __findattr__("__dict__"); + if (dict == null) { + dict = Py.None; } - if(__len__() > 0) { - buf.append(pyget(__len__() - 1).__repr__().toString()); + if (__len__() > 0) { + return new PyTuple(getType(), new PyTuple(Py.newString(typecode), + Py.newString(tostring())), dict); + } else { + return new PyTuple(getType(), new PyTuple(Py.newString(typecode)), dict); } - buf.append("]) "); - return new PyString(buf.toString()); } + @Override + public String toString() { + if (__len__() == 0) { + return String.format("array('%s')", typecode); + } + String value; + if ("c".equals(typecode)) { + value = tostring(); + } else { + value = tolist().toString(); + } + return String.format("array('%s', %s)", typecode, value); + } + /** * * @param c @@ -340,8 +437,7 @@ * written on a machine with a different byte order. */ public void byteswap() { - // unknown type - throw RuntimeError - if(getItemsize() == 0) { + if (getItemsize() == 0) { throw Py.RuntimeError("don't know how to byteswap this array type"); } ByteSwapper.swap(data); @@ -431,7 +527,7 @@ case 'l': return Long.TYPE; case 'L': - return PyLong.class; + return Long.TYPE; case 'f': return Float.TYPE; case 'd': @@ -443,21 +539,21 @@ private static String class2char(Class cls) { if(cls.equals(Boolean.TYPE)) - return "'z'"; + return "z"; else if(cls.equals(Character.TYPE)) - return "'c'"; + return "c"; else if(cls.equals(Byte.TYPE)) - return "'b'"; + return "b"; else if(cls.equals(Short.TYPE)) - return "'h'"; + return "h"; else if(cls.equals(Integer.TYPE)) - return "'i'"; + return "i"; else if(cls.equals(Long.TYPE)) - return "'l'"; + return "l"; else if(cls.equals(Float.TYPE)) - return "'f'"; + return "f"; else if(cls.equals(Double.TYPE)) - return "'d'"; + return "d"; else return cls.getName(); } @@ -508,17 +604,18 @@ * stepping increment between start and stop */ protected void delRange(int start, int stop, int step) { - // Now the AbstractArray can support this: - // throw Py.TypeError("can't remove from array"); - if(step > 0 && stop < start) - stop = start; - if(step == 1) { + if (step == 1) { delegate.remove(start, stop); - } else { - int n = sliceLength(start, stop, step); - for(int i = start, j = 0; j < n; i += step, j++) { + } else if (step > 1) { + for (int i = start; i < stop; i += step) { delegate.remove(i); + i--; + stop--; } + } else if (step < 0) { + for (int i = start; i >= 0 && i >= stop; i += step) { + delegate.remove(i); + } } } @@ -554,13 +651,13 @@ */ private void extendInternal(PyObject iterable) { // string input - if(iterable instanceof PyString) { + if (iterable instanceof PyString) { fromstring(((PyString)iterable).toString()); // PyArray input - } else if(iterable instanceof PyArray) { + } else if (iterable instanceof PyArray) { PyArray source = (PyArray)iterable; - if(!source.type.equals(this.type)) { - throw Py.TypeError("can only extend with an array of the same kind"); + if (!source.typecode.equals(typecode)) { + throw Py.TypeError("can only extend with array of same kind"); } delegate.appendArray(source.delegate.copyArray()); } else { @@ -647,9 +744,9 @@ * input list object that will be appended to the array */ public void fromlist(PyObject obj) { - // check for list - if(!(obj instanceof PyList)) - throw Py.TypeError("expected list argument"); + if(!(obj instanceof PyList)) { + throw Py.TypeError("arg must be list"); + } // store the current size of the internal array int size = delegate.getSize(); try { @@ -714,7 +811,7 @@ } } else if(type == Character.TYPE) { for(int i = 0; i < count; i++, index++) { - Array.setChar(data, index, (char)dis.readByte()); + Array.setChar(data, index, (char)(dis.readByte() & 0xff)); delegate.size++; } } else if(type == Integer.TYPE) { @@ -748,6 +845,10 @@ return (index - origsize); } + public void fromstring(String input) { + array_fromstring(input); + } + /** * Appends items from the string, interpreting the string as an array of * machine values (as if it had been read from a file using the @@ -756,7 +857,8 @@ * @param input * string of bytes containing array data */ - public void fromstring(String input) { + @ExposedMethod + final void array_fromstring(String input) { int itemsize = getItemsize(); int strlen = input.length(); if((strlen % itemsize) != 0) { @@ -776,6 +878,18 @@ } } + public void fromunicode(String input) { + array_fromunicode(input); + } + + @ExposedMethod + final void array_fromunicode(String input) { + if (!"u".equals(typecode)) { + throw Py.ValueError("fromunicode() may only be called on type 'u' arrays"); + } + array_fromstring(input); + } + /** * Get the element at position <em>i</em> from the array * @@ -888,15 +1002,18 @@ * @return A new PyArray object containing the described slice */ protected PyObject getslice(int start, int stop, int step) { - if(step > 0 && stop < start) + if (step > 0 && stop < start) { stop = start; + } int n = sliceLength(start, stop, step); PyArray ret = new PyArray(type, n); - if(step == 1) { + // XXX: + ret.typecode = typecode; + if (step == 1) { System.arraycopy(data, start, ret.data, 0, n); return ret; } - for(int i = start, j = 0; j < n; i += step, j++) { + for (int i = start, j = 0; j < n; i += step, j++) { Array.set(ret.data, j, Array.get(data, i)); } return ret; @@ -969,6 +1086,7 @@ * value to be inserted into array */ public void insert(int index, PyObject value) { + index = calculateIndex(index); delegate.makeInsertSpace(index); Array.set(data, index, Py.tojava(value, type)); } @@ -997,8 +1115,13 @@ * @return array element popped from index */ public PyObject pop(int index) { - // todo: python-style error handling - index = (index < 0) ? delegate.getSize() + index : index; + if (delegate.getSize() == 0) { + throw Py.IndexError("pop from empty array"); + } + index = fixindex(index); + if (index == -1) { + throw Py.IndexError("pop index out of range"); + } PyObject ret = Py.java2py(Array.get(data, index)); delegate.remove(index); return ret; @@ -1036,6 +1159,8 @@ protected PyObject repeat(int count) { Object arraycopy = delegate.copyArray(); PyArray ret = new PyArray(type, 0); + // XXX: + ret.typecode = typecode; for(int i = 0; i < count; i++) { ret.delegate.appendArray(arraycopy); } @@ -1085,9 +1210,9 @@ } catch(ClassCastException e) { throw Py.TypeError("Type not compatible with array type"); } - if(val < Byte.MIN_VALUE) { + if(val < (isSigned() ? 0 : Byte.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > Byte.MAX_VALUE) { + } else if(val > (isSigned() ? Byte.MAX_VALUE * 2 + 1 : Byte.MAX_VALUE)) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Short.TYPE) { @@ -1097,9 +1222,9 @@ } catch(ClassCastException e) { throw Py.TypeError("Type not compatible with array type"); } - if(val < Short.MIN_VALUE) { + if(val < (isSigned() ? 0 : Short.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > Short.MAX_VALUE) { + } else if(val > (isSigned() ? Byte.MAX_VALUE * 2 + 1 : Short.MAX_VALUE)) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Integer.TYPE) { @@ -1109,21 +1234,30 @@ } catch(ClassCastException e) { throw Py.TypeError("Type not compatible with array type"); } - if(val < Integer.MIN_VALUE) { + if(val < (isSigned() ? 0 : Integer.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > Integer.MAX_VALUE) { + } else if(val > (isSigned() ? Short.MAX_VALUE * 2 + 1 : Integer.MAX_VALUE)) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Long.TYPE) { - Object o; - try { - o = value.__tojava__(Long.TYPE); - } catch(ClassCastException e) { - throw Py.TypeError("Type not compatible with array type"); + if (isSigned() && value instanceof PyInteger) { + if (((PyInteger)value).getValue() < 0) { + throw Py.OverflowError("value too small for " + type.getName()); + } + } else if (value instanceof PyLong) { + ((PyLong)value).getLong(isSigned() ? 0 : Long.MIN_VALUE, + Long.MAX_VALUE); + } else { + Object o; + try { + o = value.__tojava__(Long.TYPE); + } catch(ClassCastException e) { + throw Py.TypeError("Type not compatible with array type"); + } + if(o == Py.NoConversion) { + throw Py.TypeError("Type not compatible with array type"); + } } - if(o == Py.NoConversion) { - throw Py.OverflowError("value out of range for long"); - } } Object o = Py.tojava(value, type); if(o == Py.NoConversion) { @@ -1132,6 +1266,10 @@ Array.set(data, i, o); } + private boolean isSigned() { + return typecode.length() == 1 && typecode.equals(typecode.toUpperCase()); + } + /** * Sets a slice of the array. <em>value</em> can be a string (for * <code>byte</code> and <code>char</code> types) or PyArray. If a @@ -1146,6 +1284,9 @@ * stepping increment of the slice */ protected void setslice(int start, int stop, int step, PyObject value) { + if (stop < start) { + stop = start; + } if(type == Character.TYPE && value instanceof PyString) { char[] chars = null; // if (value instanceof PyString) { @@ -1153,20 +1294,7 @@ throw Py.ValueError("invalid bounds for setting from string"); } chars = value.toString().toCharArray(); - // } - // else if (value instanceof PyArray && - // ((PyArray)value).type == Character.TYPE) { - // PyArray other = (PyArray)value; - // chars = (char[])other.delegate.copyArray(); - // } - int insertSpace = chars.length - (stop - start); - // adjust the array, either adding space or removing space - if(insertSpace > 0) { - delegate.makeInsertSpace(start, insertSpace); - } else if(insertSpace < 0) { - delegate.remove(start, -insertSpace + start - 1); - } - delegate.replaceSubArray(chars, start); + delegate.replaceSubArray(start, stop, chars, 0, chars.length); } else { if(value instanceof PyString && type == Byte.TYPE) { byte[] chars = ((PyString)value).toBytes(); @@ -1177,22 +1305,40 @@ } } else if(value instanceof PyArray) { PyArray array = (PyArray)value; - int insertSpace = array.delegate.getSize() - (stop - start); - // adjust the array, either adding space or removing space - // ...snapshot in case "value" is "this" - Object arrayCopy = array.delegate.copyArray(); - if(insertSpace > 0) { - delegate.makeInsertSpace(start, insertSpace); - } else if(insertSpace < 0) { - delegate.remove(start, -insertSpace + start - 1); + if (!array.typecode.equals(typecode)) { + throw Py.TypeError("bad argument type for built-in operation|" + array.typecode + "|" + typecode); } - try { - delegate.replaceSubArray(arrayCopy, start); - } catch(IllegalArgumentException e) { - throw Py.TypeError("Slice typecode '" + array.typecode - + "' is not compatible with this array (typecode '" - + this.typecode + "')"); + if (step == 1) { + Object arrayDelegate; + if (array == this) { + arrayDelegate = array.delegate.copyArray(); + } else { + arrayDelegate = array.delegate.getArray(); + } + try { + delegate.replaceSubArray(start, stop, arrayDelegate, 0, array.delegate.getSize()); + } catch(IllegalArgumentException e) { + throw Py.TypeError("Slice typecode '" + array.typecode + + "' is not compatible with this array (typecode '" + + this.typecode + "')"); + } + } else if (step > 1) { + int len = array.__len__(); + for (int i = 0, j = 0; i < len; i++, j += step) { + Array.set(data, j + start, Array.get(array.data, i)); + } + } else if (step < 0) { + if (array == this) { + array = (PyArray)array.clone(); + } + int len = array.__len__(); + for (int i = 0, j = delegate.getSize() - 1; i < len; i++, j += step) { + Array.set(data, j, Array.get(array.data, i)); + } } + } else { + throw Py.TypeError(String.format("can only assign array (not \"%.200s\") to array " + + "slice", value.getType().fastGetName())); } } } @@ -1304,4 +1450,34 @@ } return StringUtil.fromBytes(bos.toByteArray()); } + + @ExposedMethod + public final PyObject array_tounicode() { + if (!"u".equals(typecode)) { + throw Py.ValueError("tounicode() may only be called on type 'u' arrays"); + } + return new PyUnicode(tostring()); + } + + // PyArray can't extend anymore, so delegate + private class ArrayDelegate extends AbstractArray { + + private ArrayDelegate() { + super(data == null ? 0 : Array.getLength(data)); + } + + protected Object getArray() { + return data; + } + + protected void setArray(Object array) { + data = array; + } + + @Override + protected Object createArray(int size) { + Class baseType = data.getClass().getComponentType(); + return Array.newInstance(baseType, size); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-23 01:58:04
|
Revision: 4988 http://jython.svn.sourceforge.net/jython/?rev=4988&view=rev Author: fwierzbicki Date: 2008-07-23 01:58:01 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Made Str offsets better match CPython. PythonTree now extends BaseTree (too much of CommonTree was getting changed anyway). astdump.py repaired so that it is a useful testing ground for ast comparisons. Modified Paths: -------------- branches/asm/ast/astdump.py branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/PythonTree.java Modified: branches/asm/ast/astdump.py =================================================================== --- branches/asm/ast/astdump.py 2008-07-23 01:21:32 UTC (rev 4987) +++ branches/asm/ast/astdump.py 2008-07-23 01:58:01 UTC (rev 4988) @@ -29,9 +29,11 @@ pyfiles = [code_path] for pyfile in pyfiles: - print "%s to %s" % (pyfile, output_dir) import pprint - fh = open(makepath(os.path.join(output_dir, pyfile)), 'w') + path = pyfile.split(os.path.sep) + print "%s to %s: %s" % (pyfile, output_dir, os.path.join(output_dir, *path)) + fh = open(makepath(os.path.join(output_dir, *path)), 'w') + print fh pprint.pprint(astview.tree(pyfile), fh) if __name__ == '__main__': Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-23 01:21:32 UTC (rev 4987) +++ branches/asm/grammar/Python.g 2008-07-23 01:58:01 UTC (rev 4988) @@ -393,8 +393,7 @@ } Token extractStringToken(List s) { - //XXX: really we want the *last* one. - return (Token)s.get(0); + return (Token)s.get(s.size() - 1); } @@ -956,7 +955,7 @@ | LONGINT -> ^(NumTok<Num>[$LONGINT, makeInt($LONGINT)]) | FLOAT -> ^(NumTok<Num>[$FLOAT, makeFloat($FLOAT)]) | COMPLEX -> ^(NumTok<Num>[$COMPLEX, makeComplex($COMPLEX)]) - | (S+=STRING)+ {debug("S+: " + $S);} + | (S+=STRING)+ -> ^(StrTok<Str>[extractStringToken($S), extractStrings($S)]) ; @@ -1299,7 +1298,12 @@ | '"""' (options {greedy=false;}:TRIQUOTE)* '"""' | '"' (ESC|~('\\'|'\n'|'"'))* '"' | '\'' (ESC|~('\\'|'\n'|'\''))* '\'' - ) + ) { + if (state.tokenStartLine != input.getLine()) { + state.tokenStartLine = input.getLine(); + state.tokenStartCharPositionInLine = -2; + } + } ; /** the two '"'? cause a warning -- is there a way to avoid that? */ Modified: branches/asm/src/org/python/antlr/PythonTree.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTree.java 2008-07-23 01:21:32 UTC (rev 4987) +++ branches/asm/src/org/python/antlr/PythonTree.java 2008-07-23 01:58:01 UTC (rev 4988) @@ -1,7 +1,7 @@ package org.python.antlr; import org.antlr.runtime.tree.BaseTree; -import org.antlr.runtime.tree.CommonTree; +import org.antlr.runtime.tree.Tree; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; @@ -10,14 +10,27 @@ import org.python.antlr.ast.VisitorIF; -public class PythonTree extends CommonTree implements AST { +public class PythonTree extends BaseTree implements AST { public boolean from_future_checked = false; private int charStartIndex = -1; private int charStopIndex = -1; + /** A single token is the payload */ + public 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 */ + public PythonTree parent; + + /** What index is this node in the child list? Range: 0..n-1 */ + public int childIndex = -1; + public PythonTree(int ttype, Token t) { - super(); CommonToken c = new CommonToken(ttype, t.getText()); c.setLine(t.getLine()); c.setTokenIndex(t.getTokenIndex()); @@ -28,16 +41,109 @@ token = c; } - public PythonTree(Token token) { - super(token); + public PythonTree(Token t) { + this.token = t; } public PythonTree(PythonTree node) { - super(node); + super(node); + token = node.token; + startIndex = node.startIndex; + stopIndex = node.stopIndex; charStartIndex = node.getCharStartIndex(); charStopIndex = node.getCharStopIndex(); } + + public Token getToken() { + return token; + } + public Tree dupNode() { + return new PythonTree(this); + } + + public boolean isNil() { + return token==null; + } + + public int getType() { + if (token==null) { + return Token.INVALID_TOKEN_TYPE; + } + return token.getType(); + } + + public String getText() { + if (token==null) { + return null; + } + return token.getText(); + } + + public int getLine() { + if (token==null || token.getLine()==0) { + if ( getChildCount()>0 ) { + return getChild(0).getLine(); + } + return 0; + } + return token.getLine(); + } + + public int getCharPositionInLine() { + 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(); + } + + public int getTokenStartIndex() { + if ( startIndex==-1 && token!=null ) { + return token.getTokenIndex(); + } + return startIndex; + } + + public void setTokenStartIndex(int index) { + startIndex = index; + } + + public int getTokenStopIndex() { + if ( stopIndex==-1 && token!=null ) { + return token.getTokenIndex(); + } + return stopIndex; + } + + public void setTokenStopIndex(int index) { + stopIndex = index; + } + + public int getChildIndex() { + return childIndex; + } + + public Tree getParent() { + return parent; + } + + public void setParent(Tree t) { + this.parent = (PythonTree)t; + } + + public void setChildIndex(int index) { + this.childIndex = index; + } + public int getCharStartIndex() { if (charStartIndex == -1 && token != null) { if (token instanceof CommonToken) { @@ -54,13 +160,23 @@ charStartIndex = index; } + /* + * Adding one to stopIndex from Tokens. ANTLR defines the char position as + * being the array index of the actual characters. Most tools these days + * define document offsets as the positions between the characters. If you + * imagine drawing little boxes around each character and think of the + * numbers as pointing to either the left or right side of a character's + * box, then 0 is before the first character - and in a Document of 10 + * characters, position 10 is after the last character. + */ public int getCharStopIndex() { + if (charStopIndex == -1 && token != null) { if (token instanceof CommonToken) { - return ((CommonToken)token).getStopIndex(); + return ((CommonToken)token).getStopIndex() + 1; } if (token instanceof ImaginaryToken) { - return ((ImaginaryToken)token).getStopIndex(); + return ((ImaginaryToken)token).getStopIndex() + 1; } } return charStopIndex; @@ -74,6 +190,13 @@ if (isNil()) { return "None"; } + if ( getType()==Token.INVALID_TOKEN_TYPE ) { + return "<errornode>"; + } + if ( token==null ) { + return null; + } + return token.getText() + "(" + this.getLine() + "," + this.getCharPositionInLine() + ")"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-24 07:22:42
|
Revision: 4993 http://jython.svn.sourceforge.net/jython/?rev=4993&view=rev Author: pjenvey Date: 2008-07-24 07:22:38 +0000 (Thu, 24 Jul 2008) Log Message: ----------- fix a regression from the bug 1140 fix Modified Paths: -------------- branches/asm/Lib/test/test_re_jy.py branches/asm/src/org/python/modules/sre/PatternObject.java Modified: branches/asm/Lib/test/test_re_jy.py =================================================================== --- branches/asm/Lib/test/test_re_jy.py 2008-07-23 20:55:03 UTC (rev 4992) +++ branches/asm/Lib/test/test_re_jy.py 2008-07-24 07:22:38 UTC (rev 4993) @@ -4,6 +4,11 @@ class ReTest(unittest.TestCase): + def test_bug_1140_addendum(self): + result = re.sub('', lambda match : None, 'foo') + self.assertEqual(result, 'foo') + self.assert_(isinstance(result, str)) + def test_unkown_groupname(self): self.assertRaises(IndexError, re.match("(?P<int>\d+)\.(\d*)", '3.14').group, Modified: branches/asm/src/org/python/modules/sre/PatternObject.java =================================================================== --- branches/asm/src/org/python/modules/sre/PatternObject.java 2008-07-23 20:55:03 UTC (rev 4992) +++ branches/asm/src/org/python/modules/sre/PatternObject.java 2008-07-24 07:22:38 UTC (rev 4993) @@ -170,22 +170,20 @@ appended = true; } - // XXX - does this break derived types? anyway, following rule enumerated in - // test_re.test_bug_1140 - + // Follows rules enumerated in test_re.test_bug_1140 PyString outstring; - if (__builtin__.isinstance(instring, PyString.TYPE) && - (buf.length() == 0 || __builtin__.isinstance(template, PyString.TYPE))) { - outstring = new PyString(buf.toString()); + if (buf.length() == 0) { + outstring = instring.createInstance(buf.toString()); + } else if (template instanceof PyUnicode || instring instanceof PyUnicode) { + outstring = Py.newUnicode(buf.toString()); + } else { + outstring = Py.newString(buf.toString()); } - else { - outstring = new PyUnicode(buf.toString()); - } - if (subn) + if (subn) { return new PyTuple(outstring, Py.newInteger(n)); - else - return outstring; + } + return outstring; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-24 07:29:56
|
Revision: 4994 http://jython.svn.sourceforge.net/jython/?rev=4994&view=rev Author: pjenvey Date: 2008-07-24 07:29:54 +0000 (Thu, 24 Jul 2008) Log Message: ----------- add codecs.charmap_build which builds optimized encoding maps now used by the charmap encoder Modified Paths: -------------- branches/asm/CoreExposed.includes branches/asm/src/org/python/modules/_codecs.java Modified: branches/asm/CoreExposed.includes =================================================================== --- branches/asm/CoreExposed.includes 2008-07-24 07:22:38 UTC (rev 4993) +++ branches/asm/CoreExposed.includes 2008-07-24 07:29:54 UTC (rev 4994) @@ -35,6 +35,7 @@ org/python/core/PyType.class org/python/core/PyUnicode.class org/python/core/PyXRange.class +org/python/modules/_codecs$EncodingMap.class org/python/modules/_weakref/CallableProxyType.class org/python/modules/_weakref/ReferenceType.class org/python/modules/_weakref/ProxyType.class Modified: branches/asm/src/org/python/modules/_codecs.java =================================================================== --- branches/asm/src/org/python/modules/_codecs.java 2008-07-24 07:22:38 UTC (rev 4993) +++ branches/asm/src/org/python/modules/_codecs.java 2008-07-24 07:29:54 UTC (rev 4994) @@ -11,6 +11,7 @@ import java.nio.charset.Charset; import org.python.core.Py; +import org.python.core.PyDictionary; import org.python.core.PyInteger; import org.python.core.PyNone; import org.python.core.PyObject; @@ -19,6 +20,7 @@ import org.python.core.PyTuple; import org.python.core.PyUnicode; import org.python.core.codecs; +import org.python.expose.ExposedType; public class _codecs { @@ -38,6 +40,10 @@ codecs.register_error(name, errorHandler); } + public static PyObject charmap_build(PyUnicode map) { + return EncodingMap.buildEncodingMap(map); + } + private static PyTuple decode_tuple(String s, int len) { return new PyTuple(new PyUnicode(s), Py.newInteger(len)); } @@ -247,11 +253,21 @@ PyObject mapping, StringBuilder v, boolean letLookupHandleError) { + EncodingMap encodingMap = mapping instanceof EncodingMap ? (EncodingMap)mapping : null; int size = str.length(); for (int i = 0; i < size; i++) { char ch = str.charAt(i); - PyObject w = Py.newInteger(ch); - PyObject x = mapping.__finditem__(w); + PyObject x; + if (encodingMap != null) { + int result = encodingMap.lookup(ch); + if (result == -1) { + x = null; + } else { + x = Py.newInteger(result); + } + } else { + x = mapping.__finditem__(Py.newInteger(ch)); + } if (x == null) { if (letLookupHandleError) { i = handleBadMapping(str, errors, mapping, v, size, i); @@ -626,5 +642,155 @@ public static PyTuple unicode_internal_decode(String str, String errors) { return decode_tuple(str, str.length()); } + + /** + * Optimized charmap encoder mapping. + * + * Uses a trie structure instead of a dictionary; the speedup primarily comes from not + * creating integer objects in the process. The trie is created by inverting the + * encoding map. + */ + @ExposedType(name = "EncodingMap") + public static class EncodingMap extends PyObject { + + char[] level1; + + char[] level23; + + int count2; + + int count3; + + private EncodingMap(char[] level1, char[] level23, int count2, int count3) { + this.level1 = level1; + this.level23 = level23; + this.count2 = count2; + this.count3 = count3; + } + + /** + * Create and populate an EncodingMap from a 256 length PyUnicode char. Returns a + * PyDictionary if the mapping isn't easily optimized. + * + * @param string a 256 length unicode mapping + * @return an encoder mapping + */ + public static PyObject buildEncodingMap(PyObject string) { + if (!(string instanceof PyUnicode) || string.__len__() != 256) { + throw Py.TypeError("bad argument type for built-in operation"); + } + + boolean needDict = false; + char[] level1 = new char[32]; + char[] level23 = new char[512]; + int i; + int count2 = 0; + int count3 = 0; + String decode = string.toString(); + for (i = 0; i < level1.length; i++) { + level1[i] = 0xFF; + } + for (i = 0; i < level23.length; i++) { + level23[i] = 0xFF; + } + if (decode.charAt(0) != 0) { + needDict = true; + } + for (i = 1; i < 256; i++) { + int l1, l2; + char charAt = decode.charAt(i); + if (charAt == 0) { + needDict = true; + } + if (charAt == 0xFFFE) { + // unmapped character + continue; + } + l1 = charAt >> 11; + l2 = charAt >> 7; + if (level1[l1] == 0xFF) { + level1[l1] = (char)count2++; + } + if (level23[l2] == 0xFF) { + level23[l2] = (char)count3++; + } + } + + if (count2 > 0xFF || count3 > 0xFF) { + needDict = true; + } + + if (needDict) { + PyObject result = new PyDictionary(); + for (i = 0; i < 256; i++) { + result.__setitem__(Py.newInteger(decode.charAt(i)), Py.newInteger(i)); + } + return result; + } + + // Create a three-level trie + int length2 = 16 * count2; + int length3 = 128 * count3; + level23 = new char[length2 + length3]; + PyObject result = new EncodingMap(level1, level23, count2, count3); + for (i = 0; i < length2; i++) { + level23[i] = 0xFF; + } + for (i = length2; i < length2 + length3; i++) { + level23[i] = 0; + } + count3 = 0; + for (i = 1; i < 256; i++) { + int o1, o2, o3, i2, i3; + char charAt = decode.charAt(i); + if (charAt == 0xFFFE) { + // unmapped character + continue; + } + o1 = charAt >> 11; + o2 = (charAt >> 7) & 0xF; + i2 = 16 * level1[o1] + o2; + if (level23[i2] == 0xFF) { + level23[i2] = (char)count3++; + } + o3 = charAt & 0x7F; + i3 = 128 * level23[i2] + o3; + level23[length2 + i3] = (char)i; + } + return result; + } + + /** + * Lookup a char in the EncodingMap. + * + * @param c a char + * @return an int, -1 for failure + */ + public int lookup(char c) { + int l1 = c >> 11; + int l2 = (c >> 7) & 0xF; + int l3 = c & 0x7F; + int i; + if (c == 0) { + return 0; + } + // level 1 + i = level1[l1]; + if (i == 0xFF) { + return -1; + } + // level 2 + i = level23[16 * i + l2]; + if (i == 0xFF) { + return -1; + } + // level 3 + i = level23[16 * count2 + 128 * i + l3]; + if (i == 0) { + return -1; + } + return i; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-28 19:46:42
|
Revision: 5012 http://jython.svn.sourceforge.net/jython/?rev=5012&view=rev Author: pjenvey Date: 2008-07-28 19:46:39 +0000 (Mon, 28 Jul 2008) Log Message: ----------- fix stock UserList/test_userlist: o handle __get/set/delslice__ start/stop as null or None in PySlice.indices2 o fix list slice assignments of the same underlying list (always copy first as CPython does) Modified Paths: -------------- branches/asm/src/org/python/core/PyList.java branches/asm/src/org/python/core/PySlice.java Removed Paths: ------------- branches/asm/Lib/UserList.py branches/asm/Lib/test/test_userlist.py Deleted: branches/asm/Lib/UserList.py =================================================================== --- branches/asm/Lib/UserList.py 2008-07-28 13:33:50 UTC (rev 5011) +++ branches/asm/Lib/UserList.py 2008-07-28 19:46:39 UTC (rev 5012) @@ -1,94 +0,0 @@ -"""A more or less complete user-defined wrapper around list objects.""" - -#Imported from Python 2.3.5 and added _fixindex -class UserList: - def __init__(self, initlist=None): - self.data = [] - if initlist is not None: - # XXX should this accept an arbitrary sequence? - if type(initlist) == type(self.data): - self.data[:] = initlist - elif isinstance(initlist, UserList): - self.data[:] = initlist.data[:] - else: - self.data = list(initlist) - def __repr__(self): return repr(self.data) - def __lt__(self, other): return self.data < self.__cast(other) - def __le__(self, other): return self.data <= self.__cast(other) - def __eq__(self, other): return self.data == self.__cast(other) - def __ne__(self, other): return self.data != self.__cast(other) - def __gt__(self, other): return self.data > self.__cast(other) - def __ge__(self, other): return self.data >= self.__cast(other) - def __cast(self, other): - if isinstance(other, UserList): return other.data - else: return other - def __cmp__(self, other): - return cmp(self.data, self.__cast(other)) - def __contains__(self, item): return item in self.data - def __len__(self): return len(self.data) - def __getitem__(self, i): return self.data[i] - def __setitem__(self, i, item): self.data[i] = item - def __delitem__(self, i): del self.data[i] - def __getslice__(self, i, j): - i = self._fixindex(i); j = self._fixindex(j) - return self.__class__(self.data[i:j]) - def __setslice__(self, i, j, other): - i = self._fixindex(i); j = self._fixindex(j) - if isinstance(other, UserList): - self.data[i:j] = other.data - elif isinstance(other, type(self.data)): - self.data[i:j] = other - else: - self.data[i:j] = list(other) - def __delslice__(self, i, j): - i = self._fixindex(i); j = self._fixindex(j) - del self.data[i:j] - def __add__(self, other): - if isinstance(other, UserList): - return self.__class__(self.data + other.data) - elif isinstance(other, type(self.data)): - return self.__class__(self.data + other) - else: - return self.__class__(self.data + list(other)) - def __radd__(self, other): - if isinstance(other, UserList): - return self.__class__(other.data + self.data) - elif isinstance(other, type(self.data)): - return self.__class__(other + self.data) - else: - return self.__class__(list(other) + self.data) - def __iadd__(self, other): - if isinstance(other, UserList): - self.data += other.data - elif isinstance(other, type(self.data)): - self.data += other - else: - self.data += list(other) - return self - def __mul__(self, n): - return self.__class__(self.data*n) - __rmul__ = __mul__ - def __imul__(self, n): - self.data *= n - return self - def append(self, item): self.data.append(item) - def insert(self, i, item): self.data.insert(i, item) - def pop(self, i=-1): return self.data.pop(i) - def remove(self, item): self.data.remove(item) - def count(self, item): return self.data.count(item) - def index(self, item, *args): return self.data.index(item, *args) - def reverse(self): self.data.reverse() - def sort(self, *args): self.data.sort(*args) - def extend(self, other): - if isinstance(other, UserList): - self.data.extend(other.data) - else: - self.data.extend(other) - def _fixindex(self, index): - if index < 0: - index += len(self.data) - elif index > len(self.data): - index = len(self.data) - index = max(index, 0) - return index - Deleted: branches/asm/Lib/test/test_userlist.py =================================================================== --- branches/asm/Lib/test/test_userlist.py 2008-07-28 13:33:50 UTC (rev 5011) +++ branches/asm/Lib/test/test_userlist.py 2008-07-28 19:46:39 UTC (rev 5012) @@ -1,269 +0,0 @@ -# Check every path through every method of UserList - -#imported from Python 2.3.5 - -from UserList import UserList -import unittest, test.test_support - -class UserListTest(unittest.TestCase): - - def test_constructors(self): - l0 = [] - l1 = [0] - l2 = [0, 1] - - u = UserList() - u0 = UserList(l0) - u1 = UserList(l1) - u2 = UserList(l2) - - uu = UserList(u) - uu0 = UserList(u0) - uu1 = UserList(u1) - uu2 = UserList(u2) - - v = UserList(tuple(u)) - class OtherList: - def __init__(self, initlist): - self.__data = initlist - def __len__(self): - return len(self.__data) - def __getitem__(self, i): - return self.__data[i] - v0 = UserList(OtherList(u0)) - vv = UserList("this is also a sequence") - - def test_repr(self): - l0 = [] - l2 = [0, 1, 2] - u0 = UserList(l0) - u2 = UserList(l2) - - self.assertEqual(str(u0), str(l0)) - self.assertEqual(repr(u0), repr(l0)) - self.assertEqual(`u2`, `l2`) - - def test_cmplen(self): - l0 = [] - l1 = [0] - l2 = [0, 1] - - # Test constructors - - u = UserList() - u0 = UserList(l0) - u1 = UserList(l1) - u2 = UserList(l2) - - uu = UserList(u) - uu0 = UserList(u0) - uu1 = UserList(u1) - uu2 = UserList(u2) - - def mycmp(x, y): - r = cmp(x, y) - if r < 0: return -1 - if r > 0: return 1 - return r - - all = [l0, l1, l2, u, u0, u1, u2, uu, uu0, uu1, uu2] - for a in all: - for b in all: - self.assertEqual(mycmp(a, b), mycmp(len(a), len(b))) - - self.assert_(u0 <= u2) - self.assert_(u2 >= u0) - - def test_getitem(self): - u = UserList([0, 1, 2]) - for i in xrange(len(u)): - self.assertEqual(u[i], i) - - def test_setitem(self): - u = UserList([0, 1]) - u[0] = 0 - u[1] = 100 - self.assertEqual(u, [0, 100]) - self.assertRaises(IndexError, u.__setitem__, 2, 200) - - def test_delitem(self): - u = UserList([0, 1]) - del u[1] - del u[0] - self.assertRaises(IndexError, u.__delitem__, 0) - - def test_getslice(self): - l = [0, 1] - u = UserList(l) - for i in xrange(-3, 4): - self.assertEqual(u[:i], l[:i]) - self.assertEqual(u[i:], l[i:]) - for j in xrange(-3, 4): - self.assertEqual(u[i:j], l[i:j]) - - def test_setslice(self): - l = [0, 1] - u = UserList(l) - - # Test __setslice__ - for i in range(-3, 4): - u[:i] = l[:i] - self.assertEqual(u, l) - u2 = u[:] - u2[:i] = u[:i] - self.assertEqual(u2, u) - u[i:] = l[i:] - self.assertEqual(u, l) - u2 = u[:] - u2[i:] = u[i:] - self.assertEqual(u2, u) - for j in range(-3, 4): - u[i:j] = l[i:j] - self.assertEqual(u, l) - u2 = u[:] - u2[i:j] = u[i:j] - self.assertEqual(u2, u) - - uu2 = u2[:] - uu2[:0] = [-2, -1] - self.assertEqual(uu2, [-2, -1, 0, 1]) - uu2[0:] = [] - self.assertEqual(uu2, []) - - def test_contains(self): - u = UserList([0, 1, 2]) - for i in u: - self.assert_(i in u) - for i in min(u)-1, max(u)+1: - self.assert_(i not in u) - - def test_delslice(self): - u = UserList([0, 1]) - del u[1:2] - del u[0:1] - self.assertEqual(u, []) - - u = UserList([0, 1]) - del u[1:] - del u[:1] - self.assertEqual(u, []) - - def test_addmul(self): - u1 = UserList([0]) - u2 = UserList([0, 1]) - self.assertEqual(u1, u1 + []) - self.assertEqual(u1, [] + u1) - self.assertEqual(u1 + [1], u2) - self.assertEqual([-1] + u1, [-1, 0]) - self.assertEqual(u2, u2*1) - self.assertEqual(u2, 1*u2) - self.assertEqual(u2+u2, u2*2) - self.assertEqual(u2+u2, 2*u2) - self.assertEqual(u2+u2+u2, u2*3) - self.assertEqual(u2+u2+u2, 3*u2) - - def test_add_specials(self): - u = UserList("spam") - u2 = u + "eggs" - self.assertEqual(u2, list("spameggs")) - - def test_radd_specials(self): - u = UserList("eggs") - u2 = "spam" + u - self.assertEqual(u2, list("spameggs")) - u2 = u.__radd__(UserList("spam")) - self.assertEqual(u2, list("spameggs")) - - def test_append(self): - u = UserList((0, )) - u.append(1) - self.assertEqual(u, [0, 1]) - - def test_insert(self): - u = UserList((0, 1)) - u.insert(0, -1) - self.assertEqual(u, [-1, 0, 1]) - - def test_pop(self): - u = UserList((-1, 0, 1)) - u.pop() - self.assertEqual(u, [-1, 0]) - u.pop(0) - self.assertEqual(u, [0]) - - def test_remove(self): - u = UserList((0, 1)) - u.remove(1) - self.assertEqual(u, [0]) - - def test_count(self): - u = UserList((0, 1))*3 - self.assertEqual(u.count(0), 3) - self.assertEqual(u.count(1), 3) - self.assertEqual(u.count(2), 0) - - def test_index(self): - u = UserList((0, 1)) - self.assertEqual(u.index(0), 0) - self.assertEqual(u.index(1), 1) - self.assertRaises(ValueError, u.index, 2) - - u = UserList([-2,-1,0,0,1,2]) - self.assertEqual(u.count(0), 2) - self.assertEqual(u.index(0), 2) - self.assertEqual(u.index(0,2), 2) - self.assertEqual(u.index(-2,-10), 0) - self.assertEqual(u.index(0,3), 3) - self.assertEqual(u.index(0,3,4), 3) - self.assertRaises(ValueError, u.index, 2,0,-10) - - def test_reverse(self): - u = UserList((0, 1)) - u2 = u[:] - u.reverse() - self.assertEqual(u, [1, 0]) - u.reverse() - self.assertEqual(u, u2) - - def test_sort(self): - u = UserList([1, 0]) - u.sort() - self.assertEqual(u, [0, 1]) - - def test_slice(self): - u = UserList("spam") - u[:2] = "h" - self.assertEqual(u, list("ham")) - - def test_iadd(self): - u = UserList((0, 1)) - u += [0, 1] - self.assertEqual(u, [0, 1, 0, 1]) - u += UserList([0, 1]) - self.assertEqual(u, [0, 1, 0, 1, 0, 1]) - - u = UserList("spam") - u += "eggs" - self.assertEqual(u, list("spameggs")) - - def test_extend(self): - u1 = UserList((0, )) - u2 = UserList((0, 1)) - u = u1[:] - u.extend(u2) - self.assertEqual(u, u1 + u2) - - u = UserList("spam") - u.extend("eggs") - self.assertEqual(u, list("spameggs")) - - def test_imul(self): - u = UserList((0, 1)) - u *= 3 - self.assertEqual(u, [0, 1, 0, 1, 0, 1]) - -def test_main(): - test.test_support.run_unittest(UserListTest) - -if __name__ == "__main__": - test_main() Modified: branches/asm/src/org/python/core/PyList.java =================================================================== --- branches/asm/src/org/python/core/PyList.java 2008-07-28 13:33:50 UTC (rev 5011) +++ branches/asm/src/org/python/core/PyList.java 2008-07-28 19:46:39 UTC (rev 5012) @@ -190,7 +190,7 @@ protected void setsliceList(int start, int stop, int step, List value) { if(step != 1) { - throw Py.TypeError("setslice with java.util.List and step != 1 not " + "supported yet"); + throw Py.TypeError("setslice with java.util.List and step != 1 not supported yet"); } int n = value.size(); list.ensureCapacity(start + n); @@ -200,23 +200,16 @@ } protected void setsliceIterable(int start, int stop, int step, PyObject value) { - PyObject iter; + PyObject[] seq; try { - iter = value.__iter__(); - } catch(PyException pye) { - if(Py.matchException(pye, Py.TypeError)) { + seq = Py.make_array(value); + } catch (PyException pye) { + if (Py.matchException(pye, Py.TypeError)) { throw Py.TypeError("can only assign an iterable"); } throw pye; } - PyObject next; - for(int j = 0; (next = iter.__iternext__()) != null; j += step) { - if(step < 0) { - list.pyset(start + j, next); - } else { - list.add(start + j, next); - } - } + setslicePySequence(start, stop, step, new PyList(seq)); } protected PyObject repeat(int count) { Modified: branches/asm/src/org/python/core/PySlice.java =================================================================== --- branches/asm/src/org/python/core/PySlice.java 2008-07-28 13:33:50 UTC (rev 5011) +++ branches/asm/src/org/python/core/PySlice.java 2008-07-28 19:46:39 UTC (rev 5012) @@ -188,8 +188,9 @@ */ public static PyObject[] indices2(PyObject obj, PyObject start, PyObject stop) { PyObject[] indices = new PyObject[2]; - int istart = start == null ? 0 : calculateSliceIndex(start); - int istop = stop == null ? PySystemState.maxint : calculateSliceIndex(stop); + int istart = (start == null || start == Py.None) ? 0 : calculateSliceIndex(start); + int istop = (stop == null || stop == Py.None) + ? PySystemState.maxint : calculateSliceIndex(stop); if (istart < 0 || istop < 0) { try { int len = obj.__len__(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-29 12:31:50
|
Revision: 5018 http://jython.svn.sourceforge.net/jython/?rev=5018&view=rev Author: fwierzbicki Date: 2008-07-29 12:31:46 +0000 (Tue, 29 Jul 2008) Log Message: ----------- Move testing classes out of main code. Added Paths: ----------- branches/asm/tests/java/org/python/antlr/ branches/asm/tests/java/org/python/antlr/GrammarTester.java branches/asm/tests/java/org/python/antlr/PythonPartialTester.java branches/asm/tests/java/org/python/antlr/PythonTreeTester.java branches/asm/tests/java/org/python/antlr/WalkerTester.java Removed Paths: ------------- branches/asm/src/org/python/antlr/GrammarTester.java branches/asm/src/org/python/antlr/PythonPartialTester.java branches/asm/src/org/python/antlr/PythonTreeTester.java branches/asm/src/org/python/antlr/WalkerTester.java Deleted: branches/asm/src/org/python/antlr/GrammarTester.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarTester.java 2008-07-29 01:40:32 UTC (rev 5017) +++ branches/asm/src/org/python/antlr/GrammarTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -1,11 +0,0 @@ -package org.python.antlr; - -public class GrammarTester { - - public static void main(String[] args) throws Exception { - PythonTreeTester walker = new PythonTreeTester(); - walker.setParseOnly(true); - walker.parse(args); - } - -} Deleted: branches/asm/src/org/python/antlr/PythonPartialTester.java =================================================================== --- branches/asm/src/org/python/antlr/PythonPartialTester.java 2008-07-29 01:40:32 UTC (rev 5017) +++ branches/asm/src/org/python/antlr/PythonPartialTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -1,47 +0,0 @@ -package org.python.antlr; - -import org.antlr.runtime.ANTLRFileStream; -import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.Token; - -/** - * A walker producing a <code>PythonTree</code> AST. - */ -public class PythonPartialTester { - - public static class PPLexer extends PythonPartialLexer { - public PPLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - - public void parse(String[] args) throws Exception { - try { - PythonTree result = null; - CharStream input = new ANTLRFileStream(args[0]); - PythonPartialLexer lexer = new PPLexer(input); - CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); - //PythonTokenSource indentedSource = new PythonTokenSource(tokens); - PythonPartialTokenSource indentedSource = new PythonPartialTokenSource(tokens); - tokens = new CommonTokenStream(indentedSource); - PythonPartialParser parser = new PythonPartialParser(tokens); - parser.single_input(); - System.out.println("SUCCEED"); - } catch (ParseException e) { - System.out.println("FAIL:" + e); - } - } - - public static void main(String[] args) throws Exception { - PythonPartialTester p = new PythonPartialTester(); - p.parse(args); - } - -} Deleted: branches/asm/src/org/python/antlr/PythonTreeTester.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTreeTester.java 2008-07-29 01:40:32 UTC (rev 5017) +++ branches/asm/src/org/python/antlr/PythonTreeTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -1,98 +0,0 @@ -package org.python.antlr; - -import org.antlr.runtime.ANTLRFileStream; -import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.RecognitionException; -import org.antlr.runtime.Token; -import org.antlr.runtime.tree.CommonTreeAdaptor; -import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.antlr.runtime.tree.Tree; -import org.antlr.runtime.tree.TreeAdaptor; - -/** - * A walker producing a <code>PythonTree</code> AST. - */ -public class PythonTreeTester { - - public enum Block { MODULE, INTERACTIVE, EXPRESSION }; - - private boolean _parseOnly; - private Block _block; - - public PythonTreeTester() { - setParseOnly(false); - setBlock(Block.MODULE); - } - - public PythonTree parse(String[] args) throws Exception { - PythonTree result = null; - CharStream input = new ANTLRFileStream(args[0]); - PythonLexer lexer = new ModuleParser.PyLexer(input); - CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); - PythonTokenSource indentedSource = new PythonTokenSource(tokens); - tokens = new CommonTokenStream(indentedSource); - PythonParser parser = new PythonParser(tokens); - parser.setTreeAdaptor(new PythonTreeAdaptor()); - Tree r = null; - switch (_block) { - case MODULE : - r = (Tree)parser.file_input().tree; - break; - case INTERACTIVE : - r = (Tree)parser.single_input().tree; - break; - case EXPRESSION : - r = (Tree)parser.eval_input().tree; - break; - } - if (args.length > 1) { - System.out.println((r).toStringTree()); - } - if (!isParseOnly()) { - CommonTreeNodeStream nodes = new CommonTreeNodeStream(r); - nodes.setTokenStream(tokens); - PythonWalker walker = new PythonWalker(nodes); - switch (_block) { - case MODULE : - result = walker.module(); - break; - case INTERACTIVE : - result = walker.interactive(); - break; - case EXPRESSION : - result = walker.expression(); - break; - } - - if (args.length > 1) { - System.out.println(result.toStringTree()); - } - } - return result; - } - - /** - * If set to <code>true</code>, only <code>PythonParser</code> is - * called. - * - * @param parseOnly - */ - public void setParseOnly(boolean parseOnly) { - _parseOnly = parseOnly; - } - - public boolean isParseOnly() { - return _parseOnly; - } - - public void setBlock(Block block) { - _block = block; - } - - public Block getBlock() { - return _block; - } - -} Deleted: branches/asm/src/org/python/antlr/WalkerTester.java =================================================================== --- branches/asm/src/org/python/antlr/WalkerTester.java 2008-07-29 01:40:32 UTC (rev 5017) +++ branches/asm/src/org/python/antlr/WalkerTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -1,11 +0,0 @@ -package org.python.antlr; - -public class WalkerTester extends PythonTreeTester { - - public static void main(String[] args) throws Exception { - PythonTreeTester walker = new PythonTreeTester(); - walker.setParseOnly(false); - walker.parse(args); - } - -} Copied: branches/asm/tests/java/org/python/antlr/GrammarTester.java (from rev 5013, branches/asm/src/org/python/antlr/GrammarTester.java) =================================================================== --- branches/asm/tests/java/org/python/antlr/GrammarTester.java (rev 0) +++ branches/asm/tests/java/org/python/antlr/GrammarTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -0,0 +1,11 @@ +package org.python.antlr; + +public class GrammarTester { + + public static void main(String[] args) throws Exception { + PythonTreeTester walker = new PythonTreeTester(); + walker.setParseOnly(true); + walker.parse(args); + } + +} Copied: branches/asm/tests/java/org/python/antlr/PythonPartialTester.java (from rev 5013, branches/asm/src/org/python/antlr/PythonPartialTester.java) =================================================================== --- branches/asm/tests/java/org/python/antlr/PythonPartialTester.java (rev 0) +++ branches/asm/tests/java/org/python/antlr/PythonPartialTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -0,0 +1,47 @@ +package org.python.antlr; + +import org.antlr.runtime.ANTLRFileStream; +import org.antlr.runtime.CharStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.Token; + +/** + * A walker producing a <code>PythonTree</code> AST. + */ +public class PythonPartialTester { + + public static class PPLexer extends PythonPartialLexer { + public PPLexer(CharStream lexer) { + super(lexer); + } + + public Token nextToken() { + startPos = getCharPositionInLine(); + return super.nextToken(); + } + } + + public void parse(String[] args) throws Exception { + try { + PythonTree result = null; + CharStream input = new ANTLRFileStream(args[0]); + PythonPartialLexer lexer = new PPLexer(input); + CommonTokenStream tokens = new CommonTokenStream(lexer); + tokens.discardOffChannelTokens(true); + //PythonTokenSource indentedSource = new PythonTokenSource(tokens); + PythonPartialTokenSource indentedSource = new PythonPartialTokenSource(tokens); + tokens = new CommonTokenStream(indentedSource); + PythonPartialParser parser = new PythonPartialParser(tokens); + parser.single_input(); + System.out.println("SUCCEED"); + } catch (ParseException e) { + System.out.println("FAIL:" + e); + } + } + + public static void main(String[] args) throws Exception { + PythonPartialTester p = new PythonPartialTester(); + p.parse(args); + } + +} Copied: branches/asm/tests/java/org/python/antlr/PythonTreeTester.java (from rev 5013, branches/asm/src/org/python/antlr/PythonTreeTester.java) =================================================================== --- branches/asm/tests/java/org/python/antlr/PythonTreeTester.java (rev 0) +++ branches/asm/tests/java/org/python/antlr/PythonTreeTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -0,0 +1,98 @@ +package org.python.antlr; + +import org.antlr.runtime.ANTLRFileStream; +import org.antlr.runtime.CharStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.Token; +import org.antlr.runtime.tree.CommonTreeAdaptor; +import org.antlr.runtime.tree.CommonTreeNodeStream; +import org.antlr.runtime.tree.Tree; +import org.antlr.runtime.tree.TreeAdaptor; + +/** + * A walker producing a <code>PythonTree</code> AST. + */ +public class PythonTreeTester { + + public enum Block { MODULE, INTERACTIVE, EXPRESSION }; + + private boolean _parseOnly; + private Block _block; + + public PythonTreeTester() { + setParseOnly(false); + setBlock(Block.MODULE); + } + + public PythonTree parse(String[] args) throws Exception { + PythonTree result = null; + CharStream input = new ANTLRFileStream(args[0]); + PythonLexer lexer = new ModuleParser.PyLexer(input); + CommonTokenStream tokens = new CommonTokenStream(lexer); + tokens.discardOffChannelTokens(true); + PythonTokenSource indentedSource = new PythonTokenSource(tokens); + tokens = new CommonTokenStream(indentedSource); + PythonParser parser = new PythonParser(tokens); + parser.setTreeAdaptor(new PythonTreeAdaptor()); + Tree r = null; + switch (_block) { + case MODULE : + r = (Tree)parser.file_input().tree; + break; + case INTERACTIVE : + r = (Tree)parser.single_input().tree; + break; + case EXPRESSION : + r = (Tree)parser.eval_input().tree; + break; + } + if (args.length > 1) { + System.out.println((r).toStringTree()); + } + if (!isParseOnly()) { + CommonTreeNodeStream nodes = new CommonTreeNodeStream(r); + nodes.setTokenStream(tokens); + PythonWalker walker = new PythonWalker(nodes); + switch (_block) { + case MODULE : + result = walker.module(); + break; + case INTERACTIVE : + result = walker.interactive(); + break; + case EXPRESSION : + result = walker.expression(); + break; + } + + if (args.length > 1) { + System.out.println(result.toStringTree()); + } + } + return result; + } + + /** + * If set to <code>true</code>, only <code>PythonParser</code> is + * called. + * + * @param parseOnly + */ + public void setParseOnly(boolean parseOnly) { + _parseOnly = parseOnly; + } + + public boolean isParseOnly() { + return _parseOnly; + } + + public void setBlock(Block block) { + _block = block; + } + + public Block getBlock() { + return _block; + } + +} Copied: branches/asm/tests/java/org/python/antlr/WalkerTester.java (from rev 5013, branches/asm/src/org/python/antlr/WalkerTester.java) =================================================================== --- branches/asm/tests/java/org/python/antlr/WalkerTester.java (rev 0) +++ branches/asm/tests/java/org/python/antlr/WalkerTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -0,0 +1,11 @@ +package org.python.antlr; + +public class WalkerTester extends PythonTreeTester { + + public static void main(String[] args) throws Exception { + PythonTreeTester walker = new PythonTreeTester(); + walker.setParseOnly(false); + walker.parse(args); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-29 22:40:08
|
Revision: 5021 http://jython.svn.sourceforge.net/jython/?rev=5021&view=rev Author: pjenvey Date: 2008-07-29 22:40:05 +0000 (Tue, 29 Jul 2008) Log Message: ----------- fix readChunk reading more than CHUNK_SIZE, which'll blow up packReadahead Modified Paths: -------------- branches/asm/Lib/test/test_file_newlines.py branches/asm/src/org/python/core/io/TextIOBase.java Modified: branches/asm/Lib/test/test_file_newlines.py =================================================================== --- branches/asm/Lib/test/test_file_newlines.py 2008-07-29 22:33:56 UTC (rev 5020) +++ branches/asm/Lib/test/test_file_newlines.py 2008-07-29 22:40:05 UTC (rev 5021) @@ -27,13 +27,14 @@ data = CRLF_TEST write_mode = 'wb' mode = 'r' + bufsize = -1 def setUp(self): self.filename = tempfile.mktemp() - self.write_fp = open(self.filename, self.write_mode) + self.write_fp = open(self.filename, self.write_mode, self.bufsize) self.write_fp.write(self.data) self.write_fp.flush() - self.fp = open(self.filename, self.mode) + self.fp = open(self.filename, self.mode, self.bufsize) def tearDown(self): if self.write_fp: @@ -259,6 +260,17 @@ read_data = data +class UniversalCRAtReadaheadBoundaryTestCase(BaseTestCase): + + mode = 'U' + bufsize = 0 + data = ('-' * 1023) + '\r\n' + ('-' * 10233) + + def test_read_cr_at_boundary(self): + # Used to raise a BufferOverflowException w/ bufsize of 0 + read(self.fp, ('-' * 1023) + '\n', 1024) + + class WriteTextNewlinesTestCase(BaseTestCase): write_mode = 'w' @@ -344,6 +356,7 @@ UniversalReadaheadBoundary3TestCase, UniversalReadaheadBoundary4TestCase, UniversalReadaheadBoundary5TestCase, + UniversalCRAtReadaheadBoundaryTestCase, WriteTextNewlinesTestCase, ReadUniversalNewlinesTestCase, WriteUniversalNewlinesTestCase] Modified: branches/asm/src/org/python/core/io/TextIOBase.java =================================================================== --- branches/asm/src/org/python/core/io/TextIOBase.java 2008-07-29 22:33:56 UTC (rev 5020) +++ branches/asm/src/org/python/core/io/TextIOBase.java 2008-07-29 22:40:05 UTC (rev 5021) @@ -227,6 +227,10 @@ // Prepare the readahead for reading readahead.clear(); + if (readahead.remaining() > CHUNK_SIZE) { + // Limit potential full reads on a resized readahead to CHUNK_SIZE + readahead.limit(readahead.position() + CHUNK_SIZE); + } bufferedIO.read1(readahead); readahead.flip(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-07-30 19:57:26
|
Revision: 5023 http://jython.svn.sourceforge.net/jython/?rev=5023&view=rev Author: zyasoft Date: 2008-07-30 19:57:16 +0000 (Wed, 30 Jul 2008) Log Message: ----------- Changed default format for __getformat__/__setformat__ to "IEEE, big-endian", and supported switching back and forth with "unknown". Modified Paths: -------------- branches/asm/Lib/test/test_float_jy.py branches/asm/src/org/python/core/PyFloat.java branches/asm/src/org/python/modules/struct.java Modified: branches/asm/Lib/test/test_float_jy.py =================================================================== --- branches/asm/Lib/test/test_float_jy.py 2008-07-30 15:46:31 UTC (rev 5022) +++ branches/asm/Lib/test/test_float_jy.py 2008-07-30 19:57:16 UTC (rev 5023) @@ -7,7 +7,7 @@ import unittest from test import test_support -jython = sys.platform.startswith('java') +jython = test_support.is_jython class FloatTestCase(unittest.TestCase): @@ -67,14 +67,12 @@ def test_nan(self): self.assert_(type(float('NaN')), float) - # XXX: FIXME - #self.assert_(type(float('nan')), float) + self.assert_(type(float('nan')), float) self.assertEqual(long(float('NaN')), 0) def test_infinity(self): self.assert_(type(float('Infinity')), float) - # XXX: FIXME - #self.assert_(type(float('inf')), float) + self.assert_(type(float('inf')), float) self.assertRaises(OverflowError, long, float('Infinity')) def test_float_none(self): Modified: branches/asm/src/org/python/core/PyFloat.java =================================================================== --- branches/asm/src/org/python/core/PyFloat.java 2008-07-30 15:46:31 UTC (rev 5022) +++ branches/asm/src/org/python/core/PyFloat.java 2008-07-30 19:57:16 UTC (rev 5023) @@ -584,26 +584,58 @@ return float___getnewargs__(); } + // standard singleton issues apply here to __getformat__/__setformat__, + // but this is what Python demands + + public enum Format { + UNKNOWN ("unknown"), + BE ("IEEE, big-endian"), + LE ("IEEE, little-endian"); + + private final String format; + Format(String format) { + this.format = format; + } + public String format() { return format; } + } + + // subset of IEEE-754, the JVM is big-endian + public static volatile Format double_format = Format.BE; + public static volatile Format float_format = Format.BE; + @ExposedClassMethod public static String float___getformat__(PyType type, String typestr) { - if (!"double".equals(typestr) && !"float".equals(typestr)) { + if ("double".equals(typestr)) { + return double_format.format(); + } else if ("float".equals(typestr)) { + return float_format.format(); + } else { throw Py.ValueError("__getformat__() argument 1 must be 'double' or 'float'"); } - return "unknown"; } - + @ExposedClassMethod public static void float___setformat__(PyType type, String typestr, String format) { + Format new_format = null; if (!"double".equals(typestr) && !"float".equals(typestr)) { throw Py.ValueError("__setformat__() argument 1 must be 'double' or 'float'"); } - if ("IEEE, little-endian".equals(format) || "IEEE, big-endian".equals(format)) { - throw Py.ValueError(String.format("can only set %s format to 'unknown' or the " - + "detected platform value", typestr)); - } else if (!"unknown".equals(format)) { - throw Py.ValueError("__setformat__() argument 2 must be 'unknown', " - + "'IEEE, little-endian' or 'IEEE, big-endian'"); - } + if (Format.LE.format().equals(format)) { + throw Py.ValueError(String.format("can only set %s format to 'unknown' or the " + "detected platform value", typestr)); + } else if (Format.BE.format().equals(format)) { + new_format = Format.BE; + } else if (Format.UNKNOWN.format().equals(format)) { + new_format = Format.UNKNOWN; + } else { + throw Py.ValueError("__setformat__() argument 2 must be 'unknown', " + "'IEEE, little-endian' or 'IEEE, big-endian'"); + } + if (new_format != null) { + if ("double".equals(typestr)) { + double_format = new_format; + } else { + float_format = new_format; + } + } } public boolean isMappingType() { return false; } Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-07-30 15:46:31 UTC (rev 5022) +++ branches/asm/src/org/python/modules/struct.java 2008-07-30 19:57:16 UTC (rev 5023) @@ -748,8 +748,13 @@ } Object unpack(ByteStream buf) { - int v = LEreadInt(buf); - return Py.newFloat(Float.intBitsToFloat(v)); + int bits = LEreadInt(buf); + float v = Float.intBitsToFloat(bits); + if (PyFloat.float_format == PyFloat.Format.UNKNOWN && ( + Float.isInfinite(v) || Float.isNaN(v))) { + throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); + } + return Py.newFloat(v); } } @@ -763,7 +768,12 @@ Object unpack(ByteStream buf) { long bits = (LEreadInt(buf) & 0xFFFFFFFFL) + (((long)LEreadInt(buf)) << 32); - return Py.newFloat(Double.longBitsToDouble(bits)); + double v = Double.longBitsToDouble(bits); + if (PyFloat.double_format == PyFloat.Format.UNKNOWN && + (Double.isInfinite(v) || Double.isNaN(v))) { + throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); + } + return Py.newFloat(v); } } @@ -775,8 +785,13 @@ } Object unpack(ByteStream buf) { - int v = BEreadInt(buf); - return Py.newFloat(Float.intBitsToFloat(v)); + int bits = BEreadInt(buf); + float v = Float.intBitsToFloat(bits); + if (PyFloat.float_format == PyFloat.Format.UNKNOWN && ( + Float.isInfinite(v) || Float.isNaN(v))) { + throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); + } + return Py.newFloat(v); } } @@ -788,9 +803,14 @@ } Object unpack(ByteStream buf) { - long bits = (((long)BEreadInt(buf)) << 32) + - (BEreadInt(buf) & 0xFFFFFFFFL); - return Py.newFloat(Double.longBitsToDouble(bits)); + long bits = (((long) BEreadInt(buf)) << 32) + + (BEreadInt(buf) & 0xFFFFFFFFL); + double v = Double.longBitsToDouble(bits); + if (PyFloat.double_format == PyFloat.Format.UNKNOWN && + (Double.isInfinite(v) || Double.isNaN(v))) { + throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); + } + return Py.newFloat(v); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-30 22:39:29
|
Revision: 5024 http://jython.svn.sourceforge.net/jython/?rev=5024&view=rev Author: pjenvey Date: 2008-07-30 22:39:24 +0000 (Wed, 30 Jul 2008) Log Message: ----------- add a builtin _functools.partial type Modified Paths: -------------- branches/asm/CoreExposed.includes branches/asm/Lib/test/test_functools.py branches/asm/src/org/python/modules/Setup.java branches/asm/src/templates/mappings Added Paths: ----------- branches/asm/src/org/python/modules/_functools/ branches/asm/src/org/python/modules/_functools/PyPartial.java branches/asm/src/org/python/modules/_functools/PyPartialDerived.java branches/asm/src/org/python/modules/_functools/_functools.java branches/asm/src/templates/partial.derived Removed Paths: ------------- branches/asm/Lib/functools.py Modified: branches/asm/CoreExposed.includes =================================================================== --- branches/asm/CoreExposed.includes 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/CoreExposed.includes 2008-07-30 22:39:24 UTC (rev 5024) @@ -36,6 +36,7 @@ org/python/core/PyUnicode.class org/python/core/PyXRange.class org/python/modules/_codecs$EncodingMap.class +org/python/modules/_functools/PyPartial.class org/python/modules/_weakref/CallableProxyType.class org/python/modules/_weakref/ReferenceType.class org/python/modules/_weakref/ProxyType.class Deleted: branches/asm/Lib/functools.py =================================================================== --- branches/asm/Lib/functools.py 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/Lib/functools.py 2008-07-30 22:39:24 UTC (rev 5024) @@ -1,63 +0,0 @@ -"""functools.py - Tools for working with functions and callable objects -""" -# Python module wrapper for _functools C module -# to allow utilities written in Python to be added -# to the functools module. -# Written by Nick Coghlan <ncoghlan at gmail.com> -# Copyright (C) 2006 Python Software Foundation. -# See C source code for _functools credits/copyright - -class partial(object): - - def __init__(*args, **kw): - self = args[0] - self.fn, self.args, self.kw = (args[1], args[2:], kw) - - def __call__(self, *args, **kw): - if kw and self.kw: - d = self.kw.copy() - d.update(kw) - else: - d = kw or self.kw - return self.fn(*(self.args + args), **d) - -# update_wrapper() and wraps() are tools to help write -# wrapper functions that can handle naive introspection - -WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__') -WRAPPER_UPDATES = ('__dict__',) -def update_wrapper(wrapper, - wrapped, - assigned = WRAPPER_ASSIGNMENTS, - updated = WRAPPER_UPDATES): - """Update a wrapper function to look like the wrapped function - - wrapper is the function to be updated - wrapped is the original function - assigned is a tuple naming the attributes assigned directly - from the wrapped function to the wrapper function (defaults to - functools.WRAPPER_ASSIGNMENTS) - updated is a tuple naming the attributes off the wrapper that - are updated with the corresponding attribute from the wrapped - function (defaults to functools.WRAPPER_UPDATES) - """ - for attr in assigned: - setattr(wrapper, attr, getattr(wrapped, attr)) - for attr in updated: - getattr(wrapper, attr).update(getattr(wrapped, attr)) - # Return the wrapper so this can be used as a decorator via partial() - return wrapper - -def wraps(wrapped, - assigned = WRAPPER_ASSIGNMENTS, - updated = WRAPPER_UPDATES): - """Decorator factory to apply update_wrapper() to a wrapper function - - Returns a decorator that invokes update_wrapper() with the decorated - function as the wrapper argument and the arguments to wraps() as the - remaining arguments. Default arguments are as for update_wrapper(). - This is a convenience function to simplify applying partial() to - update_wrapper(). - """ - return partial(update_wrapper, wrapped=wrapped, - assigned=assigned, updated=updated) Modified: branches/asm/Lib/test/test_functools.py =================================================================== --- branches/asm/Lib/test/test_functools.py 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/Lib/test/test_functools.py 2008-07-30 22:39:24 UTC (rev 5024) @@ -131,6 +131,9 @@ p = proxy(f) self.assertEqual(f.func, p.func) f = None + if test_support.is_jython: + from test_weakref import extra_collect + extra_collect() self.assertRaises(ReferenceError, getattr, p, 'func') def test_with_bound_and_unbound_methods(self): @@ -159,7 +162,7 @@ updated=functools.WRAPPER_UPDATES): # Check attributes were assigned for name in assigned: - self.failUnless(getattr(wrapper, name) is getattr(wrapped, name)) + self.failUnless(getattr(wrapper, name) == getattr(wrapped, name)) # Check attributes were updated for name in updated: wrapper_attr = getattr(wrapper, name) Modified: branches/asm/src/org/python/modules/Setup.java =================================================================== --- branches/asm/src/org/python/modules/Setup.java 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/src/org/python/modules/Setup.java 2008-07-30 22:39:24 UTC (rev 5024) @@ -54,6 +54,7 @@ "zipimport:org.python.modules.zipimport.zipimport", "collections:org.python.modules.collections.Collections", "gc", - "_hashlib" + "_hashlib", + "_functools:org.python.modules._functools._functools" }; } Added: branches/asm/src/org/python/modules/_functools/PyPartial.java =================================================================== --- branches/asm/src/org/python/modules/_functools/PyPartial.java (rev 0) +++ branches/asm/src/org/python/modules/_functools/PyPartial.java 2008-07-30 22:39:24 UTC (rev 5024) @@ -0,0 +1,171 @@ +/* Copyright (c) Jython Developers */ +package org.python.modules._functools; + +import java.util.HashMap; +import java.util.Map; + +import org.python.core.Py; +import org.python.core.PyDictionary; +import org.python.core.PyNewWrapper; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyStringMap; +import org.python.core.PyTuple; +import org.python.core.PyType; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; + +@ExposedType(name = "_functools.partial") +public class PyPartial extends PyObject { + + public static final PyType TYPE = PyType.fromClass(PyPartial.class); + + /** The wrapped callable. */ + @ExposedGet + public PyObject func; + + /** Callable's args. */ + public PyObject[] args; + + /** Callable's keywords. */ + private String[] keywords; + + /** Lazily created dict for extra attributes. */ + private PyObject __dict__; + + public PyPartial() { + super(TYPE); + } + + public PyPartial(PyType subType) { + super(subType); + } + + @ExposedNew + public static PyObject partial___new__(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { + if (args.length - keywords.length < 1) { + throw Py.TypeError("type 'partial' takes at least one argument"); + } + + PyObject func = args[0]; + if (!func.isCallable()) { + throw Py.TypeError("the first argument must be callable"); + } + + PyObject[] noFunc = new PyObject[args.length - 1]; + System.arraycopy(args, 1, noFunc, 0, args.length - 1); + args = noFunc; + + PyPartial partial; + if (new_.for_type == subtype) { + partial = new PyPartial(); + } else { + partial = new PyPartialDerived(subtype); + } + + partial.func = func; + partial.args = args; + partial.keywords = keywords; + return partial; + } + + @Override + public PyObject __call__(PyObject[] args, String[] keywords) { + return partial___call__(args, keywords); + } + + @ExposedMethod + public PyObject partial___call__(PyObject[] args, String[] keywords) { + PyObject[] argAppl; + String[] kwAppl; + int partialArgc = this.args.length - this.keywords.length; + int argc = args.length - keywords.length; + + if (partialArgc == 0 && this.keywords.length == 0) { + argAppl = args; + kwAppl = keywords; + } else if (argc == 0 && keywords.length == 0) { + argAppl = this.args; + kwAppl = this.keywords; + } else { + // first merge keywords to determine the keyword count + HashMap<String, PyObject> merged = new HashMap<String, PyObject>(); + int i; + for (i = 0; i < this.keywords.length; i++) { + String keyword = this.keywords[i]; + PyObject value = this.args[partialArgc + i]; + merged.put(keyword, value); + } + for (i = 0; i < keywords.length; i++) { + String keyword = keywords[i]; + PyObject value = args[argc + i]; + merged.put(keyword, value); + } + int keywordc = merged.size(); + + // finally merge into args and keywords arrays + argAppl = new PyObject[partialArgc + argc + keywordc]; + System.arraycopy(this.args, 0, argAppl, 0, partialArgc); + System.arraycopy(args, 0, argAppl, partialArgc, argc); + + kwAppl = new String[keywordc]; + i = 0; + int j = partialArgc + argc; + for (Map.Entry<String, PyObject> entry : merged.entrySet()) { + kwAppl[i++] = entry.getKey(); + argAppl[j++] = entry.getValue(); + } + } + return func.__call__(argAppl, kwAppl); + } + + @ExposedGet(name = "args") + public PyObject getArgs() { + PyObject[] justArgs; + if (keywords.length == 0) { + justArgs = args; + } else { + int argc = args.length - keywords.length; + justArgs = new PyObject[argc]; + System.arraycopy(args, 0, justArgs, 0, argc); + } + return new PyTuple(justArgs); + } + + @ExposedGet(name = "keywords") + public PyObject getKeywords() { + if (keywords.length == 0) { + return Py.None; + } + int argc = args.length - keywords.length; + PyObject kwDict = new PyDictionary(); + for (int i = 0; i < keywords.length; i++) { + kwDict.__setitem__(Py.newString(keywords[i]), args[argc + i]); + } + return kwDict; + } + + @ExposedGet(name = "__dict__") + public PyObject getDict() { + ensureDict(); + return __dict__; + } + + @ExposedSet(name = "__dict__") + public void setDict(PyObject val) { + if (!(val instanceof PyStringMap) && !(val instanceof PyDictionary)) { + throw Py.TypeError("setting partial object's dictionary to a non-dict"); + } + __dict__ = val; + } + + private void ensureDict() { + if (__dict__ == null) { + __dict__ = new PyStringMap(); + } + } +} Added: branches/asm/src/org/python/modules/_functools/PyPartialDerived.java =================================================================== --- branches/asm/src/org/python/modules/_functools/PyPartialDerived.java (rev 0) +++ branches/asm/src/org/python/modules/_functools/PyPartialDerived.java 2008-07-30 22:39:24 UTC (rev 5024) @@ -0,0 +1,1104 @@ +/* Generated file, do not modify. See jython/src/templates/gderived.py. */ +package org.python.modules._functools; + +import org.python.core.*; + +public class PyPartialDerived extends PyPartial implements Slotted { + + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index,PyObject value) { + slots[index]=value; + } + + private PyObject[]slots; + + public PyPartialDerived(PyType subtype) { + super(subtype); + slots=new PyObject[subtype.getNumSlots()]; + } + + public PyString __str__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__str__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__str__(); + } + + public PyString __repr__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__repr__(); + } + + public PyString __hex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__hex__(); + } + + public PyString __oct__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__oct__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__oct__(); + } + + public PyFloat __float__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__float__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyFloat) + return(PyFloat)res; + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); + } + return super.__float__(); + } + + public PyComplex __complex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__complex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyComplex) + return(PyComplex)res; + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); + } + return super.__complex__(); + } + + public PyObject __pos__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pos__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__pos__(); + } + + public PyObject __neg__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__neg__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__neg__(); + } + + public PyObject __abs__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__abs__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__abs__(); + } + + public PyObject __invert__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__invert__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__invert__(); + } + + public PyObject __reduce__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__reduce__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__reduce__(); + } + + public PyObject __add__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__add__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__add__(other); + } + + public PyObject __radd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__radd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__radd__(other); + } + + public PyObject __sub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__sub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__sub__(other); + } + + public PyObject __rsub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rsub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rsub__(other); + } + + public PyObject __mul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mul__(other); + } + + public PyObject __rmul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmul__(other); + } + + public PyObject __div__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__div__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__div__(other); + } + + public PyObject __rdiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdiv__(other); + } + + public PyObject __floordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__floordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__floordiv__(other); + } + + public PyObject __rfloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rfloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rfloordiv__(other); + } + + public PyObject __truediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__truediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__truediv__(other); + } + + public PyObject __rtruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rtruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rtruediv__(other); + } + + public PyObject __mod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mod__(other); + } + + public PyObject __rmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmod__(other); + } + + public PyObject __divmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__divmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__divmod__(other); + } + + public PyObject __rdivmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdivmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdivmod__(other); + } + + public PyObject __rpow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rpow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rpow__(other); + } + + public PyObject __lshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lshift__(other); + } + + public PyObject __rlshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rlshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rlshift__(other); + } + + public PyObject __rshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rshift__(other); + } + + public PyObject __rrshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rrshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rrshift__(other); + } + + public PyObject __and__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__and__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__and__(other); + } + + public PyObject __rand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rand__(other); + } + + public PyObject __or__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__or__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__or__(other); + } + + public PyObject __ror__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ror__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ror__(other); + } + + public PyObject __xor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__xor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__xor__(other); + } + + public PyObject __rxor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rxor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rxor__(other); + } + + public PyObject __lt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lt__(other); + } + + public PyObject __le__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__le__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__le__(other); + } + + public PyObject __gt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__gt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__gt__(other); + } + + public PyObject __ge__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ge__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ge__(other); + } + + public PyObject __eq__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__eq__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__eq__(other); + } + + public PyObject __ne__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ne__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ne__(other); + } + + public PyObject __iadd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iadd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iadd__(other); + } + + public PyObject __isub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__isub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__isub__(other); + } + + public PyObject __imul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imul__(other); + } + + public PyObject __idiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__idiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__idiv__(other); + } + + public PyObject __ifloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ifloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ifloordiv__(other); + } + + public PyObject __itruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__itruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__itruediv__(other); + } + + public PyObject __imod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imod__(other); + } + + public PyObject __ipow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ipow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ipow__(other); + } + + public PyObject __ilshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ilshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ilshift__(other); + } + + public PyObject __irshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__irshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__irshift__(other); + } + + public PyObject __iand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iand__(other); + } + + public PyObject __ior__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ior__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ior__(other); + } + + public PyObject __ixor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ixor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ixor__(other); + } + + public PyObject __int__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__int__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) + return(PyObject)res; + throw Py.TypeError("__int__"+" should return an integer"); + } + return super.__int__(); + } + + public PyObject __long__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__long__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyLong||res instanceof PyInteger) + return res; + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); + } + return super.__long__(); + } + + public int hashCode() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hash__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) { + return((PyInteger)res).getValue(); + } else + if (res instanceof PyLong) { + return((PyLong)res).getValue().intValue(); + } + throw Py.TypeError("__hash__ should return a int"); + } + if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) { + throw Py.TypeError("unhashable type"); + } + return super.hashCode(); + } + + public PyUnicode __unicode__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__unicode__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyUnicode) + return(PyUnicode)res; + if (res instanceof PyString) + return new PyUnicode((PyString)res); + throw Py.TypeError("__unicode__"+" should return a "+"unicode"); + } + return super.__unicode__(); + } + + public int __cmp__(PyObject other) { + PyType self_type=getType(); + PyType[]where_type=new PyType[1]; + PyObject impl=self_type.lookup_where("__cmp__",where_type); + // Full Compatibility with CPython __cmp__: + // If the derived type don't override __cmp__, the + // *internal* super().__cmp__ should be called, not the + // exposed one. The difference is that the exposed __cmp__ + // throws a TypeError if the argument is an instance of the same type. + if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) { + return super.__cmp__(other); + } + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res instanceof PyInteger) { + int v=((PyInteger)res).getValue(); + return v<0?-1:v>0?1:0; + } + throw Py.TypeError("__cmp__ should return a int"); + } + + public boolean __nonzero__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__nonzero__"); + if (impl==null) { + impl=self_type.lookup("__len__"); + if (impl==null) + return super.__nonzero__(); + } + return impl.__get__(this,self_type).__call__().__nonzero__(); + } + + public boolean __contains__(PyObject o) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__contains__"); + if (impl==null) + return super.__contains__(o); + return impl.__get__(this,self_type).__call__(o).__nonzero__(); + } + + public int __len__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__len__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) + return((PyInteger)res).getValue(); + throw Py.TypeError("__len__ should return a int"); + } + return super.__len__(); + } + + public PyObject __iter__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iter__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + impl=self_type.lookup("__getitem__"); + if (impl==null) + return super.__iter__(); + return new PySequenceIter(this); + } + + public PyObject __iternext__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("next"); + if (impl!=null) { + try { + return impl.__get__(this,self_type).__call__(); + } catch (PyException exc) { + if (Py.matchException(exc,Py.StopIteration)) + return null; + throw exc; + } + } + return super.__iternext__(); // ??? + } + + public PyObject __finditem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(key); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __getitem__(PyObject key) { + // Same as __finditem__, without swallowing LookupErrors. This allows + // __getitem__ implementations written in Python to raise custom + // exceptions (such as subclasses of KeyError). + // + // We are forced to duplicate the code, instead of defining __finditem__ + // in terms of __getitem__. That's because PyObject defines __getitem__ + // in terms of __finditem__. Therefore, we would end with an infinite + // loop when self_type.lookup("__getitem__") returns null: + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__ + // + // By duplicating the (short) lookup and call code, we are safe, because + // the call chains will be: + // + // __finditem__ -> super.__finditem__ + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__ + + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(key); + return super.__getitem__(key); + } + + public void __setitem__(PyObject key,PyObject value) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key,value); + return; + } + super.__setitem__(key,value); + } + + public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); + } + return super.__getslice__(start,stop,step); + } + + public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); + return; + } + super.__setslice__(start,stop,step,value); + } + + public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); + return; + } + super.__delslice__(start,stop,step); + } + + public void __delitem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key); + return; + } + super.__delitem__(key); + } + + public PyObject __call__(PyObject args[],String keywords[]) { + ThreadState ts=Py.getThreadState(); + if (ts.recursion_depth++>ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum __call__ recursion depth exceeded"); + try { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__call__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(args,keywords); + return super.__call__(args,keywords); + } finally { + --ts.recursion_depth; + } + } + + public PyObject __findattr__(String name) { + PyType self_type=getType(); + PyObject getattribute=self_type.lookup("__getattribute__"); + PyString py_name=null; + try { + if (getattribute!=null) { + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + } else { + return super.__findattr__(name); + } + } catch (PyException e) { + if (Py.matchException(e,Py.AttributeError)) { + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) + try { + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); + } catch (PyException e1) { + if (!Py.matchException(e1,Py.AttributeError)) + throw e1; + } + return null; + } + throw e; + } + } + + public void __setattr__(String name,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); + return; + } + super.__setattr__(name,value); + } + + public void __delattr__(String name) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); + return; + } + super.__delattr__(name); + } + + public PyObject __get__(PyObject obj,PyObject type) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__get__"); + if (impl!=null) { + if (obj==null) + obj=Py.None; + if (type==null) + type=Py.None; + return impl.__get__(this,self_type).__call__(obj,type); + } + return super.__get__(obj,type); + } + + public void __set__(PyObject obj,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__set__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj,value); + return; + } + super.__set__(obj,value); + } + + public void __delete__(PyObject obj) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delete__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj); + return; + } + super.__delete__(obj); + } + + public PyObject __pow__(PyObject other,PyObject modulo) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pow__"); + if (impl!=null) { + PyObject res; + if (modulo==null) { + res=impl.__get__(this,self_type).__call__(other); + } else { + res=impl.__get__(this,self_type).__call__(other,modulo); + } + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__pow__(other,modulo); + } + + public void dispatch__init__(PyType type,PyObject[]args,String[]keywords) { + PyType self_type=getType(); + if (self_type.isSubType(type)) { + PyObject impl=self_type.lookup("__init__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(args,keywords); + if (res!=Py.None) { + throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); + } + } + } + } + + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + + public Object __tojava__(Class c) { + // If we are not being asked by the "default" conversion to java, then + // we can provide this as the result, as long as it is a instance of the + // specified class. Without this, derived.__tojava__(PyObject.class) + // would broke. (And that's not pure speculation: PyReflectedFunction's + // ReflectedArgs asks for things like that). + if ((c!=Object.class)&&(c.isInstance(this))) { + return this; + } + // Otherwise, we call the derived __tojava__, if it exists: + PyType self_type=getType(); + PyObject impl=self_type.lookup("__tojava__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava__(Object.class); + return super.__tojava__(c); + } + + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + +} Added: branches/asm/src/org/python/modules/_functools/_functools.java =================================================================== --- branches/asm/src/org/python/modules/_functools/_functools.java (rev 0) +++ branches/asm/src/org/python/modules/_functools/_functools.java 2008-07-30 22:39:24 UTC (rev 5024) @@ -0,0 +1,24 @@ +/* Copyright (c) Jython Developers */ +package org.python.modules._functools; + +import org.python.core.ClassDictInit; +import org.python.core.Py; +import org.python.core.PyObject; +import org.python.core.PyString; + +/** + * The Python _functools module. + */ +public class _functools implements ClassDictInit { + + public static final PyString __doc__ = new PyString("Tools that operate on functions."); + + public static void classDictInit(PyObject dict) { + dict.__setitem__("__name__", new PyString("_functools")); + dict.__setitem__("__doc__", __doc__); + dict.__setitem__("partial", PyPartial.TYPE); + + // Hide from Python + dict.__setitem__("classDictInit", null); + } +} Modified: branches/asm/src/templates/mappings =================================================================== --- branches/asm/src/templates/mappings 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/src/templates/mappings 2008-07-30 22:39:24 UTC (rev 5024) @@ -24,6 +24,7 @@ local.derived:org.python.modules.thread.PyLocalDerived module.derived:org.python.core.PyModuleDerived object.derived:org.python.core.PyObjectDerived +partial.derived:org.python.modules._functools.PyPartialDerived property.derived:org.python.core.PyPropertyDerived random.derived:org.python.modules.random.PyRandomDerived set.derived:org.python.core.PySetDerived Added: branches/asm/src/templates/partial.derived =================================================================== --- branches/asm/src/templates/partial.derived (rev 0) +++ branches/asm/src/templates/partial.derived 2008-07-30 22:39:24 UTC (rev 5024) @@ -0,0 +1,4 @@ +base_class: PyPartial +want_dict: false +ctr: +incl: object This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-31 13:11:05
|
Revision: 5026 http://jython.svn.sourceforge.net/jython/?rev=5026&view=rev Author: fwierzbicki Date: 2008-07-31 13:10:57 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Switch to Antlr 3.1b2. Modified Paths: -------------- branches/asm/build.xml branches/asm/grammar/Python.g Added Paths: ----------- branches/asm/extlibs/antlr-3.1b2.jar branches/asm/extlibs/antlr-runtime-3.1b2.jar branches/asm/extlibs/stringtemplate-3.2.jar Removed Paths: ------------- branches/asm/extlibs/antlr-3.1b1.jar branches/asm/extlibs/antlr-runtime-3.1b1.jar branches/asm/extlibs/stringtemplate-3.1b1.jar Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-07-30 23:00:32 UTC (rev 5025) +++ branches/asm/build.xml 2008-07-31 13:10:57 UTC (rev 5026) @@ -156,8 +156,8 @@ <pathelement path="${extlibs.dir}/mysql-connector-java-5.1.6.jar" /> <pathelement path="${extlibs.dir}/postgresql-8.3-603.jdbc4.jar" /> <pathelement path="${extlibs.dir}/antlr-2.7.7.jar" /> - <pathelement path="${extlibs.dir}/antlr-3.1b1.jar" /> - <pathelement path="${extlibs.dir}/stringtemplate-3.1b1.jar" /> + <pathelement path="${extlibs.dir}/antlr-3.1b2.jar" /> + <pathelement path="${extlibs.dir}/stringtemplate-3.2.jar" /> </path> <available property="informix.present" classname="com.informix.jdbc.IfxDriver" classpath="${informix.jar}" /> @@ -501,7 +501,7 @@ <target name="jarjar" depends="init,needed-check" unless="jarjar.notneeded"> <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="extlibs/jarjar-0.7.jar"/> <jarjar destfile="${output.dir}/jarjar.jar"> - <zipfileset src="extlibs/antlr-runtime-3.1b1.jar"/> + <zipfileset src="extlibs/antlr-runtime-3.1b2.jar"/> <zipfileset src="extlibs/asm-3.1.jar"/> <zipfileset src="extlibs/asm-commons-3.1.jar"/> <zipfileset src="extlibs/asm-util-3.1.jar"/> Property changes on: branches/asm/extlibs/antlr-3.1b2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Property changes on: branches/asm/extlibs/antlr-runtime-3.1b2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Property changes on: branches/asm/extlibs/stringtemplate-3.2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-30 23:00:32 UTC (rev 5025) +++ branches/asm/grammar/Python.g 2008-07-31 13:10:57 UTC (rev 5026) @@ -1044,11 +1044,14 @@ if ($a1.gen) { throwGenExpNotSoleArg($a1.tree); } + //FIXME: not working in 3.1b2 + /* for (int i=0;i<$a2.size();i++) { if (((argument_return)$a2.get(i)).gen) { throwGenExpNotSoleArg(((argument_return)$a2.get(i)).tree); } } + */ } } -> ^(Args argument+) ^(StarArgs $starargs)? ^(KWArgs $kwargs)? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-31 16:15:04
|
Revision: 5028 http://jython.svn.sourceforge.net/jython/?rev=5028&view=rev Author: fwierzbicki Date: 2008-07-31 16:14:55 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Adding a Jython specific version of CommonErrorNode to use when there are errors in the AST but we want to continue parsing (for now this is only of use by external tools, but I'm considering making it an option since the information can be useful. Thanks to Allan Davis for the original version of CommonErrorNode. I've refactored his version so that PythonErrorNode does not repeat much of CommonErrorNode and put the creation logic into PythonTreeAdaptor. I have also added an interface ErrorHandler that allows the error handling in antlr to be customized. FailFastHandler implements the default behavior of dying on the first parse error. I also made the parse error output more useful, and factored a BaseParser out of the org/python/antlr/*Parser classes. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonPartial.g branches/asm/grammar/PythonWalker.g branches/asm/src/org/python/antlr/ExpressionParser.java branches/asm/src/org/python/antlr/InteractiveParser.java branches/asm/src/org/python/antlr/ModuleParser.java branches/asm/src/org/python/antlr/ParseException.java branches/asm/src/org/python/antlr/PythonTree.java branches/asm/src/org/python/antlr/PythonTreeAdaptor.java Added Paths: ----------- branches/asm/src/org/python/antlr/BaseParser.java branches/asm/src/org/python/antlr/ErrorHandler.java branches/asm/src/org/python/antlr/FailFastHandler.java branches/asm/src/org/python/antlr/PythonErrorNode.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/grammar/Python.g 2008-07-31 16:14:55 UTC (rev 5028) @@ -182,16 +182,19 @@ } @members { - //If you want to use antlr's default error recovery mechanisms change this - //and the same one in the lexer to true. - public boolean antlrErrorHandling = false; - //XXX: only used for single_input -- seems kludgy. public boolean inSingle = false; - private boolean seenSingleOuterSuite = false; boolean debugOn = false; + private ErrorHandler errorHandler; + + private boolean seenSingleOuterSuite = false; + + public void setErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; + } + private void debug(String message) { if (debugOn) { System.out.println(message); @@ -398,7 +401,7 @@ protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException { - if (antlrErrorHandling) { + if (errorHandler.isRecoverable()) { super.mismatch(input, ttype, follow); } else { throw new MismatchedTokenException(ttype, input); @@ -408,7 +411,7 @@ protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException { - if (antlrErrorHandling) { + if (errorHandler.isRecoverable()) { return super.recoverFromMismatchedToken(input, ttype, follow); } mismatch(input, ttype, follow); @@ -419,13 +422,9 @@ @rulecatch { catch (RecognitionException re) { - if (antlrErrorHandling) { - reportError(re); - recover(input,re); - retval.tree = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); - } else { - throw new ParseException(re); - } + errorHandler.reportError(this, re); + errorHandler.recover(this, input,re); + retval.tree = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); } } @@ -440,44 +439,55 @@ * 4] */ -//If you want to use antlr's default error recovery mechanisms change this -//and the same one in the parser to true. -public boolean antlrErrorHandling = false; +//If you want to use another error recovery mechanisms change this +//and the same one in the parser. +private ErrorHandler errorHandler; //XXX: Hopefully we can remove inSingle when we get PyCF_DONT_IMPLY_DEDENT support. public boolean inSingle = false; int implicitLineJoiningLevel = 0; int startPos=-1; - public Token nextToken() { - if (antlrErrorHandling) { - return super.nextToken(); - } - while (true) { - state.token = null; - state.channel = Token.DEFAULT_CHANNEL; - state.tokenStartCharIndex = input.index(); - state.tokenStartCharPositionInLine = input.getCharPositionInLine(); - state.tokenStartLine = input.getLine(); - state.text = null; - if ( input.LA(1)==CharStream.EOF ) { - return Token.EOF_TOKEN; - } - try { - mTokens(); - if ( state.token==null ) { - emit(); - } - else if ( state.token==Token.SKIP_TOKEN ) { - continue; - } - return state.token; - } - catch (RecognitionException re) { - throw new ParseException(re); - } - } + public void setErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; } + + /** + * Taken directly from antlr's Lexer.java -- needs to be re-integrated every time + * we upgrade from Antlr (need to consider a Lexer subclass, though the issue would + * remain). + */ + public Token nextToken() { + while (true) { + state.token = null; + state.channel = Token.DEFAULT_CHANNEL; + state.tokenStartCharIndex = input.index(); + state.tokenStartCharPositionInLine = input.getCharPositionInLine(); + state.tokenStartLine = input.getLine(); + state.text = null; + if ( input.LA(1)==CharStream.EOF ) { + return Token.EOF_TOKEN; + } + try { + mTokens(); + if ( state.token==null ) { + emit(); + } + else if ( state.token==Token.SKIP_TOKEN ) { + continue; + } + return state.token; + } + catch (NoViableAltException nva) { + errorHandler.reportError(this, nva); + errorHandler.recover(this, nva); // throw out current char and try again + } + catch (RecognitionException re) { + errorHandler.reportError(this, re); + // match() routine has already called recover() + } + } + } } //single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE Modified: branches/asm/grammar/PythonPartial.g =================================================================== --- branches/asm/grammar/PythonPartial.g 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/grammar/PythonPartial.g 2008-07-31 16:14:55 UTC (rev 5028) @@ -165,7 +165,7 @@ return state.token; } catch (RecognitionException re) { - throw new ParseException(re); + throw new ParseException("failed partial", re); } } } Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/grammar/PythonWalker.g 2008-07-31 16:14:55 UTC (rev 5028) @@ -90,7 +90,13 @@ } @members { boolean debugOn = false; + private ErrorHandler errorHandler; + public void setErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; + } + + public void debug(String message) { if (debugOn) { System.out.println(message); @@ -283,8 +289,9 @@ } @rulecatch { -catch (RecognitionException r) { - throw new ParseException(r); +catch (RecognitionException re) { + errorHandler.reportError(this, re); + errorHandler.recover(this, input,re); } } Added: branches/asm/src/org/python/antlr/BaseParser.java =================================================================== --- branches/asm/src/org/python/antlr/BaseParser.java (rev 0) +++ branches/asm/src/org/python/antlr/BaseParser.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -0,0 +1,36 @@ +package org.python.antlr; + +import org.antlr.runtime.CharStream; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.Token; +import org.antlr.runtime.tree.CommonTree; +import org.antlr.runtime.tree.CommonTreeAdaptor; +import org.antlr.runtime.tree.CommonTreeNodeStream; +import org.antlr.runtime.tree.Tree; +import org.antlr.runtime.tree.TreeAdaptor; +import org.python.antlr.ast.modType; +import org.python.antlr.ast.Module; +import org.python.antlr.ast.stmtType; + +public class BaseParser { + public static class PyLexer extends PythonLexer { + public PyLexer(CharStream lexer) { + super(lexer); + } + + public Token nextToken() { + startPos = getCharPositionInLine(); + return super.nextToken(); + } + } + + protected CharStream charStream; + protected boolean partial; + protected ErrorHandler errorHandler = new FailFastHandler(); + + public void setAntlrErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; + } +} Added: branches/asm/src/org/python/antlr/ErrorHandler.java =================================================================== --- branches/asm/src/org/python/antlr/ErrorHandler.java (rev 0) +++ branches/asm/src/org/python/antlr/ErrorHandler.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -0,0 +1,12 @@ +package org.python.antlr; + +import org.antlr.runtime.BaseRecognizer; +import org.antlr.runtime.IntStream; +import org.antlr.runtime.RecognitionException; + +interface ErrorHandler { + void reportError(BaseRecognizer br, RecognitionException re); + void recover(BaseRecognizer br, RecognitionException re); + void recover(BaseRecognizer br, IntStream input, RecognitionException re); + boolean isRecoverable(); +} Modified: branches/asm/src/org/python/antlr/ExpressionParser.java =================================================================== --- branches/asm/src/org/python/antlr/ExpressionParser.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/ExpressionParser.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -14,22 +14,8 @@ import org.python.antlr.ast.Module; import org.python.antlr.ast.stmtType; -public class ExpressionParser { +public class ExpressionParser extends BaseParser { - private CharStream charStream; - - //Extract superclass from this and the other XParsers. - public static class PyLexer extends PythonLexer { - public PyLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - public ExpressionParser(CharStream cs) { this.charStream = cs; } @@ -37,11 +23,13 @@ public modType parse() { modType tree = null; PythonLexer lexer = new PyLexer(this.charStream); + lexer.setErrorHandler(errorHandler); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); + parser.setErrorHandler(errorHandler); parser.setTreeAdaptor(new PythonTreeAdaptor()); try { @@ -49,6 +37,7 @@ CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree); nodes.setTokenStream(tokens); PythonWalker walker = new PythonWalker(nodes); + walker.setErrorHandler(errorHandler); tree = walker.expression(); } catch (RecognitionException e) { //XXX: this can't happen. Need to strip the throws from antlr Added: branches/asm/src/org/python/antlr/FailFastHandler.java =================================================================== --- branches/asm/src/org/python/antlr/FailFastHandler.java (rev 0) +++ branches/asm/src/org/python/antlr/FailFastHandler.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -0,0 +1,31 @@ +package org.python.antlr; + +import org.antlr.runtime.BaseRecognizer; +import org.antlr.runtime.IntStream; +import org.antlr.runtime.RecognitionException; + +public class FailFastHandler implements ErrorHandler { + private BaseRecognizer recognizer; + + public void reportError(BaseRecognizer br, RecognitionException re) { + throw new ParseException(message(br,re), re); + } + + public void recover(BaseRecognizer br, RecognitionException re) { + throw new ParseException(message(br,re), re); + } + + public void recover(BaseRecognizer br, IntStream input, RecognitionException re) { + throw new ParseException(message(br,re), re); + } + + public boolean isRecoverable() { + return false; + } + + private String message(BaseRecognizer br, RecognitionException re) { + String hdr = br.getErrorHeader(re); + String msg = br.getErrorMessage(re, br.getTokenNames()); + return hdr+" "+msg; + } +} Modified: branches/asm/src/org/python/antlr/InteractiveParser.java =================================================================== --- branches/asm/src/org/python/antlr/InteractiveParser.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/InteractiveParser.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -17,22 +17,10 @@ import org.python.antlr.ast.Module; import org.python.antlr.ast.stmtType; -public class InteractiveParser { +public class InteractiveParser extends BaseParser { private BufferedReader bufreader; - //Extract superclass from this and the other XParsers. - public static class PyLexer extends PythonLexer { - public PyLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - public static class PPLexer extends PythonPartialLexer { public PPLexer(CharStream lexer) { super(lexer); @@ -51,6 +39,7 @@ public modType parse() throws IOException { modType tree = null; PythonLexer lexer = new PyLexer(new NoCloseReaderStream(bufreader)); + lexer.setErrorHandler(errorHandler); //XXX: Hopefully we can remove inSingle when we get PyCF_DONT_IMPLY_DEDENT support. lexer.inSingle = true; CommonTokenStream tokens = new CommonTokenStream(lexer); @@ -58,6 +47,7 @@ PythonTokenSource indentedSource = new PythonTokenSource(tokens); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); + parser.setErrorHandler(errorHandler); parser.inSingle = true; parser.setTreeAdaptor(new PythonTreeAdaptor()); @@ -66,6 +56,7 @@ CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree); nodes.setTokenStream(tokens); PythonWalker walker = new PythonWalker(nodes); + walker.setErrorHandler(errorHandler); tree = walker.interactive(); } catch (RecognitionException e) { //I am only throwing ParseExceptions, but "throws RecognitionException" still gets Modified: branches/asm/src/org/python/antlr/ModuleParser.java =================================================================== --- branches/asm/src/org/python/antlr/ModuleParser.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/ModuleParser.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -14,22 +14,7 @@ import org.python.antlr.ast.Module; import org.python.antlr.ast.stmtType; -public class ModuleParser { - public static class PyLexer extends PythonLexer { - public PyLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - - - private CharStream charStream; - private boolean partial; - +public class ModuleParser extends BaseParser { public ModuleParser(CharStream cs) { this(cs, false); } @@ -42,17 +27,20 @@ public modType file_input() { modType tree = null; PythonLexer lexer = new PyLexer(this.charStream); + lexer.setErrorHandler(errorHandler); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); + parser.setErrorHandler(errorHandler); parser.setTreeAdaptor(new PythonTreeAdaptor()); try { PythonParser.file_input_return r = parser.file_input(); CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree); nodes.setTokenStream(tokens); PythonWalker walker = new PythonWalker(nodes); + walker.setErrorHandler(errorHandler); tree = walker.module(); if (tree == null) { //XXX: seems like I should be able to get antlr to give me an empty Module instead @@ -66,4 +54,5 @@ return tree; } + } Modified: branches/asm/src/org/python/antlr/ParseException.java =================================================================== --- branches/asm/src/org/python/antlr/ParseException.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/ParseException.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -25,8 +25,8 @@ super(message); } - public ParseException(RecognitionException r) { - super(getErrorMessage(r)); + public ParseException(String message, RecognitionException r) { + super(message); input = r.input; index = r.index; token = r.token; @@ -37,120 +37,4 @@ approximateLineInfo = r.approximateLineInfo; } - /** - * getErrorMessage is a modified version of org.antlr.runtime.BaseRecognizer's - * method of the same name from * antlr-3.1 beta1. When we upgrade we should - * make sure to remain consistent. - */ - private static String getErrorMessage(RecognitionException e) { - String msg = e.getMessage(); - String tokenNames[] = PythonParser.tokenNames; - if ( e instanceof UnwantedTokenException ) { - UnwantedTokenException ute = (UnwantedTokenException)e; - String tokenName="<unknown>"; - if ( ute.expecting== Token.EOF ) { - tokenName = "EOF"; - } - else { - tokenName = tokenNames[ute.expecting]; - } - msg = "extraneous input "+getTokenErrorDisplay(ute.getUnexpectedToken())+ - " expecting "+tokenName; - } - else if ( e instanceof MissingTokenException ) { - MissingTokenException mte = (MissingTokenException)e; - String tokenName="<unknown>"; - if ( mte.expecting== Token.EOF ) { - tokenName = "EOF"; - } - else { - tokenName = tokenNames[mte.expecting]; - } - msg = "missing "+tokenName+" at "+getTokenErrorDisplay(e.token); - } - if ( e instanceof MismatchedTokenException ) { - MismatchedTokenException mte = (MismatchedTokenException)e; - String tokenName="<unknown>"; - if ( mte.expecting== Token.EOF ) { - tokenName = "EOF"; - } - else { - tokenName = tokenNames[mte.expecting]; - } - msg = "mismatched input "+getTokenErrorDisplay(e.token)+ - " expecting "+tokenName; - } - else if ( e instanceof MismatchedTreeNodeException ) { - MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e; - String tokenName="<unknown>"; - if ( mtne.expecting==Token.EOF ) { - tokenName = "EOF"; - } - else { - tokenName = tokenNames[mtne.expecting]; - } - msg = "mismatched tree node: "+mtne.node+ - " expecting "+tokenName; - } - else if ( e instanceof NoViableAltException ) { - NoViableAltException nvae = (NoViableAltException)e; - // for development, can add "decision=<<"+nvae.grammarDecisionDescription+">>" - // and "(decision="+nvae.decisionNumber+") and - // "state "+nvae.stateNumber - msg = "no viable alternative at input "+getTokenErrorDisplay(e.token); - } - else if ( e instanceof EarlyExitException ) { - EarlyExitException eee = (EarlyExitException)e; - // for development, can add "(decision="+eee.decisionNumber+")" - msg = "required (...)+ loop did not match anything at input "+ - getTokenErrorDisplay(e.token); - } - else if ( e instanceof MismatchedSetException ) { - MismatchedSetException mse = (MismatchedSetException)e; - msg = "mismatched input "+getTokenErrorDisplay(e.token)+ - " expecting set "+mse.expecting; - } - else if ( e instanceof MismatchedNotSetException ) { - MismatchedNotSetException mse = (MismatchedNotSetException)e; - msg = "mismatched input "+getTokenErrorDisplay(e.token)+ - " expecting set "+mse.expecting; - } - else if ( e instanceof FailedPredicateException ) { - FailedPredicateException fpe = (FailedPredicateException)e; - msg = "rule "+fpe.ruleName+" failed predicate: {"+ - fpe.predicateText+"}?"; - } - return msg; - } - - private static String getTokenErrorDisplay(Token t) { - if (t == null) { - return ""; - } else { - return t.getText(); - } - } - - public int getOffset() { - if (input != null) { - if (input instanceof CharStream) { - return index; - } else { - return ((CommonToken)token).getStartIndex(); - } - } - return -1; - } - - public String info() { - return "info: " + - "input:" + input + - "\nindex:" + index + - "\ntoken:" + token + - "\nnode:" + node + - "\nc:" + c + - "\nline:" + line + - "\ncharPositionInLine:" + charPositionInLine + - "\napproximateLineInfo:" + approximateLineInfo; - } } Added: branches/asm/src/org/python/antlr/PythonErrorNode.java =================================================================== --- branches/asm/src/org/python/antlr/PythonErrorNode.java (rev 0) +++ branches/asm/src/org/python/antlr/PythonErrorNode.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -0,0 +1,38 @@ +package org.python.antlr; + +import org.antlr.runtime.Token; +import org.antlr.runtime.TokenStream; +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.tree.CommonErrorNode; + +/** A node representing erroneous token range in token stream + */ +public class PythonErrorNode extends PythonTree { + + private CommonErrorNode errorNode; + + public PythonErrorNode(TokenStream input, Token start, Token stop, + RecognitionException e) { + this.errorNode = new CommonErrorNode(input, start, stop, e); + } + + public PythonErrorNode(CommonErrorNode errorNode){ + this.errorNode = errorNode; + } + + public boolean isNil() { + return errorNode.isNil(); + } + + public int getType() { + return errorNode.getType(); + } + + public String getText() { + return errorNode.getText(); + } + + public String toString() { + return errorNode.toString(); + } +} Modified: branches/asm/src/org/python/antlr/PythonTree.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTree.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/PythonTree.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -30,6 +30,12 @@ /** What index is this node in the child list? Range: 0..n-1 */ public int childIndex = -1; + /** + * The empty constructor is intended only for use by PythonErrorNode. + */ + public PythonTree() { + } + public PythonTree(int ttype, Token t) { CommonToken c = new CommonToken(ttype, t.getText()); c.setLine(t.getLine()); Modified: branches/asm/src/org/python/antlr/PythonTreeAdaptor.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTreeAdaptor.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/PythonTreeAdaptor.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -1,7 +1,9 @@ package org.python.antlr; import org.antlr.runtime.CommonToken; +import org.antlr.runtime.RecognitionException; import org.antlr.runtime.Token; +import org.antlr.runtime.TokenStream; import org.antlr.runtime.tree.CommonTreeAdaptor; public class PythonTreeAdaptor extends CommonTreeAdaptor { @@ -45,6 +47,14 @@ return new PythonTree(token); } + public Object errorNode(TokenStream input, Token start, Token stop, + RecognitionException e) + { + PythonErrorNode t = new PythonErrorNode(input, start, stop, e); + //System.out.println("returning error node '"+t+"' @index="+input.index()); + return t; + } + public Object dupNode(Object t) { if (t == null) { return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 19:50:52
|
Revision: 5030 http://jython.svn.sourceforge.net/jython/?rev=5030&view=rev Author: pjenvey Date: 2008-07-31 19:50:45 +0000 (Thu, 31 Jul 2008) Log Message: ----------- o fix test_softspace and reset softspace (and append a newline) in various places (equiv. of CPython's ceval.c::Py_FlushLine) o fix traceback source lines without trailing newlines (fixes #1087) Modified Paths: -------------- branches/asm/Lib/test/regrtest.py branches/asm/src/org/python/core/Py.java branches/asm/src/org/python/core/PySystemState.java branches/asm/src/org/python/core/PyTraceback.java branches/asm/src/org/python/core/StdoutWrapper.java branches/asm/src/org/python/util/PythonInterpreter.java Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/Lib/test/regrtest.py 2008-07-31 19:50:45 UTC (rev 5030) @@ -1493,7 +1493,6 @@ test_pyclbr test_quopri test_random - test_softspace test_syntax test_trace test_ucn Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/Py.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -992,6 +992,7 @@ exceptHook.__call__(exc.type, exc.value, exc.traceback); } catch (PyException exc2) { exc2.normalize(); + flushLine(); stderr.println("Error in sys.excepthook:"); displayException(exc2.type, exc2.value, exc2.traceback, file); stderr.println(); @@ -1006,12 +1007,13 @@ ts.exception = null; } - public static void displayException(PyObject type, PyObject value, - PyObject tb, PyObject file) { + public static void displayException(PyObject type, PyObject value, PyObject tb, + PyObject file) { StdoutWrapper stderr = Py.stderr; if (file != null) { stderr = new FixedFileWrapper(file); } + flushLine(); if (tb instanceof PyTraceback) { stderr.print(((PyTraceback) tb).dumpStack()); @@ -1317,6 +1319,10 @@ stdout.println(); } + public static void flushLine() { + stdout.flushLine(); + } + /* * A collection of convenience functions for converting PyObjects to Java primitives */ Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/PySystemState.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -342,6 +342,7 @@ Py.printException(exc); } } + Py.flushLine(); } public ClassLoader getClassLoader() { Modified: branches/asm/src/org/python/core/PyTraceback.java =================================================================== --- branches/asm/src/org/python/core/PyTraceback.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/PyTraceback.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -90,6 +90,11 @@ i++; } line = line.substring(i); + if (!line.endsWith("\n")) { + line += "\n"; + } + } else { + line = null; } return line; } Modified: branches/asm/src/org/python/core/StdoutWrapper.java =================================================================== --- branches/asm/src/org/python/core/StdoutWrapper.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/StdoutWrapper.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -46,7 +46,11 @@ if (obj instanceof PyFile) { ((PyFile) obj).flush(); } else { - obj.invoke("flush"); + try { + obj.invoke("flush"); + } catch (PyException pye) { + // ok + } } } @@ -68,7 +72,7 @@ write(StringUtil.fromBytes(data, off, len)); } - public void clearSoftspace() { + public void flushLine() { PyObject obj = myFile(); if (obj instanceof PyFile) { @@ -83,45 +87,63 @@ if (ss != null && ss.__nonzero__()) { obj.invoke("write", Py.Newline); } - obj.invoke("flush"); + try { + obj.invoke("flush"); + } catch (PyException pye) { + // ok + } obj.__setattr__("softspace", Py.Zero); } } public void print(PyObject o, boolean space, boolean newline) { - PyString string = o.__str__(); PyObject obj = myFile(); if (obj instanceof PyFile) { - PyFile file = (PyFile) obj; + PyFile file = (PyFile)obj; + if (file.softspace) { + file.write(" "); + file.softspace = false; + } + PyString string = o.__str__(); String s = string.toString(); + int len = s.length(); + file.write(s); + if (o instanceof PyString) { + if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) + || s.charAt(len - 1) == ' ') { + file.softspace = space; + } + } else { + file.softspace = space; + } if (newline) { - s = s + "\n"; + file.write("\n"); + file.softspace = false; } - if (file.softspace) { - s = " " + s; - } - file.write(s); file.flush(); - if (space && s.endsWith("\n")) { - space = false; - } - file.softspace = space; } else { PyObject ss = obj.__findattr__("softspace"); if (ss != null && ss.__nonzero__()) { obj.invoke("write", Py.Space); + obj.__setattr__("softspace", Py.Zero); } + PyString string = o.__str__(); + String s = o.toString(); + int len = s.length(); obj.invoke("write", string); + if (o instanceof PyString) { + if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) + || s.charAt(len - 1) == ' ') { + obj.__setattr__("softspace", space ? Py.One : Py.Zero); + } + } else { + obj.__setattr__("softspace", space ? Py.One : Py.Zero); + } if (newline) { obj.invoke("write", Py.Newline); + obj.__setattr__("softspace", Py.Zero); } - // obj.invoke("flush"); - - if (space && string.toString().endsWith("\n")) { - space = false; - } - obj.__setattr__("softspace", space ? Py.One : Py.Zero); } } Modified: branches/asm/src/org/python/util/PythonInterpreter.java =================================================================== --- branches/asm/src/org/python/util/PythonInterpreter.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/util/PythonInterpreter.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -121,6 +121,7 @@ setState(); Py.exec(Py.compile_flags(s, "<string>", "exec",cflags), locals, locals); + Py.flushLine(); } /** @@ -131,6 +132,7 @@ public void exec(PyObject code) { setState(); Py.exec(code, locals, locals); + Py.flushLine(); } /** @@ -141,6 +143,7 @@ public void execfile(String s) { setState(); __builtin__.execfile_flags(s, locals, locals, cflags); + Py.flushLine(); } public void execfile(java.io.InputStream s) { @@ -150,6 +153,7 @@ public void execfile(java.io.InputStream s, String name) { setState(); Py.runCode((PyCode)Py.compile_flags(s, name, "exec",cflags), locals, locals); + Py.flushLine(); } // Getting and setting the locals dictionary This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 23:49:52
|
Revision: 5037 http://jython.svn.sourceforge.net/jython/?rev=5037&view=rev Author: pjenvey Date: 2008-07-31 23:49:50 +0000 (Thu, 31 Jul 2008) Log Message: ----------- fix a couple test_coercion cases: o fix broken PyComplex.__rfloordiv__ o prevent stack overflows when old style classes return __coerce__ args in reversed order Modified Paths: -------------- branches/asm/Misc/make_binops.py branches/asm/src/org/python/core/PyComplex.java branches/asm/src/org/python/core/PyInstance.java Modified: branches/asm/Misc/make_binops.py =================================================================== --- branches/asm/Misc/make_binops.py 2008-07-31 23:32:03 UTC (rev 5036) +++ branches/asm/Misc/make_binops.py 2008-07-31 23:49:50 UTC (rev 5037) @@ -153,10 +153,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__%(name)s__", o2); - else - return %(function)s; + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return %(function)s; + } finally { + --ts.recursion_depth; + } + } } } Modified: branches/asm/src/org/python/core/PyComplex.java =================================================================== --- branches/asm/src/org/python/core/PyComplex.java 2008-07-31 23:32:03 UTC (rev 5036) +++ branches/asm/src/org/python/core/PyComplex.java 2008-07-31 23:49:50 UTC (rev 5037) @@ -435,7 +435,7 @@ } public PyObject __rfloordiv__(PyObject left) { - return complex___floordiv__(left); + return complex___rfloordiv__(left); } @ExposedMethod(type = MethodType.BINARY) Modified: branches/asm/src/org/python/core/PyInstance.java =================================================================== --- branches/asm/src/org/python/core/PyInstance.java 2008-07-31 23:32:03 UTC (rev 5036) +++ branches/asm/src/org/python/core/PyInstance.java 2008-07-31 23:49:50 UTC (rev 5037) @@ -896,10 +896,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__add__", o2); - else - return o1._add(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._add(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -914,10 +924,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__radd__", o2); - else - return o2._add(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._add(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -943,10 +963,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__sub__", o2); - else - return o1._sub(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._sub(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -961,10 +991,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rsub__", o2); - else - return o2._sub(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._sub(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -990,10 +1030,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__mul__", o2); - else - return o1._mul(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._mul(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1008,10 +1058,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rmul__", o2); - else - return o2._mul(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._mul(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1037,10 +1097,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__div__", o2); - else - return o1._div(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._div(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1055,10 +1125,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rdiv__", o2); - else - return o2._div(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._div(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1084,10 +1164,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__floordiv__", o2); - else - return o1._floordiv(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._floordiv(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1102,10 +1192,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rfloordiv__", o2); - else - return o2._floordiv(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._floordiv(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1131,10 +1231,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__truediv__", o2); - else - return o1._truediv(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._truediv(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1149,10 +1259,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rtruediv__", o2); - else - return o2._truediv(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._truediv(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1178,10 +1298,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__mod__", o2); - else - return o1._mod(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._mod(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1196,10 +1326,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rmod__", o2); - else - return o2._mod(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._mod(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1225,10 +1365,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__divmod__", o2); - else - return o1._divmod(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._divmod(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1243,10 +1393,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rdivmod__", o2); - else - return o2._divmod(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._divmod(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1261,10 +1421,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__pow__", o2); - else - return o1._pow(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._pow(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1279,10 +1449,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rpow__", o2); - else - return o2._pow(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._pow(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1308,10 +1488,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__lshift__", o2); - else - return o1._lshift(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._lshift(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1326,10 +1516,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rlshift__", o2); - else - return o2._lshift(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._lshift(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1355,10 +1555,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rshift__", o2); - else - return o1._rshift(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._rshift(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1373,10 +1583,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rrshift__", o2); - else - return o2._rshift(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._rshift(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1402,10 +1622,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__and__", o2); - else - return o1._and(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._and(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1420,10 +1650,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rand__", o2); - else - return o2._and(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._and(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1449,10 +1689,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__or__", o2); - else - return o1._or(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._or(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1467,10 +1717,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__ror__", o2); - else - return o2._or(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._or(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1496,10 +1756,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__xor__", o2); - else - return o1._xor(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._xor(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1514,10 +1784,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rxor__", o2); - else - return o2._xor(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._xor(o1); + } finally { + --ts.recursion_depth; + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 23:59:27
|
Revision: 5039 http://jython.svn.sourceforge.net/jython/?rev=5039&view=rev Author: pjenvey Date: 2008-07-31 23:59:25 +0000 (Thu, 31 Jul 2008) Log Message: ----------- o filter operator slice args through __index__ o workaround Jython's lack of a real repeat/concat binop in test_operator Modified Paths: -------------- branches/asm/Lib/test/test_operator.py branches/asm/src/org/python/modules/operator.java Modified: branches/asm/Lib/test/test_operator.py =================================================================== --- branches/asm/Lib/test/test_operator.py 2008-07-31 23:57:11 UTC (rev 5038) +++ branches/asm/Lib/test/test_operator.py 2008-07-31 23:59:25 UTC (rev 5039) @@ -122,7 +122,9 @@ self.failUnless(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4]) self.failUnless(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7]) self.failUnless(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7]) - self.failUnlessRaises(TypeError, operator.concat, 13, 29) + if not test_support.is_jython: + # Jython concat is add + self.failUnlessRaises(TypeError, operator.concat, 13, 29) def test_countOf(self): self.failUnlessRaises(TypeError, operator.countOf) @@ -291,7 +293,9 @@ self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]) self.failUnless(operator.repeat(a, 1) == [4, 5, 6]) self.failUnless(operator.repeat(a, 0) == []) - self.failUnlessRaises(TypeError, operator.repeat, 6, 7) + if not test_support.is_jython: + # Jython repeat is mul + self.failUnlessRaises(TypeError, operator.repeat, 6, 7) def test_rshift(self): self.failUnlessRaises(TypeError, operator.rshift) Modified: branches/asm/src/org/python/modules/operator.java =================================================================== --- branches/asm/src/org/python/modules/operator.java 2008-07-31 23:57:11 UTC (rev 5038) +++ branches/asm/src/org/python/modules/operator.java 2008-07-31 23:59:25 UTC (rev 5039) @@ -85,8 +85,8 @@ public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { switch (index) { - case 22: arg1.__delslice__(arg2, arg3); return Py.None; - case 24: return arg1.__getslice__(arg2, arg3); + case 22: arg1.__delslice__(arg2.__index__(), arg3.__index__()); return Py.None; + case 24: return arg1.__getslice__(arg2.__index__(), arg3.__index__()); case 25: arg1.__setitem__(arg2, arg3); return Py.None; default: throw info.unexpectedCall(3, false); @@ -98,7 +98,7 @@ { switch (index) { case 26: - arg1.__setslice__(arg2, arg3, arg4); + arg1.__setslice__(arg2.__index__(), arg3.__index__(), arg4); return Py.None; default: throw info.unexpectedCall(4, false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-01 20:06:47
|
Revision: 5041 http://jython.svn.sourceforge.net/jython/?rev=5041&view=rev Author: nriley Date: 2008-08-01 20:06:44 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Make the ihooks module importable. Modified Paths: -------------- branches/asm/CPythonLib.includes branches/asm/src/org/python/modules/imp.java Modified: branches/asm/CPythonLib.includes =================================================================== --- branches/asm/CPythonLib.includes 2008-08-01 00:50:28 UTC (rev 5040) +++ branches/asm/CPythonLib.includes 2008-08-01 20:06:44 UTC (rev 5041) @@ -69,6 +69,7 @@ htmllib.py HTMLParser.py httplib.py +ihooks.py imaplib.py imghdr.py inspect.py Modified: branches/asm/src/org/python/modules/imp.java =================================================================== --- branches/asm/src/org/python/modules/imp.java 2008-08-01 00:50:28 UTC (rev 5040) +++ branches/asm/src/org/python/modules/imp.java 2008-08-01 20:06:44 UTC (rev 5041) @@ -33,6 +33,7 @@ public static final int PY_COMPILED = 2; public static final int C_EXTENSION = 3; public static final int PKG_DIRECTORY = 5; + public static final int C_BUILTIN = 6; public static final int PY_FROZEN = 7; public static final int IMP_HOOK = 9; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-01 20:22:24
|
Revision: 5043 http://jython.svn.sourceforge.net/jython/?rev=5043&view=rev Author: nriley Date: 2008-08-01 20:22:22 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Replace python.prepath with python.path. Modified Paths: -------------- branches/asm/NEWS branches/asm/src/org/python/core/PySystemState.java Modified: branches/asm/NEWS =================================================================== --- branches/asm/NEWS 2008-08-01 20:07:47 UTC (rev 5042) +++ branches/asm/NEWS 2008-08-01 20:22:22 UTC (rev 5043) @@ -2,6 +2,7 @@ Jython 2.5 Incompatible Changes + - The python.prepath property has been removed; use python.path instead. - To implement the Java Map interface, PyDictionary.values now returns a Collection instead of a PyList - The -E codec command line option (use a different codec when reading from Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-08-01 20:07:47 UTC (rev 5042) +++ branches/asm/src/org/python/core/PySystemState.java 2008-08-01 20:22:22 UTC (rev 5043) @@ -703,12 +703,11 @@ private static PyList initPath(Properties props, boolean standalone, String jarFileName) { PyList path = new PyList(); - addPaths(path, props.getProperty("python.prepath", "")); + addPaths(path, props.getProperty("python.path", "")); if (prefix != null) { String libpath = new File(prefix, "Lib").toString(); path.append(new PyString(libpath)); } - addPaths(path, props.getProperty("python.path", "")); if (standalone) { // standalone jython: add the /Lib directory inside JYTHON_JAR to the path addPaths(path, jarFileName + "/Lib"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-01 20:37:49
|
Revision: 5044 http://jython.svn.sourceforge.net/jython/?rev=5044&view=rev Author: fwierzbicki Date: 2008-08-01 20:37:46 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Better handling of bad dedent. Not perfect since it throws the wrong exception. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/PythonTokenSource.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-01 20:22:22 UTC (rev 5043) +++ branches/asm/grammar/Python.g 2008-08-01 20:37:46 UTC (rev 5044) @@ -1385,8 +1385,10 @@ for (int i=0; i<spaces; i++) { indentation[i] = ' '; } - String s = new String(indentation); - emit(new ClassicToken(LEADING_WS,new String(indentation))); + ClassicToken c = new ClassicToken(LEADING_WS,new String(indentation)); + c.setLine(input.getLine()); + c.setCharPositionInLine(input.getCharPositionInLine()); + emit(c); } // kill trailing newline if present and then ignore ( ('\r')? '\n' {if (state.token!=null) state.token.setChannel(HIDDEN); else $channel=HIDDEN;})* Modified: branches/asm/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-01 20:22:22 UTC (rev 5043) +++ branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-01 20:37:46 UTC (rev 5044) @@ -202,7 +202,7 @@ } else if (cpos < lastIndent) { // they dedented // how far back did we dedent? - int prevIndex = findPreviousIndent(cpos); + int prevIndex = findPreviousIndent(cpos, t); //System.out.println("dedented; prevIndex of cpos="+cpos+" is "+prevIndex); // generate DEDENTs for each indent level we backed up over for (int d = sp - 1; d >= prevIndex; d--) { @@ -255,13 +255,20 @@ } /** Return the index on stack of previous indent level == i else -1 */ - protected int findPreviousIndent(int i) { + protected int findPreviousIndent(int i, Token t) { for (int j = sp - 1; j >= 0; j--) { if (indentStack[j] == i) { return j; } } - return FIRST_CHAR_POSITION; + //The -2 is for the special case of getCharPositionInLine in multiline str nodes. + if (i == -1 || i == -2) { + return FIRST_CHAR_POSITION; + } + ParseException p = new ParseException("unindent does not match any outer indentation level"); + p.line = t.getLine(); + p.charPositionInLine = t.getCharPositionInLine(); + throw p; } public String stackString() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-01 21:49:32
|
Revision: 5046 http://jython.svn.sourceforge.net/jython/?rev=5046&view=rev Author: pjenvey Date: 2008-08-01 21:49:29 +0000 (Fri, 01 Aug 2008) Log Message: ----------- fix instancemethod cmp to make test_class pass Modified Paths: -------------- branches/asm/Lib/test/regrtest.py branches/asm/Lib/test/test_class.py branches/asm/src/org/python/core/PyMethod.java Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-08-01 21:47:30 UTC (rev 5045) +++ branches/asm/Lib/test/regrtest.py 2008-08-01 21:49:29 UTC (rev 5046) @@ -1469,7 +1469,6 @@ 'java': """ test_ast - test_class test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp Modified: branches/asm/Lib/test/test_class.py =================================================================== --- branches/asm/Lib/test/test_class.py 2008-08-01 21:47:30 UTC (rev 5045) +++ branches/asm/Lib/test/test_class.py 2008-08-01 21:49:29 UTC (rev 5046) @@ -250,8 +250,8 @@ del testme if sys.platform[:4] == 'java': - import java - java.lang.System.gc() + from test_weakref import extra_collect + extra_collect() # Interfering tests Modified: branches/asm/src/org/python/core/PyMethod.java =================================================================== --- branches/asm/src/org/python/core/PyMethod.java 2008-08-01 21:47:30 UTC (rev 5045) +++ branches/asm/src/org/python/core/PyMethod.java 2008-08-01 21:49:29 UTC (rev 5046) @@ -127,16 +127,20 @@ if (!(other instanceof PyMethod)) { return -2; } - PyMethod mother = (PyMethod)other; - if (im_self != mother.im_self) { - return System.identityHashCode(im_self) < - System.identityHashCode(mother.im_self) ? -1 : 1; + PyMethod otherMethod = (PyMethod)other; + int cmp = im_func._cmp(otherMethod.im_func); + if (cmp != 0) { + return cmp; } - if (im_func != mother.im_func) { - return System.identityHashCode(im_func) < - System.identityHashCode(mother.im_func) ? -1 : 1; + if (im_self == otherMethod.im_self) { + return 0; } - return 0; + if (im_self == null || otherMethod.im_self == null) { + return System.identityHashCode(im_self) < System.identityHashCode(otherMethod.im_self) + ? -1 : 1; + } else { + return im_self._cmp(otherMethod.im_self); + } } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-01 22:38:35
|
Revision: 5049 http://jython.svn.sourceforge.net/jython/?rev=5049&view=rev Author: pjenvey Date: 2008-08-01 22:38:32 +0000 (Fri, 01 Aug 2008) Log Message: ----------- list.__nonzero__ needn't be exposed, couple test_descrtut fixes (though it still fails due to parser problems) Modified Paths: -------------- branches/asm/Lib/test/test_descrtut.py branches/asm/src/org/python/core/PyList.java Modified: branches/asm/Lib/test/test_descrtut.py =================================================================== --- branches/asm/Lib/test/test_descrtut.py 2008-08-01 22:28:52 UTC (rev 5048) +++ branches/asm/Lib/test/test_descrtut.py 2008-08-01 22:38:32 UTC (rev 5049) @@ -73,7 +73,7 @@ >>> exec "x = 3; print x" in a 3 >>> print sorted(a.keys()) - [1, 2, '__builtins__', 'x'] + [1, 2, 'x'] >>> print a['x'] 3 >>> @@ -199,10 +199,10 @@ '__mul__', '__ne__', '__new__', + '__radd__', '__reduce__', '__reduce_ex__', '__repr__', - '__reversed__', '__rmul__', '__setattr__', '__setitem__', Modified: branches/asm/src/org/python/core/PyList.java =================================================================== --- branches/asm/src/org/python/core/PyList.java 2008-08-01 22:28:52 UTC (rev 5048) +++ branches/asm/src/org/python/core/PyList.java 2008-08-01 22:38:32 UTC (rev 5049) @@ -377,11 +377,6 @@ return ret; } - @ExposedMethod - final boolean list___nonzero__() { - return seq___nonzero__(); - } - public PyObject __iter__() { return list___iter__(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-02 19:51:20
|
Revision: 5053 http://jython.svn.sourceforge.net/jython/?rev=5053&view=rev Author: pjenvey Date: 2008-08-02 19:51:15 +0000 (Sat, 02 Aug 2008) Log Message: ----------- switch some new style unary ops to throw TypeErrors instead of AttributeErrors when not implemented. the old styles still raise AttributeErrors (both styles now match CPython). we assume __len/int/long/float/complex__ raise AttributeErrors in many places so leaving them alone for now Modified Paths: -------------- branches/asm/Lib/test/test_descr_jy.py branches/asm/src/org/python/core/PyInstance.java branches/asm/src/org/python/core/PyObject.java branches/asm/src/org/python/core/__builtin__.java Modified: branches/asm/Lib/test/test_descr_jy.py =================================================================== --- branches/asm/Lib/test/test_descr_jy.py 2008-08-02 08:49:57 UTC (rev 5052) +++ branches/asm/Lib/test/test_descr_jy.py 2008-08-02 19:51:15 UTC (rev 5053) @@ -2,10 +2,21 @@ Made for Jython. """ -import test_support import types import unittest +from test import test_support +class Old: + pass + + +class New(object): + pass + + +old = Old() +new = New() + class TestDescrTestCase(unittest.TestCase): def test_class_dict_is_copy(self): @@ -255,10 +266,39 @@ self.assertEqual(foo, set([1])) +class DescrExceptionsTestCase(unittest.TestCase): + + def test_hex(self): + self._test(hex) + + def test_oct(self): + self._test(oct) + + def test_other(self): + for op in '-', '+', '~': + try: + eval('%s(old)' % op) + except AttributeError: + pass + else: + self._assert(False, 'Expected an AttributeError, op: %s' % op) + try: + eval('%s(new)' % op) + except TypeError: + pass + else: + self._assert(False, 'Expected a TypeError, op: %s' % op) + + def _test(self, func): + self.assertRaises(AttributeError, func, old) + self.assertRaises(TypeError, func, new) + + def test_main(): test_support.run_unittest(TestDescrTestCase, SubclassDescrTestCase, - InPlaceTestCase) + InPlaceTestCase, + DescrExceptionsTestCase) if __name__ == '__main__': test_main() Modified: branches/asm/src/org/python/core/PyInstance.java =================================================================== --- branches/asm/src/org/python/core/PyInstance.java 2008-08-02 08:49:57 UTC (rev 5052) +++ branches/asm/src/org/python/core/PyInstance.java 2008-08-02 19:51:15 UTC (rev 5053) @@ -264,7 +264,7 @@ } } if (f == null) f = ifindfunction(name); - if (f == null) throw Py.AttributeError(name); + if (f == null) noAttributeError(name); return f.__call__(); } @@ -281,7 +281,7 @@ } } if (f == null) f = ifindfunction(name); - if (f == null) throw Py.AttributeError(name); + if (f == null) noAttributeError(name); return f.__call__(arg1); } @@ -298,11 +298,16 @@ } } if (f == null) f = ifindfunction(name); - if (f == null) throw Py.AttributeError(name); + if (f == null) noAttributeError(name); return f.__call__(arg1, arg2); } + public void noAttributeError(String name) { + throw Py.AttributeError(String.format("%.50s instance has no attribute '%.400s'", + instclass.__name__, name)); + } + public void __setattr__(String name, PyObject value) { if (name == "__class__") { if (value instanceof PyClass) { Modified: branches/asm/src/org/python/core/PyObject.java =================================================================== --- branches/asm/src/org/python/core/PyObject.java 2008-08-02 08:49:57 UTC (rev 5052) +++ branches/asm/src/org/python/core/PyObject.java 2008-08-02 19:51:15 UTC (rev 5053) @@ -581,7 +581,8 @@ * @exception Py.KeyError if the key is not found in the container **/ public void __delitem__(PyObject key) { - throw Py.AttributeError("__delitem__"); + throw Py.TypeError(String.format("'%.200s' object doesn't support item deletion", + getType().fastGetName())); } /** @@ -1504,7 +1505,7 @@ * @return a string representing this object as a hexadecimal number. **/ public PyString __hex__() { - throw Py.AttributeError("__hex__"); + throw Py.TypeError("hex() argument can't be converted to hex"); } /** @@ -1515,7 +1516,7 @@ * @return a string representing this object as an octal number. **/ public PyString __oct__() { - throw Py.AttributeError("__oct__"); + throw Py.TypeError("oct() argument can't be converted to oct"); } /** @@ -1568,7 +1569,8 @@ * @return +this. **/ public PyObject __pos__() { - throw Py.AttributeError("__pos__"); + throw Py.TypeError(String.format("bad operand type for unary +: '%.200s'", + getType().fastGetName())); } /** @@ -1577,7 +1579,8 @@ * @return -this. **/ public PyObject __neg__() { - throw Py.AttributeError("__neg__"); + throw Py.TypeError(String.format("bad operand type for unary -: '%.200s'", + getType().fastGetName())); } /** @@ -1586,7 +1589,8 @@ * @return abs(this). **/ public PyObject __abs__() { - throw Py.AttributeError("__abs__"); + throw Py.TypeError(String.format("bad operand type for abs(): '%.200s'", + getType().fastGetName())); } /** @@ -1595,7 +1599,8 @@ * @return ~this. **/ public PyObject __invert__() { - throw Py.AttributeError("__invert__"); + throw Py.TypeError(String.format("bad operand type for unary ~: '%.200s'", + getType().fastGetName())); } /** Modified: branches/asm/src/org/python/core/__builtin__.java =================================================================== --- branches/asm/src/org/python/core/__builtin__.java 2008-08-02 08:49:57 UTC (rev 5052) +++ branches/asm/src/org/python/core/__builtin__.java 2008-08-02 19:51:15 UTC (rev 5053) @@ -387,10 +387,7 @@ } public static PyObject abs(PyObject o) { - if (o.isNumberType()) { - return o.__abs__(); - } - throw Py.TypeError("bad operand type for abs()"); + return o.__abs__(); } public static PyObject apply(PyObject o) { @@ -725,14 +722,7 @@ } public static PyString hex(PyObject o) { - try { - return o.__hex__(); - } catch (PyException e) { - if (Py.matchException(e, Py.AttributeError)) { - throw Py.TypeError("hex() argument can't be converted to hex"); - } - throw e; - } + return o.__hex__(); } public static long id(PyObject o) { @@ -856,14 +846,7 @@ } public static PyString oct(PyObject o) { - try { - return o.__oct__(); - } catch (PyException e) { - if (Py.matchException(e, Py.AttributeError)) { - throw Py.TypeError("oct() argument can't be converted to oct"); - } - throw e; - } + return o.__oct__(); } public static final int ord(PyObject c) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-08-02 21:43:29
|
Revision: 5056 http://jython.svn.sourceforge.net/jython/?rev=5056&view=rev Author: zyasoft Date: 2008-08-02 21:43:22 +0000 (Sat, 02 Aug 2008) Log Message: ----------- Fixed roundtripping so that eval(str(a)) == a where a uses a typecode of a Java object, along with other similar minor issues. Rewrote test_array_jy to use unittest, and removed testing now being done by standard 2.5 test_array Modified Paths: -------------- branches/asm/Lib/test/test_array_jy.py branches/asm/src/org/python/core/PyArray.java branches/asm/src/org/python/modules/ArrayModule.java Removed Paths: ------------- branches/asm/Lib/test/output/test_array_jy Deleted: branches/asm/Lib/test/output/test_array_jy =================================================================== --- branches/asm/Lib/test/output/test_array_jy 2008-08-02 21:40:59 UTC (rev 5055) +++ branches/asm/Lib/test/output/test_array_jy 2008-08-02 21:43:22 UTC (rev 5056) @@ -1,4 +0,0 @@ -test_array -array module (test_array.py) -array -zeros Modified: branches/asm/Lib/test/test_array_jy.py =================================================================== --- branches/asm/Lib/test/test_array_jy.py 2008-08-02 21:40:59 UTC (rev 5055) +++ branches/asm/Lib/test/test_array_jy.py 2008-08-02 21:43:22 UTC (rev 5056) @@ -1,438 +1,51 @@ -# CAU: Adaptation of the cpython 2.2 test_array.py for jython 2.2 -# Formerly test_jarray.py, now test_array.py so that this -# test completely supercedes the cpthyhon test. It would -# be better to simply complement the cpython test, but that -# test bombs out too early due to basic incompatibilities. -# -# The jarray module is being phased out, with all functionality -# now available in the array module. +# The jarray module is being phased out, with all functionality +# now available in the array module. -from test_support import * +import unittest +from test import test_support from array import array, zeros -import sys from java.lang import String from java.lang.reflect import Array from java.util import Arrays -print 'array module (test_array.py)' +class ArrayJyTestCase(unittest.TestCase): -def main(): - - test_jarray() # while it's still supported - - test_java_compat() - test_java_object_arrays() + def test_jarray(self): # until it is fully formally removed - testtype('c', 'c') - for type in (['b', 'h', 'i', 'l', 'f', 'd']): - testtype(type, 1) - - #test a mix of known success and failure cases - init_tests() - extend_tests() - fromlist_tests() + # While jarray is still being phased out, just flex the initilaizers. + # The rest of the test for array will catch all the big problems. + import jarray + jarray.array(range(5), 'i') + jarray.array([String("a"), String("b"), String("c")], String) + jarray.zeros(5, 'i') + jarray.zeros(5, String) - unlink(TESTFN) + def test_java_object_arrays(self): + jStringArr = array(String, [String("a"), String("b"), String("c")]) + self.assert_( + Arrays.equals(jStringArr.typecode, str(String)), + "String array typecode of wrong type, expected %s, found %s" % + (jStringArr.typecode, str(String))) + self.assertEqual(zeros(String, 5), Array.newInstance(String, 5)) -def test_jarray(): # until it is fully formally removed + import java # require for eval to work + self.assertEqual(jStringArr, eval(str(jStringArr))) - # While jarray is still being phased out, just flex the initilaizers. - # The rest of the test for array will catch all the big problems. - import jarray - jarray.array(range(5), 'i') - jarray.array([String("a"), String("b"), String("c")], String) - jarray.zeros(5, 'i') - jarray.zeros(5, String) + def test_java_compat(self): + from java import awt + hsb = awt.Color.RGBtoHSB(0,255,255, None) + self.assertEqual(hsb, array('f', [0.5,1,1]), + "output hsb float array does not correspond to input rgb values") + rgb = apply(awt.Color.HSBtoRGB, tuple(hsb)) + self.assertEqual(rgb, -0xff0001, + "output rgb bytes don't match input hsb floats") + hsb1 = zeros('f', 3) + awt.Color.RGBtoHSB(0,255,255, hsb1) + self.assertEqual(hsb, hsb1, "hsb float arrays were not equal") -def test_java_object_arrays(): - jStringArr = array(String, [String("a"), String("b"), String("c")]) - verify(Arrays.equals(jStringArr.typecode, str(String)), - "String array typecode of wrong type, expected %s, found %s" % - (jStringArr.typecode, str(String))) - verify(zeros(String, 5) == Array.newInstance(String, 5)) +def test_main(): + test_support.run_unittest(ArrayJyTestCase) - import java # require for eval to work - if jStringArr != eval(str(jStringArr)): - raise TestFailed, "eval(str(%s)) <> %s" % (jStringArr,)*2 - - -def test_java_compat(): - print 'array' - from java import awt - hsb = awt.Color.RGBtoHSB(0,255,255, None) - #print hsb - verify(hsb == array('f', [0.5,1,1]), - "output hsb float array does not correspond to input rgb values") - - rgb = apply(awt.Color.HSBtoRGB, tuple(hsb)) - #print hex(rgb) - verify(rgb == 0xff00ffff, "output rgb bytes don't match input hsb floats") - - print 'zeros' - hsb1 = zeros('f', 3) - awt.Color.RGBtoHSB(0,255,255, hsb1) - #print hsb, hsb1 - verify(hsb == hsb1, "hsb float arrays were not equal") - -def testoverflow(type, lowerLimit, upperLimit): - # should not overflow assigning lower limit - if verbose: - print "test overflow: array(%s, [%s])" % (lowerLimit, type) - try: - a = array(type, [lowerLimit]) - except: - raise TestFailed("array(%s) overflowed assigning %s" % - (lowerLimit, type)) - # should overflow assigning less than lower limit - if verbose: - print "test overflow: array(%s, [%s])" % (lowerLimit-1, type) - try: - a = array(type, [lowerLimit-1]) - raise TestFailed, "array(%s) did not overflow assigning %s" %\ - (lowerLimit-1, type) - except OverflowError: - pass - # should not overflow assigning upper limit - if verbose: - print "test verflow: array(%s, [%s])" % (upperLimit, type) - try: - a = array(type, [upperLimit]) - except: - raise TestFailed, "array(%s) overflowed assigning %s" %\ - (upperLimit, type) - # should overflow assigning more than upper limit - if verbose: - print "test overflow: array(%s, [%s])" % (upperLimit+1, type) - try: - a = array(type, [upperLimit+1]) - raise TestFailed, "array(%s) did not overflow assigning %s" %\ - (upperLimit+1, type) - except OverflowError: - pass - - -def testtype(type, example): - - if verbose: - print "testing type ", type - - a = array(type) - a.append(example) - if verbose: - print 40*'*' - print 'array after append: ', a - a.typecode - a.itemsize - - if a <> eval(str(a)): - raise TestFailed, "eval(str(%s)) <> %s" % (a,a) - - if a.typecode in ('i', 'b', 'h', 'l'): - a.byteswap() - - if a.typecode == 'c': - f = open(TESTFN, "w") - f.write("The quick brown fox jumps over the lazy dog.\n") - f.close() - f = open(TESTFN, 'r') - a.fromfile(f, 10) - f.close() - if verbose: - print 'char array with 10 bytes of TESTFN appended: ', a - a.fromlist(['a', 'b', 'c']) - if verbose: - print 'char array with list appended: ', a - - a.insert(0, example) - if verbose: - print 'array of %s after inserting another:' % a.typecode, a - f = open(TESTFN, 'w') - a.tofile(f) - f.close() - - # This block is just to verify that the operations don't blow up. - a.tolist() - a.tostring() - repr(a) - str(a) - - if verbose: - print 'array of %s converted to a list: ' % a.typecode, a.tolist() - if verbose: - print 'array of %s converted to a string: ' \ - % a.typecode, a.tostring() - - if type == 'c': - a = array(type, "abcde") - a[:-1] = a - if a != array(type, "abcdee"): - raise TestFailed, "array(%s) self-slice-assign (head)" % type - a = array(type, "abcde") - a[1:] = a - if a != array(type, "aabcde"): - raise TestFailed, "array(%s) self-slice-assign (tail)" % type - a = array(type, "abcde") - a[1:-1] = a - if a != array(type, "aabcdee"): - raise TestFailed, "array(%s) self-slice-assign (cntr)" % type - if a.index("e") != 5: - raise TestFailed, "array(%s) index-test" % type - if a.count("a") != 2: - raise TestFailed, "array(%s) count-test" % type - a.remove("e") - if a != array(type, "aabcde"): - raise TestFailed, "array(%s) remove-test" % type - if a.pop(0) != "a": - raise TestFailed, "array(%s) pop-test" % type - if a.pop(1) != "b": - raise TestFailed, "array(%s) pop-test" % type - a.extend(array(type, "xyz")) - if a != array(type, "acdexyz"): - raise TestFailed, "array(%s) extend-test" % type - a.pop() - a.pop() - a.pop() - x = a.pop() - if x != 'e': - raise TestFailed, "array(%s) pop-test" % type - if a != array(type, "acd"): - raise TestFailed, "array(%s) pop-test" % type - a.reverse() - if a != array(type, "dca"): - raise TestFailed, "array(%s) reverse-test" % type - else: - a = array(type, [1, 2, 3, 4, 5]) - a[:-1] = a - if a != array(type, [1, 2, 3, 4, 5, 5]): - raise TestFailed, "array(%s) self-slice-assign (head)" % type - a = array(type, [1, 2, 3, 4, 5]) - a[1:] = a - if a != array(type, [1, 1, 2, 3, 4, 5]): - raise TestFailed, "array(%s) self-slice-assign (tail)" % type - a = array(type, [1, 2, 3, 4, 5]) - a[1:-1] = a - if a != array(type, [1, 1, 2, 3, 4, 5, 5]): - raise TestFailed, "array(%s) self-slice-assign (cntr)" % type - if a.index(5) != 5: - raise TestFailed, "array(%s) index-test" % type - if a.count(1) != 2: - raise TestFailed, "array(%s) count-test" % type - a.remove(5) - if a != array(type, [1, 1, 2, 3, 4, 5]): - raise TestFailed, "array(%s) remove-test" % type - if a.pop(0) != 1: - raise TestFailed, "array(%s) pop-test" % type - if a.pop(1) != 2: - raise TestFailed, "array(%s) pop-test" % type - a.extend(array(type, [7, 8, 9])) - if a != array(type, [1, 3, 4, 5, 7, 8, 9]): - raise TestFailed, "array(%s) extend-test" % type - a.pop() - a.pop() - a.pop() - x = a.pop() - if x != 5: - raise TestFailed, "array(%s) pop-test" % type - if a != array(type, [1, 3, 4]): - raise TestFailed, "array(%s) pop-test" % type - a.reverse() - if a != array(type, [4, 3, 1]): - raise TestFailed, "array(%s) reverse-test" % type - - # test that overflow exceptions are raised as expected for assignment - # to array of specific integral types - from math import pow - - #check using long inputs - if type in ('b', 'h', 'i', 'l'): - a = array(type) - signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1)) - signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L - unsignedLowerLimit = 0 - unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L - testoverflow(type, signedLowerLimit, signedUpperLimit) - - #check using integer inputs - int cannot hold MAXINT+1 nor MININT-1 - # so only valid test types are byte and short for this test - if type in ('b', 'h'): - a = array(type) - signedLowerLimit = -1 * int(pow(2, a.itemsize * 8 - 1)) - signedUpperLimit = int(pow(2, a.itemsize * 8 - 1)) - 1 - unsignedLowerLimit = 0 - unsignedUpperLimit = int(pow(2, a.itemsize * 8)) - 1 - testoverflow(type, signedLowerLimit, signedUpperLimit) - - -def init_tests(): - test = array('c', ['t','e','s','t']) - verify(init_test( "test: String initialisation", "test", 'c') == test, - "string initialisation failed") - - test = array('i', [41,42,43,44]) - s = test.tostring(); - verify(init_test( "test: String2 initialisation", s, 'i') == test, - "string 2 initialisation failed") - - init_test( "test: List initialisation", [1,2,3,4], 'i') - - init_test( "test: Tuple initialisation", (1,2,3,4), 'i') - - test = array('i', [1,2,3,4]) - verify(init_test( "test: array initialisation", test, 'i') == test, - "array init failed") - - try: - init_test('test: "broken" list initialisation', [1,2,3,4, 'fred'], 'i') - raise TestFailed, '"broken" list initialisation' - except TypeError: - pass - - test = array('i', [1,2,3,4]) - try: - init_test('test: "broken" PyArray initialisation', test, 'd') - raise TestFailed, '"broken" PyArray initialisation' - except TypeError: - pass - - f = open(TESTFN, "w") - #f.write("\x00\x00\x00\x01") - f.write("test message\nline2\nline3"); - f.close(); - - f = open(TESTFN, "r") - try: - init_test( "test: Invalid initialisation object (file)", f, 'i') - raise TestFailed, "Invalid initialisation object (file)" - except TypeError: - pass - f.close() - - try: - init_test( "test: Invalid initialisation object (module)", sys, 'i') - raise TestFailed, "Invalid initialisation object (module)" - except TypeError: - pass - -def extend_tests(): - test = array('c', 'testextend') - verify(extend_test("test: String extend", "test", "extend", 'c') == test, - "String extend failed") - - test = array('i', [1,2,3,4,51,52,53,54]); - verify( extend_test("test: List extend", [1,2,3,4], [51,52,53,54], 'i') == test, - "List extend failed") - - test = array('i', (1,2,3,4,51,52,53,54)); - verify( extend_test("test: Tuple extend", (1,2,3,4), (51,52,53,54), 'i') == test, - "Tuple extend failed") - - try: - extend_test('test: "broken" list extend', [1,2,3,4], [51,52,53,"fred"], 'i') - raise TestFailed, 'test: "broken" list extend' - except TypeError: - pass - - a = array('d', [123.45, 567.89]) - test = array('i', [1,2,3,4]) - try: - assert extend_test("test: Array type mismatch", [1,2,3,4], a, 'i') == test, \ - "Array mismatch test failed" - raise TestFailed, "test: Array type mismatch" - except TypeError: - pass - del a - - f = open(TESTFN, "r") - try: - extend_test("test: incorrect type extend (file)", [1,2,3,4], f, 'i') - raise TestFailed, "test: incorrect type extend (file)" - except TypeError: - pass - f.close() - - try: - extend_test("test: incorrect type extend (module)", (1,2,3,4), sys, 'i') - raise TestFailed, "test: incorrect type extend (module)" - except TypeError: - pass - - try: - extend_test("test: incorrect type extend (integer)", [], 456, 'i') - raise TestFailed, "test: incorrect type extend (integer)" - except TypeError: - pass - -def fromlist_tests(): - test = array('c', ['t','e','s','t','h','e','l','l','o']) - verify(fromlist_test("test: String fromlist", "test", ['h','e','l','l','o'], 'c') == test, - "String fromlist failed") - - test = array('i', [1,2,3,4,51,52,53,54]) - verify(fromlist_test("test: integer fromlist", [1,2,3,4], [51,52,53,54], 'i') == test, - "integer fromlist failed") - - try: - fromlist_test('test: "broken" fromlist (integer)', [1,2,3,4], [51,52,53,"fred"], 'i') - raise TestFailed, 'test: "broken" fromlist (integer)' - except TypeError: - pass - - try: - fromlist_test("test: invalid fromlist (tuple)", [1,2,3,4], (51,52,53,54), 'i') - raise TestFailed, "test: invalid fromlist (tuple)" - except TypeError: - pass - -def init_test(name, init, typecode): - if verbose: - print 40*'*' - print name, "- type:", typecode - print "initialiser:", init - - a = array(typecode, init) - - if verbose: - print a - - return a - -def extend_test(name, init, extend, typecode): - if verbose: - print 40*'*' - print name, "- type:", typecode - - a = array(typecode, init) - - if verbose: - print "initial:", a - print "extended by:", extend - - a.extend(extend) - - #if no exceptions then - if verbose: - print "final:", a - - return a - -def fromlist_test(name, init, listdata, typecode): - if verbose: - print 40*'*' - print name , "- type:", typecode - - a = array(typecode, init) - - if verbose: - print "initial:", a - print "fromlist source:", listdata - - a.fromlist(listdata) - - #if no exceptions then - if verbose: - print "final:", a - - return a - -main() +if __name__ == "__main__": + test_main() Modified: branches/asm/src/org/python/core/PyArray.java =================================================================== --- branches/asm/src/org/python/core/PyArray.java 2008-08-02 21:40:59 UTC (rev 5055) +++ branches/asm/src/org/python/core/PyArray.java 2008-08-02 21:43:22 UTC (rev 5056) @@ -371,17 +371,22 @@ @Override public String toString() { if (__len__() == 0) { - return String.format("array('%s')", typecode); + return String.format("array(%s)", encodeTypecode(typecode)); } String value; if ("c".equals(typecode)) { - value = tostring(); + value = PyString.encode_UnicodeEscape(tostring(), true); } else { value = tolist().toString(); } - return String.format("array('%s', %s)", typecode, value); + return String.format("array(%s, %s)", encodeTypecode(typecode), value); } + private String encodeTypecode(String typecode) { + if (typecode.length() > 1) return typecode; + else return "'" + typecode + "'"; + } + /** * * @param c Modified: branches/asm/src/org/python/modules/ArrayModule.java =================================================================== --- branches/asm/src/org/python/modules/ArrayModule.java 2008-08-02 21:40:59 UTC (rev 5055) +++ branches/asm/src/org/python/modules/ArrayModule.java 2008-08-02 21:43:22 UTC (rev 5056) @@ -24,13 +24,13 @@ " 'z' boolean 1 \n" + " 'c' character 1 \n" + " 'b' signed integer 1 \n" + - //" 'B' unsigned integer 1 \n" + + " 'B' unsigned integer 1 \n" + " 'h' signed integer 2 \n" + - //" 'H' unsigned integer 2 \n" + + " 'H' unsigned integer 2 \n" + " 'i' signed integer 2 \n" + - //" 'I' unsigned integer 2 \n" + + " 'I' unsigned integer 2 \n" + " 'l' signed integer 4 \n" + - //" 'L' unsigned integer 4 \n" + + " 'L' unsigned integer 4 \n" + " 'f' floating point 4 \n" + " 'd' floating point 8 \n" + "\n" + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |