2021-03-17 18:55:52 +00:00
|
|
|
from typing import Any, Tuple
|
|
|
|
from warnings import warn
|
|
|
|
|
2021-01-28 07:18:06 +00:00
|
|
|
from sanic.mixins.exceptions import ExceptionMixin
|
|
|
|
from sanic.mixins.listeners import ListenerMixin
|
|
|
|
from sanic.mixins.middleware import MiddlewareMixin
|
|
|
|
from sanic.mixins.routes import RouteMixin
|
2021-03-14 08:09:07 +00:00
|
|
|
from sanic.mixins.signals import SignalMixin
|
2021-01-28 07:18:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BaseSanic(
|
|
|
|
RouteMixin,
|
|
|
|
MiddlewareMixin,
|
|
|
|
ListenerMixin,
|
|
|
|
ExceptionMixin,
|
2021-03-14 08:09:07 +00:00
|
|
|
SignalMixin,
|
2021-01-28 07:18:06 +00:00
|
|
|
):
|
2021-03-17 18:55:52 +00:00
|
|
|
__fake_slots__: Tuple[str, ...]
|
|
|
|
|
2021-03-21 08:09:31 +00:00
|
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
|
|
for base in BaseSanic.__bases__:
|
|
|
|
base.__init__(self, *args, **kwargs) # type: ignore
|
|
|
|
|
2021-03-03 14:58:18 +00:00
|
|
|
def __str__(self) -> str:
|
|
|
|
return f"<{self.__class__.__name__} {self.name}>"
|
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
return f'{self.__class__.__name__}(name="{self.name}")'
|
2021-03-17 18:55:52 +00:00
|
|
|
|
|
|
|
def __setattr__(self, name: str, value: Any) -> None:
|
|
|
|
# This is a temporary compat layer so we can raise a warning until
|
|
|
|
# setting attributes on the app instance can be removed and deprecated
|
|
|
|
# with a proper implementation of __slots__
|
|
|
|
if name not in self.__fake_slots__:
|
|
|
|
warn(
|
|
|
|
f"Setting variables on {self.__class__.__name__} instances is "
|
|
|
|
"deprecated and will be removed in version 21.9. You should "
|
|
|
|
f"change your {self.__class__.__name__} instance to use "
|
|
|
|
f"instance.ctx.{name} instead."
|
|
|
|
)
|
|
|
|
super().__setattr__(name, value)
|