summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2011-01-15 06:31:38 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2011-01-15 06:31:38 +0000
commitd7fa33af78aeae8a6a6e8261c697c7a03a821595 (patch)
tree198cc2be83335999406d4b8a2db9ccff911847ac /django/core
parentdf5c01b8c545b4e48ac48c51237566bd9200a4cf (diff)
Fixed #14928 -- Ensure that a fully qualified domain name can be used for runserver. Thanks to Karmel Allison for the report, Łukasz Rekucki for the patch, and claudep for the tests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15215 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management/commands/runserver.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
index b63b57a67c..55c7869fea 100644
--- a/django/core/management/commands/runserver.py
+++ b/django/core/management/commands/runserver.py
@@ -9,7 +9,12 @@ from django.core.handlers.wsgi import WSGIHandler
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException
from django.utils import autoreload
-naiveip_re = r'^(?:(?P<addr>\d{1,3}(?:\.\d{1,3}){3}|\[[a-fA-F0-9:]+\]):)?(?P<port>\d+)$'
+naiveip_re = re.compile(r"""^(?:
+(?P<addr>
+ (?P<ipv4>\d{1,3}(?:\.\d{1,3}){3}) | # IPv4 address
+ (?P<ipv6>\[[a-fA-F0-9:]+\]) | # IPv6 address
+ (?P<fqdn>[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*) # FQDN
+):)?(?P<port>\d+)$""", re.X)
DEFAULT_PORT = "8000"
class BaseRunserverCommand(BaseCommand):
@@ -33,28 +38,29 @@ class BaseRunserverCommand(BaseCommand):
def handle(self, addrport='', *args, **options):
self.use_ipv6 = options.get('use_ipv6')
- if self.use_ipv6 and not hasattr(socket, 'AF_INET6'):
+ if self.use_ipv6 and not socket.has_ipv6:
raise CommandError('Your Python does not support IPv6.')
if args:
raise CommandError('Usage is runserver %s' % self.args)
+ self._raw_ipv6 = False
if not addrport:
self.addr = ''
self.port = DEFAULT_PORT
else:
m = re.match(naiveip_re, addrport)
if m is None:
- raise CommandError('%r is not a valid port number'
+ raise CommandError('"%s" is not a valid port number '
'or address:port pair.' % addrport)
- self.addr, self.port = m.groups()
+ self.addr, _ipv4, _ipv6, _fqdn, self.port = m.groups()
if not self.port.isdigit():
raise CommandError("%r is not a valid port number." % self.port)
if self.addr:
- if self.addr.startswith('[') and self.addr.endswith(']'):
+ if _ipv6:
self.addr = self.addr[1:-1]
self.use_ipv6 = True
- elif self.use_ipv6:
- raise CommandError('IPv6 addresses must be surrounded '
- 'with brackets, e.g. [::1].')
+ self._raw_ipv6 = True
+ elif self.use_ipv6 and not _fqdn:
+ raise CommandError('"%s" is not a valid IPv6 address.' % self.addr)
if not self.addr:
self.addr = self.use_ipv6 and '::1' or '127.0.0.1'
self.run(*args, **options)
@@ -86,7 +92,7 @@ class BaseRunserverCommand(BaseCommand):
) % {
"version": self.get_version(),
"settings": settings.SETTINGS_MODULE,
- "addr": self.use_ipv6 and '[%s]' % self.addr or self.addr,
+ "addr": self._raw_ipv6 and '[%s]' % self.addr or self.addr,
"port": self.port,
"quit_command": quit_command,
})