11import asyncio
2- from abc import (
3- ABC , abstractmethod , abstractclassmethod , abstractproperty ,
4- abstractstaticmethod
5- )
2+ from abc import ABC , abstractmethod
63from enum import IntEnum
74from typing import Any , Mapping , Coroutine , Union , Callable , Dict , Tuple
85
@@ -16,7 +13,8 @@ class AbstractWebSocket(ABC):
1613 def __init__ (self , request : Request ):
1714 raise NotImplementedError (request )
1815
19- @abstractclassmethod
16+ @classmethod
17+ @abstractmethod
2018 def configure (cls , keepalive_timeout : int ,
2119 client_timeout : int ,
2220 max_concurrent_requests : int ) -> None :
@@ -55,7 +53,8 @@ async def authorize(self) -> bool:
5553 async def __handle_request (self ) -> WebSocketResponse :
5654 raise NotImplementedError
5755
58- @abstractclassmethod
56+ @classmethod
57+ @abstractmethod
5958 def broadcast (
6059 cls , func , callback = None , return_exceptions = True ,
6160 ** kwargs : Mapping [str , Any ]
@@ -115,7 +114,7 @@ def __getattr__(self, item: str):
115114EventListenerType = Callable [[Dict [str , Any ]], Any ]
116115
117116
118- class AbstactWSRPC (ABC ):
117+ class WSRPCBase (ABC ):
119118 @abstractmethod
120119 def __init__ (self , loop : asyncio .AbstractEventLoop = None ,
121120 timeout : Union [int , float ] = None ):
@@ -138,28 +137,31 @@ async def handle_message(self, message: WSMessage):
138137 async def _on_message (self , msg : WSMessage ):
139138 raise NotImplementedError
140139
141- @abstractclassmethod
140+ @classmethod
141+ @abstractmethod
142142 def get_routes (cls ) -> Mapping [str , "RouteType" ]:
143143 raise NotImplementedError
144144
145145 @classmethod
146- def get_clients (cls ) -> Dict [str , "AbstactWSRPC " ]:
146+ def get_clients (cls ) -> Dict [str , "AbstractWSRPC " ]:
147147 raise NotImplementedError
148148
149- @abstractproperty
149+ @property
150+ @abstractmethod
150151 def routes (self ) -> Dict [str , "RouteType" ]:
151152 raise NotImplementedError
152153
153154 @property
154- def clients (self ) -> Dict [str , "AbstactWSRPC " ]:
155+ def clients (self ) -> Dict [str , "AbstractWSRPC " ]:
155156 """ Property which contains the socket clients """
156157 raise NotImplementedError
157158
158159 @abstractmethod
159160 def prepare_args (self , args ) -> Tuple [Tuple [Any , ...], Dict [str , Any ]]:
160161 raise NotImplementedError
161162
162- @abstractstaticmethod
163+ @staticmethod
164+ @abstractmethod
163165 def is_route (func ) -> bool :
164166 raise NotImplementedError
165167
@@ -217,30 +219,6 @@ async def make_something(self, foo, bar):
217219 async def emit (self , event : Any ) -> None :
218220 pass
219221
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-
244222 @abstractmethod
245223 def add_event_listener (self , func : EventListenerType ) -> None :
246224 raise NotImplementedError
@@ -255,7 +233,8 @@ def remove_route(cls, route: str, fail=True):
255233
256234 raise NotImplementedError
257235
258- @abstractproperty
236+ @property
237+ @abstractmethod
259238 def proxy (self ) -> Proxy :
260239 """ Special property which allow run the remote functions
261240 by `dot` notation
@@ -272,8 +251,39 @@ def proxy(self) -> Proxy:
272251
273252
274253RouteType = 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 ]],
277256 AbstractRoute
278257]
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
279289FrameMappingItemType = Mapping [IntEnum , Callable [[WSMessage ], Any ]]
0 commit comments