Decorator to enable DebugPrint for a given function.

    Args:
        __func: Function to wrap
    Returns:
        Wrapped function
967055
def noisy_wrap(__func: Callable) -> Callable:
    
    # pylint: disable=missing-docstring
    def wrapper(*args, **kwargs):
        DebugPrint.enable()
        try:
            __func(*args, **kwargs)
        finally:
            DebugPrint.disable()
    return wrapper
1054814
def _wrapper(self, func):
        
        def wrapped(*args, **kwargs):
            ret_val = func(*args, **kwargs)
            if isinstance(ret_val, pymongo.cursor.Cursor):
                ret_val = self.from_cursor(ret_val)
            return ret_val

        return wrapped
229625
def disable_logging(func):
    return func
    
    handler = logging.NullHandler()

    @wraps(func)
    def wrapper(*args, **kwargs):
        logger = logging.getLogger()
        logger.addHandler(handler)
        resp = func(*args, **kwargs)
        logger.removeHandler(handler)
        return resp
    return wrapper
457656
def decorate(func, caller):
    
    evaldict = dict(_call_=caller, _func_=func)
    fun = FunctionMaker.create(
        func, "return _call_(_func_, %(shortsignature)s)",
        evaldict, __wrapped__=func)
    if hasattr(func, '__qualname__'):
        fun.__qualname__ = func.__qualname__
    return fun
792452
def exception(function):
    
    @functools.wraps(function)
    def wrapper(*exception, **kwargs):
        result = function(**kwargs)
        if exception:
            result.exception = exception[0]
        return result
    return wrapper
160510
def wrap_object(func, before, after):
    '''
    
    '''
    def _wrapper(*args, **kwargs):
        before()
        try:
            return func(*args, **kwargs)
        except Exception as e:
            raise e
        finally:
            after()
    return _wrapper
1004567
def trace(f):
    
    @functools.wraps(f)
    def decorator(*args, **kwargs):
        print 'Calling ' + f.func_name + ' in ' + str(args[0])
        return f(*args, **kwargs)
    return decorator
214853
def auto_string_formatter(func):
    
    @wraps(func)
    def auto_string_formatter_wrapper(function, *args, **kwargs):
        if isinstance(function, string_types):
            function = StringFormatter(function)

        return func(function, *args, **kwargs)

    return auto_string_formatter_wrapper
800894
def exception(function):
    
    @functools.wraps(function)
    def wrapper(*args, **kwargs):
        try:
            return function(*args, **kwargs)
        except Exception as e:
            # print 
            err = "There was an exception in %s():"%(function.__name__)
            print(("%s \n %s \n%s"%(err,e,sys.exc_info())))
            return -1
 
    return wrapper
1025404
def connected(func):
    
    @wraps(func)
    def wrapper(*args, **kwargs):
        self = args[0]
        if not self.connected:
            self.show_output("Not connected.")
        else:
            try:
                return func(*args, **kwargs)
            except APIError:
                self.show_output("ZooKeeper internal error.")
            except AuthFailedError:
                self.show_output("Authentication failed.")
            except NoAuthError:
                self.show_output("Not authenticated.")
            except BadVersionError:
                self.show_output("Bad version.")
            except ConnectionLoss:
                self.show_output("Connection loss.")
            except NotReadOnlyCallError:
                self.show_output("Not a read-only operation.")
            except BadArgumentsError:
                self.show_output("Bad arguments.")
            except SessionExpiredError:
                self.show_output("Session expired.")
            except UnimplementedError as ex:
                self.show_output("Not implemented by the server: %s." % str(ex))
            except ZookeeperError as ex:
                self.show_output("Unknown ZooKeeper error: %s" % str(ex))

    return wrapper
201697
def call_and_wrap(func, *args, **kw):
    '''
    '''
    try:
        return func(*args, **kw)
    except api.exceptions.APIException as ex:
        click_exception(ex)
    except urllib3exc.SSLError:
        # see monkey patch above re InsecurePlatformWarning
        if _insecure_warning:
            click.echo(click.style(str(_insecure_warning[0]), fg='red'))
        raise
430865
def decorate(func, caller):
    
    evaldict = func.__globals__.copy()
    evaldict['_call_'] = caller
    evaldict['_func_'] = func
    fun = FunctionMaker.create(
        func, "return _call_(_func_, %(shortsignature)s)",
        evaldict, __wrapped__=func)
    if hasattr(func, '__qualname__'):
        fun.__qualname__ = func.__qualname__
    return fun
368144
def optional_args_func(func) -> callable:
    
    if getattr(func, '_optional_args_func', False):
        return func

    is_generator = inspect.isgeneratorfunction(func)
    func_sig = inspect.signature(func)
    expects_nothing = not func_sig.parameters

    if is_generator:
        @functools.wraps(func)
        def wrapped(*args, **kwargs):
            if expects_nothing:
                yield from func()
            else:
                bound_arguments = func_sig.bind(*args, **{k: v for k, v in kwargs.items() if k in func_sig.parameters})
                yield from func(*bound_arguments.args, **bound_arguments.kwargs)
    else:
        @functools.wraps(func)
        def wrapped(*args, **kwargs):
            if expects_nothing:
                return func()
            else:
                bound_arguments = func_sig.bind(*args, **{k: v for k, v in kwargs.items() if k in func_sig.parameters})
                return func(*bound_arguments.args, **bound_arguments.kwargs)

    # Mark it so that we don't double wrap our own
    setattr(wrapped, '_optional_args_func', True)

    return wrapped
901913
def deprecated(func):
    
    @functools.wraps(func)
    def new_func(*args, **kwargs):
        if sys.version_info < (3, 0):
            warnings.warn_explicit(
                "Call to deprecated function {}.".format(func.__name__),
                category=DeprecationWarning,
                filename=func.func_code.co_filename,
                lineno=func.func_code.co_firstlineno + 1
            )
        else:
            warnings.warn_explicit(
                "Call to deprecated function {}.".format(func.__name__),
                category=DeprecationWarning,
                filename=func.__code__.co_filename,
                lineno=func.__code__.co_firstlineno + 1
            )
        return func(*args, **kwargs)
    return new_func
337674
def clean_fail(func):
    '''
    
    '''
    def func_wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except botocore.exceptions.ClientError as e:
            print(str(e), file=sys.stderr)
            sys.exit(1)
    return func_wrapper
1101828
def _dual_decorator(func):
    

    @functools.wraps(func)
    def inner(*args, **kwargs):
        if ((len(args) == 1 and not kwargs and callable(args[0])
             and not (type(args[0]) == type and issubclass(args[0], BaseException)))):
            return func()(args[0])
        elif len(args) == 2 and inspect.isclass(args[0]) and callable(args[1]):
            return func(args[0], **kwargs)(args[1])
        else:
            return func(*args, **kwargs)
    return inner
745884
def to_method(func):
    
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        """Wrapper function.
        """
        return func(*args[1:], **kwargs)

    return wrapper