wslink 2.3.1__tar.gz → 2.3.2__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {wslink-2.3.1 → wslink-2.3.2}/PKG-INFO +1 -1
- {wslink-2.3.1 → wslink-2.3.2}/setup.cfg +1 -1
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/emitter.py +30 -19
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/websocket.py +3 -1
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink.egg-info/PKG-INFO +1 -1
- {wslink-2.3.1 → wslink-2.3.2}/MANIFEST.in +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/README.rst +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/setup.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/LICENSE +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/__init__.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/__init__.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/aiohttp/__init__.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/aiohttp/launcher.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/aiohttp/relay.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/generic/__init__.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/generic/core.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/jupyter/__init__.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/jupyter/core.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/tornado/__init__.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/backends/tornado/core.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/chunking.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/launcher.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/protocol.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/publish.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/relay.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/server.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/ssl_context.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink/uri.py +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink.egg-info/SOURCES.txt +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink.egg-info/dependency_links.txt +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink.egg-info/requires.txt +0 -0
- {wslink-2.3.1 → wslink-2.3.2}/src/wslink.egg-info/top_level.txt +0 -0
@@ -3,34 +3,26 @@ import functools
|
|
3
3
|
|
4
4
|
|
5
5
|
class EventEmitter:
|
6
|
-
def __init__(self):
|
6
|
+
def __init__(self, allowed_events=None):
|
7
7
|
self._listeners = {}
|
8
8
|
|
9
|
+
if allowed_events is None:
|
10
|
+
allowed_events = []
|
11
|
+
|
12
|
+
self._allowed_events = set(allowed_events)
|
13
|
+
|
14
|
+
for event in self._allowed_events:
|
15
|
+
setattr(self, event, functools.partial(self.emit, event))
|
16
|
+
|
9
17
|
def clear(self):
|
10
18
|
self._listeners = {}
|
11
19
|
|
12
20
|
def __call__(self, event, *args, **kwargs):
|
13
21
|
self.emit(event, *args, **kwargs)
|
14
22
|
|
15
|
-
def __getattr__(self, name):
|
16
|
-
return functools.partial(self.emit, name)
|
17
|
-
|
18
|
-
def exception(self, *args, **kwargs):
|
19
|
-
self.emit("exception", *args, **kwargs)
|
20
|
-
|
21
|
-
def error(self, *args, **kwargs):
|
22
|
-
self.emit("error", *args, **kwargs)
|
23
|
-
|
24
|
-
def critical(self, *args, **kwargs):
|
25
|
-
self.emit("critical", *args, **kwargs)
|
26
|
-
|
27
|
-
def info(self, *args, **kwargs):
|
28
|
-
self.emit("info", *args, **kwargs)
|
29
|
-
|
30
|
-
def debug(self, *args, **kwargs):
|
31
|
-
self.emit("debug", *args, **kwargs)
|
32
|
-
|
33
23
|
def emit(self, event, *args, **kwargs):
|
24
|
+
self._validate_event(event)
|
25
|
+
|
34
26
|
listeners = self._listeners.get(event)
|
35
27
|
if listeners is None:
|
36
28
|
return
|
@@ -47,6 +39,8 @@ class EventEmitter:
|
|
47
39
|
listener(*args, **kwargs)
|
48
40
|
|
49
41
|
def add_event_listener(self, event, listener):
|
42
|
+
self._validate_event(event)
|
43
|
+
|
50
44
|
listeners = self._listeners.get(event)
|
51
45
|
if listeners is None:
|
52
46
|
listeners = set()
|
@@ -55,6 +49,8 @@ class EventEmitter:
|
|
55
49
|
listeners.add(listener)
|
56
50
|
|
57
51
|
def remove_event_listener(self, event, listener):
|
52
|
+
self._validate_event(event)
|
53
|
+
|
58
54
|
listeners = self._listeners.get(event)
|
59
55
|
if listeners is None:
|
60
56
|
return
|
@@ -66,8 +62,23 @@ class EventEmitter:
|
|
66
62
|
return self.listeners_count(event) > 0
|
67
63
|
|
68
64
|
def listeners_count(self, event):
|
65
|
+
self._validate_event(event)
|
66
|
+
|
69
67
|
listeners = self._listeners.get(event)
|
70
68
|
if listeners is None:
|
71
69
|
return 0
|
72
70
|
|
73
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
|
+
)
|
@@ -126,7 +126,9 @@ class ServerProtocol(object):
|
|
126
126
|
|
127
127
|
def __init__(self):
|
128
128
|
self.network_monitor = NetworkMonitor()
|
129
|
-
self.log_emitter = EventEmitter(
|
129
|
+
self.log_emitter = EventEmitter(
|
130
|
+
allowed_events=["exception", "error", "critical", "info", "debug"]
|
131
|
+
)
|
130
132
|
self.linkProtocols = []
|
131
133
|
self.secret = None
|
132
134
|
self.initialize()
|
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
|
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
|