Ticket #7735: runserver-ipv6-r7871.diff

File runserver-ipv6-r7871.diff, 2.9 KB (added by jbalonso, 16 years ago)

IPv6 support for runserver against rev 7871

  • core/servers/basehttp.py

     
    658658        start_response(status, headers.items())
    659659        return output
    660660
    661 def run(addr, port, wsgi_handler):
     661def run(addr, port, wsgi_handler, enable_ipv6=False):
    662662    server_address = (addr, port)
    663     httpd = WSGIServer(server_address, WSGIRequestHandler)
     663    if not enable_ipv6:
     664        httpd = WSGIServer(server_address, WSGIRequestHandler)
     665    else:
     666        import socket
     667        class WSGIServerV6(WSGIServer):
     668            address_family = socket.AF_INET6
     669        httpd = WSGIServerV6(server_address, WSGIRequestHandler)
    664670    httpd.set_app(wsgi_handler)
    665671    httpd.serve_forever()
  • core/management/commands/runserver.py

     
    55
    66class Command(BaseCommand):
    77    option_list = BaseCommand.option_list + (
     8        make_option('--ipv6', '-6', action='store_true', dest='enable_ipv6', default=False,
     9            help='Enables IPv6 support.'),
    810        make_option('--noreload', action='store_false', dest='use_reloader', default=True,
    911            help='Tells Django to NOT use the auto-reloader.'),
    1012        make_option('--adminmedia', dest='admin_media_path', default='',
     
    2022        import django
    2123        from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
    2224        from django.core.handlers.wsgi import WSGIHandler
     25        enable_ipv6=options.get('enable_ipv6')
     26        if enable_ipv6:
     27                import socket
     28                if not hasattr(socket, 'AF_INET6'):
     29                        raise CommandError("This Python does not support IPv6.")
     30
    2331        if args:
    2432            raise CommandError('Usage is runserver %s' % self.args)
    2533        if not addrport:
     
    2735            port = '8000'
    2836        else:
    2937            try:
    30                 addr, port = addrport.split(':')
     38                addr, port = addrport.rsplit(':',1)
    3139            except ValueError:
    3240                addr, port = '', addrport
    3341        if not addr:
    34             addr = '127.0.0.1'
     42            if not enable_ipv6: addr = '127.0.0.1'
     43            else: addr = '::1'
    3544
    3645        if not port.isdigit():
    3746            raise CommandError("%r is not a valid port number." % port)
     
    5160            try:
    5261                path = admin_media_path or django.__path__[0] + '/contrib/admin/media'
    5362                handler = AdminMediaHandler(WSGIHandler(), path)
    54                 run(addr, int(port), handler)
     63                run(addr, int(port), handler, enable_ipv6=enable_ipv6)
    5564            except WSGIServerException, e:
    5665                # Use helpful error messages instead of ugly tracebacks.
    5766                ERRORS = {
Back to Top