Added additional docstrings to blueprints.py

This commit is contained in:
Sean Parsons 2016-12-25 00:47:51 -05:00
parent 6cf3754051
commit a03f216f42

View File

@ -3,6 +3,7 @@ from collections import defaultdict
class BlueprintSetup: class BlueprintSetup:
""" """
Creates a blueprint state like object.
""" """
def __init__(self, blueprint, app, options): def __init__(self, blueprint, app, options):
@ -29,13 +30,13 @@ class BlueprintSetup:
def add_exception(self, handler, *args, **kwargs): def add_exception(self, handler, *args, **kwargs):
""" """
Registers exceptions to sanic Registers exceptions to sanic.
""" """
self.app.exception(*args, **kwargs)(handler) self.app.exception(*args, **kwargs)(handler)
def add_static(self, uri, file_or_directory, *args, **kwargs): def add_static(self, uri, file_or_directory, *args, **kwargs):
""" """
Registers static files to sanic Registers static files to sanic.
""" """
if self.url_prefix: if self.url_prefix:
uri = self.url_prefix + uri uri = self.url_prefix + uri
@ -44,7 +45,7 @@ class BlueprintSetup:
def add_middleware(self, middleware, *args, **kwargs): def add_middleware(self, middleware, *args, **kwargs):
""" """
Registers middleware to sanic Registers middleware to sanic.
""" """
if args or kwargs: if args or kwargs:
self.app.middleware(*args, **kwargs)(middleware) self.app.middleware(*args, **kwargs)(middleware)
@ -73,11 +74,13 @@ class Blueprint:
def make_setup_state(self, app, options): def make_setup_state(self, app, options):
""" """
Returns a new BlueprintSetup object
""" """
return BlueprintSetup(self, app, options) return BlueprintSetup(self, app, options)
def register(self, app, options): def register(self, app, options):
""" """
Registers the blueprint to the sanic app.
""" """
state = self.make_setup_state(app, options) state = self.make_setup_state(app, options)
for deferred in self.deferred_functions: for deferred in self.deferred_functions:
@ -85,6 +88,9 @@ class Blueprint:
def route(self, uri, methods=None): 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): def decorator(handler):
self.record(lambda s: s.add_route(handler, uri, methods)) self.record(lambda s: s.add_route(handler, uri, methods))
@ -93,12 +99,18 @@ class Blueprint:
def add_route(self, handler, uri, methods=None): 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)) self.record(lambda s: s.add_route(handler, uri, methods))
return handler return handler
def listener(self, event): def listener(self, event):
""" """
Create a listener from a decorated function.
:param event: Event to listen to.
""" """
def decorator(listener): def decorator(listener):
self.listeners[event].append(listener) self.listeners[event].append(listener)
@ -107,6 +119,7 @@ class Blueprint:
def middleware(self, *args, **kwargs): def middleware(self, *args, **kwargs):
""" """
Creates a blueprint middleware from a decorated function.
""" """
def register_middleware(middleware): def register_middleware(middleware):
self.record( self.record(
@ -123,6 +136,7 @@ class Blueprint:
def exception(self, *args, **kwargs): def exception(self, *args, **kwargs):
""" """
Creates a blueprint exception from a decorated function.
""" """
def decorator(handler): def decorator(handler):
self.record(lambda s: s.add_exception(handler, *args, **kwargs)) 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): 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( self.record(
lambda s: s.add_static(uri, file_or_directory, *args, **kwargs)) lambda s: s.add_static(uri, file_or_directory, *args, **kwargs))