Exemplo n.º 1
0
 def set(value, context):
     source = context["model"].source
     name = context["key"]
     self.assertEqual(source, exp_source)
     self.assertEqual(name, exp_name)
     method = getattr(source, method_name)
     return defer.maybeDeferred(method, value)
Exemplo n.º 2
0
Arquivo: call.py Projeto: f3at/feat
def _perform(method, value, params, args, kwargs):
    keywords = dict(kwargs)
    keywords.update(params)
    keywords["value"] = value
    arguments = []

    func = method

    if isinstance(method, types.MethodType):
        func = method.im_func

    if hasattr(func, 'original_func'):
        func = func.original_func

    argspec = inspect.getargspec(func)

    for name in argspec.args:
        if name in ("self"):
            continue
        if name not in keywords:
            break
        arguments.append(keywords.pop(name))

    arguments.extend(args)

    if not argspec.keywords:
        expected = set(argspec.args)
        for name in keywords.keys():
            if name not in expected:
                del keywords[name]

    return defer.maybeDeferred(method, *arguments, **keywords)
Exemplo n.º 3
0
 def _call(self, method, *args, **kwargs):
     '''Call the method, wrap it in Deferred and bind error handler'''
     if self._deferred:
         self._deferred.cancel()
     self._deferred = d = defer.maybeDeferred(method, *args, **kwargs)
     d.addErrback(self._error_handler)
     return d
Exemplo n.º 4
0
 def to_call(callback):
     if state:
         self._set_state(state)
     self.log('Calling method: %r with args: %r', method, args)
     d = defer.maybeDeferred(method, *args, **kwargs)
     d.addErrback(self._error_handler)
     d.addCallback(callback.callback)
Exemplo n.º 5
0
 def stop_listening(self):
     if self._port is not None:
         d = defer.maybeDeferred(self._port.stopListening)
         d.addCallback(defer.override_result, None)
         self._port = None
         self._url = None
         return d
     return defer.succeed(None)
Exemplo n.º 6
0
 def _run_and_wait(self, _, method, *args, **kwargs):
     '''
     Run a agent-side method and wait for all the protocols
     to finish processing.
     '''
     d = defer.maybeDeferred(method, *args, **kwargs)
     d.addBoth(defer.drop_param, self.wait_for_protocols_finish)
     return d
Exemplo n.º 7
0
Arquivo: base.py Projeto: f3at/feat
    def stop_listening(self):
        def stopped(_):
            self._port = None
            return self

        if self._port is not None:
            d = defer.maybeDeferred(self._port.stopListening)
            d.addCallback(defer.drop_param, self._on_stopped)
            d.addCallback(stopped)
            return d

        return defer.succeed(self)
Exemplo n.º 8
0
    def _external_route_action(self, _method, _action, backend_id, **kwargs):

        defers = []
        for backend in self._backends.values():
            method = getattr(backend, _method)
            d = defer.maybeDeferred(method, backend_id, **kwargs)
            d.addErrback(defer.print_trace)
            d.addCallback(lambda res: (backend.channel_type, res))
            defers.append(d)

        d = defer.DeferredList(defers, consumeErrors=True)
        d.addCallback(self._external_route_action_cb, _action, backend_id, kwargs)
        return d
Exemplo n.º 9
0
 def disconnect(self):
     '''
     This is called as part of the agency shutdown.
     '''
     self.log("Disconnecting broker %r.", self)
     if self.is_master():
         d = self.listener.stopListening()
         d.addCallback(defer.drop_param, self.factory.disconnect)
     elif self.is_slave():
         d = defer.maybeDeferred(self.factory.disconnect)
     elif self._cmp_state(BrokerRole.disconnected):
         return defer.succeed(None)
     d.addCallback(defer.drop_param, self.become_disconnected)
     return d
Exemplo n.º 10
0
    def _call(self, method, *args, **kwargs):

        def raise_on_fiber(res):
            if isinstance(res, fiber.Fiber):
                raise RuntimeError("We are not expecting method %r to "
                                   "return a Fiber, which it did!" % method)
            return res

        self.log('Calling method %r, with args: %r, kwargs: %r', method,
                 args, kwargs)
        d = defer.maybeDeferred(method, *args, **kwargs)
        d.addCallback(raise_on_fiber)
        d.addErrback(self._error_handler)
        return d
Exemplo n.º 11
0
Arquivo: setter.py Projeto: f3at/feat
def _set(method, key, value, args, kwargs):
    return defer.maybeDeferred(method, key, value, *args, **kwargs)
Exemplo n.º 12
0
 def _call(self, method, *args, **kwargs):
     '''Call the method, wrap it in Deferred and bind error handler'''
     d = defer.maybeDeferred(method, *args, **kwargs)
     d.addErrback(lambda f: error_handler(self, f))
     return d
Exemplo n.º 13
0
 def _expired(self, arg):
     self._set_state(TaskState.expired)
     d = defer.maybeDeferred(self.task.expired)
     return d
Exemplo n.º 14
0
 def _initiate(self, *args, **kwargs):
     d = defer.maybeDeferred(self.task.initiate, *args, **kwargs)
     d.addCallbacks(self._completed, self._error)
     return d
Exemplo n.º 15
0
 def _run(self):
     d = defer.maybeDeferred(self.run)
     d.addErrback(defer.inject_param, 1, error.handle_failure, self,
                  "Failure during stealth task execution")
     d.addCallback(self._schedule)
     return d
Exemplo n.º 16
0
Arquivo: poster.py Projeto: f3at/feat
 def notify(self, *args, **kwargs):
     d = defer.maybeDeferred(self.pack_payload, *args, **kwargs)
     d.addCallback(self._build_message)
     return d
Exemplo n.º 17
0
Arquivo: call.py Projeto: f3at/feat
def _call(method, args, kwargs):
    return defer.maybeDeferred(method, *args, **kwargs)
Exemplo n.º 18
0
 def perform(self):
     d = defer.maybeDeferred(self.method, *self.args, **self.kwargs)
     d.addCallback(defer.keep_param, self.callback.callback)
     return d
Exemplo n.º 19
0
 def _cancel_long_running_protocols(self):
     return defer.DeferredList([defer.maybeDeferred(x.cancel)
                                for x in self._long_running_protocols])
Exemplo n.º 20
0
def _get(method, key, args, kwargs):
    return defer.maybeDeferred(method, key, *args, **kwargs)
Exemplo n.º 21
0
Arquivo: call.py Projeto: f3at/feat
def _filter(method, value, args, kwargs):
    return defer.maybeDeferred(method, value, *args, **kwargs)
Exemplo n.º 22
0
Arquivo: common.py Projeto: f3at/feat
 def _notify(self, callbacks):
     defers = map(lambda cb: defer.maybeDeferred(cb), callbacks)
     return defer.DeferredList(defers, consumeErrors=True)
Exemplo n.º 23
0
 def _call_initiate(self, **kwargs):
     self._set_state(AgencyAgentState.initiating)
     d = defer.maybeDeferred(self.agent.initiate_agent, **kwargs)
     d.addCallback(fiber.drop_param, self._set_state,
                   AgencyAgentState.initiated)
     return d