fdutils/decorators.py
def context_decorator(method_name_or_func, func_before=None, func_after=None):
    """ decorates a function with a context given by a method of the object where this is applied to
        or by a func
    """
    if not (isinstance(method_name_or_func, str) or is_instance_of_context_mgr(method_name_or_func)):
        raise TypeError('the method or name provided ({}) is not a string or ContextManager'
                        ''.format(method_name_or_func))

    def _context_decor(f):
        @functools.wraps(f)
        def wrapper(*args, **kwargs):
            self = f.__self__ if hasattr(f, '__self__') and f.__self__ else args[0]
            with getattr(self, method_name_or_func)():
                if func_before is not None:
                    func_before()

                ret = f(*args, **kwargs)

                if func_after is not None:
                    func_after()

                return ret

        return wrapper
    return _context_decor
 decorates a function with a context given by a method of the object where this is applied to
        or by a func
    
decorates a function with a context given by a method of the object where this is applied to
or by a func
decorates a function with a context given by a method of the object where this is applied to or by a func
def context_decorator(method_name_or_func, func_before=None, func_after=None):
    if not (isinstance(method_name_or_func, str) or is_instance_of_context_mgr(method_name_or_func)):
        raise TypeError('the method or name provided ({}) is not a string or ContextManager'
                        ''.format(method_name_or_func))
    def _context_decor(f):
        @functools.wraps(f)
        def wrapper(*args, **kwargs):
            self = f.__self__ if hasattr(f, '__self__') and f.__self__ else args[0]
            with getattr(self, method_name_or_func)():
                if func_before is not None:
                    func_before()
                ret = f(*args, **kwargs)
                if func_after is not None:
                    func_after()
                return ret
        return wrapper
    return _context_decor
def context_decorator ( method_name_or_func , func_before = None , func_after = None ) : if not ( isinstance ( method_name_or_func , str ) or is_instance_of_context_mgr ( method_name_or_func ) ) : raise TypeError ( 'the method or name provided ({}) is not a string or ContextManager' '' . format ( method_name_or_func ) ) def _context_decor ( f ) : @ functools . wraps ( f ) def wrapper ( * args , ** kwargs ) : self = f . __self__ if hasattr ( f , '__self__' ) and f . __self__ else args [ 0 ] with getattr ( self , method_name_or_func ) ( ) : if func_before is not None : func_before ( ) ret = f ( * args , ** kwargs ) if func_after is not None : func_after ( ) return ret return wrapper return _context_decor
decorates a function with a context given by a method of the object where this is applied to
or by a func
decorates a function with a context given by a method of the object where this is applied to or by a func
""" decorates a function with a context given by a method of the object where this is applied to
        or by a func
    """
method_name_or_func
func_before
func_after