From 3a4847887e7b49cefb61f153bb7ffdd2ac888141 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 12 Jul 2015 23:37:43 -0500 Subject: [PATCH 1/2] Fix invalid py2 syntax --- channels/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/channels/decorators.py b/channels/decorators.py index 63ba59d..5a94850 100644 --- a/channels/decorators.py +++ b/channels/decorators.py @@ -5,7 +5,7 @@ from django.utils import six from channels import channel_backends, DEFAULT_CHANNEL_BACKEND -def consumer(self, *channels, alias=DEFAULT_CHANNEL_BACKEND): +def consumer(self, alias=DEFAULT_CHANNEL_BACKEND, *channels): """ Decorator that registers a function as a consumer. """ From 964c457df1f59c06880353db7f76a1cd6b974f1c Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 12 Jul 2015 23:52:02 -0500 Subject: [PATCH 2/2] Make groups actually work --- channels/__init__.py | 2 +- channels/channel.py | 10 +++++----- channels/decorators.py | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/channels/__init__.py b/channels/__init__.py index 2b9a471..e5d43b7 100644 --- a/channels/__init__.py +++ b/channels/__init__.py @@ -17,4 +17,4 @@ from .hacks import monkeypatch_django monkeypatch_django() # Promote channel to top-level (down here to avoid circular import errs) -from .channel import Channel +from .channel import Channel, Group diff --git a/channels/channel.py b/channels/channel.py index 6724eba..faf5f3a 100644 --- a/channels/channel.py +++ b/channels/channel.py @@ -58,7 +58,7 @@ class Group(object): of the group after an expiry time (keep re-adding to keep them in). """ - def __init__(self, alias=DEFAULT_CHANNEL_BACKEND, channel_backend=None): + def __init__(self, name, alias=DEFAULT_CHANNEL_BACKEND, channel_backend=None): self.name = name if channel_backend: self.channel_backend = channel_backend @@ -66,13 +66,13 @@ class Group(object): self.channel_backend = channel_backends[alias] def add(self, channel): - self.channel_backend.add(self.name, channel) + self.channel_backend.group_add(self.name, channel) def discard(self, channel): - self.channel_backend.discard(self.name, channel) + self.channel_backend.group_discard(self.name, channel) def channels(self): - self.channel_backend.channels(self.name) + self.channel_backend.group_channels(self.name) def send(self, **kwargs): - self.channel_backend.send_group(self, self.name, kwargs) + self.channel_backend.send_group(self.name, kwargs) diff --git a/channels/decorators.py b/channels/decorators.py index 5a94850..584f66a 100644 --- a/channels/decorators.py +++ b/channels/decorators.py @@ -5,10 +5,12 @@ from django.utils import six from channels import channel_backends, DEFAULT_CHANNEL_BACKEND -def consumer(self, alias=DEFAULT_CHANNEL_BACKEND, *channels): +def consumer(*channels, **kwargs): """ Decorator that registers a function as a consumer. """ + # We can't put a kwarg after *args in py2 + alias = kwargs.get("alias", DEFAULT_CHANNEL_BACKEND) # Upconvert if you just pass in a string if isinstance(channels, six.string_types): channels = [channels]