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. |