wslink 2.0.0__py3-none-any.whl → 2.0.2__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 +10 -5
- wslink/server.py +7 -13
- {wslink-2.0.0.dist-info → wslink-2.0.2.dist-info}/METADATA +1 -1
- {wslink-2.0.0.dist-info → wslink-2.0.2.dist-info}/RECORD +8 -8
- {wslink-2.0.0.dist-info → wslink-2.0.2.dist-info}/WHEEL +0 -0
- {wslink-2.0.0.dist-info → wslink-2.0.2.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
@@ -2,6 +2,7 @@ import sys
|
|
2
2
|
import secrets
|
3
3
|
import msgpack
|
4
4
|
from typing import Dict, Tuple, Union
|
5
|
+
|
5
6
|
if sys.version_info >= (3, 8):
|
6
7
|
from typing import TypedDict # pylint: disable=no-name-in-module
|
7
8
|
else:
|
@@ -18,16 +19,20 @@ MESSAGE_SIZE_LENGTH = UINT32_LENGTH
|
|
18
19
|
HEADER_LENGTH = ID_LENGTH + MESSAGE_OFFSET_LENGTH + MESSAGE_SIZE_LENGTH
|
19
20
|
|
20
21
|
|
21
|
-
def _encode_header(id:
|
22
|
+
def _encode_header(id: int, offset: int, size: int) -> bytes:
|
22
23
|
return (
|
23
|
-
id
|
24
|
+
id.to_bytes(ID_LENGTH, "little", signed=False)
|
24
25
|
+ offset.to_bytes(MESSAGE_OFFSET_LENGTH, "little", signed=False)
|
25
26
|
+ size.to_bytes(MESSAGE_SIZE_LENGTH, "little", signed=False)
|
26
27
|
)
|
27
28
|
|
28
29
|
|
29
|
-
def _decode_header(header: bytes) -> Tuple[
|
30
|
-
id =
|
30
|
+
def _decode_header(header: bytes) -> Tuple[int, int, int]:
|
31
|
+
id = int.from_bytes(
|
32
|
+
header[ID_LOCATION:ID_LENGTH],
|
33
|
+
"little",
|
34
|
+
signed=False,
|
35
|
+
)
|
31
36
|
offset = int.from_bytes(
|
32
37
|
header[
|
33
38
|
MESSAGE_OFFSET_LOCATION : MESSAGE_OFFSET_LOCATION + MESSAGE_OFFSET_LENGTH
|
@@ -51,7 +56,7 @@ def generate_chunks(message: bytes, max_size: int):
|
|
51
56
|
else:
|
52
57
|
max_content_size = max(max_size - HEADER_LENGTH, 1)
|
53
58
|
|
54
|
-
id = secrets.token_bytes(ID_LENGTH)
|
59
|
+
id = int.from_bytes(secrets.token_bytes(ID_LENGTH), "little", signed=False)
|
55
60
|
|
56
61
|
offset = 0
|
57
62
|
|
wslink/server.py
CHANGED
@@ -18,13 +18,13 @@ ws_server = None
|
|
18
18
|
|
19
19
|
# =============================================================================
|
20
20
|
# Setup default arguments to be parsed
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
21
|
+
# --nosignalhandlers
|
22
|
+
# --debug
|
23
|
+
# --host localhost
|
24
24
|
# -p, --port 8080
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
25
|
+
# --timeout 300 (seconds)
|
26
|
+
# --content '/www' (No content means WebSocket only)
|
27
|
+
# --authKey vtkweb-secret
|
28
28
|
# =============================================================================
|
29
29
|
|
30
30
|
|
@@ -35,16 +35,14 @@ def add_arguments(parser):
|
|
35
35
|
"""
|
36
36
|
|
37
37
|
parser.add_argument(
|
38
|
-
"
|
38
|
+
"--debug", help="log debugging messages to stdout", action="store_true"
|
39
39
|
)
|
40
40
|
parser.add_argument(
|
41
|
-
"-s",
|
42
41
|
"--nosignalhandlers",
|
43
42
|
help="Prevent installation of signal handlers so server can be started inside a thread.",
|
44
43
|
action="store_true",
|
45
44
|
)
|
46
45
|
parser.add_argument(
|
47
|
-
"-i",
|
48
46
|
"--host",
|
49
47
|
type=str,
|
50
48
|
default="localhost",
|
@@ -58,26 +56,22 @@ def add_arguments(parser):
|
|
58
56
|
help="port number for the web-server to listen on (default: 8080)",
|
59
57
|
)
|
60
58
|
parser.add_argument(
|
61
|
-
"-t",
|
62
59
|
"--timeout",
|
63
60
|
type=int,
|
64
61
|
default=300,
|
65
62
|
help="timeout for reaping process on idle in seconds (default: 300s, 0 to disable)",
|
66
63
|
)
|
67
64
|
parser.add_argument(
|
68
|
-
"-c",
|
69
65
|
"--content",
|
70
66
|
default="",
|
71
67
|
help="root for web-pages to serve (default: none)",
|
72
68
|
)
|
73
69
|
parser.add_argument(
|
74
|
-
"-a",
|
75
70
|
"--authKey",
|
76
71
|
default="wslink-secret",
|
77
72
|
help="Authentication key for clients to connect to the WebSocket.",
|
78
73
|
)
|
79
74
|
parser.add_argument(
|
80
|
-
"-ws",
|
81
75
|
"--ws-endpoint",
|
82
76
|
type=str,
|
83
77
|
default="ws",
|
@@ -1,11 +1,11 @@
|
|
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=YKrl-gwM38It8d6BSuJwRw_5LQgw4OwJslV5ejFyVbU,7282
|
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
|
7
7
|
wslink/relay.py,sha256=E8Lzu2Ay7KbOheN1-ArAZawo8lLqdDgJXOZSBuMknYs,86
|
8
|
-
wslink/server.py,sha256=
|
8
|
+
wslink/server.py,sha256=kS0v17uidq6auF4k2kD4L_FHU6i-OdxvG2tH1KeJOpk,9325
|
9
9
|
wslink/ssl_context.py,sha256=hNOJJCdrStws1Qf6vPvY4vTk9Bf8J5d90W3fS0cRv8o,2290
|
10
10
|
wslink/uri.py,sha256=woCQ4yChUqTMg9IT6YYDtUYeKmCg7OUCEgeBGA-19DY,384
|
11
11
|
wslink/websocket.py,sha256=pBiWqkL8Zn8LuSJ9nv3yA-KjEynbolOQ2gLHtQFJ2Ic,4611
|
@@ -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.2.dist-info/METADATA,sha256=q1smyqsGU9ClvWSuOti28QpgT3X044vybCtNTRsdMs4,3045
|
23
|
+
wslink-2.0.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
24
|
+
wslink-2.0.2.dist-info/top_level.txt,sha256=N0d8eqvhwhfW1p1yPTmvxlbzhjz7ZyhBfysNvaFqpQY,7
|
25
|
+
wslink-2.0.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|