Ticket #7735: runserver-ipv6-r7871.diff
File runserver-ipv6-r7871.diff, 2.9 KB (added by , 16 years ago) |
---|
-
core/servers/basehttp.py
658 658 start_response(status, headers.items()) 659 659 return output 660 660 661 def run(addr, port, wsgi_handler ):661 def run(addr, port, wsgi_handler, enable_ipv6=False): 662 662 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) 664 670 httpd.set_app(wsgi_handler) 665 671 httpd.serve_forever() -
core/management/commands/runserver.py
5 5 6 6 class Command(BaseCommand): 7 7 option_list = BaseCommand.option_list + ( 8 make_option('--ipv6', '-6', action='store_true', dest='enable_ipv6', default=False, 9 help='Enables IPv6 support.'), 8 10 make_option('--noreload', action='store_false', dest='use_reloader', default=True, 9 11 help='Tells Django to NOT use the auto-reloader.'), 10 12 make_option('--adminmedia', dest='admin_media_path', default='', … … 20 22 import django 21 23 from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException 22 24 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 23 31 if args: 24 32 raise CommandError('Usage is runserver %s' % self.args) 25 33 if not addrport: … … 27 35 port = '8000' 28 36 else: 29 37 try: 30 addr, port = addrport. split(':')38 addr, port = addrport.rsplit(':',1) 31 39 except ValueError: 32 40 addr, port = '', addrport 33 41 if not addr: 34 addr = '127.0.0.1' 42 if not enable_ipv6: addr = '127.0.0.1' 43 else: addr = '::1' 35 44 36 45 if not port.isdigit(): 37 46 raise CommandError("%r is not a valid port number." % port) … … 51 60 try: 52 61 path = admin_media_path or django.__path__[0] + '/contrib/admin/media' 53 62 handler = AdminMediaHandler(WSGIHandler(), path) 54 run(addr, int(port), handler )63 run(addr, int(port), handler, enable_ipv6=enable_ipv6) 55 64 except WSGIServerException, e: 56 65 # Use helpful error messages instead of ugly tracebacks. 57 66 ERRORS = {