示例#1
0
  def _step(self, result):
    """Takes a single step in the generator / deferred interaction."""

    # Largely based on the twisted.internet.defer.inlineCallbacks implementation.

    # This function is complicated by the need to prevent unbounded recursion
    # arising from repeatedly yielding immediately ready deferreds.  This while
    # loop and the waiting variable solve that by manually unfolding the
    # recursion.
    while self._state != STATE_CANCELLED:
      try:
        # Send the last result back as the result of the yield expression.
        if isinstance(result, failure.Failure):
          result = result.throwExceptionIntoGenerator(self._generator)
        else:
          result = self._generator.send(result)
      except StopIteration:
        # Fell off the end, or "return" statement
        if self._state != STATE_CANCELLED:
          self.callback(None)
        return
      except defer._DefGen_Return, e: # Need to access protected member for consistency. # pylint: disable=W0212
        if self._state != STATE_CANCELLED:
          context.setCurrent(self._context)
          self.callback(e.value)
        return
      except:
示例#2
0
    def _step(self, result):
        """Takes a single step in the generator / deferred interaction."""

        # Largely based on the twisted.internet.defer.inlineCallbacks implementation.

        # This function is complicated by the need to prevent unbounded recursion
        # arising from repeatedly yielding immediately ready deferreds.  This while
        # loop and the waiting variable solve that by manually unfolding the
        # recursion.
        while self._state != STATE_CANCELLED:
            try:
                # Send the last result back as the result of the yield expression.
                if isinstance(result, failure.Failure):
                    result = result.throwExceptionIntoGenerator(self._generator)
                else:
                    result = self._generator.send(result)
            except StopIteration:
                # Fell off the end, or "return" statement
                if self._state != STATE_CANCELLED:
                    self.callback(None)
                return
            except defer._DefGen_Return, e:  # Need to access protected member for consistency. # pylint: disable=W0212
                if self._state != STATE_CANCELLED:
                    context.setCurrent(self._context)
                    self.callback(e.value)
                return
            except:
示例#3
0
    def call(*args, **kwargs):
        """The new function."""
        # Save and restore the context afterwards so fn() doesn't interfere with other deferreds
        current = context.current()
        reprFn = None
        if args[:1] and hasattr(args[0], 'describeDeferred'):
            reprFn = args[0].describeDeferred
        className = None
        if isMethod and args:
            try:
                className = args[0].__class__.__name__
            except AttributeError:
                pass
        d = InlinedCallbacks(fn(*args, **kwargs),
                             reprFn=reprFn,
                             className=className)
        context.setCurrent(current)

        if d.called:
            if isinstance(d.result, failure.Failure):
                f = d.result
                d.addErrback(
                    lambda _: None
                )  # Eat the error so we don't get Unhandled Error In Deferred.
                f.raiseException()
            else:
                return d.result
        else:
            return d
示例#4
0
  def call(*args, **kwargs):
    """The new function."""
    # Save and restore the context afterwards so fn() doesn't interfere with other deferreds
    current = context.current()
    reprFn = None
    if args[:1] and hasattr(args[0], 'describeDeferred'):
      reprFn = args[0].describeDeferred
    className = None
    if isMethod and args:
      try:
        className = args[0].__class__.__name__
      except AttributeError:
        pass
    d = InlinedCallbacks(fn(*args, **kwargs), reprFn=reprFn, className=className)
    context.setCurrent(current)

    if d.called:
      if isinstance(d.result, failure.Failure):
        f = d.result
        d.addErrback(lambda _: None) # Eat the error so we don't get Unhandled Error In Deferred.
        f.raiseException()
      else:
        return d.result
    else:
      return d
示例#5
0
  def call(*args, **kwargs):
    """The new function."""
    # Save and restore the context afterwards so fn() doesn't interfere with other deferreds
    current = context.current()
    d = InlinedCallbacks(fn(*args, **kwargs))
    context.setCurrent(current)

    if d.called:
      if isinstance(d.result, failure.Failure):
        f = d.result
        d.addErrback(lambda _: None) # Eat the error so we don't get Unhandled Error In Deferred.
        f.raiseException()
      else:
        return d.result
    else:
      return d
示例#6
0
    def call(*args, **kwargs):
        """The new function."""
        # Save and restore the context afterwards so fn() doesn't interfere with other deferreds
        current = context.current()
        d = InlinedCallbacks(fn(*args, **kwargs))
        context.setCurrent(current)

        if d.called:
            if isinstance(d.result, failure.Failure):
                f = d.result
                d.addErrback(lambda _: None)  # Eat the error so we don't get Unhandled Error In Deferred.
                f.raiseException()
            else:
                return d.result
        else:
            return d