Beispiel #1
0
 def __init__(self, wrapped, iscalled=True, calls=None, callback=None, extended=False, results=False,
              recurse_lock=None, binding=None):
     assert not results or iscalled, "`iscalled` must be True if `results` is True"
     mimic(self, wrapped)
     self.__wrapped = wrapped
     self.__entanglement = None
     self.__iscalled = iscalled
     self.__binding = binding
     self.__callback = callback
     self.__extended = extended
     self.__results = results
     self.__recurse_lock = recurse_lock
     self.calls = [] if not callback and calls is None else calls
Beispiel #2
0
 def __init__(self, wrapped, iscalled=True, calls=None, callback=None, extended=False, results=False,
              recurse_lock=None, binding=None):
     assert not results or iscalled, "`iscalled` must be True if `results` is True"
     mimic(self, wrapped)
     self.__wrapped = wrapped
     self.__entanglement = None
     self.__iscalled = iscalled
     self.__binding = binding
     self.__callback = callback
     self.__extended = extended
     self.__results = results
     self.__recurse_lock = recurse_lock
     self.calls = [] if not callback and calls is None else calls
Beispiel #3
0
 def __get__(self, binding, owner):
     return mimic(type(self)(
         self._wrapped.__get__(binding, owner) if hasattr(self._wrapped, '__get__') else self._wrapped,
         handle=self._handle,
         binding=binding,
         owner=owner,
     ), self)
Beispiel #4
0
 def __get__(self, binding, owner):
     return mimic(type(self)(
         self._wrapped.__get__(binding, owner) if hasattr(self._wrapped, '__get__') else self._wrapped,
         handle=self._handle,
         binding=binding,
         owner=owner,
     ), self)
def decorate_advising_asyncgenerator_py35(advising_function, cutpoint_function,
                                          bind):
    assert isasyncgenfunction(cutpoint_function) or iscoroutinefunction(
        cutpoint_function)

    async def advising_asyncgenerator_wrapper_py35(*args, **kwargs):
        if bind:
            advisor = advising_function(cutpoint_function, *args, **kwargs)
        else:
            advisor = advising_function(*args, **kwargs)
        if not isgenerator(advisor):
            raise ExpectedGenerator(
                "advising_function %s did not return a generator." %
                advising_function)
        try:
            advice = next(advisor)
            while True:
                logdebug('Got advice %r from %s', advice, advising_function)
                if advice is Proceed or advice is None or isinstance(
                        advice, Proceed):
                    if isinstance(advice, Proceed):
                        args = advice.args
                        kwargs = advice.kwargs
                    gen = cutpoint_function(*args, **kwargs)
                    try:
                        result = await gen
                    except BaseException:
                        advice = advisor.throw(*sys.exc_info())
                    else:
                        try:
                            advice = advisor.send(result)
                        except StopIteration:
                            return result
                    finally:
                        gen.close()
                elif advice is Return:
                    return
                elif isinstance(advice, Return):
                    return advice.value
                else:
                    raise UnacceptableAdvice("Unknown advice %s" % advice)
        finally:
            advisor.close()

    return mimic(advising_asyncgenerator_wrapper_py35, cutpoint_function)
def decorate_advising_generator_py3(advising_function, cutpoint_function, bind):
    assert isgeneratorfunction(cutpoint_function)

    def advising_generator_wrapper_py3(*args, **kwargs):
        if bind:
            advisor = advising_function(cutpoint_function, *args, **kwargs)
        else:
            advisor = advising_function(*args, **kwargs)
        if not isgenerator(advisor):
            raise ExpectedGenerator("advising_function %s did not return a generator." % advising_function)
        try:
            advice = next(advisor)
            while True:
                logdebug('Got advice %r from %s', advice, advising_function)
                if advice is Proceed or advice is None or isinstance(advice, Proceed):
                    if isinstance(advice, Proceed):
                        args = advice.args
                        kwargs = advice.kwargs
                    gen = cutpoint_function(*args, **kwargs)
                    try:
                        result = yield from gen
                    except BaseException:
                        advice = advisor.throw(*sys.exc_info())
                    else:
                        try:
                            advice = advisor.send(result)
                        except StopIteration:
                            return
                    finally:
                        gen.close()
                elif advice is Return:
                    return
                elif isinstance(advice, Return):
                    raise StopIteration(advice.value)
                else:
                    raise UnacceptableAdvice("Unknown advice %s" % advice)
        finally:
            advisor.close()
    return mimic(advising_generator_wrapper_py3, cutpoint_function)
Beispiel #7
0
 def __init__(self, cutpoint_function, binding=None):
     mimic(self, cutpoint_function)
     self.cutpoint_function = cutpoint_function
     self.final_function = super(__logged__, self).__call__(cutpoint_function)
     self.binding = binding
 def __init__(self, cutpoint_function, binding=None):
     mimic(self, cutpoint_function)
     self.cutpoint_function = cutpoint_function
     self.final_function = super(__logged__, self).__call__(cutpoint_function)
     self.binding = binding