wslink 2.3.0__tar.gz → 2.3.2__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.
Files changed (32) hide show
  1. {wslink-2.3.0 → wslink-2.3.2}/PKG-INFO +1 -1
  2. {wslink-2.3.0 → wslink-2.3.2}/setup.cfg +1 -1
  3. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/emitter.py +35 -14
  4. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/websocket.py +3 -6
  5. {wslink-2.3.0 → wslink-2.3.2}/src/wslink.egg-info/PKG-INFO +1 -1
  6. {wslink-2.3.0 → wslink-2.3.2}/MANIFEST.in +0 -0
  7. {wslink-2.3.0 → wslink-2.3.2}/README.rst +0 -0
  8. {wslink-2.3.0 → wslink-2.3.2}/setup.py +0 -0
  9. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/LICENSE +0 -0
  10. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/__init__.py +0 -0
  11. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/__init__.py +0 -0
  12. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/aiohttp/__init__.py +0 -0
  13. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/aiohttp/launcher.py +0 -0
  14. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/aiohttp/relay.py +0 -0
  15. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/generic/__init__.py +0 -0
  16. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/generic/core.py +0 -0
  17. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/jupyter/__init__.py +0 -0
  18. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/jupyter/core.py +0 -0
  19. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/tornado/__init__.py +0 -0
  20. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/backends/tornado/core.py +0 -0
  21. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/chunking.py +0 -0
  22. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/launcher.py +0 -0
  23. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/protocol.py +0 -0
  24. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/publish.py +0 -0
  25. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/relay.py +0 -0
  26. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/server.py +0 -0
  27. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/ssl_context.py +0 -0
  28. {wslink-2.3.0 → wslink-2.3.2}/src/wslink/uri.py +0 -0
  29. {wslink-2.3.0 → wslink-2.3.2}/src/wslink.egg-info/SOURCES.txt +0 -0
  30. {wslink-2.3.0 → wslink-2.3.2}/src/wslink.egg-info/dependency_links.txt +0 -0
  31. {wslink-2.3.0 → wslink-2.3.2}/src/wslink.egg-info/requires.txt +0 -0
  32. {wslink-2.3.0 → wslink-2.3.2}/src/wslink.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wslink
3
- Version: 2.3.0
3
+ Version: 2.3.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,5 +1,5 @@
1
1
  [metadata]
2
- version = 2.3.0
2
+ version = 2.3.2
3
3
 
4
4
  [egg_info]
5
5
  tag_build =
@@ -1,26 +1,28 @@
1
- from typing import TypeVar, Generic, LiteralString
2
-
3
1
  import asyncio
4
2
  import functools
5
3
 
6
4
 
7
- T = TypeVar("T", bound=LiteralString)
5
+ class EventEmitter:
6
+ def __init__(self, allowed_events=None):
7
+ self._listeners = {}
8
8
 
9
+ if allowed_events is None:
10
+ allowed_events = []
9
11
 
10
- class EventEmitter(Generic[T]):
11
- def __init__(self):
12
- self._listeners = {}
12
+ self._allowed_events = set(allowed_events)
13
+
14
+ for event in self._allowed_events:
15
+ setattr(self, event, functools.partial(self.emit, event))
13
16
 
14
17
  def clear(self):
15
18
  self._listeners = {}
16
19
 
17
- def __call__(self, event: T, *args, **kwargs):
20
+ def __call__(self, event, *args, **kwargs):
18
21
  self.emit(event, *args, **kwargs)
19
22
 
20
- def __getattr__(self, name: T):
21
- return functools.partial(self.emit, name)
23
+ def emit(self, event, *args, **kwargs):
24
+ self._validate_event(event)
22
25
 
23
- def emit(self, event: T, *args, **kwargs):
24
26
  listeners = self._listeners.get(event)
25
27
  if listeners is None:
26
28
  return
@@ -36,7 +38,9 @@ class EventEmitter(Generic[T]):
36
38
  else:
37
39
  listener(*args, **kwargs)
38
40
 
39
- def add_event_listener(self, event: T, listener):
41
+ def add_event_listener(self, event, listener):
42
+ self._validate_event(event)
43
+
40
44
  listeners = self._listeners.get(event)
41
45
  if listeners is None:
42
46
  listeners = set()
@@ -44,7 +48,9 @@ class EventEmitter(Generic[T]):
44
48
 
45
49
  listeners.add(listener)
46
50
 
47
- def remove_event_listener(self, event: T, listener):
51
+ def remove_event_listener(self, event, listener):
52
+ self._validate_event(event)
53
+
48
54
  listeners = self._listeners.get(event)
49
55
  if listeners is None:
50
56
  return
@@ -52,12 +58,27 @@ class EventEmitter(Generic[T]):
52
58
  if listener in listeners:
53
59
  listeners.remove(listener)
54
60
 
55
- def has(self, event: T):
61
+ def has(self, event):
56
62
  return self.listeners_count(event) > 0
57
63
 
58
- def listeners_count(self, event: T):
64
+ def listeners_count(self, event):
65
+ self._validate_event(event)
66
+
59
67
  listeners = self._listeners.get(event)
60
68
  if listeners is None:
61
69
  return 0
62
70
 
63
71
  return len(listeners)
72
+
73
+ @property
74
+ def allowed_events(self):
75
+ return self._allowed_events
76
+
77
+ def _validate_event(self, event):
78
+ if len(self.allowed_events) == 0:
79
+ return
80
+
81
+ if event not in self.allowed_events:
82
+ raise ValueError(
83
+ f"'{event}' is not a known event of this EventEmitter: {self.allowed_events}"
84
+ )
@@ -6,8 +6,6 @@ ServerProtocol to hook all the needed LinkProtocols together.
6
6
 
7
7
  import logging
8
8
  import asyncio
9
- from typing import Literal
10
- from dataclasses import dataclass
11
9
 
12
10
  from wslink import register as exportRpc
13
11
  from wslink import schedule_callback
@@ -120,9 +118,6 @@ class NetworkMonitor:
120
118
  await self.event.wait()
121
119
 
122
120
 
123
- LogEmitterEvents = Literal["exception", "error", "critical", "info", "debug"]
124
-
125
-
126
121
  class ServerProtocol(object):
127
122
  """
128
123
  Defines the core server protocol for wslink. Gathers a list of LinkProtocol
@@ -131,7 +126,9 @@ class ServerProtocol(object):
131
126
 
132
127
  def __init__(self):
133
128
  self.network_monitor = NetworkMonitor()
134
- self.log_emitter = EventEmitter[LogEmitterEvents]()
129
+ self.log_emitter = EventEmitter(
130
+ allowed_events=["exception", "error", "critical", "info", "debug"]
131
+ )
135
132
  self.linkProtocols = []
136
133
  self.secret = None
137
134
  self.initialize()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wslink
3
- Version: 2.3.0
3
+ Version: 2.3.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.
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