Skip to content

Commit e456312

Browse files
committed
rename
1 parent b51b116 commit e456312

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pusher/util.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
# The prefix any e2e channel must have
2323
ENCRYPTED_PREFIX = "private-encrypted-"
2424
SERVER_TO_USER_PREFIX = "#server-to-user-"
25+
MAX_PAYLOAD_SIZE_BYTES = 10240
26+
MAX_CHANNELS = 100
27+
MAX_CHANNEL_NAME_SIZE = 200
2528

2629
channel_name_re = re.compile(r'\A[-a-zA-Z0-9_=@,.;]+\Z')
2730
server_to_user_channel_re = re.compile(rf'\A{SERVER_TO_USER_PREFIX}[-a-zA-Z0-9_=@,.;]+\Z')
@@ -96,7 +99,7 @@ def validate_user_id(user_id):
9699
if length == 0:
97100
raise ValueError("User id is empty")
98101

99-
if length > 200:
102+
if length > MAX_CHANNEL_NAME_SIZE:
100103
raise ValueError("User id too long: '{}'".format(user_id))
101104

102105
if not channel_name_re.match(user_id):
@@ -108,7 +111,7 @@ def validate_user_id(user_id):
108111
def validate_channel(channel):
109112
channel = ensure_text(channel, "channel")
110113

111-
if len(channel) > 200:
114+
if len(channel) > MAX_CHANNEL_NAME_SIZE:
112115
raise ValueError("Channel too long: %s" % channel)
113116

114117
if channel.startswith(SERVER_TO_USER_PREFIX):
@@ -128,7 +131,7 @@ def validate_channels(channels):
128131
channels, (collections.Sized, collections.Iterable)):
129132
raise TypeError("Expected a single or a list of channels")
130133

131-
if len(channels) > 100:
134+
if len(channels) > MAX_CHANNELS:
132135
raise ValueError("Too many channels")
133136

134137
channels = [validate_channel(ch) for ch in channels]
@@ -140,7 +143,7 @@ def validate_channels(channels):
140143

141144
def validate_event_name(event_name):
142145
event_name = ensure_text(event_name, "event_name")
143-
if len(event_name) > 200:
146+
if len(event_name) > MAX_CHANNEL_NAME_SIZE:
144147
raise ValueError("event_name too long")
145148
return event_name
146149

@@ -152,7 +155,7 @@ def validate_data(data, json_encoder=None):
152155
"""
153156

154157
data = data_to_string(data, json_encoder)
155-
if len(data) > 10240:
158+
if len(data) > MAX_PAYLOAD_SIZE_BYTES:
156159
raise ValueError("Too much data")
157160
return data
158161

0 commit comments

Comments
 (0)