Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTS v21.12 Deprecations #2306

Merged
merged 28 commits into from Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4c12bb7
Begin deprecations for v21.12
ahopkins Nov 7, 2021
d52c954
Start slots
ahopkins Nov 8, 2021
9d422db
Use common deprecation convenience wrapper
ahopkins Dec 20, 2021
0815979
Add slots to Sanic and Blueprint
ahopkins Dec 20, 2021
c4a8f48
Reorganize modules
ahopkins Dec 20, 2021
6da3a78
Reorganize modules
ahopkins Dec 20, 2021
426ff8d
Begin cleaning up tests
ahopkins Dec 21, 2021
6dd89a5
Cleanup tests
ahopkins Dec 21, 2021
d693ffb
Deprecate register argument (#2342)
prryplatypus Dec 21, 2021
3b1f3c9
Resolve issues with existing tests
ahopkins Dec 23, 2021
6e18d79
Merge branch 'deprecations' of github.com:sanic-org/sanic into deprec…
ahopkins Dec 23, 2021
e65d720
Resolve merge conflicts
ahopkins Dec 23, 2021
8c15197
Resolve broken tests
ahopkins Dec 23, 2021
7c145f7
Add deprecation test
ahopkins Dec 23, 2021
c7759e2
Add deprecation test
ahopkins Dec 23, 2021
8b669c8
Version
ahopkins Dec 23, 2021
73c751d
Update changelog
ahopkins Dec 23, 2021
bb35492
Update tests/test_exceptions_handler.py
ahopkins Dec 23, 2021
f5187e6
Update examples/blueprints.py
ahopkins Dec 23, 2021
77ff8f6
Update examples/delayed_response.py
ahopkins Dec 23, 2021
8f05a80
Merge conflicts
ahopkins Dec 23, 2021
3ab870c
Merge branch 'deprecations' of github.com:sanic-org/sanic into deprec…
ahopkins Dec 23, 2021
a672e36
Update examples/modify_header_example.py
ahopkins Dec 23, 2021
4689bd5
Update examples/request_stream/server.py
ahopkins Dec 23, 2021
72892f1
Update tests/test_app.py
ahopkins Dec 23, 2021
e992138
Update tests/test_unix_socket.py
ahopkins Dec 23, 2021
f091321
Merge conflicts
ahopkins Dec 23, 2021
ebb50b7
squash
ahopkins Dec 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/add_task_sanic.py
Expand Up @@ -5,7 +5,7 @@
from sanic import Sanic


app = Sanic(__name__)
app = Sanic("Example")


async def notify_server_started_after_five_seconds():
Expand Down
2 changes: 1 addition & 1 deletion examples/amending_request_object.py
Expand Up @@ -4,7 +4,7 @@
from sanic.response import text


app = Sanic(__name__)
app = Sanic("Example")


@app.middleware("request")
Expand Down
2 changes: 1 addition & 1 deletion examples/authorized_sanic.py
Expand Up @@ -6,7 +6,7 @@
from sanic.response import json


app = Sanic(__name__)
app = Sanic("Example")


def check_request_for_authorization_status(request):
Expand Down
4 changes: 2 additions & 2 deletions examples/blueprint_middlware_execution_order.py
Expand Up @@ -8,9 +8,9 @@
On a valid request, it should print "1 2 3 6 5 4" to terminal
"""

app = Sanic(__name__)
app = Sanic("Example")

bp = Blueprint("bp_" + __name__)
bp = Blueprint("bp_example")


@bp.on_request
Expand Down
2 changes: 1 addition & 1 deletion examples/blueprints.py
Expand Up @@ -2,7 +2,7 @@
from sanic.response import file, json


app = Sanic(__name__)
app = Sanic("Example")
blueprint = Blueprint("name", url_prefix="/my_blueprint")
blueprint2 = Blueprint("name2", url_prefix="/my_blueprint2")
blueprint3 = Blueprint("name3", url_prefix="/my_blueprint3")
ahopkins marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/delayed_response.py
Expand Up @@ -3,7 +3,7 @@
from sanic import Sanic, response


app = Sanic(__name__, strict_slashes=True)
app = Sanic("DelayedResponseApp", strict_slashes=True)
ahopkins marked this conversation as resolved.
Show resolved Hide resolved


@app.get("/")
Expand Down
2 changes: 1 addition & 1 deletion examples/exception_monitoring.py
Expand Up @@ -41,7 +41,7 @@ def default(self, request, exception):


handler = CustomHandler()
app = Sanic(__name__, error_handler=handler)
app = Sanic("Example", error_handler=handler)


@app.route("/")
Expand Down
8 changes: 4 additions & 4 deletions examples/hello_world.py
@@ -1,13 +1,13 @@
from sanic import Sanic
from sanic import response
from sanic import Sanic, response

app = Sanic(__name__)

app = Sanic("Example")


@app.route("/")
async def test(request):
return response.json({"test": True})


if __name__ == '__main__':
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
2 changes: 1 addition & 1 deletion examples/limit_concurrency.py
Expand Up @@ -6,7 +6,7 @@
from sanic.response import json


app = Sanic(__name__)
app = Sanic("Example")

sem = None

Expand Down
2 changes: 1 addition & 1 deletion examples/log_request_id.py
Expand Up @@ -44,7 +44,7 @@ def filter(self, record):
}


app = Sanic(__name__, log_config=LOG_SETTINGS)
app = Sanic("Example", log_config=LOG_SETTINGS)


@app.on_request
Expand Down
2 changes: 1 addition & 1 deletion examples/logdna_example.py
Expand Up @@ -43,7 +43,7 @@ def get_mac_address():
logdna.setLevel(logging.INFO)
logdna.addHandler(logdna_handler)

app = Sanic(__name__)
app = Sanic("Example")


@app.middleware
Expand Down
23 changes: 12 additions & 11 deletions examples/modify_header_example.py
Expand Up @@ -2,27 +2,28 @@
Modify header or status in response
"""

from sanic import Sanic
from sanic import response
from sanic import Sanic, response

app = Sanic(__name__)

app = Sanic("Example")

@app.route('/')

@app.route("/")
def handle_request(request):
return response.json(
{'message': 'Hello world!'},
headers={'X-Served-By': 'sanic'},
status=200
{"message": "Hello world!"},
headers={"X-Served-By": "sanic"},
status=200,
)


@app.route('/unauthorized')
@app.route("/unauthorized")
def handle_request(request):
return response.json(
{'message': 'You are not authorized'},
headers={'X-Served-By': 'sanic'},
status=404
{"message": "You are not authorized"},
headers={"X-Served-By": "sanic"},
status=404,
)


app.run(host="0.0.0.0", port=8000, debug=True)
ahopkins marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion examples/pytest_xdist.py
Expand Up @@ -32,7 +32,7 @@ def test_port(worker_id):

@pytest.fixture(scope="session")
def app():
app = Sanic()
app = Sanic("Example")

@app.route("/")
async def index(request):
Expand Down
12 changes: 4 additions & 8 deletions examples/raygun_example.py
Expand Up @@ -8,7 +8,6 @@


class RaygunExceptionReporter(ErrorHandler):

def __init__(self, raygun_api_key=None):
super().__init__()
if raygun_api_key is None:
Expand All @@ -22,16 +21,13 @@ def default(self, request, exception):


raygun_error_reporter = RaygunExceptionReporter()
app = Sanic(__name__, error_handler=raygun_error_reporter)
app = Sanic("Example", error_handler=raygun_error_reporter)


@app.route("/raise")
async def test(request):
raise SanicException('You Broke It!')
raise SanicException("You Broke It!")


if __name__ == '__main__':
app.run(
host="0.0.0.0",
port=getenv("PORT", 8080)
)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=getenv("PORT", 8080))
18 changes: 9 additions & 9 deletions examples/redirect_example.py
@@ -1,18 +1,18 @@
from sanic import Sanic
from sanic import response
from sanic import Sanic, response

