Bind views to exceptions for aiohttp
Usage
import asyncio
from aiohttp import web
from aiohttp_exc_handlers import (
exc_handlers_middleware,
bind_exc_handler,
)
class CustomException(Exception):
pass
async def custom_exception_handler(request, exc):
return web.Response(text="Hello, {!s}!".format(exc))
async def hello(request):
raise CustomException('world')
# add middleware
app = web.Application(middlewares=[exc_handlers_middleware])
# bind handler to exception
bind_exc_handler(app, CustomException, custom_exception_handler)
app.router.add_route('GET', '/', hello)
loop = asyncio.get_event_loop()
handler = app.make_handler()
f = loop.create_server(handler, '0.0.0.0', 8080)
srv = loop.run_until_complete(f)
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.run_until_complete(handler.finish_connections(1.0))
srv.close()
loop.run_until_complete(srv.wait_closed())
loop.run_until_complete(app.finish())
loop.close()
Tests
$ pip install pytest
$ py.test tests.py
Metadata
Release files for aiohttp_exc_handlers 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiohttp_exc_handlers-0.2.tar.bz2 | 2.2 kB | Without provenance | Details for aiohttp_exc_handlers-0.2.tar.bz2 |
Release files / aiohttp_exc_handlers-0.2.tar.bz2
| Download URL | aiohttp_exc_handlers-0.2.tar.bz2 |
|---|---|
| Size | 2.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c579cd42dc20973f3a6ba1238b3fdb81295a32fe784b7e98d9f04fcc23b0893
|
|
BLAKE2b-256 checksum How to use checksums |
6c2b1b0faf67db8da4553f2e285964b99abfde42c8be2bc9ea6b930feeeb8fc1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for aiohttp_exc_handlers 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.