From 682e5442a93100962b2ab380247725860ae187c6 Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Thu, 19 Jul 2018 10:14:21 +0200 Subject: [PATCH] made create_application usage allow for both defer and non-defer --- daphne/http_protocol.py | 4 ++-- daphne/server.py | 2 -- daphne/ws_protocol.py | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/daphne/http_protocol.py b/daphne/http_protocol.py index 3ff10be..c4e17fe 100755 --- a/daphne/http_protocol.py +++ b/daphne/http_protocol.py @@ -3,7 +3,7 @@ import time import traceback from urllib.parse import unquote -from twisted.internet.defer import inlineCallbacks +from twisted.internet.defer import inlineCallbacks, maybeDeferred from twisted.internet.interfaces import IProtocolNegotiationFactory from twisted.protocols.policies import ProtocolWrapper from twisted.web import http @@ -146,7 +146,7 @@ class WebRequest(http.Request): logger.debug("HTTP %s request for %s", self.method, self.client_addr) self.content.seek(0, 0) # Work out the application scope and create application - self.application_queue = yield self.server.create_application(self, { + self.application_queue = yield maybeDeferred(self.server.create_application, self, { "type": "http", # TODO: Correctly say if it's 1.1 or 1.0 "http_version": self.clientproto.split(b"/")[-1].decode("ascii"), diff --git a/daphne/server.py b/daphne/server.py index 305bf59..cff80f2 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -24,7 +24,6 @@ from concurrent.futures import CancelledError from twisted.internet import defer, reactor from twisted.internet.endpoints import serverFromString -from twisted.internet.threads import deferToThread from twisted.logger import STDLibLogObserver, globalLogBeginner from twisted.web import http @@ -171,7 +170,6 @@ class Server(object): ### Internal event/message handling - @defer.inlineCallbacks def create_application(self, protocol, scope): """ Creates a new application instance that fronts a Protocol instance diff --git a/daphne/ws_protocol.py b/daphne/ws_protocol.py index a7331b5..8ae8749 100755 --- a/daphne/ws_protocol.py +++ b/daphne/ws_protocol.py @@ -66,7 +66,7 @@ class WebSocketProtocol(WebSocketServerProtocol): ] # Make new application instance with scope self.path = request.path.encode("ascii") - self.application_deferred = self.server.create_application(self, { + self.application_deferred = defer.maybeDeferred(self.server.create_application, self, { "type": "websocket", "path": unquote(self.path.decode("ascii")), "headers": self.clean_headers,