Django WSGIHandler is deprecated. Port webserver for Py3.

This commit is contained in:
Ryan Stein 2017-10-29 21:54:06 -04:00
parent 7477cc56e0
commit eabdf27565

View file

@ -1,15 +1,16 @@
""" """
This implements resources for twisted webservers using the wsgi This implements resources for Twisted webservers using the WSGI
interface of django. This alleviates the need of running e.g. an interface of Django. This alleviates the need of running e.g. an
apache server to serve Evennia's web presence (although you could do Apache server to serve Evennia's web presence (although you could do
that too if desired). that too if desired).
The actual servers are started inside server.py as part of the Evennia The actual servers are started inside server.py as part of the Evennia
application. application.
(Lots of thanks to http://githup.com/clemensha/twisted-wsgi-django for (Lots of thanks to http://github.com/clemesha/twisted-wsgi-django for
a great example/aid on how to do this.) a great example/aid on how to do this.)
""" """
import urllib.parse import urllib.parse
from urllib.parse import quote as urlquote from urllib.parse import quote as urlquote
@ -23,7 +24,8 @@ from twisted.internet import defer
from twisted.web.wsgi import WSGIResource from twisted.web.wsgi import WSGIResource
from django.conf import settings from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler from django.core.wsgi import get_wsgi_application
from evennia.utils import logger from evennia.utils import logger
@ -119,9 +121,10 @@ class EvenniaReverseProxyResource(ReverseProxyResource):
request.content.seek(0, 0) request.content.seek(0, 0)
qs = urllib.parse.urlparse(request.uri)[4] qs = urllib.parse.urlparse(request.uri)[4]
if qs: if qs:
rest = self.path + '?' + qs rest = self.path + '?' + qs.decode()
else: else:
rest = self.path rest = self.path
rest = rest.encode()
clientFactory = self.proxyClientFactoryClass( clientFactory = self.proxyClientFactoryClass(
request.method, rest, request.clientproto, request.method, rest, request.clientproto,
request.getAllHeaders(), request.content.read(), request) request.getAllHeaders(), request.content.read(), request)
@ -156,8 +159,8 @@ class DjangoWebRoot(resource.Resource):
self.pool = pool self.pool = pool
self._echo_log = True self._echo_log = True
self._pending_requests = {} self._pending_requests = {}
resource.Resource.__init__(self) super().__init__()
self.wsgi_resource = WSGIResource(reactor, pool, WSGIHandler()) self.wsgi_resource = WSGIResource(reactor, pool, get_wsgi_application())
def empty_threadpool(self): def empty_threadpool(self):
""" """
@ -242,14 +245,14 @@ class WSGIWebServer(internet.TCPServer):
""" """
self.pool = pool self.pool = pool
internet.TCPServer.__init__(self, *args, **kwargs) super().__init__(*args, **kwargs)
def startService(self): def startService(self):
""" """
Start the pool after the service starts. Start the pool after the service starts.
""" """
internet.TCPServer.startService(self) super().startService()
self.pool.start() self.pool.start()
def stopService(self): def stopService(self):
@ -257,5 +260,5 @@ class WSGIWebServer(internet.TCPServer):
Safely stop the pool after the service stops. Safely stop the pool after the service stops.
""" """
internet.TCPServer.stopService(self) super().stopService()
self.pool.stop() self.pool.stop()