Fix all docstring errors.

When generating documentation with sphinx-apidoc, there are currently
many docstring errors, mostly minor. This commit fixes all errors.
This commit is contained in:
Cadel Watson 2016-12-25 20:43:45 +11:00
parent 7654c2f902
commit 52c59e7133
7 changed files with 43 additions and 15 deletions

View File

@ -51,6 +51,7 @@ class Handler:
def response(self, request, exception): def response(self, request, exception):
""" """
Fetches and executes an exception handler and returns a response object Fetches and executes an exception handler and returns a response object
:param request: Request :param request: Request
:param exception: Exception to handle :param exception: Exception to handle
:return: Response object :return: Response object

View File

@ -132,6 +132,7 @@ File = namedtuple('File', ['type', 'body', 'name'])
def parse_multipart_form(body, boundary): def parse_multipart_form(body, boundary):
""" """
Parses a request body and returns fields and files Parses a request body and returns fields and files
:param body: Bytes request body :param body: Bytes request body
:param boundary: Bytes multipart boundary :param boundary: Bytes multipart boundary
:return: fields (RequestParameters), files (RequestParameters) :return: fields (RequestParameters), files (RequestParameters)

View File

@ -26,11 +26,19 @@ class RouteExists(Exception):
class Router: class Router:
""" """
Router supports basic routing with parameters and method checks Router supports basic routing with parameters and method checks
Usage: Usage:
.. code-block:: python
@sanic.route('/my/url/<my_parameter>', methods=['GET', 'POST', ...]) @sanic.route('/my/url/<my_parameter>', methods=['GET', 'POST', ...])
def my_route(request, my_parameter): def my_route(request, my_parameter):
do stuff... do stuff...
or or
.. code-block:: python
@sanic.route('/my/url/<my_paramter>:type', methods['GET', 'POST', ...]) @sanic.route('/my/url/<my_paramter>:type', methods['GET', 'POST', ...])
def my_route_with_type(request, my_parameter): def my_route_with_type(request, my_parameter):
do stuff... do stuff...
@ -55,6 +63,7 @@ class Router:
def add(self, uri, methods, handler): def add(self, uri, methods, handler):
""" """
Adds a handler to the route list Adds a handler to the route list
:param uri: Path to match :param uri: Path to match
:param methods: Array of accepted method names. :param methods: Array of accepted method names.
If none are provided, any method is allowed If none are provided, any method is allowed
@ -113,6 +122,7 @@ class Router:
""" """
Gets a request handler based on the URL of the request, or raises an Gets a request handler based on the URL of the request, or raises an
error error
:param request: Request object :param request: Request object
:return: handler, arguments, keyword arguments :return: handler, arguments, keyword arguments
""" """

View File

@ -44,6 +44,7 @@ class Sanic:
def route(self, uri, methods=None): def route(self, uri, methods=None):
""" """
Decorates a function to be registered as a route Decorates a function to be registered as a route
:param uri: path of the URL :param uri: path of the URL
:param methods: list or tuple of methods allowed :param methods: list or tuple of methods allowed
:return: decorated function :return: decorated function
@ -65,6 +66,7 @@ class Sanic:
A helper method to register class instance or A helper method to register class instance or
functions as a handler to the application url functions as a handler to the application url
routes. routes.
:param handler: function or class instance :param handler: function or class instance
:param uri: path of the URL :param uri: path of the URL
:param methods: list or tuple of methods allowed :param methods: list or tuple of methods allowed
@ -77,7 +79,8 @@ class Sanic:
def exception(self, *exceptions): def exception(self, *exceptions):
""" """
Decorates a function to be registered as a handler for exceptions Decorates a function to be registered as a handler for exceptions
:param *exceptions: exceptions
:param \*exceptions: exceptions
:return: decorated function :return: decorated function
""" """
@ -123,6 +126,7 @@ class Sanic:
def blueprint(self, blueprint, **options): def blueprint(self, blueprint, **options):
""" """
Registers a blueprint on the application. Registers a blueprint on the application.
:param blueprint: Blueprint object :param blueprint: Blueprint object
:param options: option dictionary with blueprint defaults :param options: option dictionary with blueprint defaults
:return: Nothing :return: Nothing
@ -155,6 +159,7 @@ class Sanic:
Takes a request from the HTTP Server and returns a response object to Takes a request from the HTTP Server and returns a response object to
be sent back The HTTP Server only expects a response object, so be sent back The HTTP Server only expects a response object, so
exception handling must be done here exception handling must be done here
:param request: HTTP Request object :param request: HTTP Request object
:param response_callback: Response function to be called with the :param response_callback: Response function to be called with the
response as the only argument response as the only argument
@ -236,6 +241,7 @@ class Sanic:
""" """
Runs the HTTP Server and listens until keyboard interrupt or term Runs the HTTP Server and listens until keyboard interrupt or term
signal. On termination, drains connections before closing. signal. On termination, drains connections before closing.
:param host: Address to host on :param host: Address to host on
:param port: Port to host on :param port: Port to host on
:param debug: Enables debug output (slows server) :param debug: Enables debug output (slows server)
@ -324,6 +330,7 @@ class Sanic:
""" """
Starts multiple server processes simultaneously. Stops on interrupt Starts multiple server processes simultaneously. Stops on interrupt
and terminate signals, and drains connections when complete. and terminate signals, and drains connections when complete.
:param server_settings: kw arguments to be passed to the serve function :param server_settings: kw arguments to be passed to the serve function
:param workers: number of workers to launch :param workers: number of workers to launch
:param stop_event: if provided, is used as a stop signal :param stop_event: if provided, is used as a stop signal

