From: <pj...@us...> - 2008-07-17 00:29:55
|
Revision: 4957 http://jython.svn.sourceforge.net/jython/?rev=4957&view=rev Author: pjenvey Date: 2008-07-17 00:29:54 +0000 (Thu, 17 Jul 2008) Log Message: ----------- allow passing unicode hostnames to socket.connect Modified Paths: -------------- trunk/jython/Lib/socket.py trunk/jython/Lib/test/test_socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2008-07-16 02:13:48 UTC (rev 4956) +++ trunk/jython/Lib/socket.py 2008-07-17 00:29:54 UTC (rev 4957) @@ -639,11 +639,17 @@ # 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) - hostname = address_tuple[0].strip() + 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" Modified: trunk/jython/Lib/test/test_socket.py =================================================================== --- trunk/jython/Lib/test/test_socket.py 2008-07-16 02:13:48 UTC (rev 4956) +++ trunk/jython/Lib/test/test_socket.py 2008-07-17 00:29:54 UTC (rev 4957) @@ -1436,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, @@ -1457,7 +1465,8 @@ PrivateFileObjectTestCase, UnbufferedFileObjectClassTestCase, LineBufferedFileObjectClassTestCase, - SmallBufferedFileObjectClassTestCase + SmallBufferedFileObjectClassTestCase, + UnicodeTest ] if hasattr(socket, "socketpair"): tests.append(BasicSocketPairTest) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |