Skip to content

Commit

Permalink
Merge pull request #5 from hawkowl/py3
Browse files Browse the repository at this point in the history
Port channels to py3
  • Loading branch information
andrewgodwin committed Jul 13, 2015
2 parents 372d174 + 8497b08 commit dfc11d4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions channels/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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")},
"path": request.path,
Expand Down
5 changes: 4 additions & 1 deletion channels/response.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.http import HttpResponse
from six import PY3


def encode_response(response):
Expand All @@ -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

Expand Down
10 changes: 8 additions & 2 deletions channels/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import types
from django.apps import apps

from six import PY3

def auto_import_consumers():
"""
Expand All @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ to test your new code::
socket.onmessage = function(e) {
alert(e.data);
}
socket.send("hello world");
socket.onopen = function() {
socket.send("hello world");
}

You should see an alert come back immediately saying "hello world" - your
message has round-tripped through the server and come back to trigger the alert.
Expand Down

0 comments on commit dfc11d4

Please sign in to comment.