-
-
Notifications
You must be signed in to change notification settings - Fork 823
Add warning for the length of the group name #2122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2e8c005
add warning of length of group
IronJam11 a58f8d9
fix minor issues to pass the tests
IronJam11 19879b2
add regression test
IronJam11 1bbd2d9
update the structure of the test code
IronJam11 cc46101
add the erased test
IronJam11 50f53bc
remove unnecessary assertions
IronJam11 48533bd
inline the error_message
IronJam11 a13f9eb
change the function name to require_valid_group_name and remove asser…
IronJam11 792c79e
applying the same changes for channel
IronJam11 ae711a3
refactor all to use for loop
IronJam11 027aad1
remove lint errors
IronJam11 8b6c547
correct the return instance
IronJam11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,36 +144,32 @@ def match_type_and_length(self, name): | |
| invalid_name_error = ( | ||
| "{} name must be a valid unicode string " | ||
| + "with length < {} ".format(MAX_NAME_LENGTH) | ||
| + "containing only ASCII alphanumerics, hyphens, underscores, or periods, " | ||
| + "not {}" | ||
| + "containing only ASCII alphanumerics, hyphens, underscores, or periods." | ||
| ) | ||
|
|
||
| def valid_channel_name(self, name, receive=False): | ||
| if self.match_type_and_length(name): | ||
| if bool(self.channel_name_regex.match(name)): | ||
| # Check cases for special channels | ||
| if "!" in name and not name.endswith("!") and receive: | ||
| raise TypeError( | ||
| "Specific channel names in receive() must end at the !" | ||
| ) | ||
| return True | ||
| raise TypeError(self.invalid_name_error.format("Channel", name)) | ||
|
|
||
| def valid_group_name(self, name): | ||
| if self.match_type_and_length(name): | ||
| if bool(self.group_name_regex.match(name)): | ||
| return True | ||
| raise TypeError(self.invalid_name_error.format("Group", name)) | ||
| def require_valid_channel_name(self, name, receive=False): | ||
| if not self.match_type_and_length(name): | ||
| raise TypeError(self.invalid_name_error.format("Channel")) | ||
| if not bool(self.channel_name_regex.match(name)): | ||
| raise TypeError(self.invalid_name_error.format("Channel")) | ||
| if "!" in name and not name.endswith("!") and receive: | ||
| raise TypeError("Specific channel names in receive() must end at the !") | ||
| return True | ||
|
|
||
| def require_valid_group_name(self, name): | ||
| if not self.match_type_and_length(name): | ||
| raise TypeError(self.invalid_name_error.format("Group")) | ||
| if not bool(self.group_name_regex.match(name)): | ||
| raise TypeError(self.invalid_name_error.format("Group")) | ||
| return True | ||
|
|
||
| def valid_channel_names(self, names, receive=False): | ||
| _non_empty_list = True if names else False | ||
| _names_type = isinstance(names, list) | ||
| assert _non_empty_list and _names_type, "names must be a non-empty list" | ||
|
|
||
| assert all( | ||
| self.valid_channel_name(channel, receive=receive) for channel in names | ||
| ) | ||
| return True | ||
| for channel in names: | ||
| self.require_valid_channel_name(channel, receive=receive) | ||
| return | ||
|
||
|
|
||
| def non_local_name(self, name): | ||
| """ | ||
|
|
@@ -243,7 +239,7 @@ async def send(self, channel, message): | |
| """ | ||
| # Typecheck | ||
| assert isinstance(message, dict), "message is not a dict" | ||
| assert self.valid_channel_name(channel), "Channel name not valid" | ||
| self.require_valid_channel_name(channel) | ||
| # If it's a process-local channel, strip off local part and stick full | ||
| # name in message | ||
| assert "__asgi_channel__" not in message | ||
|
|
@@ -263,7 +259,7 @@ async def receive(self, channel): | |
| If more than one coroutine waits on the same channel, a random one | ||
| of the waiting coroutines will get the result. | ||
| """ | ||
| assert self.valid_channel_name(channel) | ||
| self.require_valid_channel_name(channel) | ||
| self._clean_expired() | ||
|
|
||
| queue = self.channels.setdefault( | ||
|
|
@@ -341,16 +337,16 @@ async def group_add(self, group, channel): | |
| Adds the channel name to a group. | ||
| """ | ||
| # Check the inputs | ||
| assert self.valid_group_name(group), "Group name not valid" | ||
| assert self.valid_channel_name(channel), "Channel name not valid" | ||
| self.require_valid_group_name(group) | ||
| self.require_valid_channel_name(channel) | ||
| # Add to group dict | ||
| self.groups.setdefault(group, {}) | ||
| self.groups[group][channel] = time.time() | ||
|
|
||
| async def group_discard(self, group, channel): | ||
| # Both should be text and valid | ||
| assert self.valid_channel_name(channel), "Invalid channel name" | ||
| assert self.valid_group_name(group), "Invalid group name" | ||
| self.require_valid_channel_name(channel) | ||
| self.require_valid_group_name(group) | ||
| # Remove from group set | ||
| group_channels = self.groups.get(group, None) | ||
| if group_channels: | ||
|
|
@@ -363,7 +359,7 @@ async def group_discard(self, group, channel): | |
| async def group_send(self, group, message): | ||
| # Check types | ||
| assert isinstance(message, dict), "Message is not a dict" | ||
| assert self.valid_group_name(group), "Invalid group name" | ||
| self.require_valid_group_name(group) | ||
| # Run clean | ||
| self._clean_expired() | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.