From 38c6df812574b3910dfbf524f4f03215c15c02a2 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 24 Feb 2016 00:39:48 +0000 Subject: [PATCH] Move ResponseLater into exceptions module --- channels/exceptions.py | 16 ++++++++++++++++ channels/handler.py | 10 +++------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 channels/exceptions.py diff --git a/channels/exceptions.py b/channels/exceptions.py new file mode 100644 index 0000000..3e52699 --- /dev/null +++ b/channels/exceptions.py @@ -0,0 +1,16 @@ +class ConsumeLater(Exception): + """ + Exception that says that the current message should be re-queued back + onto its channel as it's not ready to be consumd yet (e.g. global order + is being enforced) + """ + pass + + +class ResponseLater(Exception): + """ + Exception raised inside a Django view when the view has passed + responsibility for the response to another consumer, and so is not + returning a response. + """ + pass diff --git a/channels/handler.py b/channels/handler.py index e41007e..a32d1af 100644 --- a/channels/handler.py +++ b/channels/handler.py @@ -14,6 +14,8 @@ from django.core.urlresolvers import set_script_prefix from django.utils import six from django.utils.functional import cached_property +from .exceptions import ResponseLater as ResponseLaterOuter + logger = logging.getLogger('django.request') @@ -23,13 +25,7 @@ class AsgiRequest(http.HttpRequest): dict, and wraps request body handling. """ - class ResponseLater(Exception): - """ - Exception that will cause any handler to skip around response - transmission and presume something else will do it later. - """ - def __init__(self): - Exception.__init__(self, "Response later") + ResponseLater = ResponseLaterOuter def __init__(self, message): self.message = message