[Zope-Checkins] SVN: Zope/trunk/src/ZServer/ Detect IPv6 hosts and use the appropriate address family.
Matthew Wilkes
matthew at matthewwilkes.co.uk
Fri Mar 18 11:38:20 EDT 2011
Log message for revision 121036:
Detect IPv6 hosts and use the appropriate address family.
Changed:
U Zope/trunk/src/ZServer/medusa/http_server.py
U Zope/trunk/src/ZServer/tests/test_config.py
-=-
Modified: Zope/trunk/src/ZServer/medusa/http_server.py
===================================================================
--- Zope/trunk/src/ZServer/medusa/http_server.py 2011-03-18 15:15:00 UTC (rev 121035)
+++ Zope/trunk/src/ZServer/medusa/http_server.py 2011-03-18 15:38:19 UTC (rev 121036)
@@ -542,8 +542,13 @@
self.ip = ip
self.port = port
asyncore.dispatcher.__init__ (self)
- self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
+ if ':' in ip:
+ socket_type = socket.AF_INET6
+ else:
+ socket_type = socket.AF_INET
+ self.create_socket (socket_type, socket.SOCK_STREAM)
+
self.handlers = []
if not logger_object:
@@ -555,7 +560,10 @@
# lower this to 5 if your OS complains
self.listen (1024)
- host, port = self.socket.getsockname()
+ name = self.socket.getsockname()
+ host = name[0]
+ port = name[1]
+
if not ip:
self.log_info('Computing default hostname', 'warning')
try:
Modified: Zope/trunk/src/ZServer/tests/test_config.py
===================================================================
--- Zope/trunk/src/ZServer/tests/test_config.py 2011-03-18 15:15:00 UTC (rev 121035)
+++ Zope/trunk/src/ZServer/tests/test_config.py 2011-03-18 15:38:19 UTC (rev 121036)
@@ -134,6 +134,22 @@
self.assertEqual(server.port, 9381)
server.close()
+ def test_http_over_ipv6(self):
+ factory = self.load_factory("""\
+ <http-server>
+ address [::1]:81
+ </http-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.HTTPServerFactory))
+ self.assertEqual(factory.host, "::1")
+ self.assertEqual(factory.port, 81)
+ self.check_prepare(factory)
+ server = factory.create()
+ self.assertEqual(server.ip, '::1')
+ self.assertEqual(server.port, 9381)
+ server.close()
+
def test_http_factory_defaulthost(self):
factory = self.load_factory("""\
<http-server>
More information about the Zope-Checkins
mailing list