Commit Graph

2312 Commits

Author SHA1 Message Date
Jacob
638322d905
docs: Fix doc build (#1833)
* docs: Fix doc build

* docs: Use python-3.8 instead

* test: Remove pytest-asyncio form tox.ini
2020-04-24 14:13:35 -07:00
wangqr
ae40f960ff
Import ASGIDispatch from top-level httpx (#1806)
As importing from submodules of httpx is deprecated and removed in 0.12.0
2020-04-10 12:03:51 -07:00
koug44
d969fdc19f
[Doc] Update getting_started.rst (#1814)
* Update getting_started.rst

Replacing command to install Sanic without uvloop as the provided one is not working (at least in my case)

* Same thing as oneliner

* Update getting_started.rst

Dummy commit for Travis
2020-04-09 10:07:07 -07:00
L. Kärkkäinen
710024125e
Remove server config args that can be read directly from app. (#1807)
* Remove server config args that can be read directly from app.

* Linter

Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
2020-04-08 22:10:58 -07:00
Mykhailo Yusko
9a39aff803
Replaced str.format() method in core functionality (#1819)
* Replaced str.format() method in core functionality

* Fixed linter checks
2020-04-06 12:45:25 -07:00
L. Kärkkäinen
78e912ea45
Update docs with changes done in 20.3 (#1822)
* Remove raw_args from docs (deprecated feature removed in Sanic 20.3).

* Add missing Sanic(name) arguments in docs. Merge async/non-async class view examples.

Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
2020-03-31 10:57:09 -07:00
L. Kärkkäinen
aa6ea5b5a0
Updated deployment docs (#1821)
* Updated deployment docs

* Wording and formatting.

Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
2020-03-28 11:43:42 -07:00
L. Kärkkäinen
48800e657f
Deprecation and test cleanup (#1818)
* Remove remove_route, deprecated in 19.6.

* No need for py35 compat anymore.

* Rewrite asyncio.coroutines with async/await.

* Remove deprecated request.raw_args.

* response.text() takes str only: avoid deprecation warning in all but one test.

* Remove unused import.

* Revert unnecessary deprecation warning.

* Remove apparently unnecessary py38 compat.

* Avoid asyncio.Task.all_tasks deprecation warning.

* Avoid warning on a test that tests deprecated response.text(int).

* Add pytest-asyncio to tox deps.

* Run the coroutine returned by AsyncioServer.close.

Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
2020-03-28 11:43:14 -07:00
L. Kärkkäinen
120f0262f7
Fix Ctrl+C and tests on Windows. (#1808)
* Fix Ctrl+C on Windows.

* Disable testing of a function N/A on Windows.

* Add test for coverage, avoid crash on missing _stopping.

* Initialise StreamingHTTPResponse.protocol = None

* Improved comments.

* Reduce amount of data in test_request_stream to avoid failures on Windows.

* The Windows test doesn't work on Windows :(

* Use port numbers more likely to be free than 8000.

* Disable the other signal tests on Windows as well.

* Windows doesn't properly support SO_REUSEADDR, so that's disabled in Python, and thus rebinding fails. For successful testing, reuse port instead.

* app.run argument handling: added server kwargs (alike create_server), added warning on extra kwargs, made auto_reload explicit argument. Another go at Windows tests

* Revert "app.run argument handling: added server kwargs (alike create_server), added warning on extra kwargs, made auto_reload explicit argument. Another go at Windows tests"

This reverts commit dc5d682448.

* Use random test server port on most tests. Should avoid port/addr reuse issues.

* Another test to random port instead of 8000.

* Fix deprecation warnings about missing name on Sanic() in tests.

* Linter and typing

* Increase test coverage

* Rewrite test for ctrlc_windows_workaround

* py36 compat

* py36 compat

* py36 compat

* Don't rely on loop internals but add a stopping flag to app.

* App may be restarted.

* py36 compat

* Linter

* Add a constant for OS checking.

Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
2020-03-25 21:42:46 -07:00
L. Kärkkäinen
4db075ffc1
Streaming migration for 20.3 release (#1800)
* Compatibility and deprecations for Sanic 20.3 in preparation of the streaming branch.

* Add test for new API.

* isort tests

* More coverage

* json takes str, not bytes

Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
2020-03-24 10:11:09 -07:00
Kevin Guillaumond
60b4efad67
Update config docs to match DEFAULT_CONFIG (#1803)
* Set REAL_IP_HEADER's default value to "X-Real-IP"

* Update config instead
2020-03-14 08:57:39 -07:00
L. Kärkkäinen
319388d78b
Remove the old request context API deprecated in 19.9. Use request.ctx instead. (#1801)
Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
2020-03-05 21:40:46 -08:00
Subham Roy
ce71514d71
bump httpx dependency version to 0.11.1 (#1794) 2020-03-01 11:42:11 -08:00
L. Kärkkäinen
7833d70d9e
Allow multiple workers on MacOS with Python 3.8. Fallback to single worker on Windows until pickling can be fixed. (#1798) 2020-03-01 11:41:09 -08:00
Mykhailo Yusko
16961fab9d
Use f-strings instead of str.format() (#1793) 2020-02-25 14:01:13 -06:00
L. Kärkkäinen
861e87347a
Fix #1788 incorrect url_for for routes with hosts, added tests. (#1789)
* Fix #1788 incorrect url_for for routes with hosts, added tests.

* Linter

* Remove debug print
2020-02-21 09:10:22 -08:00
Tim Gates
91f6abaa81
Fix simple typo: viewes -> views (#1783)
Closes #1782
2020-02-17 10:16:58 -06:00
Eli Uriegas
d380b52f9a
Merge pull request #1784 from gdub/changelog_correction
Corrected changelog for docs move of MD to RST (#1691).
2020-02-15 17:09:41 -08:00
Gary Wilson Jr
d656a06a19 Corrected changelog for docs move of MD to RST (#1691). 2020-02-11 11:45:56 -06:00
Adam Hopkins
258dbee3b9
Py38 tox env (#1752)
* Set version

Set version

* Add Python 3.8 to tests and package classifiers

Add Python3.8 to Appveyor config
2020-02-05 13:17:55 -06:00
Sudeep Mandal
6b9287b076
Update README re: experimental support for Windows (#1778)
As mentioned in #1517 , Windows support is "experimental" and does not currently support multiple workers.
2020-02-03 10:27:56 -06:00
L. Kärkkäinen
dac0514441 Code cleanup in file responses (#1769)
* Code cleanup in file responses.

* Lint
2020-01-26 22:08:34 -08:00
L. Kärkkäinen
bffdb3b5c2 More robust response datatype handling (#1674)
* HTTP1 header formatting moved to headers.format_headers and rewritten.

- New implementation is one line of code and twice faster than the old one.
- Whole header block encoded to UTF-8 in one pass.
- No longer supports custom encode method on header values.
- Cookie objects now have __str__ in addition to encode, to work with this.

* Linter

* format_http1_response

* Replace encode_body with faster implementation based on f-string.

Benchmarks:

def encode_body(data):
    try:
        # Try to encode it regularly
        return data.encode()
    except AttributeError:
        # Convert it to a str if you can't
        return str(data).encode()

def encode_body2(data):
    return f"{data}".encode()

def encode_body3(data):
    return str(data).encode()

data_str, data_int = "foo", 123

%timeit encode_body(data_int)
928 ns ± 2.96 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit encode_body2(data_int)
280 ns ± 2.09 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit encode_body3(data_int)
387 ns ± 1.7 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit encode_body(data_str)
202 ns ± 1.9 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit encode_body2(data_str)
197 ns ± 0.507 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

%timeit encode_body3(data_str)
313 ns ± 1.28 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

* Wtf linter

* Content-type fixes.

* Body encoding sanitation, first pass.
- body/data type autodetection fixed.
- do not repr(body).encode() bytes-ish values.
- support __html__ and _repr_html_ in sanic.response.html().

* <any type>-to-str response autoconversion limited to sanic.response.text() only.

* Workaround MyPy issue.

* Add an empty line to make isort happy.

* Add html test for __html__ and _repr_html_.

* Remove StreamingHTTPResponse.get_headers helper function.

* Add back HTTPResponse Keep-Alive removed by earlier merge or something.

* Revert "Remove StreamingHTTPResponse.get_headers helper function."

Tests depend on this otherwise useless function.

This reverts commit 9651e6ae01.

* Add deprecation warnings; instead of assert for wrong HTTP version, and for non-string response.text.

* Add back missing import.

* Avoid duplicate response header tweaking code.

* Linter errors
2020-01-20 10:34:32 -06:00
L. Kärkkäinen
e908ca8cef [Trio] Quick fixes to make Sanic usable on hypercorn -k trio myweb.app (#1767)
* Quick fixes to make Sanic usable on hypercorn -k trio myweb.app

* Quick'n dirty compatibility and autodetection of hypercorn trio mode.

* mypy ignore for aiofiles/trio.

* lint
2020-01-20 10:29:06 -06:00
Ashley Sommer
801595e24a Add server.start_serving and server.serve_forever to AsyncioServer proxy object, to match asyncio-python3.7 example doc, fixes #1754 (#1762) 2020-01-20 09:00:48 -06:00
L. Kärkkäinen
ba9b432993 No tracebacks on normal errors and prettier error pages (#1768)
* Default error handler now only logs traceback on 500 errors and all responses are HTML formatted.

* Tests passing.

* Ability to flag any exception object with self.quiet = True following @ashleysommer suggestion.

* Refactor HTML formatting into errorpages.py. String escapes for debug tracebacks.

* Remove extra includes

* Auto-set quiet flag also when decorator is used.

* Cleanup, make error pages (probably) HTML5-compliant and similar for debug and non-debug modes.

* Fix lookup of non-existant status codes

* No logging of 503 errors after all.

* lint
2020-01-20 08:58:14 -06:00
Ashley Sommer
b565072ed9 Allow route decorators to stack up again (#1764)
* Allow route decorators to stack up without causing a function signature inspection crash
Fix #1742

* Apply fix to @websocket routes docorator too
Add test for double-stacked websocket decorator
remove introduction of new variable in route wrapper, extend routes in-place.
Add explanation of why a handler will be a tuple in the case of a double-stacked route decorator
2020-01-10 21:50:16 -08:00
Ashley Sommer
caa1b4d69b Fix dangling comma in arguments list for HTTPResponse in response.empty() (#1761)
* Fix dangling comma arguments list for HTTPResponse in response.empty()

* Found another black error, including another dangling comma
2020-01-10 19:58:01 -08:00
Liran Nuna
865536c5c4 Simplify status code to text lookup (#1738) 2020-01-10 08:43:44 -06:00
Eli Uriegas
784d5cce52
Merge pull request #1755 from Lagicrus/empty-response
Update docs
2020-01-04 19:15:24 -08:00
Lagicrus
0fd08c6114 Update response.rst 2020-01-04 21:26:03 +00:00
Lagicrus
cd779b6e4f Update response.rst 2020-01-04 19:51:50 +00:00
好风
3430907046 fix 1748 : Drop DeprecationWarning in python 3.8 (#1750)
https://github.com/huge-success/sanic/issues/1748
2020-01-03 20:20:42 -08:00
Eli Uriegas
2f776eba85
Release v19.12.0 (#1747)
Release v19.12.0
2020-01-03 11:50:33 -08:00
Adam Hopkins
b9cd2ed1f1
Merge pull request #1751 from huge-success/master
Move Release into LTS Branch
2020-01-02 23:45:08 +02:00
Adam Hopkins
850b63f642
Merge pull request #1743 from eric-nieuwland/master
Forgotten slot
2020-01-02 23:17:35 +02:00
Eric Nieuwland
a9c669f17b
Forgotten slot
Crashes the server at __init__() time
2019-12-28 15:21:27 +01:00
Stephen Sadowski
075affec23
Release v19.12.0 (#1740)
* Bumping up version from 19.9.0 to 19.12.0

* Pipfile crud removed
2019-12-27 07:10:46 -06:00
Stephen Sadowski
3411a12c40 Pipfile crud removed 2019-12-26 18:50:52 -06:00
Stephen Sadowski
28899356c8 Bumping up version from 19.12.0 to 19.12.0 2019-12-26 18:47:56 -06:00
Eli Uriegas
2b5f8d20de ci: Add python nightlies to test matrix (#1710)
Signed-off-by: Eli Uriegas <seemethere101@gmail.com>
2019-12-25 16:50:31 -08:00
Adam Hopkins
243f240e5f Add RFC labels to stale exclusion list (#1737) 2019-12-23 17:31:33 -06:00
L. Kärkkäinen
0a25868a86 HTTP1 header formatting moved to headers.format_headers and rewritten. (#1669)
* HTTP1 header formatting moved to headers.format_headers and rewritten.

- New implementation is one line of code and twice faster than the old one.
- Whole header block encoded to UTF-8 in one pass.
- No longer supports custom encode method on header values.
- Cookie objects now have __str__ in addition to encode, to work with this.

* Add an import missed in merge.
2019-12-23 17:30:45 -06:00
Liran Nuna
fccbc1adc4 Allow empty body without Content-Type; Introduce response.empty() (#1736) 2019-12-23 14:16:53 -06:00
Adam Hopkins
3f6a978328 Swap out requests-async for httpx (#1728)
* Begin swap of requests-async for httpx

* Finalize httpx adoption and resolve tests

Resolve linting and formatting

* Remove documentation references to requests-async in favor of httpx
2019-12-20 19:23:52 -08:00
Harsha Narayana
a6077a1790 GIT-37: fix blueprint middleware application (#1690)
* GIT-37: fix blueprint middleware application

1. If you register a middleware via `@blueprint.middleware` then it will apply only to the routes defined by the blueprint.
2. If you register a middleware via `@blueprint_group.middleware` then it will apply to all blueprint based routes that are part of the group.
3. If you define a middleware via `@app.middleware` then it will be applied on all available routes

Fixes #37

Signed-off-by: Harsha Narayana <harsha2k4@gmail.com>

* GIT-37: add changelog

Signed-off-by: Harsha Narayana <harsha2k4@gmail.com>
2019-12-20 10:01:04 -06:00
Eli Uriegas
179a07942e
Merge pull request #1734 from seemethere/testing_host
testing: Add host argument to SanicTestClient
2019-12-18 16:50:59 -08:00
Eli Uriegas
c3aed01096
testing: Add host argument to SanicTestClient
Adds the ability to specify a host argument when using the
SanicTestClient.

Signed-off-by: Eli Uriegas <eliuriegas@fb.com>
2019-12-18 16:31:38 -08:00
7
028778ed56 Fix #1714 (#1716)
* fix abort call errors out when calling inside stream handler

* handle pending task properly after cleanup
2019-12-16 09:46:18 -06:00
Adam Bannister
2d72874b0b Add return type to Sanic.create_server for type hinting and docs (#1724)
* add type hint and doc when create_server returns AsyncioServer

* fix linting
2019-12-12 10:25:13 -06:00