Browse Source
- Made server instance available in interceptors. - Fixed typo in variable namepull/45/head
7 changed files with 128 additions and 109 deletions
@ -1,11 +1,12 @@ |
|||||
from .middleware import Middleware |
from .middleware import Middleware |
||||
|
from .interceptor import Interceptor |
||||
from .namespace import Namespace |
from .namespace import Namespace |
||||
from .base_manager import BaseManager |
from .base_manager import BaseManager |
||||
from .pubsub_manager import PubSubManager |
from .pubsub_manager import PubSubManager |
||||
from .kombu_manager import KombuManager |
from .kombu_manager import KombuManager |
||||
from .redis_manager import RedisManager |
from .redis_manager import RedisManager |
||||
from .server import Server |
from .server import Server |
||||
from .util import apply_middleware |
from .util import apply_interceptor |
||||
|
|
||||
__all__ = [Middleware, Namespace, Server, BaseManager, PubSubManager, |
__all__ = [Interceptor, Middleware, Namespace, Server, BaseManager, |
||||
KombuManager, RedisManager, apply_middleware] |
PubSubManager, KombuManager, RedisManager, apply_interceptor] |
||||
|
@ -0,0 +1,17 @@ |
|||||
|
class Interceptor(object): |
||||
|
"""Base class for event handler interceptors.""" |
||||
|
|
||||
|
def __init__(self, server): |
||||
|
self.server = server |
||||
|
|
||||
|
def ignore_for(self, event, namespace): |
||||
|
return False |
||||
|
|
||||
|
def before_event(self, event, namespace, args): |
||||
|
pass |
||||
|
|
||||
|
def after_event(self, event, namespace, args): |
||||
|
pass |
||||
|
|
||||
|
def handle_exception(self, event, namespace, exc): |
||||
|
raise exc |
@ -1,16 +1,16 @@ |
|||||
def apply_middleware(middleware): |
def apply_interceptor(interceptor): |
||||
"""Returns a decorator for event handlers that adds the given |
"""Returns a decorator for event handlers that adds the given |
||||
middleware to the handler decorated with it. |
interceptor to the handler decorated with it. |
||||
|
|
||||
:param middleware: The middleware to add |
:param interceptor: The interceptor to add |
||||
|
|
||||
Ensure that you only add well-behaving decorators after this one |
Ensure that you only add well-behaving decorators after this one |
||||
(meaning such that preserve attributes) because you'll loose them |
(meaning such that preserve attributes) because you'll loose them |
||||
otherwise. |
otherwise. |
||||
""" |
""" |
||||
def wrapper(handler): |
def wrapper(handler): |
||||
if not hasattr(handler, '_sio_middlewares'): |
if not hasattr(handler, '_sio_interceptors'): |
||||
handler._sio_middlewares = [] |
handler._sio_interceptors = [] |
||||
handler._sio_middlewares.append(middleware) |
handler._sio_interceptors.append(interceptor) |
||||
return handler |
return handler |
||||
return wrapper |
return wrapper |
||||
|
Loading…
Reference in new issue