Merge pull request #1383 from huge-success/docbuild

Fix documentation build errors
This commit is contained in:
Stephen Sadowski 2018-10-26 08:19:10 -05:00 committed by GitHub
commit c7c46da975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 19 deletions

0
docs/_static/.gitkeep vendored Normal file
View File

View File

@ -24,6 +24,8 @@ Guides
sanic/sockets sanic/sockets
sanic/ssl sanic/ssl
sanic/logging sanic/logging
sanic/versioning
sanic/debug_mode
sanic/testing sanic/testing
sanic/deploying sanic/deploying
sanic/extensions sanic/extensions

View File

@ -17,7 +17,7 @@ string representing its type: `'request'` or `'response'`.
The simplest middleware doesn't modify the request or response at all: The simplest middleware doesn't modify the request or response at all:
```python ```
@app.middleware('request') @app.middleware('request')
async def print_on_request(request): async def print_on_request(request):
print("I print when a request is received by the server") print("I print when a request is received by the server")
@ -33,7 +33,7 @@ Middleware can modify the request or response parameter it is given, *as long
as it does not return it*. The following example shows a practical use-case for as it does not return it*. The following example shows a practical use-case for
this. this.
```python ```
app = Sanic(__name__) app = Sanic(__name__)
@app.middleware('response') @app.middleware('response')
@ -60,7 +60,7 @@ and the response will be returned. If this occurs to a request before the
relevant user route handler is reached, the handler will never be called. relevant user route handler is reached, the handler will never be called.
Returning a response will also prevent any further middleware from running. Returning a response will also prevent any further middleware from running.
```python ```
@app.middleware('request') @app.middleware('request')
async def halt_request(request): async def halt_request(request):
return text('I halted the request') return text('I halted the request')
@ -79,11 +79,11 @@ If you want to execute startup/teardown code as your server starts or closes, yo
- `before_server_stop` - `before_server_stop`
- `after_server_stop` - `after_server_stop`
These listeners are implemented as decorators on functions which accept the app object as well as the asyncio loop. These listeners are implemented as decorators on functions which accept the app object as well as the asyncio loop.
For example: For example:
```python ```
@app.listener('before_server_start') @app.listener('before_server_start')
async def setup_db(app, loop): async def setup_db(app, loop):
app.db = await db_setup() app.db = await db_setup()
@ -101,16 +101,16 @@ async def close_db(app, loop):
await app.db.close() await app.db.close()
``` ```
It's also possible to register a listener using the `register_listener` method. It's also possible to register a listener using the `register_listener` method.
This may be useful if you define your listeners in another module besides This may be useful if you define your listeners in another module besides
the one you instantiate your app in. the one you instantiate your app in.
```python ```
app = Sanic() app = Sanic()
async def setup_db(app, loop): async def setup_db(app, loop):
app.db = await db_setup() app.db = await db_setup()
app.register_listener(setup_db, 'before_server_start') app.register_listener(setup_db, 'before_server_start')
``` ```
@ -118,7 +118,7 @@ app.register_listener(setup_db, 'before_server_start')
If you want to schedule a background task to run after the loop has started, If you want to schedule a background task to run after the loop has started,
Sanic provides the `add_task` method to easily do so. Sanic provides the `add_task` method to easily do so.
```python ```
async def notify_server_started_after_five_seconds(): async def notify_server_started_after_five_seconds():
await asyncio.sleep(5) await asyncio.sleep(5)
print('Server successfully started!') print('Server successfully started!')
@ -128,7 +128,7 @@ app.add_task(notify_server_started_after_five_seconds())
Sanic will attempt to automatically inject the app, passing it as an argument to the task: Sanic will attempt to automatically inject the app, passing it as an argument to the task:
```python ```
async def notify_server_started_after_five_seconds(app): async def notify_server_started_after_five_seconds(app):
await asyncio.sleep(5) await asyncio.sleep(5)
print(app.name) print(app.name)
@ -138,7 +138,7 @@ app.add_task(notify_server_started_after_five_seconds)
Or you can pass the app explicitly for the same effect: Or you can pass the app explicitly for the same effect:
```python ```
async def notify_server_started_after_five_seconds(app): async def notify_server_started_after_five_seconds(app):
await asyncio.sleep(5) await asyncio.sleep(5)
print(app.name) print(app.name)

View File

@ -43,6 +43,7 @@ and ``recv`` methods to send and receive data respectively.
You could setup your own WebSocket configuration through ``app.config``, like You could setup your own WebSocket configuration through ``app.config``, like
.. code:: python .. code:: python
app.config.WEBSOCKET_MAX_SIZE = 2 ** 20 app.config.WEBSOCKET_MAX_SIZE = 2 ** 20
app.config.WEBSOCKET_MAX_QUEUE = 32 app.config.WEBSOCKET_MAX_QUEUE = 32
app.config.WEBSOCKET_READ_LIMIT = 2 ** 16 app.config.WEBSOCKET_READ_LIMIT = 2 ** 16

View File

@ -52,5 +52,5 @@ if __name__ == "__main__":
" Example File: project/sanic_server.py -> app\n" " Example File: project/sanic_server.py -> app\n"
" Example Module: project.sanic_server.app".format(e.name) " Example Module: project.sanic_server.app".format(e.name)
) )
except ValueError as e: except ValueError:
logger.exception("Failed to run app") logger.exception("Failed to run app")

View File

@ -371,8 +371,7 @@ class Sanic:
): ):
"""Decorate a function to be registered as a websocket route """Decorate a function to be registered as a websocket route
:param uri: path of the URL :param uri: path of the URL
:param subprotocols: optional list of strings with the supported :param subprotocols: optional list of str with supported subprotocols
subprotocols
:param host: :param host:
:return: decorated function :return: decorated function
""" """
@ -568,7 +567,7 @@ class Sanic:
return self.blueprint(*args, **kwargs) return self.blueprint(*args, **kwargs)
def url_for(self, view_name: str, **kwargs): def url_for(self, view_name: str, **kwargs):
"""Build a URL based on a view name and the values provided. r"""Build a URL based on a view name and the values provided.
In order to build a URL, all request parameters must be supplied as In order to build a URL, all request parameters must be supplied as
keyword arguments, and each parameter must pass the test for the keyword arguments, and each parameter must pass the test for the
@ -579,7 +578,7 @@ class Sanic:
the output URL's query string. the output URL's query string.
:param view_name: string referencing the view name :param view_name: string referencing the view name
:param \*\*kwargs: keys and values that are used to build request :param \**kwargs: keys and values that are used to build request
parameters and query string arguments. parameters and query string arguments.
:return: the built URL :return: the built URL

View File

@ -18,7 +18,7 @@ _Translator.update({ord('"'): '\\"', ord("\\"): "\\\\"})
def _quote(str): def _quote(str):
"""Quote a string for use in a cookie header. r"""Quote a string for use in a cookie header.
If the string does not need to be double-quoted, then just return the If the string does not need to be double-quoted, then just return the
string. Otherwise, surround the string in doublequotes and quote string. Otherwise, surround the string in doublequotes and quote
(with a \) special characters. (with a \) special characters.

View File

@ -34,7 +34,7 @@ class SanicTestClient:
) as response: ) as response:
try: try:
response.text = await response.text() response.text = await response.text()
except UnicodeDecodeError as e: except UnicodeDecodeError:
response.text = None response.text = None
try: try: