prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  nosetests crashes under IPv4 (error: getsockaddrarg: bad family)
  Turns out tornado is really eager to use IPv6. Unless you expressly hand the server the address, it doesn't even check for socket IPv6 support. I'll submit a pull request for the one-line fix in dummyserver/server.py momentarily.
  
  Source: https://groups.google.com/group/python-tornado/browse_thread/thread/3ec04536e57a2833?pli=1
  
  
  </issue>
  <code>
  [start of dummyserver/server.py]
  1 #!/usr/bin/env python
  2 
  3 """
  4 Dummy server used for unit testing.
  5 """
  6 from __future__ import print_function
  7 
  8 import logging
  9 import os
  10 import sys
  11 import threading
  12 import socket
  13 
  14 import tornado.wsgi
  15 import tornado.httpserver
  16 import tornado.ioloop
  17 
  18 from dummyserver.handlers import TestingApp
  19 
  20 
  21 log = logging.getLogger(__name__)
  22 
  23 CERTS_PATH = os.path.join(os.path.dirname(__file__), 'certs')
  24 DEFAULT_CERTS = {
  25     'certfile': os.path.join(CERTS_PATH, 'server.crt'),
  26     'keyfile': os.path.join(CERTS_PATH, 'server.key'),
  27 }
  28 DEFAULT_CA = os.path.join(CERTS_PATH, 'cacert.pem')
  29 DEFAULT_CA_BAD = os.path.join(CERTS_PATH, 'client_bad.pem')
  30 
  31 
  32 # Different types of servers we have:
  33 
  34 
  35 class SocketServerThread(threading.Thread):
  36     """
  37     :param socket_handler: Callable which receives a socket argument for one
  38         request.
  39     :param ready_lock: Lock which gets released when the socket handler is
  40         ready to receive requests.
  41     """
  42     def __init__(self, socket_handler, host='localhost', port=8081,
  43                  ready_lock=None):
  44         threading.Thread.__init__(self)
  45 
  46         self.socket_handler = socket_handler
  47         self.host = host
  48         self.port = port
  49         self.ready_lock = ready_lock
  50 
  51     def _start_server(self):
  52         sock = socket.socket()
  53         sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  54         sock.bind((self.host, self.port))
  55 
  56         # Once listen() returns, the server socket is ready
  57         sock.listen(1)
  58 
  59         if self.ready_lock:
  60             self.ready_lock.release()
  61 
  62         self.socket_handler(sock)
  63 
  64     def run(self):
  65         self.server = self._start_server()
  66 
  67 
  68 class TornadoServerThread(threading.Thread):
  69     def __init__(self, host='localhost', port=8081, scheme='http', certs=None):
  70         threading.Thread.__init__(self)
  71 
  72         self.host = host
  73         self.port = port
  74         self.scheme = scheme
  75         self.certs = certs
  76 
  77     def _start_server(self):
  78         container = tornado.wsgi.WSGIContainer(TestingApp())
  79 
  80         if self.scheme == 'https':
  81             http_server = tornado.httpserver.HTTPServer(container,
  82                                                         ssl_options=self.certs)
  83         else:
  84             http_server = tornado.httpserver.HTTPServer(container)
  85 
  86         http_server.listen(self.port)
  87         return http_server
  88 
  89     def run(self):
  90         self.server = self._start_server()
  91         self.ioloop = tornado.ioloop.IOLoop.instance()
  92         self.ioloop.start()
  93 
  94     def stop(self):
  95         self.server.stop()
  96         self.ioloop.stop()
  97 
  98 
  99 if __name__ == '__main__':
  100     log.setLevel(logging.DEBUG)
  101     log.addHandler(logging.StreamHandler(sys.stderr))
  102 
  103     from urllib3 import get_host
  104 
  105     url = "http://localhost:8081"
  106     if len(sys.argv) > 1:
  107         url = sys.argv[1]
  108 
  109     print("Starting WGI server at: %s" % url)
  110 
  111     scheme, host, port = get_host(url)
  112     t = TornadoServerThread(scheme=scheme, host=host, port=port)
  113     t.start()
  114
  [end of dummyserver/server.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/dummyserver/server.py b/dummyserver/server.py
  --- a/dummyserver/server.py
  +++ b/dummyserver/server.py
  @@ -83,7 +83,7 @@
           else:
               http_server = tornado.httpserver.HTTPServer(container)
   
  -        http_server.listen(self.port)
  +        http_server.listen(self.port, address=self.host)
           return http_server
   
       def run(self):
  @@ -106,7 +106,7 @@
       if len(sys.argv) > 1:
           url = sys.argv[1]
   
  -    print("Starting WGI server at: %s" % url)
  +    print("Starting WSGI server at: %s" % url)
   
       scheme, host, port = get_host(url)
       t = TornadoServerThread(scheme=scheme, host=host, port=port)
  
verification_info: {"golden_diff": "diff --git a/dummyserver/server.py b/dummyserver/server.py\n--- a/dummyserver/server.py\n+++ b/dummyserver/server.py\n@@ -83,7 +83,7 @@\n         else:\n             http_server = tornado.httpserver.HTTPServer(container)\n \n-        http_server.listen(self.port)\n+        http_server.listen(self.port, address=self.host)\n         return http_server\n \n     def run(self):\n@@ -106,7 +106,7 @@\n     if len(sys.argv) > 1:\n         url = sys.argv[1]\n \n-    print(\"Starting WGI server at: %s\" % url)\n+    print(\"Starting WSGI server at: %s\" % url)\n \n     scheme, host, port = get_host(url)\n     t = TornadoServerThread(scheme=scheme, host=host, port=port)\n", "issue": "nosetests crashes under IPv4 (error: getsockaddrarg: bad family)\nTurns out tornado is really eager to use IPv6. Unless you expressly hand the server the address, it doesn't even check for socket IPv6 support. I'll submit a pull request for the one-line fix in dummyserver/server.py momentarily.\n\nSource: https://groups.google.com/group/python-tornado/browse_thread/thread/3ec04536e57a2833?pli=1\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\nDummy server used for unit testing.\n\"\"\"\nfrom __future__ import print_function\n\nimport logging\nimport os\nimport sys\nimport threading\nimport socket\n\nimport tornado.wsgi\nimport tornado.httpserver\nimport tornado.ioloop\n\nfrom dummyserver.handlers import TestingApp\n\n\nlog = logging.getLogger(__name__)\n\nCERTS_PATH = os.path.join(os.path.dirname(__file__), 'certs')\nDEFAULT_CERTS = {\n    'certfile': os.path.join(CERTS_PATH, 'server.crt'),\n    'keyfile': os.path.join(CERTS_PATH, 'server.key'),\n}\nDEFAULT_CA = os.path.join(CERTS_PATH, 'cacert.pem')\nDEFAULT_CA_BAD = os.path.join(CERTS_PATH, 'client_bad.pem')\n\n\n# Different types of servers we have:\n\n\nclass SocketServerThread(threading.Thread):\n    \"\"\"\n    :param socket_handler: Callable which receives a socket argument for one\n        request.\n    :param ready_lock: Lock which gets released when the socket handler is\n        ready to receive requests.\n    \"\"\"\n    def __init__(self, socket_handler, host='localhost', port=8081,\n                 ready_lock=None):\n        threading.Thread.__init__(self)\n\n        self.socket_handler = socket_handler\n        self.host = host\n        self.port = port\n        self.ready_lock = ready_lock\n\n    def _start_server(self):\n        sock = socket.socket()\n        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n        sock.bind((self.host, self.port))\n\n        # Once listen() returns, the server socket is ready\n        sock.listen(1)\n\n        if self.ready_lock:\n            self.ready_lock.release()\n\n        self.socket_handler(sock)\n\n    def run(self):\n        self.server = self._start_server()\n\n\nclass TornadoServerThread(threading.Thread):\n    def __init__(self, host='localhost', port=8081, scheme='http', certs=None):\n        threading.Thread.__init__(self)\n\n        self.host = host\n        self.port = port\n        self.scheme = scheme\n        self.certs = certs\n\n    def _start_server(self):\n        container = tornado.wsgi.WSGIContainer(TestingApp())\n\n        if self.scheme == 'https':\n            http_server = tornado.httpserver.HTTPServer(container,\n                                                        ssl_options=self.certs)\n        else:\n            http_server = tornado.httpserver.HTTPServer(container)\n\n        http_server.listen(self.port)\n        return http_server\n\n    def run(self):\n        self.server = self._start_server()\n        self.ioloop = tornado.ioloop.IOLoop.instance()\n        self.ioloop.start()\n\n    def stop(self):\n        self.server.stop()\n        self.ioloop.stop()\n\n\nif __name__ == '__main__':\n    log.setLevel(logging.DEBUG)\n    log.addHandler(logging.StreamHandler(sys.stderr))\n\n    from urllib3 import get_host\n\n    url = \"http://localhost:8081\"\n    if len(sys.argv) > 1:\n        url = sys.argv[1]\n\n    print(\"Starting WGI server at: %s\" % url)\n\n    scheme, host, port = get_host(url)\n    t = TornadoServerThread(scheme=scheme, host=host, port=port)\n    t.start()\n", "path": "dummyserver/server.py"}]}