A collection of WSGI packages.
Project description
WSGI-Tools
A collection of WSGI packages
Usage
ErrorHandler
The error handler is a WSGI app which calls another WSGI app.
If that WSGI app raises a wsgi_tools.error.HTTPException
, the error code and an optional message will be returńed.
If that WSGI app raises a normal Exception, the error code 500
will be returńed.
Import:
from wsgi_tools.error import ErrorHandler, JSONErrorHandler, HTMLErrorHandler
To use the ErrorHandler
you have to overwrite the abstract handle
method or use the prebuild JSONErrorHandler
or HTMLErrorHandler
.
app = JSONErrorHandler(app0)
Friedly
With this you can serve easy-to-use functions over WSGI.
def app0(request):
data = request.body_json
response = do_something(data)
return 200, response
Router
The router is a WSGI app which reads the path of the request and calls another corresponding WSGI app.
Import:
from wsgi_tools.routing import Router
Create the Router:
app = Router(
{
('POST', ('/create')): app0,
('GET', ('/', int, '/options')): app1
}
)
If you send a POST
request to /create
, app0
will be called.
If you send a GET
request to /3/options
, app1
will be called and environ['wsgi_tools.routing.args']
will be [3]
. If you are using wsgi_tools.friendly
, request.routing_args
will be [3]
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for wsgi_tools-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e73d05853f687ef1bdba707d1a0a0ab0fbcc4f8d70daeff137a3c532ceb0cac |
|
MD5 | a102711dcea1830bb047103f9a29c601 |
|
BLAKE2b-256 | f31df0edd1d5c4379590d8541b098d137ecbbf5a97aabbcd5a8189b28b5c49eb |