Skip to main content

a collection of function decorators to handle common procedures done on the entry and exit points.

Project description

This module provides a collection of function decorators to handle common procedures done on the entry and exit points.

Directory

In Directory

Before the function is executed, the current working directory is saved and the directory is changed to the provided path. After the function has completed, the directory is changed to the saved working directory.

from terse import in_dir
from glob import glob
import os

@in_dir('/sys/class/net')
def interfaces():
  return glob('*')

print(os.getcwd())
print(interfaces())
print(os.getcwd())

On Exit

No Exception

Decorator will catch all exceptions leaked or produced by callee. If provided with callback function, then the callback will only be invoked when an exception occurs. If provided with instead_return, then the value will be returned when an exception occurs.

from terse import no_except

def simple_log(function, exception):
  print(exception)

@no_except(instead_return=False)
def example(raise_exception=False):
  if raise_exception:
    raise Exception("exception from example")
  return True

assert example()
assert example(False) == False

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

terse-0.0.4.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

terse-0.0.4-py2.py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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