From 918e2ba8d06ca0aff63cc2354539274a6a1f6105 Mon Sep 17 00:00:00 2001 From: zyguan Date: Mon, 24 Jul 2017 11:53:11 +0800 Subject: [PATCH 01/10] Revert "fix #752" This reverts commit 599fbcee6e1e427829a9f03de7f7aad2ee67ac22. --- sanic/app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index f1e8be7e..f0ccad86 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -33,9 +33,7 @@ class Sanic: logging.config.dictConfig(log_config) # Only set up a default log handler if the # end-user application didn't set anything up. - if not (logging.root.handlers and - log.level == logging.NOTSET and - log_config): + if not logging.root.handlers and log.level == logging.NOTSET: formatter = logging.Formatter( "%(asctime)s: %(levelname)s: %(message)s") handler = logging.StreamHandler() From da91b16244958b862b95077815e6a7d39b2d019b Mon Sep 17 00:00:00 2001 From: zyguan Date: Mon, 24 Jul 2017 18:21:15 +0800 Subject: [PATCH 02/10] add tests --- tests/test_logging.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/test_logging.py b/tests/test_logging.py index fc26ca93..d6911d86 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -1,5 +1,7 @@ -import asyncio import uuid +from importlib import reload + +from sanic.config import LOGGING from sanic.response import text from sanic import Sanic from io import StringIO @@ -10,6 +12,11 @@ function: %(funcName)s(); \ message: %(message)s''' +def reset_logging(): + logging.shutdown() + reload(logging) + + def test_log(): log_stream = StringIO() for handler in logging.root.handlers[:]: @@ -32,5 +39,19 @@ def test_log(): log_text = log_stream.getvalue() assert rand_string in log_text + +def test_default_log_fmt(): + + reset_logging() + Sanic() + for fmt in [h.formatter for h in logging.getLogger('sanic').handlers]: + assert fmt._fmt == LOGGING['formatters']['simple']['format'] + + reset_logging() + Sanic(log_config=None) + for fmt in [h.formatter for h in logging.getLogger('sanic').handlers]: + assert fmt._fmt == "%(asctime)s: %(levelname)s: %(message)s" + + if __name__ == "__main__": test_log() From 621343112d13010a228b39766c3b805ae8bd8993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Ma=C5=BEukna?= Date: Tue, 25 Jul 2017 13:29:17 +0300 Subject: [PATCH 03/10] Fix typo in documentation --- docs/sanic/versioning.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sanic/versioning.md b/docs/sanic/versioning.md index 85cbd278..ab6dab22 100644 --- a/docs/sanic/versioning.md +++ b/docs/sanic/versioning.md @@ -10,11 +10,11 @@ You can pass a version number to the routes directly. from sanic import response -@app.route('/text', verion=1) +@app.route('/text', version=1) def handle_request(request): return response.text('Hello world! Version 1') -@app.route('/text', verion=2) +@app.route('/text', version=2) def handle_request(request): return response.text('Hello world! Version 2') From 40776e5324f3d880e8b3c94cd0c5ebe786d41701 Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 26 Jul 2017 12:44:30 +0200 Subject: [PATCH 04/10] Comment: F821 undefined name is done on purpose Comment helps readers and `# noqa` silences linters --- tests/test_exceptions_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_exceptions_handler.py b/tests/test_exceptions_handler.py index 006c2cc4..6a959382 100644 --- a/tests/test_exceptions_handler.py +++ b/tests/test_exceptions_handler.py @@ -24,7 +24,7 @@ def handler_3(request): @exception_handler_app.route('/4') def handler_4(request): - foo = bar + foo = bar # noqa -- F821 undefined name 'bar' is done to throw exception return text(foo) From b65eb69d9f680cdd00644186b8b4518081401aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20KUBLER?= Date: Thu, 27 Jul 2017 23:00:27 +0200 Subject: [PATCH 05/10] Simplified the Unauthorized exception __init__ signature. (again). Use of **kwargs makes it more straight forward and easier to use. --- sanic/exceptions.py | 45 ++++++++++++++++++---------------------- tests/test_exceptions.py | 21 +++++++++---------- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/sanic/exceptions.py b/sanic/exceptions.py index 21ab2a94..d23fcfee 100644 --- a/sanic/exceptions.py +++ b/sanic/exceptions.py @@ -208,44 +208,39 @@ class Unauthorized(SanicException): """ Unauthorized exception (401 HTTP status code). + :param message: Message describing the exception. :param scheme: Name of the authentication scheme to be used. - :param challenge: A dict containing values to add to the WWW-Authenticate - header that is generated. This is especially useful when dealing with - the Digest scheme. (optional) + + When present, kwargs is used to complete the WWW-Authentication header. Examples:: # With a Basic auth-scheme, realm MUST be present: - challenge = {"realm": "Restricted Area"} - raise Unauthorized("Auth required.", "Basic", challenge) + raise Unauthorized("Auth required.", "Basic", realm="Restricted Area") # With a Digest auth-scheme, things are a bit more complicated: - challenge = { - "realm": "Restricted Area", - "qop": "auth, auth-int", - "algorithm": "MD5", - "nonce": "abcdef", - "opaque": "zyxwvu" - } - raise Unauthorized("Auth required.", "Digest", challenge) + raise Unauthorized("Auth required.", + "Digest", + realm="Restricted Area", + qop="auth, auth-int", + algorithm="MD5", + nonce="abcdef", + opaque="zyxwvu") - # With a Bearer auth-scheme, realm is optional: - challenge = {"realm": "Restricted Area"} - raise Unauthorized("Auth required.", "Bearer", challenge) + # With a Bearer auth-scheme, realm is optional so you can write: + raise Unauthorized("Auth required.", "Bearer") + + # or, if you want to specify the realm: + raise Unauthorized("Auth required.", "Bearer", realm="Restricted Area") """ - pass - - def __init__(self, message, scheme, challenge=None): + def __init__(self, message, scheme, **kwargs): super().__init__(message) - chal = "" - - if challenge is not None: - values = ["{!s}={!r}".format(k, v) for k, v in challenge.items()] - chal = ', '.join(values) + values = ["{!s}={!r}".format(k, v) for k, v in kwargs.items()] + challenge = ', '.join(values) self.headers = { - "WWW-Authenticate": "{} {}".format(scheme, chal).rstrip() + "WWW-Authenticate": "{} {}".format(scheme, challenge).rstrip() } diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 620e7891..1521c9ed 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -33,18 +33,17 @@ def exception_app(): @app.route('/401/basic') def handler_401_basic(request): - raise Unauthorized("Unauthorized", "Basic", {"realm": "Sanic"}) + raise Unauthorized("Unauthorized", "Basic", realm="Sanic") @app.route('/401/digest') def handler_401_digest(request): - challenge = { - "realm": "Sanic", - "qop": "auth, auth-int", - "algorithm": "MD5", - "nonce": "abcdef", - "opaque": "zyxwvu", - } - raise Unauthorized("Unauthorized", "Digest", challenge) + raise Unauthorized("Unauthorized", + "Digest", + realm="Sanic", + qop="auth, auth-int", + algorithm="MD5", + nonce="abcdef", + opaque="zyxwvu") @app.route('/401/bearer') def handler_401_bearer(request): @@ -122,7 +121,7 @@ def test_forbidden_exception(exception_app): request, response = exception_app.test_client.get('/403') assert response.status == 403 - + def test_unauthorized_exception(exception_app): """Test the built-in Unauthorized exception""" request, response = exception_app.test_client.get('/401/basic') @@ -132,7 +131,7 @@ def test_unauthorized_exception(exception_app): request, response = exception_app.test_client.get('/401/digest') assert response.status == 401 - + auth_header = response.headers.get('WWW-Authenticate') assert auth_header is not None assert auth_header.startswith('Digest') From eb8f65c58b1b02117dc795bf70869d77e0d6a2c2 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Thu, 27 Jul 2017 22:21:19 -0700 Subject: [PATCH 06/10] switch to use dist: precise --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d8e17093..afac549a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ sudo: false +dist: precise language: python cache: directories: From 69a8bb5e1f26b974ef6f57484eaeb73a9aa13245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20KUBLER?= Date: Fri, 28 Jul 2017 22:29:45 +0200 Subject: [PATCH 07/10] Fixed a trailing white space in the docstring. --- sanic/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/exceptions.py b/sanic/exceptions.py index d23fcfee..0edb0562 100644 --- a/sanic/exceptions.py +++ b/sanic/exceptions.py @@ -211,7 +211,7 @@ class Unauthorized(SanicException): :param message: Message describing the exception. :param scheme: Name of the authentication scheme to be used. - When present, kwargs is used to complete the WWW-Authentication header. + When present, kwargs is used to complete the WWW-Authentication header. Examples:: From 1b687f3feb3216fe2f37c4677723b7244041b951 Mon Sep 17 00:00:00 2001 From: akc Date: Tue, 1 Aug 2017 16:32:15 +0800 Subject: [PATCH 08/10] add some example links --- README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.rst b/README.rst index 410bd0b8..a9bfa982 100644 --- a/README.rst +++ b/README.rst @@ -55,6 +55,16 @@ Documentation :target: https://pypi.python.org/pypi/sanic/ .. |PyPI version| image:: https://img.shields.io/pypi/pyversions/sanic.svg :target: https://pypi.python.org/pypi/sanic/ + + +Examples +-------- +`Non-Core examples `_. Examples of plugins and Sanic that are outside the scope of Sanic core. + +`Extensions `_. Sanic extensions created by the community. + +`Projects `_. Sanic in production use. + TODO ---- From 9b3fbe45932b70d0872458e70cb39fd1688a3055 Mon Sep 17 00:00:00 2001 From: 7 Date: Wed, 2 Aug 2017 10:15:18 -0700 Subject: [PATCH 09/10] fixed small doc issue (#877) --- .gitignore | 1 + docs/sanic/testing.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 73e923d3..4a834a7a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ settings.py docs/_build/ docs/_api/ build/* +.DS_Store diff --git a/docs/sanic/testing.md b/docs/sanic/testing.md index b8427a00..0aca9184 100644 --- a/docs/sanic/testing.md +++ b/docs/sanic/testing.md @@ -59,7 +59,7 @@ the available arguments to aiohttp can be found [in the documentation for ClientSession](https://aiohttp.readthedocs.io/en/stable/client_reference.html#client-session). -# pytest-sanic +## pytest-sanic [pytest-sanic](https://github.com/yunstanford/pytest-sanic) is a pytest plugin, it helps you to test your code asynchronously. Just write tests like, From f80a6ae228cb0576f2c4660845210ed9da4241d9 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Wed, 2 Aug 2017 19:11:53 -0700 Subject: [PATCH 10/10] Increment to 0.6.0 --- sanic/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/__init__.py b/sanic/__init__.py index 4cc0710f..8f35a283 100644 --- a/sanic/__init__.py +++ b/sanic/__init__.py @@ -1,6 +1,6 @@ from sanic.app import Sanic from sanic.blueprints import Blueprint -__version__ = '0.5.4' +__version__ = '0.6.0' __all__ = ['Sanic', 'Blueprint']