From a03f216f42f36cb7acdaca7259d031e4aa10f21a Mon Sep 17 00:00:00 2001 From: Sean Parsons Date: Sun, 25 Dec 2016 00:47:51 -0500 Subject: [PATCH 1/4] Added additional docstrings to blueprints.py --- sanic/blueprints.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/sanic/blueprints.py b/sanic/blueprints.py index 92e376f1..af5ab337 100644 --- a/sanic/blueprints.py +++ b/sanic/blueprints.py @@ -3,6 +3,7 @@ from collections import defaultdict class BlueprintSetup: """ + Creates a blueprint state like object. """ def __init__(self, blueprint, app, options): @@ -29,13 +30,13 @@ class BlueprintSetup: def add_exception(self, handler, *args, **kwargs): """ - Registers exceptions to sanic + Registers exceptions to sanic. """ self.app.exception(*args, **kwargs)(handler) def add_static(self, uri, file_or_directory, *args, **kwargs): """ - Registers static files to sanic + Registers static files to sanic. """ if self.url_prefix: uri = self.url_prefix + uri @@ -44,7 +45,7 @@ class BlueprintSetup: def add_middleware(self, middleware, *args, **kwargs): """ - Registers middleware to sanic + Registers middleware to sanic. """ if args or kwargs: self.app.middleware(*args, **kwargs)(middleware) @@ -73,11 +74,13 @@ class Blueprint: def make_setup_state(self, app, options): """ + Returns a new BlueprintSetup object """ return BlueprintSetup(self, app, options) def register(self, app, options): """ + Registers the blueprint to the sanic app. """ state = self.make_setup_state(app, options) for deferred in self.deferred_functions: @@ -85,6 +88,9 @@ class Blueprint: def route(self, uri, methods=None): """ + Creates a blueprint route from a decorated function. + :param uri: Endpoint at which the route will be accessible. + :param methods: List of acceptable HTTP methods. """ def decorator(handler): self.record(lambda s: s.add_route(handler, uri, methods)) @@ -93,12 +99,18 @@ class Blueprint: def add_route(self, handler, uri, methods=None): """ + Creates a blueprint route from a function. + :param handler: Function to handle uri request. + :param uri: Endpoint at which the route will be accessible. + :param methods: List of acceptable HTTP methods. """ self.record(lambda s: s.add_route(handler, uri, methods)) return handler def listener(self, event): """ + Create a listener from a decorated function. + :param event: Event to listen to. """ def decorator(listener): self.listeners[event].append(listener) @@ -107,6 +119,7 @@ class Blueprint: def middleware(self, *args, **kwargs): """ + Creates a blueprint middleware from a decorated function. """ def register_middleware(middleware): self.record( @@ -123,6 +136,7 @@ class Blueprint: def exception(self, *args, **kwargs): """ + Creates a blueprint exception from a decorated function. """ def decorator(handler): self.record(lambda s: s.add_exception(handler, *args, **kwargs)) @@ -131,6 +145,9 @@ class Blueprint: def static(self, uri, file_or_directory, *args, **kwargs): """ + Creates a blueprint static route from a decorated function. + :param uri: Endpoint at which the route will be accessible. + :param file_or_directory: Static asset. """ self.record( lambda s: s.add_static(uri, file_or_directory, *args, **kwargs)) From 2b10860c32a6a96dbb66199027480068b0d9b49a Mon Sep 17 00:00:00 2001 From: Sean Parsons Date: Sun, 25 Dec 2016 01:05:26 -0500 Subject: [PATCH 2/4] Added docstrings to sanic.response.py for issue 41 --- sanic/response.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sanic/response.py b/sanic/response.py index 2c4c7f27..5031b1c8 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -139,21 +139,45 @@ class HTTPResponse: def json(body, status=200, headers=None): + """ + Returns serialized python object to json format. + :param body: Response data to be serialized. + :param status: Response code. + :param headers: Custom Headers. + """ return HTTPResponse(json_dumps(body), headers=headers, status=status, content_type="application/json") def text(body, status=200, headers=None): + """ + Returns body in text format. + :param body: Response data to be encoded. + :param status: Response code. + :param headers: Custom Headers. + """ return HTTPResponse(body, status=status, headers=headers, content_type="text/plain; charset=utf-8") def html(body, status=200, headers=None): + """ + Returns body in html format. + :param body: Response data to be encoded. + :param status: Response code. + :param headers: Custom Headers. + """ return HTTPResponse(body, status=status, headers=headers, content_type="text/html; charset=utf-8") async def file(location, mime_type=None, headers=None): + """ + Returns file with mime_type. + :param location: Location of file on system. + :param mime_type: Specific mime_type. + :param headers: Custom Headers. + """ filename = path.split(location)[-1] async with open_async(location, mode='rb') as _file: From a486fb99a9cdc381ac39c0ae9f733432aa0af837 Mon Sep 17 00:00:00 2001 From: Sean Parsons Date: Sun, 25 Dec 2016 01:06:40 -0500 Subject: [PATCH 3/4] Updated json function docstrings to be more consistent. --- sanic/response.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/response.py b/sanic/response.py index 5031b1c8..1bae348d 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -140,7 +140,7 @@ class HTTPResponse: def json(body, status=200, headers=None): """ - Returns serialized python object to json format. + Returns body in json format. :param body: Response data to be serialized. :param status: Response code. :param headers: Custom Headers. From d5ad5e46da53bb47a204585929178892aa162053 Mon Sep 17 00:00:00 2001 From: Sean Parsons Date: Sun, 25 Dec 2016 01:24:17 -0500 Subject: [PATCH 4/4] Update response docstrings to be explicit on whats returned. --- sanic/response.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sanic/response.py b/sanic/response.py index 1bae348d..407ec9f2 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -140,7 +140,7 @@ class HTTPResponse: def json(body, status=200, headers=None): """ - Returns body in json format. + Returns response object with body in json format. :param body: Response data to be serialized. :param status: Response code. :param headers: Custom Headers. @@ -151,7 +151,7 @@ def json(body, status=200, headers=None): def text(body, status=200, headers=None): """ - Returns body in text format. + Returns response object with body in text format. :param body: Response data to be encoded. :param status: Response code. :param headers: Custom Headers. @@ -162,7 +162,7 @@ def text(body, status=200, headers=None): def html(body, status=200, headers=None): """ - Returns body in html format. + Returns response object with body in html format. :param body: Response data to be encoded. :param status: Response code. :param headers: Custom Headers. @@ -173,7 +173,7 @@ def html(body, status=200, headers=None): async def file(location, mime_type=None, headers=None): """ - Returns file with mime_type. + Returns response object with file data. :param location: Location of file on system. :param mime_type: Specific mime_type. :param headers: Custom Headers.