You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
573 B

def apply_middleware(middleware):
"""Returns a decorator for event handlers that adds the given
middleware to the handler decorated with it.
:param middleware: The middleware to add
Ensure that you only add well-behaving decorators after this one
(meaning such that preserve attributes) because you'll loose them
otherwise.
"""
def wrapper(handler):
if not hasattr(handler, '_sio_middlewares'):
handler._sio_middlewares = []
handler._sio_middlewares.append(middleware)
return handler
return wrapper