WSGI-Tools
A collection of WSGI packages
Usage
See: example.py
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:
The first argument of Router is the list of rules you want to use.
A rule an instance of an subclass of wsgi_tools.routing.Rule.
The order of these rules is important, because you don't want to throw an 405 Method Not Allowed error if there are no endpoints which match one of the endpoint and the method.
So the path-checking rule must be before the method checking rule.
There are premade rules for matching path, method and content-type:
from wsgi_tools.routing import PathRule, METHOD_RULE, CONTENT_TYPE_RULE
The second argument is the dict with tuples as keys, which represent the args for the rules and wsgi apps as keys.
from wsgi_tools.routing import Router, PathRule, METHOD_RULE, CONTENT_TYPE_RULE
path_rule = PathRule()
app = Router(
[path_rule, METHOD_RULE, CONTENT_TYPE_RULE],
{
(('/create',), 'POST', 'json'): create_app,
(('/', int, '/options'), 'GET', None): options_app
}
)
If you send a POST request to /create and the content-type is */json, */*+json, */json+* or */*+json+*, create_app will be called.
If you send a GET request to /3/options, options_app will be called and path_rule.args will be [3].
Release files for wsgi-tools 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wsgi-tools-0.5.1.tar.gz | 15.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wsgi_tools-0.5.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.6 kB
Release files / wsgi-tools-0.5.1.tar.gz
| Download URL | wsgi-tools-0.5.1.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be5e366f6a7d005d603849309923c42a713ff417af5225df37652473a3e72539
|
|
BLAKE2b-256 checksum How to use checksums |
4dc76d1cda4b457e04d5528e8ea80f96eae25789240dc3091dfe0775b559e628
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Release files / wsgi_tools-0.5.1-py3-none-any.whl
| Download URL | wsgi_tools-0.5.1-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62e1ce935e39a08f7623af88147dfac02c7e1a34449b899c72e825167ad1ab14
|
|
BLAKE2b-256 checksum How to use checksums |
5bf74d09d375a75b2e5139b149d3d8deab36d37072db2aa7c9db25c58c1e0e80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|