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):
"""
Fetches and executes an exception handler and returns a response object
:param request: Request
:param exception: Exception to handle
:return: Response object

View File

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

View File

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

View File

@ -44,6 +44,7 @@ class Sanic:
def route(self, uri, methods=None):
"""
Decorates a function to be registered as a route
:param uri: path of the URL
:param methods: list or tuple of methods allowed
:return: decorated function
@ -65,6 +66,7 @@ class Sanic:
A helper method to register class instance or
functions as a handler to the application url
routes.
:param handler: function or class instance
:param uri: path of the URL
:param methods: list or tuple of methods allowed
@ -77,7 +79,8 @@ class Sanic:
def exception(self, *exceptions):
"""
Decorates a function to be registered as a handler for exceptions
:param *exceptions: exceptions
:param \*exceptions: exceptions
:return: decorated function
"""
@ -123,6 +126,7 @@ class Sanic:
def blueprint(self, blueprint, **options):
"""
Registers a blueprint on the application.
:param blueprint: Blueprint object
:param options: option dictionary with blueprint defaults
:return: Nothing
@ -155,9 +159,10 @@ class Sanic:
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
exception handling must be done here
:param request: HTTP Request object
:param response_callback: Response function to be called with the
response as the only argument
response as the only argument
:return: Nothing
"""
try:
@ -236,20 +241,21 @@ class Sanic:
"""
Runs the HTTP Server and listens until keyboard interrupt or term
signal. On termination, drains connections before closing.
:param host: Address to host on
:param port: Port to host on
:param debug: Enables debug output (slows server)
:param before_start: Function to be executed before the server starts
accepting connections
accepting connections
:param after_start: Function to be executed after the server starts
accepting connections
accepting connections
:param before_stop: Function to be executed when a stop signal is
received before it is respected
received before it is respected
:param after_stop: Function to be executed when all requests are
complete
complete
:param sock: Socket for the server to accept connections from
:param workers: Number of processes
received before it is respected
received before it is respected
:param loop: asyncio compatible event loop
:return: Nothing
"""
@ -324,6 +330,7 @@ class Sanic:
"""
Starts multiple server processes simultaneously. Stops on interrupt
and terminate signals, and drains connections when complete.
:param server_settings: kw arguments to be passed to the serve function
:param workers: number of workers to launch
: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
at the end of every keep-alive request to update the request timeout time
:param loop:
: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):
"""
Starts asynchronous HTTP Server on an individual process.
:param host: Address to host on
:param port: Port to host on
:param request_handler: Sanic request handler with middleware
: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
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 request_timeout: time in seconds
: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
router and registering a handler.
:param app: Sanic
:param file_or_directory: File or directory path to serve from
:param uri: URL to serve from
:param pattern: regular expression used to match files in the URL
: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,

View File

@ -7,21 +7,25 @@ class HTTPMethodView:
to every HTTP method you want to support.
For example:
class DummyView(View):
.. code-block:: python
class DummyView(View):
def get(self, request, *args, **kwargs):
return text('I am get method')
def put(self, request, *args, **kwargs):
return text('I am put method')
etc.
If someone tries to use a non-implemented method, there will be a
405 response.
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):
return text('I am get method with %s' % my_param_here)