app = Sanic(__name__)


@app.route('/')
app = Sanic("Example")


@app.route("/")
def handle_request(request):
return response.redirect('/redirect')
return response.redirect("/redirect")
ahopkins marked this conversation as resolved.
Show resolved Hide resolved


@app.route('/redirect')
@app.route("/redirect")
async def test(request):
return response.json({"Redirected": True})


if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
40 changes: 19 additions & 21 deletions examples/request_stream/server.py
@@ -1,65 +1,63 @@
from sanic import Sanic
from sanic.views import CompositionView
from sanic.views import HTTPMethodView
from sanic.views import stream as stream_decorator
from sanic.blueprints import Blueprint
from sanic.response import stream, text
from sanic.views import HTTPMethodView
from sanic.views import stream as stream_decorator

bp = Blueprint('blueprint_request_stream')
app = Sanic('request_stream')

bp = Blueprint("blueprint_request_stream")
app = Sanic("request_stream")
ahopkins marked this conversation as resolved.
Show resolved Hide resolved

class SimpleView(HTTPMethodView):

class SimpleView(HTTPMethodView):
@stream_decorator
async def post(self, request):
result = ''
result = ""
while True:
body = await request.stream.get()
if body is None:
break
result += body.decode('utf-8')
result += body.decode("utf-8")
return text(result)


