|
1 | 1 | from django.conf import settings
|
2 | 2 | from django.core.management.commands.runserver import Command as BaseCommand
|
3 | 3 | from django.core.management.base import CommandError, handle_default_options
|
4 |
| -from django.core.servers.basehttp import WSGIServerException, WSGIServer |
| 4 | +from django.core.servers.basehttp import WSGIServer |
5 | 5 | from django.core.handlers.wsgi import WSGIHandler
|
6 | 6 |
|
7 | 7 | import os
|
8 | 8 | import sys
|
9 | 9 | import imp
|
| 10 | +import errno |
| 11 | +import socket |
10 | 12 | import SocketServer
|
11 | 13 | from optparse import make_option
|
12 | 14 |
|
13 | 15 | from devserver.handlers import DevServerHandler
|
14 | 16 | from devserver.utils.http import SlimWSGIRequestHandler
|
15 | 17 |
|
| 18 | +try: |
| 19 | + from django.core.servers.basehttp import (WSGIServerException as |
| 20 | + wsgi_server_exc_cls) |
| 21 | +except ImportError: # Django 1.6 |
| 22 | + wsgi_server_exc_cls = socket.error |
| 23 | + |
16 | 24 |
|
17 | 25 | STATICFILES_APPS = ('django.contrib.staticfiles', 'staticfiles')
|
18 | 26 |
|
@@ -189,15 +197,23 @@ def inner_run(self, *args, **options):
|
189 | 197 | else:
|
190 | 198 | run(self.addr, int(self.port), app, mixin, ipv6=options['use_ipv6'])
|
191 | 199 |
|
192 |
| - except WSGIServerException, e: |
| 200 | + except wsgi_server_exc_cls, e: |
193 | 201 | # Use helpful error messages instead of ugly tracebacks.
|
194 | 202 | ERRORS = {
|
195 |
| - 13: "You don't have permission to access that port.", |
196 |
| - 98: "That port is already in use.", |
197 |
| - 99: "That IP address can't be assigned-to.", |
| 203 | + errno.EACCES: "You don't have permission to access that port.", |
| 204 | + errno.EADDRINUSE: "That port is already in use.", |
| 205 | + errno.EADDRNOTAVAIL: "That IP address can't be assigned-to.", |
198 | 206 | }
|
| 207 | + if not isinstance(e, socket.error): # Django < 1.6 |
| 208 | + ERRORS[13] = ERRORS.pop(errno.EACCES) |
| 209 | + ERRORS[98] = ERRORS.pop(errno.EADDRINUSE) |
| 210 | + ERRORS[99] = ERRORS.pop(errno.EADDRNOTAVAIL) |
| 211 | + |
199 | 212 | try:
|
200 |
| - error_text = ERRORS[e.args[0].args[0]] |
| 213 | + if not isinstance(e, socket.error): # Django < 1.6 |
| 214 | + error_text = ERRORS[e.args[0].args[0]] |
| 215 | + else: |
| 216 | + error_text = ERRORS[e.errno] |
201 | 217 | except (AttributeError, KeyError):
|
202 | 218 | error_text = str(e)
|
203 | 219 | sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
|
|
0 commit comments