a collection of function decorators to handle common procedures done on the entry and exit points.
Project description
# Python terse Library
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.
```python
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.
```python
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
```
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.
```python
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.
```python
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
terse-0.0.3.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for terse-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebfa537556d660cbc2605ff5d6266f80000fe7b2a743d157b56cc9c660a79568 |
|
MD5 | b20c133350cdc4344548d36339a6f87f |
|
BLAKE2b-256 | aa418199cc5f88708cb7cc0c45ff17f789df2139f8bdad69ba10ee397722b171 |