diff options
Diffstat (limited to 'dummyserver/server.py')
-rwxr-xr-x | dummyserver/server.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/dummyserver/server.py b/dummyserver/server.py index 6ee9a5d..63124d3 100755 --- a/dummyserver/server.py +++ b/dummyserver/server.py @@ -13,9 +13,11 @@ import string import sys import threading import socket +import warnings + +from urllib3.exceptions import HTTPWarning from tornado.platform.auto import set_close_exec -import tornado.wsgi import tornado.httpserver import tornado.ioloop import tornado.web @@ -40,6 +42,11 @@ NO_SAN_CA = os.path.join(CERTS_PATH, 'cacert.no_san.pem') # Different types of servers we have: +class NoIPv6Warning(HTTPWarning): + "IPv6 is not available" + pass + + class SocketServerThread(threading.Thread): """ :param socket_handler: Callable which receives a socket argument for one @@ -50,13 +57,19 @@ class SocketServerThread(threading.Thread): def __init__(self, socket_handler, host='localhost', port=8081, ready_event=None): threading.Thread.__init__(self) + self.daemon = True self.socket_handler = socket_handler self.host = host self.ready_event = ready_event def _start_server(self): - sock = socket.socket(socket.AF_INET6) + if socket.has_ipv6: + sock = socket.socket(socket.AF_INET6) + else: + warnings.warn("No IPv6 support. Falling back to IPv4.", + NoIPv6Warning) + sock = socket.socket(socket.AF_INET) if sys.platform != 'win32': sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((self.host, 0)) @@ -192,7 +205,7 @@ if __name__ == '__main__': host = '127.0.0.1' io_loop = tornado.ioloop.IOLoop() - app = tornado.wsgi.WSGIContainer(TestingApp()) + app = tornado.web.Application([(r".*", TestingApp)]) server, port = run_tornado_app(app, io_loop, None, 'http', host) server_thread = run_loop_in_thread(io_loop) |