예제 #1
0
 def init(self):
     deprecation(
         "AsyncioServer.init has been deprecated and will be removed "
         "in v22.6. Use Sanic.state.is_started instead.",
         22.6,
     )
     return self.app.state.is_started
예제 #2
0
    def finalize(
        cls,
        error_handler: ErrorHandler,
        config: Config,
        fallback: Optional[str] = None,
    ):
        if fallback:
            deprecation(
                "Setting the ErrorHandler fallback value via finalize() "
                "is deprecated and no longer supported. This feature will "
                "be removed in v22.6. Instead, use "
                "app.config.FALLBACK_ERROR_FORMAT.",
                22.6,
            )

        if not fallback:
            fallback = config.FALLBACK_ERROR_FORMAT

        if fallback != DEFAULT_FORMAT:
            if error_handler._fallback is not _default:
                error_logger.warning(
                    f"Setting the fallback value to {fallback}. This changes "
                    "the current non-default value "
                    f"'{error_handler._fallback}'.")
            error_handler._fallback = fallback

        if not isinstance(error_handler, cls):
            error_logger.warning(
                f"Error handler is non-conforming: {type(error_handler)}")
예제 #3
0
            def visit_Return(self, node: Return) -> Any:
                nonlocal types

                with suppress(AttributeError):
                    if node.value.func.id == "stream":  # type: ignore
                        deprecation(
                            "The sanic.response.stream method has been "
                            "deprecated and will be removed in v22.6. Please "
                            "upgrade your application to use the new style "
                            "streaming pattern. See "
                            "https://sanicframework.org/en/guide/advanced/"
                            "streaming.html#response-streaming for more "
                            "information.",
                            22.6,
                        )
                    checks = [node.value.func.id]  # type: ignore
                    if node.value.keywords:  # type: ignore
                        checks += [
                            k.value
                            for k in node.value.keywords  # type: ignore
                            if k.arg == "content_type"
                        ]

                    for check in checks:
                        if check in RESPONSE_MAPPING:
                            types.add(RESPONSE_MAPPING[check])
예제 #4
0
 def _warn_fallback_deprecation():
     deprecation(
         "Setting the ErrorHandler fallback value directly is "
         "deprecated and no longer supported. This feature will "
         "be removed in v22.6. Instead, use "
         "app.config.FALLBACK_ERROR_FORMAT.",
         22.6,
     )
예제 #5
0
    def load_environment_vars(self, prefix=SANIC_PREFIX):
        """
        Looks for prefixed environment variables and applies them to the
        configuration if present. This is called automatically when Sanic
        starts up to load environment variables into config.

        It will automatically hydrate the following types:

        - ``int``
        - ``float``
        - ``bool``

        Anything else will be imported as a ``str``. If you would like to add
        additional types to this list, you can use
        :meth:`sanic.config.Config.register_type`. Just make sure that they
        are registered before you instantiate your application.

        .. code-block:: python

            class Foo:
                def __init__(self, name) -> None:
                    self.name = name


            config = Config(converters=[Foo])
            app = Sanic(__name__, config=config)

        `See user guide re: config
        <https://sanicframework.org/guide/deployment/configuration.html>`__
        """
        lower_case_var_found = False
        for key, value in environ.items():
            if not key.startswith(prefix):
                continue
            if not key.isupper():
                lower_case_var_found = True

            _, config_key = key.split(prefix, 1)

            for converter in reversed(self._converters):
                try:
                    self[config_key] = converter(value)
                    break
                except ValueError:
                    pass
        if lower_case_var_found:
            deprecation(
                "Lowercase environment variables will not be "
                "loaded into Sanic config beginning in v22.9.",
                22.9,
            )
예제 #6
0
 def _post_set(self, attr, value) -> None:
     if self.get("_init"):
         if attr in (
                 "REQUEST_MAX_HEADER_SIZE",
                 "REQUEST_BUFFER_SIZE",
                 "REQUEST_MAX_SIZE",
         ):
             self._configure_header_size()
         elif attr == "LOGO":
             self._LOGO = value
             deprecation(
                 "Setting the config.LOGO is deprecated and will no longer "
                 "be supported starting in v22.6.",
                 22.6,
             )
예제 #7
0
    def finalize(
        cls,
        error_handler: ErrorHandler,
        fallback: Optional[str] = None,
        config: Optional[Config] = None,
    ):
        if fallback:
            deprecation(
                "Setting the ErrorHandler fallback value via finalize() "
                "is deprecated and no longer supported. This feature will "
                "be removed in v22.6. Instead, use "
                "app.config.FALLBACK_ERROR_FORMAT.",
                22.6,
            )

        if config is None:
            deprecation(
                "Starting in v22.3, config will be a required argument "
                "for ErrorHandler.finalize().",
                22.3,
            )

        if fallback and fallback != DEFAULT_FORMAT:
            if error_handler._fallback is not _default:
                error_logger.warning(
                    f"Setting the fallback value to {fallback}. This changes "
                    "the current non-default value "
                    f"'{error_handler._fallback}'."
                )
            error_handler._fallback = fallback

        if not isinstance(error_handler, cls):
            error_logger.warning(
                f"Error handler is non-conforming: {type(error_handler)}"
            )

        sig = signature(error_handler.lookup)
        if len(sig.parameters) == 1:
            deprecation(
                "You are using a deprecated error handler. The lookup "
                "method should accept two positional parameters: "
                "(exception, route_name: Optional[str]). "
                "Until you upgrade your ErrorHandler.lookup, Blueprint "
                "specific exceptions will not work properly. Beginning "
                "in v22.3, the legacy style lookup method will not "
                "work at all.",
                22.3,
            )
            legacy_lookup = error_handler._legacy_lookup
            error_handler._lookup = legacy_lookup  # type: ignore
예제 #8
0
 def __init__(
     self,
     *args,
     websocket_timeout: float = 10.0,
     websocket_max_size: Optional[int] = None,
     websocket_max_queue: Optional[int] = None,  # max_queue is deprecated
     websocket_read_limit: Optional[int] = None,  # read_limit is deprecated
     websocket_write_limit: Optional[int] = None,  # write_limit deprecated
     websocket_ping_interval: Optional[float] = 20.0,
     websocket_ping_timeout: Optional[float] = 20.0,
     **kwargs,
 ):
     super().__init__(*args, **kwargs)
     self.websocket: Optional[WebsocketImplProtocol] = None
     self.websocket_timeout = websocket_timeout
     self.websocket_max_size = websocket_max_size
     if websocket_max_queue is not None and websocket_max_queue > 0:
         # TODO: Reminder remove this warning in v22.3
         deprecation(
             "Websocket no longer uses queueing, so websocket_max_queue"
             " is no longer required.",
             22.3,
         )
     if websocket_read_limit is not None and websocket_read_limit > 0:
         # TODO: Reminder remove this warning in v22.3
         deprecation(
             "Websocket no longer uses read buffers, so "
             "websocket_read_limit is not required.",
             22.3,
         )
     if websocket_write_limit is not None and websocket_write_limit > 0:
         # TODO: Reminder remove this warning in v22.3
         deprecation(
             "Websocket no longer uses write buffers, so "
             "websocket_write_limit is not required.",
             22.3,
         )
     self.websocket_ping_interval = websocket_ping_interval
     self.websocket_ping_timeout = websocket_ping_timeout
예제 #9
0
def test_deprecation():
    message = r"\[DEPRECATION v9\.9\] hello"
    with pytest.warns(DeprecationWarning, match=message):
        deprecation("hello", 9.9)