From 73d50a46952a8b13614e4cea6dc14ca63b6b4765 Mon Sep 17 00:00:00 2001 From: Faris Chebib Date: Thu, 10 Sep 2015 14:46:24 -0600 Subject: [PATCH 1/2] updated typo in docs example --- docs/getting-started.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 5b1d88e..f2d4a36 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -138,7 +138,7 @@ Now, that's taken care of adding and removing WebSocket send channels for the we're not going to store a history of messages or anything and just replay any message sent in to all connected clients. Here's all the code:: - from channels import Channel, Group + from channels import Group # Connected to websocket.connect and websocket.keepalive def ws_add(message): @@ -261,7 +261,7 @@ just like a normal Django session. Let's use it now to build a chat server that expects you to pass a chatroom name in the path of your WebSocket request (we'll ignore auth for now - that's next):: - from channels import Channel + from channels import Group from channels.decorators import channel_session # Connected to websocket.connect @@ -281,7 +281,7 @@ name in the path of your WebSocket request (we'll ignore auth for now - that's n # Connected to websocket.receive @channel_session def ws_message(message): - Group("chat-%s" % message.channel_session['room']).send(content) + Group("chat-%s" % message.channel_session['room']).send(message.content) # Connected to websocket.disconnect @channel_session From ff9cdb71132794d343aad475f7399e8d7fc2c23d Mon Sep 17 00:00:00 2001 From: Faris Chebib Date: Thu, 10 Sep 2015 16:57:57 -0600 Subject: [PATCH 2/2] updated example and made decorators py3-ready --- channels/decorators.py | 4 ++-- docs/getting-started.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/channels/decorators.py b/channels/decorators.py index 280b493..7c28143 100644 --- a/channels/decorators.py +++ b/channels/decorators.py @@ -50,8 +50,8 @@ def channel_session(func): # Turn the reply_channel into a valid session key length thing. # We take the last 24 bytes verbatim, as these are the random section, # and then hash the remaining ones onto the start, and add a prefix - reply_name = message.reply_channel.name - session_key = "skt" + hashlib.md5(reply_name[:-24]).hexdigest()[:8] + reply_name[-24:] + reply_name = str(message.reply_channel.name).encode() + session_key = b"skt" + str(hashlib.md5(reply_name[:-24]).hexdigest()[:8]).encode() + reply_name[-24:] # Make a session storage session_engine = import_module(settings.SESSION_ENGINE) session = session_engine.SessionStore(session_key=session_key) diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 68b8b4a..7370f40 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -267,7 +267,7 @@ name in the path of your WebSocket request (we'll ignore auth for now - that's n # Connected to websocket.keepalive @channel_session - def ws_add(message): + def ws_keepalive(message): Group("chat-%s" % message.channel_session['room']).add(message.reply_channel) # Connected to websocket.receive