Make log_error actually return a value.
[matthijs/projects/xerxes.git] / tools / misc.py
1 """
2 Makes an iteratable object out of the given value. If value is already
3 iterable, it is simply returned. An exception is made for strings, which
4 are treated as non-iterable (It is assumed that you never want to have a
5 list of characters). For non iteratable values or strings, a list
6 containing only value is returned.
7 """
8 def make_iter(value):
9     if (not isinstance(value, basestring)):
10         try:
11             iter(value)
12             return value
13         except TypeError:
14             pass
15     return [value]
16 # vim: set sts=4 sw=4 expandtab:
17
18 """
19 Decarator that catches any exception raised by the decorated function,
20 prints it to stdout and raises it again.
21 """
22 def log_error(func):
23     def show(*args, **kwargs):
24         try:
25             return func(*args, **kwargs)
26         except Exception, e:
27             import traceback
28             traceback.print_exc()
29             raise e
30     return show