def attach(decorator, obj, recursive = True):
    """attach(decorator, class_or_module[, recursive = True])

    Utility to attach a \val{decorator} to the \val{obj} instance.

    If \val{obj} is a module, the decorator will be attached to every
    function and class in the module.

    If \val{obj} is a class, the decorator will be attached to every
    method and subclass of the class.

    if \val{recursive} is "True" then subclasses will be decorated.
    """
    if inspect.ismodule(obj):
        for name, fn in inspect.getmembers(obj, inspect.isfunction):
            setattr(obj, name, decorator(fn))
        for name, klass in inspect.getmembers(obj, inspect.isclass):
            attachToClass(decorator, klass, recursive)
    elif inspect.isclass(obj):
        attachToClass(decorator, obj, recursive)
attach(decorator, class_or_module[, recursive = True])

    Utility to attach a al{decorator} to the al{obj} instance.

    If al{obj} is a module, the decorator will be attached to every
    function and class in the module.

    If al{obj} is a class, the decorator will be attached to every
    method and subclass of the class.

    if al{recursive} is "True" then subclasses will be decorated.
    
recipes/Python/577551_Trace_decorator_for_debugging/recipe-577551.py