Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Commit 02a3568

Browse files
committed
Allow for single-reader channels and improve name checks
1 parent 3e33ab3 commit 02a3568

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

asgi_ipc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, prefix="asgi", expiry=60, group_expiry=86400, capacity=10, ch
5050
def send(self, channel, message):
5151
# Typecheck
5252
assert isinstance(message, dict), "message is not a dict"
53-
assert isinstance(channel, six.text_type), "%s is not unicode" % channel
53+
assert self.valid_channel_name(channel), "channel name not valid"
5454
# Write message into the correct message queue
5555
channel_list = self._channel_list(channel)
5656
with self.thread_lock:
@@ -63,7 +63,7 @@ def receive_many(self, channels, block=False):
6363
if not channels:
6464
return None, None
6565
channels = list(channels)
66-
assert all(isinstance(channel, six.text_type) for channel in channels)
66+
assert all(self.valid_channel_name(channel) for channel in channels), "one or more channel names invalid"
6767
random.shuffle(channels)
6868
# Try to pop off all of the named channels
6969
with self.thread_lock:
@@ -85,7 +85,7 @@ def new_channel(self, pattern):
8585
# Keep making channel names till one isn't present.
8686
while True:
8787
random_string = "".join(random.choice(string.ascii_letters) for i in range(12))
88-
assert pattern.endswith("!")
88+
assert pattern.endswith("!") or pattern.endswith("?")
8989
new_name = pattern + random_string
9090
# To see if it's present we open the queue without O_CREAT
9191
if not MemoryList.exists(self._channel_path(new_name)):
@@ -99,6 +99,7 @@ def group_add(self, group, channel):
9999
"""
100100
Adds the channel to the named group
101101
"""
102+
assert self.valid_group_name(group), "Invalid group name"
102103
group_dict = self._group_dict(group)
103104
with self.thread_lock:
104105
group_dict[channel] = time.time() + self.group_expiry
@@ -108,6 +109,7 @@ def group_discard(self, group, channel):
108109
Removes the channel from the named group if it is in the group;
109110
does nothing otherwise (does not error)
110111
"""
112+
assert self.valid_group_name(group), "Invalid group name"
111113
group_dict = self._group_dict(group)
112114
with self.thread_lock:
113115
group_dict.discard(channel)
@@ -116,6 +118,7 @@ def send_group(self, group, message):
116118
"""
117119
Sends a message to the entire group.
118120
"""
121+
assert self.valid_group_name(group), "Invalid group name"
119122
group_dict = self._group_dict(group)
120123
with self.thread_lock:
121124
items = list(group_dict.items())

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
'six',
2424
'posix_ipc>=1.0.0',
2525
'msgpack-python',
26-
'asgiref>=0.13',
26+
'asgiref>=0.13.1',
2727
]
2828
)

0 commit comments

Comments
 (0)