Ejemplo n.º 1
0
def update_wrapper(wrapper, wrapped):
    """Preserves the argspec for a wrapped function so that testing tools such
    as pytest can continue to use their fixture injection.

    :param wrapper: the wrapper function to update
    :param wrapped: the decorated test function
    """
    newargspec = inspect.getargspec(wrapped)
    need_self = len(newargspec[0]) > 0 and newargspec[0][0] == 'self'

    if need_self:
        newargspec = (newargspec[0], ) + newargspec[1:]

    signature = inspect.formatargspec(*newargspec)[1:-1]
    ctx = {'signature': signature, 'tgt_func': 'tgt_func'}

    evaldict = {'tgt_func': wrapper}

    six.exec_(_wrapper_template % ctx, evaldict)

    wrapper = evaldict['_wrapper_']
    if hasattr(wrapped, 'func_defaults'):
        wrapper.func_defaults = wrapped.func_defaults
    _update_wrapper(wrapper, wrapped)
    return wrapper
Ejemplo n.º 2
0
def update_wrapper(wrapper, wrapped):
    """Preserves the argspec for a wrapped function so that testing tools such
    as pytest can continue to use their fixture injection.

    :param wrapper: the wrapper function to update
    :param wrapped: the decorated test function
    """
    newargspec = inspect.getargspec(wrapped)
    need_self = len(newargspec[0]) > 0 and newargspec[0][0] == 'self'

    if need_self:
        newargspec = (newargspec[0],) + newargspec[1:]

    signature = inspect.formatargspec(*newargspec)[1:-1]
    ctx = {'signature': signature, 'tgt_func': 'tgt_func'}

    evaldict = {'tgt_func': wrapper}

    six.exec_(_wrapper_template % ctx, evaldict)

    wrapper = evaldict['_wrapper_']
    if hasattr(wrapped, 'func_defaults'):
        wrapper.func_defaults = wrapped.func_defaults
    _update_wrapper(wrapper, wrapped)
    return wrapper
Ejemplo n.º 3
0
def update_wrapper(wrapper, _decorated_fn, *, insert_args=0, insert_kwargs=''):
    '''replacement for functools.update_wrapper'''
    sig = _get_altered_signature(wrapper, insert_args, insert_kwargs,
                                 _decorated_fn)
    _update_wrapper(wrapper, _decorated_fn)
    wrapper.__signature__ = sig
    return wrapper
Ejemplo n.º 4
0
    def __init__(self, fget=None, fset=None, fdel=None, doc=None):

        doc = doc or fget.__doc__
        super(cachedproperty, self).__init__(fget, None, None, doc)

        if fget is None:
            self._func = None
            self._func_name = ''
        else:
            self._func = fget
            self._func_name = self._func.__name__

        _update_wrapper(self, fget)

        self._lock = _RLock()
Ejemplo n.º 5
0
def update_wrapper(proxy, original):
    """Update `proxy` to look like `original`.
    Uses :func:`functools.update_wrapper` internally and adds the function
    signature to the new created proxy function.
    """
    func = _update_wrapper(proxy, original)
    func.signature = getargspec(original)
    return func
Ejemplo n.º 6
0
def update_wrapper(proxy, original):
    """Update `proxy` to look like `original`.
    Uses :func:`functools.update_wrapper` internally and adds the function
    signature to the new created proxy function.
    """
    func = _update_wrapper(proxy, original)
    func.signature = getargspec(original)
    return func
Ejemplo n.º 7
0
    def __init__(self, function, *, operators: '+-*|@...' = None):
        self.function = function

        _update_wrapper(self, self.function)

        if isinstance(operators, str):
            if ' ' in operators:
                operators = operators.split()
        if operators:
            # assert is_iterable(operators)
            operators = set(operators)
            if not set(operators) <= ops.keys():
                raise ValueError(
                    str(*tuple(operators)) +
                    str(f'must be in {tuple(ops.keys())}'))

            self.forbidden = set(ops.keys() - operators)
        else:
            self.forbidden = set()
Ejemplo n.º 8
0
 def update_wrapper(wrapper, wrapped, *args, **kwargs):
     wrapper = _update_wrapper(wrapper, wrapped, *args, **kwargs)
     wrapper.__wrapped__ = wrapped
     return wrapped
Ejemplo n.º 9
0
def update_wrapper(wrapper, wrapped, *args, **kwargs):
    """Update wrapper, also setting .__wrapped__."""
    wrapper = _update_wrapper(wrapper, wrapped, *args, **kwargs)
    wrapper.__wrapped__ = wrapped
    return wrapper
Ejemplo n.º 10
0
def update_wrapper(wrapper, wrapped, *args, **kwargs):
    """Update wrapper, also setting .__wrapped__."""
    wrapper = _update_wrapper(wrapper, wrapped, *args, **kwargs)
    wrapper.__wrapped__ = wrapped
    return wrapper
Ejemplo n.º 11
0
 def __init__(self, func):
     self.func = func
     _update_wrapper(self, func)
Ejemplo n.º 12
0
def update_wrapper(wrapper, wrapped, *args, **kwargs):
    wrapper = _update_wrapper(wrapper, wrapped, *args, **kwargs)
    wrapper.__wrapped__ = wrapped
    return wrapper