From 9d86aaad34658fb5d9114f063867d1640e91e296 Mon Sep 17 00:00:00 2001 From: HawkOwl Date: Mon, 13 Jul 2015 12:53:39 +0800 Subject: [PATCH] hawkie fixes --- channels/request.py | 6 +++--- channels/response.py | 5 ++++- channels/utils.py | 10 ++++++++-- docs/getting-started.rst | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/channels/request.py b/channels/request.py index d7cd4b2..7cbdcc5 100644 --- a/channels/request.py +++ b/channels/request.py @@ -8,10 +8,10 @@ def encode_request(request): """ # TODO: More stuff value = { - "GET": request.GET.items(), - "POST": request.POST.items(), + "GET": list(request.GET.items()), + "POST": list(request.POST.items()), "COOKIES": request.COOKIES, - "META": {k: v for k, v in request.META.items() if not k.startswith("wsgi")}, + "META": dict({k: v for k, v in request.META.items() if not k.startswith("wsgi")}), "path": request.path, "path_info": request.path_info, "method": request.method, diff --git a/channels/response.py b/channels/response.py index e790250..0719c47 100644 --- a/channels/response.py +++ b/channels/response.py @@ -1,4 +1,5 @@ from django.http import HttpResponse +from six import PY3 def encode_response(response): @@ -10,8 +11,10 @@ def encode_response(response): "content_type": getattr(response, "content_type", None), "content": response.content, "status_code": response.status_code, - "headers": response._headers.values(), + "headers": list(response._headers.values()), } + if PY3: + value["content"] = value["content"].decode('utf8') response.close() return value diff --git a/channels/utils.py b/channels/utils.py index a44fe9c..4a7fb65 100644 --- a/channels/utils.py +++ b/channels/utils.py @@ -1,6 +1,7 @@ import types from django.apps import apps +from six import PY3 def auto_import_consumers(): """ @@ -12,8 +13,13 @@ def auto_import_consumers(): try: __import__(module_name) except ImportError as e: - if "no module named %s" % submodule not in str(e).lower(): - raise + err = str(e).lower() + if PY3: + if "no module named '%s'" % (module_name,) not in err: + raise + else: + if "no module named %s" % (submodule,) not in err: + raise def name_that_thing(thing): diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 892c291..00c8db2 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -27,7 +27,7 @@ app, and put this in a ``consumers.py`` file in the app:: @consumer("django.wsgi.request") def http_consumer(response_channel, path, **kwargs): response = HttpResponse("Hello world! You asked for %s" % path) - Channel(response_channel).send(response.channel_encode()) + Channel(response_channel).send(**response.channel_encode()) The most important thing to note here is that, because things we send in messages must be JSON-serialisable, the request and response messages