def call_agent_side(self, method, *args, **kwargs):
        '''
        Call the method, wrap it in Deferred and bind error handler.
        '''
        assert not self._finalize_called, ("Attempt to call agent side code "
                                           "after finalize() method has been "
                                           "called. Method: %r" % (method, ))

        ensure_state = kwargs.pop('ensure_state', None)


        d = defer.Deferred(canceller=self._cancel_agent_side_call)
        self._agent_jobs.append(d)
        if ensure_state:
            # call method only if state check is checks in
            d.addCallback(
                lambda _: (self._ensure_state(ensure_state) and
                           method(*args, **kwargs)))
        else:
            d.addCallback(defer.drop_param, method, *args, **kwargs)
        d.addErrback(self._error_handler, method)
        d.addBoth(defer.bridge_param, self._remove_agent_job, d)
        time.call_next(d.callback, None)
        return d
def call_agent_side ( self , method , * args , ** kwargs ) : assert not self . _finalize_called , ( "Attempt to call agent side code " "after finalize() method has been " "called. Method: %r" % ( method , ) ) ensure_state = kwargs . pop ( 'ensure_state' , None ) d = defer . Deferred ( canceller = self . _cancel_agent_side_call ) self . _agent_jobs . append ( d ) if ensure_state : d . addCallback ( lambda _ : ( self . _ensure_state ( ensure_state ) and method ( * args , ** kwargs ) ) ) else : d . addCallback ( defer . drop_param , method , * args , ** kwargs ) d . addErrback ( self . _error_handler , method ) d . addBoth ( defer . bridge_param , self . _remove_agent_job , d ) time . call_next ( d . callback , None ) return d
Call the method, wrap it in Deferred and bind error handler.