Skip to main content

qaviton handlers

Project description

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 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(
    foo,
    foo,
    foo,
    lambda: foo(7),
    lambda: foo(7),
    lambda: foo(7),
)
# 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

catch = Catch()

# 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}")

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

qaviton_handlers-2019.9.29.6.41.4.335461.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qaviton_handlers-2019.9.29.6.41.4.335461-py2.py3-none-any.whl (11.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file qaviton_handlers-2019.9.29.6.41.4.335461.tar.gz.

File metadata

  • Download URL: qaviton_handlers-2019.9.29.6.41.4.335461.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for qaviton_handlers-2019.9.29.6.41.4.335461.tar.gz
Algorithm Hash digest
SHA256 01d0f2db7d7cb342e3003d24b712747cdb401f6e1d830baf9b6d45f507c99a4f
MD5 ce3dd9ca38a3a7519eda5f766fa65dd5
BLAKE2b-256 4a32634583933febb55a741e4e0703f0d695227a0601afdfedb40d620a7192ad

See more details on using hashes here.

File details

Details for the file qaviton_handlers-2019.9.29.6.41.4.335461-py2.py3-none-any.whl.

File metadata

  • Download URL: qaviton_handlers-2019.9.29.6.41.4.335461-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for qaviton_handlers-2019.9.29.6.41.4.335461-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d08ad6ae24c17b87234336592e5576ef46f41df142c90c3f03cc146d47ab781d
MD5 92142f2340d3138b92ff05e61b82d3a6
BLAKE2b-256 aa24abdc389f2fef75c15a82cfdace8573551ac20bdd1a63075e43a0e5f8ab9e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page