@app.post('/stream', stream=True)
@app.post("/stream", stream=True)
async def handler(request):
async def streaming(response):
while True:
body = await request.stream.get()
if body is None:
break
body = body.decode('utf-8').replace('1', 'A')
body = body.decode("utf-8").replace("1", "A")
await response.write(body)

return stream(streaming)


@bp.put('/bp_stream', stream=True)
@bp.put("/bp_stream", stream=True)
async def bp_handler(request):
result = ''
result = ""
while True:
body = await request.stream.get()
if body is None:
break
result += body.decode('utf-8').replace('1', 'A')
result += body.decode("utf-8").replace("1", "A")
return text(result)


async def post_handler(request):
result = ''
result = ""
while True:
body = await request.stream.get()
if body is None:
break
result += body.decode('utf-8')
result += body.decode("utf-8")
return text(result)


app.blueprint(bp)
app.add_route(SimpleView.as_view(), '/method_view')
view = CompositionView()
view.add(['POST'], post_handler, stream=True)
app.add_route(view, '/composition_view')
app.add_route(SimpleView.as_view(), "/method_view")


if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
16 changes: 9 additions & 7 deletions examples/request_timeout.py
@@ -1,21 +1,23 @@
import asyncio
from sanic import Sanic
from sanic import response

from sanic import Sanic, response
from sanic.config import Config
from sanic.exceptions import RequestTimeout


Config.REQUEST_TIMEOUT = 1
app = Sanic(__name__)
app = Sanic("Example")


@app.route('/')
@app.route("/")
async def test(request):
await asyncio.sleep(3)
return response.text('Hello, world!')
return response.text("Hello, world!")


@app.exception(RequestTimeout)
def timeout(request, exception):
return response.text('RequestTimeout from error_handler.', 408)
return response.text("RequestTimeout from error_handler.", 408)


app.run(host='0.0.0.0', port=8000)
app.run(host="0.0.0.0", port=8000)
14 changes: 6 additions & 8 deletions examples/rollbar_example.py
@@ -1,21 +1,22 @@
from os import getenv

import rollbar

from sanic.handlers import ErrorHandler
from sanic import Sanic
from sanic.exceptions import SanicException
from os import getenv
from sanic.handlers import ErrorHandler


rollbar.init(getenv("ROLLBAR_API_KEY"))


class RollbarExceptionHandler(ErrorHandler):

def default(self, request, exception):
rollbar.report_message(str(exception))
return super().default(request, exception)


app = Sanic(__name__, error_handler=RollbarExceptionHandler())
app = Sanic("Example", error_handler=RollbarExceptionHandler())


@app.route("/raise")
Expand All @@ -24,7 +25,4 @@ def create_error(request):


if __name__ == "__main__":
app.run(
host="0.0.0.0",
port=getenv("PORT", 8080)
)
app.run(host="0.0.0.0", port=getenv("PORT", 8080))
2 changes: 1 addition & 1 deletion examples/run_asgi.py
Expand Up @@ -11,7 +11,7 @@
from sanic import Sanic, response


app = Sanic(__name__)
app = Sanic("Example")


@app.route("/text")
Expand Down
2 changes: 1 addition & 1 deletion examples/run_async.py
Expand Up @@ -5,7 +5,7 @@
from sanic import Sanic, response


app = Sanic(__name__)
app = Sanic("Example")


@app.route("/")
Expand Down
2 changes: 1 addition & 1 deletion examples/run_async_advanced.py
Expand Up @@ -8,7 +8,7 @@
from sanic.server import AsyncioServer


app = Sanic(__name__)
app = Sanic("Example")


@app.before_server_start
Expand Down