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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for terse-0.0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f5c70d96d1b7f92d14d317032d8e9ab4ca2a412bafbf2dd82b1f1e7661804ef |
|
MD5 | 86109d41377a31206139a784b3ef57a6 |
|
BLAKE2b-256 | 3ba3d9c1fe74f6f508d355313c2759217e6ccfe0d9019e3eaa509d69377039c0 |