mirror of
https://github.com/django/daphne.git
synced 2025-07-12 08:52:18 +03:00
Merge pull request #12 from octaflop/master
Fixing unicode in python 3 and an update in the docs
This commit is contained in:
commit
454839dafa
|
@ -50,8 +50,8 @@ def channel_session(func):
|
||||||
# Turn the reply_channel into a valid session key length thing.
|
# Turn the reply_channel into a valid session key length thing.
|
||||||
# We take the last 24 bytes verbatim, as these are the random section,
|
# 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
|
# and then hash the remaining ones onto the start, and add a prefix
|
||||||
reply_name = message.reply_channel.name
|
reply_name = str(message.reply_channel.name).encode()
|
||||||
session_key = "skt" + hashlib.md5(reply_name[:-24]).hexdigest()[:8] + reply_name[-24:]
|
session_key = b"skt" + str(hashlib.md5(reply_name[:-24]).hexdigest()[:8]).encode() + reply_name[-24:]
|
||||||
# Make a session storage
|
# Make a session storage
|
||||||
session_engine = import_module(settings.SESSION_ENGINE)
|
session_engine = import_module(settings.SESSION_ENGINE)
|
||||||
session = session_engine.SessionStore(session_key=session_key)
|
session = session_engine.SessionStore(session_key=session_key)
|
||||||
|
|
|
@ -135,7 +135,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
|
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::
|
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
|
# Connected to websocket.connect and websocket.keepalive
|
||||||
def ws_add(message):
|
def ws_add(message):
|
||||||
|
@ -253,7 +253,7 @@ just like a normal Django session.
|
||||||
Let's use it now to build a chat server that expects you to pass a chatroom
|
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)::
|
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
|
from channels.decorators import channel_session
|
||||||
|
|
||||||
# Connected to websocket.connect
|
# Connected to websocket.connect
|
||||||
|
@ -267,13 +267,13 @@ name in the path of your WebSocket request (we'll ignore auth for now - that's n
|
||||||
|
|
||||||
# Connected to websocket.keepalive
|
# Connected to websocket.keepalive
|
||||||
@channel_session
|
@channel_session
|
||||||
def ws_add(message):
|
def ws_keepalive(message):
|
||||||
Group("chat-%s" % message.channel_session['room']).add(message.reply_channel)
|
Group("chat-%s" % message.channel_session['room']).add(message.reply_channel)
|
||||||
|
|
||||||
# Connected to websocket.receive
|
# Connected to websocket.receive
|
||||||
@channel_session
|
@channel_session
|
||||||
def ws_message(message):
|
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
|
# Connected to websocket.disconnect
|
||||||
@channel_session
|
@channel_session
|
||||||
|
|
Loading…
Reference in New Issue
Block a user