Beispiel #1
0
def mutable(function):
    '''Combined decorator of guarded.mutable and journal.recorded.

    When called from outside a recording context, it returns a Deferred.
    When called from inside a recording context, it returns a L{fiber.Fiber}
    or any synchronous value.

    Same as using::

      @journal.recorded()
      @guard.mutable
      def spam(self, state, some, args):
          pass
    '''

    guard_wrapper = guard.mutable(function)

    # Register the function
    canonical = reflect.class_canonical_name(3)
    annotate.injectClassCallback("recorded", 4,
                                 "_register_recorded_call", guard_wrapper,
                                 class_canonical_name=canonical)

    def wrapper(self, *args, **kwargs):
        recorder = IRecorder(self)
        return recorder.call(guard_wrapper, args, kwargs)

    return wrapper
Beispiel #2
0
def entry_point(function):
    '''Combined decorator of guarded.mutable and journal.recorded
    that ensure the call is not reentrant.

    If a function decorated with it is called from inside a recording
    context it will raise L{f.i.j.ReentrantCallError}.

    Because the function cannot be called from inside a recording context,
    it always returns a Deferred.

    Same as using::

      @journal.recorded(reentrant=False)
      @guard.mutable
      def spam(self, state, some, args):
          pass
    '''

    guard_wrapper = guard.mutable(function)

    # Register the function
    canonical = reflect.class_canonical_name(3)
    annotate.injectClassCallback("recorded", 4,
                                 "_register_recorded_call", guard_wrapper,
                                 class_canonical_name=canonical)

    def wrapper(self, *args, **kwargs):
        recorder = IRecorder(self)
        return recorder.call(guard_wrapper, args, kwargs, reentrant=False)

    return wrapper
Beispiel #3
0
def recorded(function, custom_id=None, reentrant=True):
    """MUST only be used only with method from child
    classes of L{{Recorder}}."""
    canonical = reflect.class_canonical_name(3)
    annotate.injectClassCallback(
        "recorded", 4, "_register_recorded_call", function, custom_id=custom_id, class_canonical_name=canonical
    )

    def wrapper(self, *args, **kwargs):
        recorder = IRecorder(self)
        return recorder.call(function, args, kwargs, reentrant=reentrant)

    return wrapper