CheeseAPI 2.0.8b3__tar.gz → 2.0.8b4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/websocket.py +34 -14
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/PKG-INFO +1 -1
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/pyproject.toml +1 -1
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/.gitignore +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/__init__.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/app.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/cors.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/file.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/printer.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/request.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/response.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/route.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/scheduler.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/signal.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/static.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/CheeseAPI/validator.py +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/LICENSE +0 -0
- {cheeseapi-2.0.8b3 → cheeseapi-2.0.8b4}/README.md +0 -0
|
@@ -112,11 +112,17 @@ class WebsocketProxy:
|
|
|
112
112
|
@staticmethod
|
|
113
113
|
def _static_send(path: str, data: bytes | list | str | dict, *, websocket_key_or_keys: str | list[str] | None = None):
|
|
114
114
|
if static.websocket_sync_servers is not None:
|
|
115
|
-
data
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
if isinstance(data, bytes):
|
|
116
|
+
data = b'\x01' + json.dumps({
|
|
117
|
+
'key': websocket_key_or_keys,
|
|
118
|
+
'event': 'send'
|
|
119
|
+
}).encode() + b'\x00' + data
|
|
120
|
+
else:
|
|
121
|
+
data = b'\x00' + json.dumps({
|
|
122
|
+
'data': data,
|
|
123
|
+
'key': websocket_key_or_keys,
|
|
124
|
+
'event': 'send'
|
|
125
|
+
}).encode()
|
|
120
126
|
if static.websocket_data_encode is not None:
|
|
121
127
|
data = static.websocket_data_encode(data)
|
|
122
128
|
redis.Redis(connection_pool = static.websocket_sync_servers[0]).publish(path, data)
|
|
@@ -137,11 +143,18 @@ class WebsocketProxy:
|
|
|
137
143
|
@staticmethod
|
|
138
144
|
async def async_send(path: str, data: bytes | list | str | dict, *, websocket_key_or_keys: str | list[str] | None = None):
|
|
139
145
|
if static.websocket_sync_servers is not None:
|
|
140
|
-
data
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
if isinstance(data, bytes):
|
|
147
|
+
header = json.dumps({
|
|
148
|
+
'key': websocket_key_or_keys,
|
|
149
|
+
'event': 'send'
|
|
150
|
+
}).encode()
|
|
151
|
+
data = b'\x01' + header + b'\x00' + data
|
|
152
|
+
else:
|
|
153
|
+
data = b'\x00' + json.dumps({
|
|
154
|
+
'data': data,
|
|
155
|
+
'key': websocket_key_or_keys,
|
|
156
|
+
'event': 'send'
|
|
157
|
+
}).encode()
|
|
145
158
|
if static.websocket_data_encode is not None:
|
|
146
159
|
data = static.websocket_data_encode(data)
|
|
147
160
|
await redis.asyncio.Redis(connection_pool = static.websocket_sync_servers[1]).publish(path, data)
|
|
@@ -157,7 +170,7 @@ class WebsocketProxy:
|
|
|
157
170
|
@staticmethod
|
|
158
171
|
def _static_close(path: str, code: int = 1000, message: str = '', *, websocket_key_or_keys: str | list[str] | None = None):
|
|
159
172
|
if static.websocket_sync_servers is not None:
|
|
160
|
-
data = json.dumps({
|
|
173
|
+
data = b'\x00' + json.dumps({
|
|
161
174
|
'key': websocket_key_or_keys,
|
|
162
175
|
'event': 'close'
|
|
163
176
|
}).encode()
|
|
@@ -181,7 +194,7 @@ class WebsocketProxy:
|
|
|
181
194
|
@staticmethod
|
|
182
195
|
async def async_close(path: str, code: int = 1000, message: str = '', *, websocket_key_or_keys: str | list[str] | None = None):
|
|
183
196
|
if static.websocket_sync_servers is not None:
|
|
184
|
-
data = json.dumps({
|
|
197
|
+
data = b'\x00' + json.dumps({
|
|
185
198
|
'key': websocket_key_or_keys,
|
|
186
199
|
'event': 'close'
|
|
187
200
|
}).encode()
|
|
@@ -263,7 +276,14 @@ class WebsocketProxy:
|
|
|
263
276
|
message = message['data']
|
|
264
277
|
if static.websocket_data_decode is not None:
|
|
265
278
|
message = static.websocket_data_decode(message)
|
|
266
|
-
|
|
279
|
+
msg_type = message[0]
|
|
280
|
+
if msg_type == 0:
|
|
281
|
+
message = json.loads(message[1:].decode())
|
|
282
|
+
_data = message.get('data')
|
|
283
|
+
else:
|
|
284
|
+
sep = message.index(b'\x00', 1)
|
|
285
|
+
_data = message[sep + 1:]
|
|
286
|
+
message = json.loads(message[1:sep].decode())
|
|
267
287
|
if isinstance(message['key'], list):
|
|
268
288
|
connectors = [connector for connector in connectors if connector.key in message['key']]
|
|
269
289
|
elif isinstance(message['key'], str):
|
|
@@ -274,7 +294,7 @@ class WebsocketProxy:
|
|
|
274
294
|
if connectors:
|
|
275
295
|
if message['event'] == 'send':
|
|
276
296
|
for connector in connectors:
|
|
277
|
-
asyncio.create_task(connector.send(
|
|
297
|
+
asyncio.create_task(connector.send(_data))
|
|
278
298
|
elif message['event'] == 'close':
|
|
279
299
|
for connector in connectors:
|
|
280
300
|
asyncio.create_task(connector.close())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|