Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

middleware.py 756B

1 year ago
123456789101112131415161718192021222324
  1. class BaseMiddleware:
  2. """
  3. Base class for implementing ASGI middleware.
  4. Note that subclasses of this are not self-safe; don't store state on
  5. the instance, as it serves multiple application instances. Instead, use
  6. scope.
  7. """
  8. def __init__(self, inner):
  9. """
  10. Middleware constructor - just takes inner application.
  11. """
  12. self.inner = inner
  13. async def __call__(self, scope, receive, send):
  14. """
  15. ASGI application; can insert things into the scope and run asynchronous
  16. code.
  17. """
  18. # Copy scope to stop changes going upstream
  19. scope = dict(scope)
  20. # Run the inner application along with the scope
  21. return await self.inner(scope, receive, send)