View File

@ -201,6 +201,7 @@ def update_current_time(loop):
""" """
Caches the current time, since it is needed Caches the current time, since it is needed
at the end of every keep-alive request to update the request timeout time at the end of every keep-alive request to update the request timeout time
:param loop: :param loop:
:return: :return:
""" """
@ -229,13 +230,15 @@ def serve(host, port, request_handler, error_handler, before_start=None,
request_max_size=None, reuse_port=False, loop=None): request_max_size=None, reuse_port=False, loop=None):
""" """
Starts asynchronous HTTP Server on an individual process. Starts asynchronous HTTP Server on an individual process.
:param host: Address to host on :param host: Address to host on
:param port: Port to host on :param port: Port to host on
:param request_handler: Sanic request handler with middleware :param request_handler: Sanic request handler with middleware
:param after_start: Function to be executed after the server starts :param after_start: Function to be executed after the server starts
listening. Takes single argument `loop` listening. Takes single argument `loop`
:param before_stop: Function to be executed when a stop signal is :param before_stop: Function to be executed when a stop signal is
received before it is respected. Takes single argumenet `loop` received before it is respected. Takes single
argumenet `loop`
:param debug: Enables debug output (slows server) :param debug: Enables debug output (slows server)
:param request_timeout: time in seconds :param request_timeout: time in seconds
:param sock: Socket for the server to accept connections from :param sock: Socket for the server to accept connections from

View File

@ -15,12 +15,14 @@ def register(app, uri, file_or_directory, pattern, use_modified_since):
""" """
Registers a static directory handler with Sanic by adding a route to the Registers a static directory handler with Sanic by adding a route to the
router and registering a handler. router and registering a handler.
:param app: Sanic :param app: Sanic
:param file_or_directory: File or directory path to serve from :param file_or_directory: File or directory path to serve from
:param uri: URL to serve from :param uri: URL to serve from
:param pattern: regular expression used to match files in the URL :param pattern: regular expression used to match files in the URL
:param use_modified_since: If true, send file modified time, and return :param use_modified_since: If true, send file modified time, and return
not modified if the browser's matches the server's not modified if the browser's matches the
server's
""" """
# If we're not trying to match a file directly, # If we're not trying to match a file directly,

View File

@ -7,21 +7,25 @@ class HTTPMethodView:
to every HTTP method you want to support. to every HTTP method you want to support.
For example: For example:
class DummyView(View):
.. code-block:: python
class DummyView(View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
return text('I am get method') return text('I am get method')
def put(self, request, *args, **kwargs): def put(self, request, *args, **kwargs):
return text('I am put method') return text('I am put method')
etc. etc.
If someone tries to use a non-implemented method, there will be a If someone tries to use a non-implemented method, there will be a
405 response. 405 response.
If you need any url params just mention them in method definition: If you need any url params just mention them in method definition:
class DummyView(View):
.. code-block:: python
class DummyView(View):
def get(self, request, my_param_here, *args, **kwargs): def get(self, request, my_param_here, *args, **kwargs):
return text('I am get method with %s' % my_param_here) return text('I am get method with %s' % my_param_here)