1
1
import asyncio
2
- from abc import (
3
- ABC , abstractmethod , abstractclassmethod , abstractproperty ,
4
- abstractstaticmethod
5
- )
2
+ from abc import ABC , abstractmethod
6
3
from enum import IntEnum
7
4
from typing import Any , Mapping , Coroutine , Union , Callable , Dict , Tuple
8
5
@@ -16,7 +13,8 @@ class AbstractWebSocket(ABC):
16
13
def __init__ (self , request : Request ):
17
14
raise NotImplementedError (request )
18
15
19
- @abstractclassmethod
16
+ @classmethod
17
+ @abstractmethod
20
18
def configure (cls , keepalive_timeout : int ,
21
19
client_timeout : int ,
22
20
max_concurrent_requests : int ) -> None :
@@ -55,7 +53,8 @@ async def authorize(self) -> bool:
55
53
async def __handle_request (self ) -> WebSocketResponse :
56
54
raise NotImplementedError
57
55
58
- @abstractclassmethod
56
+ @classmethod
57
+ @abstractmethod
59
58
def broadcast (
60
59
cls , func , callback = None , return_exceptions = True ,
61
60
** kwargs : Mapping [str , Any ]
@@ -115,7 +114,7 @@ def __getattr__(self, item: str):
115
114
EventListenerType = Callable [[Dict [str , Any ]], Any ]
116
115
117
116
118
- class AbstactWSRPC (ABC ):
117
+ class WSRPCBase (ABC ):
119
118
@abstractmethod
120
119
def __init__ (self , loop : asyncio .AbstractEventLoop = None ,
121
120
timeout : Union [int , float ] = None ):
@@ -138,28 +137,31 @@ async def handle_message(self, message: WSMessage):
138
137
async def _on_message (self , msg : WSMessage ):
139
138
raise NotImplementedError
140
139
141
- @abstractclassmethod
140
+ @classmethod
141
+ @abstractmethod
142
142
def get_routes (cls ) -> Mapping [str , "RouteType" ]:
143
143
raise NotImplementedError
144
144
145
145
@classmethod
146
- def get_clients (cls ) -> Dict [str , "AbstactWSRPC " ]:
146
+ def get_clients (cls ) -> Dict [str , "AbstractWSRPC " ]:
147
147
raise NotImplementedError
148
148
149
- @abstractproperty
149
+ @property
150
+ @abstractmethod
150
151
def routes (self ) -> Dict [str , "RouteType" ]:
151
152
raise NotImplementedError
152
153
153
154
@property
154
- def clients (self ) -> Dict [str , "AbstactWSRPC " ]:
155
+ def clients (self ) -> Dict [str , "AbstractWSRPC " ]:
155
156
""" Property which contains the socket clients """
156
157
raise NotImplementedError
157
158
158
159
@abstractmethod
159
160
def prepare_args (self , args ) -> Tuple [Tuple [Any , ...], Dict [str , Any ]]:
160
161
raise NotImplementedError
161
162
162
- @abstractstaticmethod
163
+ @staticmethod
164
+ @abstractmethod
163
165
def is_route (func ) -> bool :
164
166
raise NotImplementedError
165
167
@@ -217,30 +219,6 @@ async def make_something(self, foo, bar):
217
219
async def emit (self , event : Any ) -> None :
218
220
pass
219
221
220
- @abstractclassmethod
221
- def add_route (cls , route : str ,
222
- handler : Union [AbstractRoute , Callable ]) -> None :
223
- """ Expose local function through RPC
224
-
225
- :param route: Name which function will be aliased for this function.
226
- Remote side should call function by this name.
227
- :param handler: Function or Route class (classes based on
228
- :class:`wsrpc_aiohttp.WebSocketRoute`).
229
- For route classes the public methods will
230
- be registered automatically.
231
-
232
- .. note::
233
-
234
- Route classes might be initialized only once for the each
235
- socket instance.
236
-
237
- In case the method of class will be called first,
238
- :func:`wsrpc_aiohttp.WebSocketRoute.init` will be called
239
- without params before callable method.
240
-
241
- """
242
- raise NotImplementedError
243
-
244
222
@abstractmethod
245
223
def add_event_listener (self , func : EventListenerType ) -> None :
246
224
raise NotImplementedError
@@ -255,7 +233,8 @@ def remove_route(cls, route: str, fail=True):
255
233
256
234
raise NotImplementedError
257
235
258
- @abstractproperty
236
+ @property
237
+ @abstractmethod
259
238
def proxy (self ) -> Proxy :
260
239
""" Special property which allow run the remote functions
261
240
by `dot` notation
@@ -272,8 +251,39 @@ def proxy(self) -> Proxy:
272
251
273
252
274
253
RouteType = Union [
275
- Callable [[AbstactWSRPC , Any ], Any ],
276
- Callable [[AbstactWSRPC , Any ], Coroutine [Any , None , Any ]],
254
+ Callable [[WSRPCBase , Any ], Any ],
255
+ Callable [[WSRPCBase , Any ], Coroutine [Any , None , Any ]],
277
256
AbstractRoute
278
257
]
258
+
259
+
260
+ class AbstractWSRPC (WSRPCBase , ABC ):
261
+ @classmethod
262
+ @abstractmethod
263
+ def add_route (cls , route : str , handler : RouteType ) -> None :
264
+ """ Expose local function through RPC
265
+
266
+ :param route: Name which function will be aliased for this function.
267
+ Remote side should call function by this name.
268
+ :param handler: Function or Route class (classes based on
269
+ :class:`wsrpc_aiohttp.WebSocketRoute`).
270
+ For route classes the public methods will
271
+ be registered automatically.
272
+
273
+ .. note::
274
+
275
+ Route classes might be initialized only once for each
276
+ socket instance.
277
+
278
+ In case the method of class will be called first,
279
+ :func:`wsrpc_aiohttp.WebSocketRoute.init` will be called
280
+ without params before callable method.
281
+
282
+ """
283
+ raise NotImplementedError
284
+
285
+
286
+ # backward compatibility for typo
287
+ # noinspection SpellCheckingInspection
288
+ AbstactWSRPC = AbstractWSRPC
279
289
FrameMappingItemType = Mapping [IntEnum , Callable [[WSMessage ], Any ]]
0 commit comments