Skip to content

Commit df2668c

Browse files
committed
Add python 3 support
Ref dcramer#75
1 parent 2bae91f commit df2668c

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

devserver/management/commands/runserver.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
import imp
1010
import errno
1111
import socket
12-
import SocketServer
12+
try:
13+
import socketserver
14+
except ImportError:
15+
import SocketServer as socketserver
1316
from optparse import make_option
1417

1518
from devserver.handlers import DevServerHandler
@@ -26,7 +29,7 @@
2629

2730

2831
def null_technical_500_response(request, exc_type, exc_value, tb):
29-
raise exc_type, exc_value, tb
32+
raise exc_type(exc_value, tb)
3033

3134

3235
def run(addr, port, wsgi_handler, mixin=None, ipv6=False):
@@ -138,7 +141,7 @@ def inner_run(self, *args, **options):
138141
if use_werkzeug:
139142
try:
140143
from werkzeug import run_simple, DebuggedApplication
141-
except ImportError, e:
144+
except ImportError as e:
142145
self.stderr.write("WARNING: Unable to initialize werkzeug: %s\n" % e)
143146
use_werkzeug = False
144147
else:
@@ -181,9 +184,9 @@ def inner_run(self, *args, **options):
181184
raise
182185

183186
if options['use_forked']:
184-
mixin = SocketServer.ForkingMixIn
187+
mixin = socketserver.ForkingMixIn
185188
else:
186-
mixin = SocketServer.ThreadingMixIn
189+
mixin = socketserver.ThreadingMixIn
187190

188191
middleware = getattr(settings, 'DEVSERVER_WSGI_MIDDLEWARE', [])
189192
for middleware in middleware:
@@ -202,7 +205,7 @@ def inner_run(self, *args, **options):
202205
else:
203206
run(self.addr, int(self.port), app, mixin, ipv6=options['use_ipv6'])
204207

205-
except wsgi_server_exc_cls, e:
208+
except wsgi_server_exc_cls as e:
206209
# Use helpful error messages instead of ugly tracebacks.
207210
ERRORS = {
208211
errno.EACCES: "You don't have permission to access that port.",

devserver/models.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ def load_modules():
1717
try:
1818
name, class_name = path.rsplit('.', 1)
1919
except ValueError:
20-
raise exceptions.ImproperlyConfigured, '%s isn\'t a devserver module' % path
20+
raise exceptions.ImproperlyConfigured('%s isn\'t a devserver module' % path)
2121

2222
try:
2323
module = __import__(name, {}, {}, [''])
24-
except ImportError, e:
25-
raise exceptions.ImproperlyConfigured, 'Error importing devserver module %s: "%s"' % (name, e)
24+
except ImportError as e:
25+
raise exceptions.ImproperlyConfigured('Error importing devserver module %s: "%s"' % (name, e))
2626

2727
try:
2828
cls = getattr(module, class_name)
2929
except AttributeError:
30-
raise exceptions.ImproperlyConfigured, 'Error importing devserver module "%s" does not define a "%s" class' % (name, class_name)
30+
raise exceptions.ImproperlyConfigured('Error importing devserver module "%s" does not define a "%s" class' % (name, class_name))
3131

3232
try:
3333
instance = cls(GenericLogger(cls))

devserver/testcases.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import socket
2-
import SocketServer
2+
try:
3+
import socketserver
4+
except ImportError:
5+
import SocketServer as socketserver
36
import threading
47

58
from django.conf import settings
@@ -68,14 +71,14 @@ def run(self):
6871
try:
6972
server_address = (self.address, self.port)
7073

71-
class new(SocketServer.ThreadingMixIn, StoppableWSGIServer):
74+
class new(socketserver.ThreadingMixIn, StoppableWSGIServer):
7275
def __init__(self, *args, **kwargs):
7376
StoppableWSGIServer.__init__(self, *args, **kwargs)
7477

7578
httpd = new(server_address, SlimWSGIRequestHandler)
7679
httpd.set_app(handler)
7780
self.started.set()
78-
except wsgi_server_exc_cls, e:
81+
except wsgi_server_exc_cls as e:
7982
self.error = e
8083
self.started.set()
8184
return

devserver/utils/stack.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import django
2-
import SocketServer
2+
try:
3+
import socketserver
4+
except ImportError:
5+
import SocketServer as socketserver
36
import os.path
47

58
from django.conf import settings
69
from django.views.debug import linebreak_iter
710

811
# Figure out some paths
912
django_path = os.path.realpath(os.path.dirname(django.__file__))
10-
socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__))
13+
socketserver_path = os.path.realpath(os.path.dirname(socketserver.__file__))
1114

1215

1316
def tidy_stacktrace(strace):

0 commit comments

Comments
 (0)