Skip to main content

Qaviton Handlers

logo
version open issues downloads code size

error handling utilities

Installation

pip install --upgrade qaviton_handlers  

Requirements

  • Python 3.6+

Features

  • retry decorator ✓
  • retry with context ✓
  • try functions ✓
  • catch errors ✓
  • simple Exception wrapper ✓

Usage

retry decorator

from qaviton_handlers.try_decorator import retry

@retry()
def foo():
    n = int('1'+input('select number:'))
    print(n)

foo()

retry with context

from qaviton_handlers.try_context import retry

with retry() as trying:
    while trying:
        with trying:
            print("Attempt #%d of %d" % (trying.attempt, trying.attempts))
            raise

using different try wrapper functions

from qaviton_handlers.try_functions import try_to, try_or_none, multi_try, multi_try_no_break

def foo(a=0):
    print(float(a+input("select number:")))

# simply try
try_to(foo, 1)
try_to(foo, 2)
try_to(foo, 3)
# get the error
error = try_to(foo, 4)
if error: print(error)

# if error occurred
if try_to(foo, 5):
    try_to(foo, 5)
# try with key arguments
r = try_to(lambda a,b,c:a*b*c, 1,kwargs={'b':2,'c':3})
print(r)
# try to get a number
number = try_or_none(lambda a:float(a+input("select number:")), 6)
if number: print(number)
# try many functions, return a list of results, or an error
# if an error occurred, the multi try stops
multi_try(
  lambda: foo(10), 
  lambda: foo(11), 
)

# specify errors to ignore
response = multi_try(
  lambda: foo(13),
  lambda: foo(14),
  exceptions=Exception,
)

# handle the error
response = multi_try(
  lambda: foo(13),
  lambda: foo(14),
)
if isinstance(response, Exception):
    ...
# try many functions, return a list of results, some may be errors
# if an error occurred, the multi try continues
multi_try_no_break(
    lambda: foo(8),
    lambda: foo(9),
    lambda: foo(0),
)

ignore errors now so you can handle them later

from qaviton_handlers.catch import Catch
from qaviton_handlers.utils.error import Error

catch = Catch(store=True)

# catch an error
try:
    1 + '1'
except Exception as e:
    catch(e)

# a cleaner syntax
with catch:
    1 + '1'
    2 + '2'

# ignore the error
with Catch():
    5 * 'e'

print(f"caught {catch.count} errors")
print(f"caught first {catch.first}")
print(f"caught last {catch.last}")

# make your own Catch
class MyCatch(Catch):
    def handler(self, e):
        self.stack.add(Error(e))
        print()
        return self

Metadata

Release files for qaviton-handlers 2019.9.29.7.46.16.681860

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qaviton-handlers 2019.9.29.7.46.16.681860
File Size Uploaded Provenance Actions
qaviton_handlers-2019.9.29.7.46.16.681860.tar.gz 4.9 kB Without provenance Details for qaviton_handlers-2019.9.29.7.46.16.681860.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qaviton-handlers 2019.9.29.7.46.16.681860
File Interpreter ABI Platform Actions
qaviton_handlers-2019.9.29.7.46.16.681860-py2.py3-none-any.whl Python 2, Python 3 none any Details for qaviton_handlers-2019.9.29.7.46.16.681860-py2.py3-none-any.whl

Total release size: 16.7 kB

Release files / qaviton_handlers-2019.9.29.7.46.16.681860.tar.gz

Download URL qaviton_handlers-2019.9.29.7.46.16.681860.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c0c6fbce2b13022da452d28900c93bca1c5f57f224ab3a9b253b4235c1827cfa
BLAKE2b-256 checksum
How to use checksums
a98bce723e612545e10d92ba07887e11d3a9e48926f81d18e0ae7ef8bcba6292
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

Release files / qaviton_handlers-2019.9.29.7.46.16.681860-py2.py3-none-any.whl

Download URL qaviton_handlers-2019.9.29.7.46.16.681860-py2.py3-none-any.whl
Size 11.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
69661fa9cfce5f9f9d8d87cf545dd5356f85de1361d05a1bd1a47c029146ef12
BLAKE2b-256 checksum
How to use checksums
dbb103b60171846f1f514f9e83cf4c126d32eb6b10ce7598e3b548139c1b0f7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

Security for qaviton-handlers 2019.9.29.7.46.16.681860

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page