Esempio n. 1
0
 def side_effect(*args, **kwargs):
     if 'getSlaveInfo' in args:
         return defer.fail(twisted_pb.NoSuchMethod())
     if 'getCommands' in args:
         return defer.succeed({'x': 1, 'y': 2})
     if 'getVersion' in args:
         return defer.succeed('TheVersion')
Esempio n. 2
0
 def callRemote(self, command, *args):
     self.commands.append((command, ) + args)
     response = self.response.get(command)
     if response:
         return response(*args)
     else:
         return defer.fail(pb.NoSuchMethod(command))
Esempio n. 3
0
    def remoteMessageReceived(self, broker, message, args, kwargs):
        args = broker.unserialize(args)
        kwargs = broker.unserialize(kwargs)
        method = getattr(self, "remote_%s" % message, None)
        if method is None:
            raise pb.NoSuchMethod("No such method: remote_%s" % (message, ))

        level = flog.DEBUG
        if message == 'ping':
            level = flog.LOG

        debugClass = self.logCategory.upper()
        # all this malarkey is to avoid actually interpolating variables
        # if it is not needed
        startArgs = [self.remoteLogName, debugClass, message]
        formatString, debugArgs = flog.getFormatArgs('%s --> %s: remote_%s(',
                                                     startArgs, ')', (), args,
                                                     kwargs)
        # log going into the method
        logKwArgs = self.doLog(level, method, formatString, *debugArgs)

        # invoke the remote_ method
        d = defer.maybeDeferred(method, *args, **kwargs)

        # log coming out of the method

        def callback(result):
            formatString, debugArgs = flog.getFormatArgs(
                '%s <-- %s: remote_%s(', startArgs, '): %r',
                (flog.ellipsize(result), ), args, kwargs)
            self.doLog(level, -1, formatString, *debugArgs, **logKwArgs)
            return result

        def errback(failure):
            formatString, debugArgs = flog.getFormatArgs(
                '%s <-- %s: remote_%s(', startArgs, '): failure %r',
                (failure, ), args, kwargs)
            self.doLog(level, -1, formatString, *debugArgs, **logKwArgs)
            return failure

        d.addCallbacks(callback, errback)
        return broker.serialize(d, self.perspective)
Esempio n. 4
0
    def perspectiveMessageReceivedUnserialised(self, broker, message, args,
                                               kwargs):
        method = getattr(self, "perspective_%s" % message, None)
        if method is None:
            raise pb.NoSuchMethod("No such method: perspective_%s" %
                                  (message, ))

        level = flog.DEBUG
        if message == 'ping':
            level = flog.LOG
        debugClass = self.logCategory.upper()
        startArgs = [self.remoteLogName, debugClass, message]
        formatString, debugArgs = flog.getFormatArgs(
            '%s --> %s: perspective_%s(', startArgs, ')', (), args, kwargs)
        # log going into the method
        logKwArgs = self.doLog(level, method, formatString, *debugArgs)

        # invoke the perspective_ method
        d = defer.maybeDeferred(method, *args, **kwargs)

        # log coming out of the method

        def callback(result):
            formatString, debugArgs = flog.getFormatArgs(
                '%s <-- %s: perspective_%s(', startArgs, '): %r',
                (flog.ellipsize(result), ), args, kwargs)
            self.doLog(level, -1, formatString, *debugArgs, **logKwArgs)
            return result

        def errback(failure):
            formatString, debugArgs = flog.getFormatArgs(
                '%s <-- %s: perspective_%s(', startArgs, '): failure %r',
                (failure, ), args, kwargs)
            self.doLog(level, -1, formatString, *debugArgs, **logKwArgs)
            return failure

        d.addCallbacks(callback, errback)

        return broker.serialize(d, self, method, args, kwargs)