Cleanup and remove some deprecated code
This commit is contained in:
52
sanic/app.py
52
sanic/app.py
@@ -714,28 +714,6 @@ class Sanic:
|
||||
self._blueprint_order.append(blueprint)
|
||||
blueprint.register(self, options)
|
||||
|
||||
def register_blueprint(self, *args, **kwargs):
|
||||
"""
|
||||
Proxy method provided for invoking the :func:`blueprint` method
|
||||
|
||||
.. note::
|
||||
To be deprecated in 1.0. Use :func:`blueprint` instead.
|
||||
|
||||
:param args: Blueprint object or (list, tuple) thereof
|
||||
:param kwargs: option dictionary with blueprint defaults
|
||||
:return: None
|
||||
"""
|
||||
|
||||
if self.debug:
|
||||
warnings.simplefilter("default")
|
||||
warnings.warn(
|
||||
"Use of register_blueprint will be deprecated in "
|
||||
"version 1.0. Please use the blueprint method"
|
||||
" instead",
|
||||
DeprecationWarning,
|
||||
)
|
||||
return self.blueprint(*args, **kwargs)
|
||||
|
||||
def url_for(self, view_name: str, **kwargs):
|
||||
r"""Build a URL based on a view name and the values provided.
|
||||
|
||||
@@ -1026,7 +1004,6 @@ class Sanic:
|
||||
workers: int = 1,
|
||||
protocol: Optional[Type[Protocol]] = None,
|
||||
backlog: int = 100,
|
||||
stop_event: Any = None,
|
||||
register_sys_signals: bool = True,
|
||||
access_log: Optional[bool] = None,
|
||||
unix: Optional[str] = None,
|
||||
@@ -1056,9 +1033,6 @@ class Sanic:
|
||||
:param backlog: a number of unaccepted connections that the system
|
||||
will allow before refusing new connections
|
||||
:type backlog: int
|
||||
:param stop_event: event to be triggered
|
||||
before stopping the app - deprecated
|
||||
:type stop_event: None
|
||||
:param register_sys_signals: Register SIG* events
|
||||
:type register_sys_signals: bool
|
||||
:param access_log: Enables writing access logs (slows server)
|
||||
@@ -1086,13 +1060,6 @@ class Sanic:
|
||||
protocol = (
|
||||
WebSocketProtocol if self.websocket_enabled else HttpProtocol
|
||||
)
|
||||
if stop_event is not None:
|
||||
if debug:
|
||||
warnings.simplefilter("default")
|
||||
warnings.warn(
|
||||
"stop_event will be removed from future versions.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
# if access_log is passed explicitly change config.ACCESS_LOG
|
||||
if access_log is not None:
|
||||
self.config.ACCESS_LOG = access_log
|
||||
@@ -1149,7 +1116,6 @@ class Sanic:
|
||||
sock: Optional[socket] = None,
|
||||
protocol: Type[Protocol] = None,
|
||||
backlog: int = 100,
|
||||
stop_event: Any = None,
|
||||
access_log: Optional[bool] = None,
|
||||
unix: Optional[str] = None,
|
||||
return_asyncio_server=False,
|
||||
@@ -1182,9 +1148,6 @@ class Sanic:
|
||||
:param backlog: a number of unaccepted connections that the system
|
||||
will allow before refusing new connections
|
||||
:type backlog: int
|
||||
:param stop_event: event to be triggered
|
||||
before stopping the app - deprecated
|
||||
:type stop_event: None
|
||||
:param access_log: Enables writing access logs (slows server)
|
||||
:type access_log: bool
|
||||
:param return_asyncio_server: flag that defines whether there's a need
|
||||
@@ -1204,13 +1167,6 @@ class Sanic:
|
||||
protocol = (
|
||||
WebSocketProtocol if self.websocket_enabled else HttpProtocol
|
||||
)
|
||||
if stop_event is not None:
|
||||
if debug:
|
||||
warnings.simplefilter("default")
|
||||
warnings.warn(
|
||||
"stop_event will be removed from future versions.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
# if access_log is passed explicitly change config.ACCESS_LOG
|
||||
if access_log is not None:
|
||||
self.config.ACCESS_LOG = access_log
|
||||
@@ -1292,7 +1248,6 @@ class Sanic:
|
||||
loop=None,
|
||||
protocol=HttpProtocol,
|
||||
backlog=100,
|
||||
stop_event=None,
|
||||
register_sys_signals=True,
|
||||
run_async=False,
|
||||
auto_reload=False,
|
||||
@@ -1307,13 +1262,6 @@ class Sanic:
|
||||
context = create_default_context(purpose=Purpose.CLIENT_AUTH)
|
||||
context.load_cert_chain(cert, keyfile=key)
|
||||
ssl = context
|
||||
if stop_event is not None:
|
||||
if debug:
|
||||
warnings.simplefilter("default")
|
||||
warnings.warn(
|
||||
"stop_event will be removed from future versions.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
if self.config.PROXIES_COUNT and self.config.PROXIES_COUNT < 0:
|
||||
raise ValueError(
|
||||
"PROXIES_COUNT cannot be negative. "
|
||||
|
||||
@@ -136,15 +136,18 @@ class Request:
|
||||
return f"<{class_name}: {self.method} {self.path}>"
|
||||
|
||||
def body_init(self):
|
||||
""".. deprecated:: 20.3"""
|
||||
""".. deprecated:: 20.3
|
||||
To be removed in 21.3"""
|
||||
self.body = []
|
||||
|
||||
def body_push(self, data):
|
||||
""".. deprecated:: 20.3"""
|
||||
""".. deprecated:: 20.3
|
||||
To be removed in 21.3"""
|
||||
self.body.append(data)
|
||||
|
||||
def body_finish(self):
|
||||
""".. deprecated:: 20.3"""
|
||||
""".. deprecated:: 20.3
|
||||
To be removed in 21.3"""
|
||||
self.body = b"".join(self.body)
|
||||
|
||||
async def receive_body(self):
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import warnings
|
||||
|
||||
from functools import partial
|
||||
from mimetypes import guess_type
|
||||
from os import path
|
||||
@@ -26,6 +24,8 @@ class BaseHTTPResponse:
|
||||
self.asgi = False
|
||||
|
||||
def _encode_body(self, data):
|
||||
if data is None:
|
||||
return b""
|
||||
return data.encode() if hasattr(data, "encode") else data
|
||||
|
||||
def _parse_headers(self):
|
||||
@@ -45,7 +45,7 @@ class BaseHTTPResponse:
|
||||
body=b"",
|
||||
):
|
||||
""".. deprecated:: 20.3:
|
||||
This function is not public API and will be removed."""
|
||||
This function is not public API and will be removed in 21.3."""
|
||||
|
||||
# self.headers get priority over content_type
|
||||
if self.content_type and "Content-Type" not in self.headers:
|
||||
@@ -149,22 +149,15 @@ class HTTPResponse(BaseHTTPResponse):
|
||||
status=200,
|
||||
headers=None,
|
||||
content_type=None,
|
||||
body_bytes=b"",
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
self.content_type = content_type
|
||||
self.body = body_bytes if body is None else self._encode_body(body)
|
||||
self.body = self._encode_body(body)
|
||||
self.status = status
|
||||
self.headers = Header(headers or {})
|
||||
self._cookies = None
|
||||
|
||||
if body_bytes:
|
||||
warnings.warn(
|
||||
"Parameter `body_bytes` is deprecated, use `body` instead",
|
||||
DeprecationWarning,
|
||||
)
|
||||
|
||||
def output(self, version="1.1", keep_alive=False, keep_alive_timeout=None):
|
||||
body = b""
|
||||
if has_message_body(self.status):
|
||||
@@ -228,20 +221,10 @@ def text(
|
||||
:param content_type: the content type (string) of the response
|
||||
"""
|
||||
if not isinstance(body, str):
|
||||
warnings.warn(
|
||||
"Types other than str will be deprecated in future versions for"
|
||||
f" response.text, got type {type(body).__name__})",
|
||||
DeprecationWarning,
|
||||
raise TypeError(
|
||||
f"Bad body type. Expected str, got {type(body).__name__})"
|
||||
)
|
||||
# Type conversions are deprecated and quite b0rked but still supported for
|
||||
# text() until applications get fixed. This try-except should be removed.
|
||||
try:
|
||||
# Avoid repr(body).encode() b0rkage for body that is already encoded.
|
||||
# memoryview used only to test bytes-ishness.
|
||||
with memoryview(body):
|
||||
pass
|
||||
except TypeError:
|
||||
body = f"{body}" # no-op if body is already str
|
||||
|
||||
return HTTPResponse(
|
||||
body, status=status, headers=headers, content_type=content_type
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user