Skip to main content

Aio core utils

Project description


Core definitions and utilities for the aio asyncio framework


Install with:

pip install aio.core

aio.core.exceptions usage


>>> from configparser import ConfigParser
>>> from aio.core.exceptions import MissingConfiguration
>>> def get_configuration(conf, section, option):
...     try:
...         conf[section][option]
...     except KeyError:
...         raise MissingConfiguration(
...             "Configuration option is missing: %s:%s" % (
...                 section, option))
>>> try:
...     get_configuration(ConfigParser(), "foo", "bar")
... except MissingConfiguration as e:
...     print(e)
Configuration option is missing: foo:bar


>>> from aio.core.exceptions import BadConfiguration
>>> def get_configuration(conf, section, option, option_type):
...     option_value = conf[section][option]
...     try:
...         option_type(option_value)
...     except ValueError:
...         raise BadConfiguration(
...             'Configuration is bad: %s:%s expected type %s, but got "%s"' % (
...                 section, option, option_type.__name__, option_value))
>>> config = ConfigParser()
>>> config.read_dict({"foo": {"bar": "baz"}})
>>> try:
...     get_configuration(config, "foo", "bar", int)
... except BadConfiguration as e:
...     print(e)
Configuration is bad: foo:bar expected type int, but got "baz"


>>> from aio.core.exceptions import CommandError
>>> def run_command(command):
...     options = ["egg", "chips"]
...     if command not in options:
...         raise CommandError("This command cannot be called with %s" % command)
>>> try:
...     run_command("spam")
... except CommandError as e:
...     print(e)
This command cannot be called with spam

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aio.core, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size aio.core-0.1.0.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page