wslink 2.0.1__py3-none-any.whl → 2.0.3__py3-none-any.whl
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.
- wslink/backends/generic/core.py +12 -8
- wslink/backends/jupyter/core.py +1 -1
- wslink/chunking.py +12 -6
- {wslink-2.0.1.dist-info → wslink-2.0.3.dist-info}/METADATA +1 -1
- {wslink-2.0.1.dist-info → wslink-2.0.3.dist-info}/RECORD +7 -7
- {wslink-2.0.1.dist-info → wslink-2.0.3.dist-info}/WHEEL +0 -0
- {wslink-2.0.1.dist-info → wslink-2.0.3.dist-info}/top_level.txt +0 -0
wslink/backends/generic/core.py
CHANGED
@@ -24,8 +24,8 @@ class WsConnection:
|
|
24
24
|
async def send(self, is_binary, msg):
|
25
25
|
await self._ws.onMessage(is_binary, msg, self.client_id)
|
26
26
|
|
27
|
-
def close(self):
|
28
|
-
self.
|
27
|
+
async def close(self):
|
28
|
+
await self.on_close(self._ws)
|
29
29
|
|
30
30
|
# -------------------------------------------------------------------------
|
31
31
|
# Method used by FakeWS
|
@@ -35,13 +35,17 @@ class WsConnection:
|
|
35
35
|
def client_id(self):
|
36
36
|
return self._id
|
37
37
|
|
38
|
-
def on_connect(self, ws):
|
38
|
+
async def on_connect(self, ws):
|
39
39
|
self.closed = False
|
40
40
|
self._ws = ws
|
41
|
+
await self._ws.onConnect(
|
42
|
+
{"type": "generic", "connection": self}, self.client_id
|
43
|
+
)
|
41
44
|
|
42
|
-
def on_close(self, ws):
|
45
|
+
async def on_close(self, ws):
|
43
46
|
self.closed = True
|
44
47
|
if self._ws == ws:
|
48
|
+
ws.disconnect(self.client_id)
|
45
49
|
self._ws = None
|
46
50
|
|
47
51
|
async def send_str(self, value):
|
@@ -55,19 +59,19 @@ class WsEndpoint(WslinkHandler):
|
|
55
59
|
def __init__(self, protocol=None, web_app=None):
|
56
60
|
super().__init__(protocol, web_app)
|
57
61
|
|
58
|
-
def connect(self):
|
62
|
+
async def connect(self):
|
59
63
|
conn = WsConnection()
|
60
64
|
self.connections[conn.client_id] = conn
|
61
|
-
conn.on_connect(self)
|
65
|
+
await conn.on_connect(self)
|
62
66
|
return conn
|
63
67
|
|
64
|
-
def disconnect(self, client_or_id):
|
68
|
+
async def disconnect(self, client_or_id):
|
65
69
|
client_or_id = (
|
66
70
|
client_or_id if isinstance(client_or_id, str) else client_or_id.client_id
|
67
71
|
)
|
68
72
|
if client_or_id in self.connections:
|
69
73
|
client = self.connections.pop(client_or_id)
|
70
|
-
client.
|
74
|
+
await client.onClose(client_or_id)
|
71
75
|
|
72
76
|
|
73
77
|
class GenericServer(AbstractWebApp):
|
wslink/backends/jupyter/core.py
CHANGED
@@ -114,7 +114,7 @@ class JupyterGenericServer(GenericServer):
|
|
114
114
|
connection = self._connections.get(client_id, None)
|
115
115
|
|
116
116
|
if connection is None:
|
117
|
-
connection = self._endpoint.connect()
|
117
|
+
connection = await self._endpoint.connect()
|
118
118
|
connection.on_message(partial(self.on_msg_from_server, client_id))
|
119
119
|
self._connections[client_id] = connection
|
120
120
|
|
wslink/chunking.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
import os
|
1
2
|
import sys
|
2
3
|
import secrets
|
3
4
|
import msgpack
|
4
5
|
from typing import Dict, Tuple, Union
|
6
|
+
|
5
7
|
if sys.version_info >= (3, 8):
|
6
8
|
from typing import TypedDict # pylint: disable=no-name-in-module
|
7
9
|
else:
|
@@ -18,16 +20,20 @@ MESSAGE_SIZE_LENGTH = UINT32_LENGTH
|
|
18
20
|
HEADER_LENGTH = ID_LENGTH + MESSAGE_OFFSET_LENGTH + MESSAGE_SIZE_LENGTH
|
19
21
|
|
20
22
|
|
21
|
-
def _encode_header(id:
|
23
|
+
def _encode_header(id: int, offset: int, size: int) -> bytes:
|
22
24
|
return (
|
23
|
-
id
|
25
|
+
id.to_bytes(ID_LENGTH, "little", signed=False)
|
24
26
|
+ offset.to_bytes(MESSAGE_OFFSET_LENGTH, "little", signed=False)
|
25
27
|
+ size.to_bytes(MESSAGE_SIZE_LENGTH, "little", signed=False)
|
26
28
|
)
|
27
29
|
|
28
30
|
|
29
|
-
def _decode_header(header: bytes) -> Tuple[
|
30
|
-
id =
|
31
|
+
def _decode_header(header: bytes) -> Tuple[int, int, int]:
|
32
|
+
id = int.from_bytes(
|
33
|
+
header[ID_LOCATION:ID_LENGTH],
|
34
|
+
"little",
|
35
|
+
signed=False,
|
36
|
+
)
|
31
37
|
offset = int.from_bytes(
|
32
38
|
header[
|
33
39
|
MESSAGE_OFFSET_LOCATION : MESSAGE_OFFSET_LOCATION + MESSAGE_OFFSET_LENGTH
|
@@ -51,7 +57,7 @@ def generate_chunks(message: bytes, max_size: int):
|
|
51
57
|
else:
|
52
58
|
max_content_size = max(max_size - HEADER_LENGTH, 1)
|
53
59
|
|
54
|
-
id = secrets.token_bytes(ID_LENGTH)
|
60
|
+
id = int.from_bytes(secrets.token_bytes(ID_LENGTH), "little", signed=False)
|
55
61
|
|
56
62
|
offset = 0
|
57
63
|
|
@@ -82,7 +88,7 @@ class UnChunker:
|
|
82
88
|
|
83
89
|
def __init__(self):
|
84
90
|
self.pending_messages = {}
|
85
|
-
self.max_message_size = 512
|
91
|
+
self.max_message_size = int(os.environ.get("WSLINK_AUTH_MSG_SIZE", 512))
|
86
92
|
|
87
93
|
def set_max_message_size(self, size):
|
88
94
|
self.max_message_size = size
|
@@ -1,6 +1,6 @@
|
|
1
1
|
wslink/LICENSE,sha256=I44UH7kDVqxDLnnlOWw_hFL2Fz7RjQ_4vPzZv9NYgTU,1483
|
2
2
|
wslink/__init__.py,sha256=AbEm-sUSoGL-uLpnbK1rSSjHSvyW-bMsGHWie7FgMHw,2708
|
3
|
-
wslink/chunking.py,sha256=
|
3
|
+
wslink/chunking.py,sha256=1DJlGG6fjknGFrqPOtqUUc5tCrijldP7Kdx56d5e3Wg,7337
|
4
4
|
wslink/launcher.py,sha256=8VMs3juObLkyGYQFNLjMoo4qFpKIcxWz0kS-af-DKO4,21170
|
5
5
|
wslink/protocol.py,sha256=zdf4QthFHpAgEw3hTUyyaOuN76jzHeOJBpvekPbk7aY,15886
|
6
6
|
wslink/publish.py,sha256=9G5TXqyGr-LCo_LwHYhzif6lhG2iXDvEBmEgwR8fh1M,1437
|
@@ -14,12 +14,12 @@ wslink/backends/aiohttp/__init__.py,sha256=u2UxSnaMJPoiba1CL1fOeM8bTggyOw6znQ2iG
|
|
14
14
|
wslink/backends/aiohttp/launcher.py,sha256=gHNMvtgNHEwBN_QBRDSCrTp2B4K1PsfV81rKaHi7Cxo,8897
|
15
15
|
wslink/backends/aiohttp/relay.py,sha256=oZAzIQTpsQaObWXaa-_VtoTOUQALC_QLDd9UvWspYaU,13311
|
16
16
|
wslink/backends/generic/__init__.py,sha256=Qu65gWsd2xCSsxybnDtEDI5vMjHN-F5jgPZOyNIxnGs,112
|
17
|
-
wslink/backends/generic/core.py,sha256=
|
17
|
+
wslink/backends/generic/core.py,sha256=7Tx02wzoIWsx9sTLrKB0gaZcTk2JT_OBYz_ZOOljfAU,4356
|
18
18
|
wslink/backends/jupyter/__init__.py,sha256=Qu65gWsd2xCSsxybnDtEDI5vMjHN-F5jgPZOyNIxnGs,112
|
19
|
-
wslink/backends/jupyter/core.py,sha256=
|
19
|
+
wslink/backends/jupyter/core.py,sha256=PCQN-uZPFROnRv8B5dNwnwHV67o4Bpme3_Z6V-zbOUA,3864
|
20
20
|
wslink/backends/tornado/__init__.py,sha256=Qu65gWsd2xCSsxybnDtEDI5vMjHN-F5jgPZOyNIxnGs,112
|
21
21
|
wslink/backends/tornado/core.py,sha256=tPMkkhWuO_ovkisVim0zcegwZKEAG4IRUdd_O_0a_R0,2157
|
22
|
-
wslink-2.0.
|
23
|
-
wslink-2.0.
|
24
|
-
wslink-2.0.
|
25
|
-
wslink-2.0.
|
22
|
+
wslink-2.0.3.dist-info/METADATA,sha256=KUntVYaFzK2cZ7KIT69UrYM9XlL9czyey9-ZgGgg984,3045
|
23
|
+
wslink-2.0.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
24
|
+
wslink-2.0.3.dist-info/top_level.txt,sha256=N0d8eqvhwhfW1p1yPTmvxlbzhjz7ZyhBfysNvaFqpQY,7
|
25
|
+
wslink-2.0.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|