wslink 2.0.1__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.
@@ -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._ws.disconnect(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.on_close(self)
74
+ await client.onClose(client_or_id)
71
75
 
72
76
 
73
77
  class GenericServer(AbstractWebApp):
@@ -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: bytes, offset: int, size: int) -> bytes:
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[bytes, int, int]:
30
- id = header[ID_LOCATION:ID_LENGTH]
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wslink
3
- Version: 2.0.1
3
+ Version: 2.0.2
4
4
  Summary: Python/JavaScript library for communicating over WebSocket
5
5
  Home-page: https://github.com/kitware/wslink
6
6
  Author: Kitware, Inc.
@@ -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=BZZ0YAlh6PNI8rQe80NfdxU8pAvn_Klxew47AkvUJow,7130
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
@@ -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=Gwo7nksgph96i7J77nYm4hB5NwysybQ23rRs86f0d6U,4149
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=H73IEEHyom3TsbhkyI5O88bFBbUIDzHVuvqbIF6PAIM,3858
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.1.dist-info/METADATA,sha256=0qH0MmMTMLg0ABAdOzng9T0tCbUvQF3NDuJs-zpe6NA,3045
23
- wslink-2.0.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
24
- wslink-2.0.1.dist-info/top_level.txt,sha256=N0d8eqvhwhfW1p1yPTmvxlbzhjz7ZyhBfysNvaFqpQY,7
25
- wslink-2.0.1.dist-info/RECORD,,
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