This commit is contained in:
Raphael Deem
2017-07-12 20:19:30 -07:00
10 changed files with 653 additions and 25 deletions

View File

@@ -196,7 +196,7 @@ class Config(dict):
def load_environment_vars(self):
"""
Looks for any SANIC_ prefixed environment variables and applies
Looks for any ``SANIC_`` prefixed environment variables and applies
them to the configuration if present.
"""
for k, v in os.environ.items():

View File

@@ -211,8 +211,8 @@ class Unauthorized(SanicException):
:param scheme: Name of the authentication scheme to be used.
:param realm: Description of the protected area. (optional)
: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)
header that is generated. This is especially useful when
dealing with the Digest scheme. (optional)
"""
pass
@@ -235,9 +235,10 @@ def abort(status_code, message=None):
"""
Raise an exception based on SanicException. Returns the HTTP response
message appropriate for the given status code, unless provided.
:param status_code: The HTTP status code to return.
:param message: The HTTP response body. Defaults to the messages
in response.py for the given status code.
in response.py for the given status code.
"""
if message is None:
message = COMMON_STATUS_CODES.get(status_code,

View File

@@ -237,6 +237,7 @@ def json(body, status=200, headers=None,
content_type="application/json", **kwargs):
"""
Returns response object with body in json format.
:param body: Response data to be serialized.
:param status: Response code.
:param headers: Custom Headers.
@@ -250,6 +251,7 @@ def text(body, status=200, headers=None,
content_type="text/plain; charset=utf-8"):
"""
Returns response object with body in text format.
:param body: Response data to be encoded.
:param status: Response code.
:param headers: Custom Headers.
@@ -264,6 +266,7 @@ def raw(body, status=200, headers=None,
content_type="application/octet-stream"):
"""
Returns response object without encoding the body.
:param body: Response data.
:param status: Response code.
:param headers: Custom Headers.
@@ -276,6 +279,7 @@ def raw(body, status=200, headers=None,
def html(body, status=200, headers=None):
"""
Returns response object with body in html format.
:param body: Response data to be encoded.
:param status: Response code.
:param headers: Custom Headers.

View File

@@ -99,7 +99,16 @@ class Router:
return name, _type, pattern
def add(self, uri, methods, handler, host=None, strict_slashes=False):
"""Add a handler to the route list
:param uri: path to match
:param methods: sequence of accepted method names. If none are
provided, any method is allowed
:param handler: request handler function.
When executed, it should provide a response object.
:param strict_slashes: strict to trailing slash
:return: Nothing
"""
# add regular version
self._add(uri, methods, handler, host)