wslink 2.3.1__py3-none-any.whl → 2.3.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- wslink/emitter.py +30 -19
- wslink/websocket.py +3 -1
- {wslink-2.3.1.dist-info → wslink-2.3.2.dist-info}/METADATA +1 -1
- {wslink-2.3.1.dist-info → wslink-2.3.2.dist-info}/RECORD +6 -6
- {wslink-2.3.1.dist-info → wslink-2.3.2.dist-info}/WHEEL +0 -0
- {wslink-2.3.1.dist-info → wslink-2.3.2.dist-info}/top_level.txt +0 -0
wslink/emitter.py
CHANGED
@@ -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
|
+
)
|
wslink/websocket.py
CHANGED
@@ -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()
|
@@ -1,7 +1,7 @@
|
|
1
1
|
wslink/LICENSE,sha256=I44UH7kDVqxDLnnlOWw_hFL2Fz7RjQ_4vPzZv9NYgTU,1483
|
2
2
|
wslink/__init__.py,sha256=qdLGVhzpEXBoraTnLr5S-8bX9oK8pZCQWe8rZRlwAco,2946
|
3
3
|
wslink/chunking.py,sha256=1DJlGG6fjknGFrqPOtqUUc5tCrijldP7Kdx56d5e3Wg,7337
|
4
|
-
wslink/emitter.py,sha256=
|
4
|
+
wslink/emitter.py,sha256=eniDanfasJeEa5rDC92nmgaAVWKjjmgZaqbCZwlwQIw,2228
|
5
5
|
wslink/launcher.py,sha256=8VMs3juObLkyGYQFNLjMoo4qFpKIcxWz0kS-af-DKO4,21170
|
6
6
|
wslink/protocol.py,sha256=IUvdYzXaaKP4qllJps6uQ8zvbipbH6MVwU6o6f60Kuc,17265
|
7
7
|
wslink/publish.py,sha256=Xyv9piZT4HxO5l_SA7zeReH8t6tisVHUgU57Hjzgkcg,1595
|
@@ -9,7 +9,7 @@ wslink/relay.py,sha256=E8Lzu2Ay7KbOheN1-ArAZawo8lLqdDgJXOZSBuMknYs,86
|
|
9
9
|
wslink/server.py,sha256=yvhCjpzPOfhbZrpDvW9i4H_uSyuQAe3ZOP-BRBmgHQA,9326
|
10
10
|
wslink/ssl_context.py,sha256=hNOJJCdrStws1Qf6vPvY4vTk9Bf8J5d90W3fS0cRv8o,2290
|
11
11
|
wslink/uri.py,sha256=woCQ4yChUqTMg9IT6YYDtUYeKmCg7OUCEgeBGA-19DY,384
|
12
|
-
wslink/websocket.py,sha256=
|
12
|
+
wslink/websocket.py,sha256=mQCcKHM4xAjlMj3gHeuIDgk9TM9cfNniOb5y_hMMQVg,6279
|
13
13
|
wslink/backends/__init__.py,sha256=cyJGjm-YyBSyOEX81owyTbJ3YnrA6dB7--B4LnsEtHI,1214
|
14
14
|
wslink/backends/aiohttp/__init__.py,sha256=SSK5a_lxuEZGyW_mMMipgvAhJQQLhxAImR3jRokFchM,9301
|
15
15
|
wslink/backends/aiohttp/launcher.py,sha256=gHNMvtgNHEwBN_QBRDSCrTp2B4K1PsfV81rKaHi7Cxo,8897
|
@@ -20,7 +20,7 @@ wslink/backends/jupyter/__init__.py,sha256=Qu65gWsd2xCSsxybnDtEDI5vMjHN-F5jgPZOy
|
|
20
20
|
wslink/backends/jupyter/core.py,sha256=F8R3uH4m6RHCrHHRiA5UAgDOLdyGbpuCSAgCZxANREk,2794
|
21
21
|
wslink/backends/tornado/__init__.py,sha256=Qu65gWsd2xCSsxybnDtEDI5vMjHN-F5jgPZOyNIxnGs,112
|
22
22
|
wslink/backends/tornado/core.py,sha256=tPMkkhWuO_ovkisVim0zcegwZKEAG4IRUdd_O_0a_R0,2157
|
23
|
-
wslink-2.3.
|
24
|
-
wslink-2.3.
|
25
|
-
wslink-2.3.
|
26
|
-
wslink-2.3.
|
23
|
+
wslink-2.3.2.dist-info/METADATA,sha256=XfA7lfjUyU-5hJJjQKquzZOjyTLQZDOjOjDeELLnxk0,3120
|
24
|
+
wslink-2.3.2.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
25
|
+
wslink-2.3.2.dist-info/top_level.txt,sha256=N0d8eqvhwhfW1p1yPTmvxlbzhjz7ZyhBfysNvaFqpQY,7
|
26
|
+
wslink-2.3.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|