def callRemoteLogging(self, level, stackDepth, name, *args, **kwargs): """ Call the given method with the given arguments remotely on the server-side avatar. Gets serialized to server-side perspective_ methods. @param level: the level we should log at (log.DEBUG, log.INFO, etc) @type level: int @param stackDepth: the number of stack frames to go back to get file and line information, negative or zero. @type stackDepth: non-positive int @param name: name of the remote method @type name: str """ if level is not None: debugClass = str(self.__class__).split(".")[-1].upper() startArgs = [self.remoteLogName, debugClass, name] formatString, debugArgs = log.getFormatArgs( '%s --> %s: callRemote(%s, ', startArgs, ')', (), args, kwargs) logKwArgs = self.doLog(level, stackDepth - 1, formatString, *debugArgs) if not self.remote: self.warning('Tried to callRemote(%s), but we are disconnected' % name) return defer.fail(errors.NotConnectedError()) def callback(result): formatString, debugArgs = log.getFormatArgs( '%s <-- %s: callRemote(%s, ', startArgs, '): %s', (log.ellipsize(result), ), args, kwargs) self.doLog(level, -1, formatString, *debugArgs, **logKwArgs) return result def errback(failure): formatString, debugArgs = log.getFormatArgs( '%s <-- %s: callRemote(%s, ', startArgs, '): %r', (failure, ), args, kwargs) self.doLog(level, -1, formatString, *debugArgs, **logKwArgs) return failure d = self.remote.callRemote(name, *args, **kwargs) if level is not None: d.addCallbacks(callback, errback) return d
def callRemoteLogging(self, level, stackDepth, name, *args, **kwargs): """ Call the given method with the given arguments remotely on the server-side avatar. Gets serialized to server-side perspective_ methods. @param level: the level we should log at (log.DEBUG, log.INFO, etc) @type level: int @param stackDepth: the number of stack frames to go back to get file and line information, negative or zero. @type stackDepth: non-positive int @param name: name of the remote method @type name: str """ if level is not None: debugClass = str(self.__class__).split(".")[-1].upper() startArgs = [self.remoteLogName, debugClass, name] format, debugArgs = log.getFormatArgs( '%s --> %s: callRemote(%s, ', startArgs, ')', (), args, kwargs) logKwArgs = self.doLog(level, stackDepth - 1, format, *debugArgs) if not self.remote: self.warning('Tried to callRemote(%s), but we are disconnected' % name) return defer.fail(errors.NotConnectedError()) def callback(result): format, debugArgs = log.getFormatArgs( '%s <-- %s: callRemote(%s, ', startArgs, '): %s', (log.ellipsize(result), ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return result def errback(failure): format, debugArgs = log.getFormatArgs( '%s <-- %s: callRemote(%s, ', startArgs, '): %r', (failure, ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return failure d = self.remote.callRemote(name, *args, **kwargs) if level is not None: d.addCallbacks(callback, errback) return d
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] format, debugArgs = flog.getFormatArgs( '%s --> %s: remote_%s(', startArgs, ')', (), args, kwargs) # log going into the method logKwArgs = self.doLog(level, method, format, *debugArgs) # invoke the remote_ method d = defer.maybeDeferred(method, *args, **kwargs) # log coming out of the method def callback(result): format, debugArgs = flog.getFormatArgs( '%s <-- %s: remote_%s(', startArgs, '): %r', (flog.ellipsize(result), ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return result def errback(failure): format, debugArgs = flog.getFormatArgs( '%s <-- %s: remote_%s(', startArgs, '): failure %r', (failure, ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return failure d.addCallbacks(callback, errback) return broker.serialize(d, self.perspective)
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)
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] format, debugArgs = flog.getFormatArgs( '%s --> %s: perspective_%s(', startArgs, ')', (), args, kwargs) # log going into the method logKwArgs = self.doLog(level, method, format, *debugArgs) # invoke the perspective_ method d = defer.maybeDeferred(method, *args, **kwargs) # log coming out of the method def callback(result): format, debugArgs = flog.getFormatArgs( '%s <-- %s: perspective_%s(', startArgs, '): %r', (flog.ellipsize(result), ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return result def errback(failure): format, debugArgs = flog.getFormatArgs( '%s <-- %s: perspective_%s(', startArgs, '): failure %r', (failure, ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return failure d.addCallbacks(callback, errback) return broker.serialize(d, self, method, args, kwargs)
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)
def errback(failure): format, debugArgs = flog.getFormatArgs( '%s <-- %s: callRemote(%s, ', startArgs, '): %r', (failure, ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return failure
def callback(result): format, debugArgs = flog.getFormatArgs( '%s <-- %s: callRemote(%s, ', startArgs, '): %r', (flog.ellipsize(result), ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return result
def errback(failure): format, debugArgs = flog.getFormatArgs( '%s <-- %s: perspective_%s(', startArgs, '): failure %r', (failure, ), args, kwargs) self.doLog(level, -1, format, *debugArgs, **logKwArgs) return failure
def errback(failure): formatString, debugArgs = log.getFormatArgs( '%s <-- %s: callRemote(%s, ', startArgs, '): %r', (failure, ), args, kwargs) self.doLog(level, -1, formatString, *debugArgs, **logKwArgs) return failure
def callback(result): formatString, debugArgs = log.getFormatArgs( '%s <-- %s: callRemote(%s, ', startArgs, '): %s', (log.ellipsize(result), ), args, kwargs) self.doLog(level, -1, formatString, *debugArgs, **logKwArgs) return result
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