Tori web framework is a simple web framework working on the top of CherryPy 3.1+. It is designed to get started with CherryPy without repeating the commonly used configuration or procedure to run the application.
It is also designed to with deployment in mind where the app starter can be used as standalone WSGI server, WSGI application (wrapper) or Google App Engine application.
Base interface provides all basic functionalities for developing a web interface responsible for processing and responding incoming HTTP requests. Only compatible with CherryPy 3.1+.
Cache the data.
If block_name is not given, it will return the clone of the memory blocks.
If block_data is given, the cache data block will be updated.
If block_name is given but the data is not available, it will return null pointer.
If duration is below 0, the cache memory is kept as long as the server is running. If it is more than 0, the cache memory will be purged after the cache duration in seconds. If it is 0, it won’t cache a thing.
Purge all expired cache.
Default routing to the static folder when the URL is not handled by Python.
Render template from source with kwargs as context variables/options.
For rendering options, please see tori.render.
Example: self.default_render(‘shiroyuki.html’, author=’juti noppornpitak’, direct_rendering=False)
Abstract: Check if the user is an administrator.
Abstract: Check if the user is authenticated.
Check if this request is a DELETE request.
Check if this request is a GET request.
Check if this request is a POST request.
Check if this request is a PUT request.
Return the request method (GET, POST, DELETE, PUT)
Purge cache blocks referenced by block_names
Example: self.purge_cache(‘block_a’, ‘block_b’, ...)
Note that if block names aren’t given, it will purge all cache blocks.
Redirect a URL with CherryPy’s HTTPRedirect (exception).
url is a string representing URL.
code is a HTTP status code in interger.
soft_redirection make this method not to raise a redirection exception by CherryPy. This is more customizable to what to be given back. This option is strongly recommended for Google App Engine applications.
Wrapper method for tori.BaseInterface.default_render
Example: self.render(‘shiroyuki.html’, author=’juti noppornpitak’, direct_rendering=False)
Set the response status.
code is a HTTP status code in interger.
message is a response reason.
break_now is a boolean. If True, this method will raise CherryPy’s HTTPError exception. Otherwise, return status.
Exception when dealing with errors in CherryPy wrappers which may be caused by CherryPy itself
A memory block used by caching mechanism via BaseInterface-base interfaces
Abstract class for a RESTful Interface based on BaseInterface. Only compatible with CherryPy 3.1+.
Cache the data.
If block_name is not given, it will return the clone of the memory blocks.
If block_data is given, the cache data block will be updated.
If block_name is given but the data is not available, it will return null pointer.
If duration is below 0, the cache memory is kept as long as the server is running. If it is more than 0, the cache memory will be purged after the cache duration in seconds. If it is 0, it won’t cache a thing.
Purge all expired cache.
Create a new resource
POST ./
Low-level function handling requests based on the method.
Render template from source with kwargs as context variables/options.
For rendering options, please see tori.render.
Example: self.default_render(‘shiroyuki.html’, author=’juti noppornpitak’, direct_rendering=False)
Handle DELETE request
DELETE ./*
Delete the target resource
POST ./{KEY}/delete DEL ./{KEY}
Prompt to update a new resource
GET ./{key}/edit
Handle GET request
GET ./*
List resources
GET ./
Abstract: Check if the user is an administrator.
Abstract: Check if the user is authenticated.
Check if this request is a DELETE request.
Check if this request is a GET request.
Check if this request is a POST request.
Check if this request is a PUT request.
Return the request method (GET, POST, DELETE, PUT)
Prompt to create a new resource
GET ./new
Handle POST request
POST ./
Purge cache blocks referenced by block_names
Example: self.purge_cache(‘block_a’, ‘block_b’, ...)
Note that if block names aren’t given, it will purge all cache blocks.
Handle PUT request
PUT ./*
Redirect a URL with CherryPy’s HTTPRedirect (exception).
url is a string representing URL.
code is a HTTP status code in interger.
soft_redirection make this method not to raise a redirection exception by CherryPy. This is more customizable to what to be given back. This option is strongly recommended for Google App Engine applications.
Wrapper method for tori.BaseInterface.default_render
Example: self.render(‘shiroyuki.html’, author=’juti noppornpitak’, direct_rendering=False)
Set the response status.
code is a HTTP status code in interger.
message is a response reason.
break_now is a boolean. If True, this method will raise CherryPy’s HTTPError exception. Otherwise, return status.
Show the target resource
GET ./{KEY}
Update the target resource
POST ./{key}/update PUT ./{key}
ServerInterface is like a switch to control how you deploy your application.
It supports three modes described in tori.ServiceMode.
Run the application in WSGI application/wrapper mode with a web server or on Google App Engine.
To run the application on Google App Engine, it is not recommended to use this function directly. Please use ServerInterface.auto instead.
Run in auto mode. This is vary, depending on the configuration.
Run the application in WSGI server mode (standalone).
ServiceMode is just a group of keywords to tell ServerInterface which mode to run.
This class provides only static attributes. You may instantiate but nothing works.
Exception specifically used by Tori during initilization
Minify content (text data). Work best with HTML and CSS. This function is automatically temporarily disabled if HTML tag pre or code is detected unless it is forced to do.
original_code is required as a string.
full_compression (optional, boolean, default: False). It tells the function whether it should forcefully minify everything in details. This is not recommended for mixed content.
force_op (optional, boolean, default: False) forces the function to minify content unless it is false.
file_type (optional, string, default: None) indicates the type of target content for the better minification.
Returns a string of minified original_code.
This function is to render templates. It is currently support Mako template only. It is to support other libraries in the future.
This function can have more than one parameter. There are three optional parameters only used by this function which are described below. The rest are context variables for rendering.
The required parameter source is a string indicating the location of the template. If the optional parameter direct_rendering is false, it will attempt to render the source directly as if it is a template data.
The optional parameter direct_rendering is a boolean acting as a switch to enable or disable the behaviour described above. This option may be set globally in the configuration file. It is set to ‘False’ by default.
The optional parameter text_minification is a boolean acting as a switch to enable or disable auto HTML minification. This option may be set globally in the configuration file. Currently, it doesn’t fully support JavaScript minification. It is set to ‘False’ by default.
Set up the environment
configuration_filename is the name of the configuration file in XML. By default, it is null and instruct the system to use the default settings.
use_tori_custome_error_page is a flag to tell whether the application process should use the nicer custom error page. Please note that enabling this feature will slightly decrease performance. This is a known issue for CherryPy 3.1+.
support_unicode is a flag to tell whether the application process should support unicode. Please note that enabling this feature will slightly decrease performance.
enable_compression is a flag to tell whether the application process should compress the output. Please note that enabling this feature will decrease performance and possibly mess up JavaScript. This feature is disabled by default when the X/HTML document contains pre elements. Use with caution.
auto_config is a flag to tell whether the application process should create a configuration file (named by configuration_filename) automatically if not existed. When the function detect that the configuration file doesn’t exist, with this flag enabled, it will create the configuration file with the default configuration. Then, it will terminated the process. This gives the developers an opportunity to config the settings before proceeding.
additional_config is a configuration dictionary for CherryPy 3.1+. It is for adding some additional configuration directly to CherryPy which is the underlying framework. Please note that this will override any configuration from the configuration file.
Start session (CherryPy)
See also
Module yotsuba.lib.kotoba XML Parser with CSS selectors