Return the TestClient.
Use it like
client = waterspout.TestClient()
assert client.get('/').body == 'Hello World'
Add a handler_class to App.
Parameters: |
|
---|
Decorator to add a filter to Waterspout.
Add your filter like
waterspout = Waterspout()
@waterspout.filter
def sort(l):
return l.sort()
And use it in your template
{{ [1, 4, 5, 3, 2] | sort }}
Parameters: | f – function to add as a filter. |
---|
Register an app to waterspout.
Parameters: |
|
---|
Run your Waterspout Application.
Decoration to change the user loader function.
Example
@waterspout.user_loader
def load_user(session):
return User.get(int(session["id"]))
Parameters: | f – the user loader function |
---|
The App in Waterspout is just like the App in Django. A Waterspout Application consists of plenty of Apps.
The minimal App
from waterspout.app import App
from waterspout.web import RequestHandler
class Foo(RequestHandler):
def get(self):
self.write('This is foo app.')
handlers = [
('/', Foo)
]
app = App('app name', __name__, handlers)
Return the TestClient for the current Waterspout.
Use it like
client = app.TestClient()
assert client.get('/').body == 'Hello World'
Add a handler_class to App.
Parameters: |
|
---|
Decorator to add a filter to Waterspout App.
Add your filter like
app = App('test')
@app.filter
def sort(l):
return l.sort()
And use it in your template
{{ [1, 4, 5, 3, 2] | sort }}
Parameters: | f – function to add as a filter. |
---|
Decoration to change the user loader function.
Example
@app.user_loader
def load_user(session):
return User.get(int(session["id"]))
Parameters: | f – the user loader function |
---|
Base RequestHandler for Waterspout Application
Flashes a message to the next request. In order to remove the flashed message from the session and to display it to the user, the template has to call get_flashed_messages().
Parameters: |
|
---|
Pulls all flashed messages from the session and returns them. Further calls in the same request to the function will return the same messages. By default just the messages are returned, but when with_categories is set to True, the return value will be a list of tuples in the form (category, message) instead.
Filter the flashed messages to one or more categories by providing those categories in category_filter. This allows rendering categories in separate html blocks. The with_categories and category_filter arguments are distinct:
Parameters: |
|
---|
An alias for Environment.globals in Jinja2.
Renders the template with the given arguments as the response.
Parameters: |
|
---|
Generate the given template with the given arguments.
We return the generated string. To generate and write a template as a response, use render() above.
Parameters: |
|
---|
A dictionary to be used as the default template namespace.
Handler class for writing JSON API
Writes the given chunk to the output buffer.
Parameters: |
|
---|
A test client for writing test for Tornado Application
Usage
client = TestClient(application)
assert client.get('/').body == 'Hello World'
assert client.post('/').body == '0 o'
Parameters: | application (A Tornado Application.) – The application to be tested. |
---|
Works exactly like a dict but provides ways to fill it from files or special dictionaries. There are two common patterns to populate the config.
Either you can fill the config from a config file:
config.from_pyfile('yourconfig.cfg')
Or alternatively you can define the configuration options in the module that calls from_object() or provide an import path to a module that should be loaded. It is also possible to tell it to use the same module and with that provide the configuration values just before the call:
DEBUG = True
COOKIE_SECRET = 'development key'
config.from_object(__name__)
In both cases (loading from any Python file or loading from modules), only uppercase keys are added to the config. This makes it possible to use lowercase values in the config file for temporary values that are not added to the config or to define the config keys in the same file that implements the application.
Probably the most interesting way to load configurations is from an environment variable pointing to a file:
config.from_envvar('YOURAPPLICATION_SETTINGS')
In this case before launching the application you have to set this environment variable to the file you want to use. On Linux and OS X use the export statement:
export YOURAPPLICATION_SETTINGS='/path/to/config/file'
On windows use set instead.
Parameters: |
|
---|
Like urllib.parse.quote, but quote non-ascii words only.
Returns the path to a package or cwd if that cannot be found. This returns the path of a package or the folder that contains a module.
Not to be confused with the package path returned by find_package().
Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (xml.sax.saxutils.escape) or with a colon as object delimiter (xml.sax.saxutils:escape).
If silent is True the return value will be None if the import fails.
Parameters: |
|
---|---|
Returns: | imported object |
Makes a dictionary behave like an object, with attribute-style access
foo = ObjectDict()
foo['bar'] = 42
assert foo.bar == 42
A decorator that converts a function into a lazy property. The function wrapped is called the first time to retrieve the result and then that calculated result is used the next time you access the value:
class Foo(object):
@cached_property
def foo(self):
# calculate something important here
return 42
The class has to have a __dict__ in order for this property to work.