diff --git a/LCS/Messaging/python/messaging/RPC.py b/LCS/Messaging/python/messaging/RPC.py index 7958444e1e0038a7219b8aa1aa898dd7e955b554..2e0f199e7eabe16003dd49a29ee552afcf8f3115 100644 --- a/LCS/Messaging/python/messaging/RPC.py +++ b/LCS/Messaging/python/messaging/RPC.py @@ -41,64 +41,62 @@ class RPC(): As a side-effect the sender and session are destroyed. """ - def __init__(self, service, **kwargs ): #busname=None, timeout=None, ForwardExceptions=None, Verbose=None): - """ - Initialize an Remote procedure call using: - service= <str> Service Name - bus= <str> Bus Name + def __init__(self, service, **kwargs ): + """ + Initialize an Remote procedure call using: + service= <str> Service Name + busname= <str> Bus Name timeout= <float> Time to wait in seconds before the call is considered a failure. Verbose= <bool> If True output extra logging to stdout. Use with extra care: ForwardExceptions= <bool> - This enables forwarding exceptions from the server side tobe raised at the client side durting RPC invocation. - """ - self.timeout = kwargs.pop("timeout",None) - self.ForwardExceptions = kwargs.pop("ForwardExceptions",False) - self.Verbose = kwargs.pop("Verbose",False) - self.BusName = kwargs.pop("busname",None) + This enables forwarding exceptions from the server side tobe raised at the client side durting RPC invocation. + """ + self.timeout = kwargs.pop("timeout", None) + self.ForwardExceptions = kwargs.pop("ForwardExceptions", False) + self.Verbose = kwargs.pop("Verbose", False) + self.BusName = kwargs.pop("busname", None) self.ServiceName = service if self.BusName is None: self.Request = ToBus(self.ServiceName) else: - self.Request = ToBus(self.BusName + "/" + self.ServiceName) + self.Request = ToBus("%s/%s" % (self.BusName, self.ServiceName)) if len(kwargs): - raise AttributeError("Unexpected argument passed to RPC class: %s", kwargs) + raise AttributeError("Unexpected argument passed to RPC class: %s" %( kwargs )) def __enter__(self): - """ - Internal use only. (handles scope 'with') - """ + """ + Internal use only. (handles scope 'with') + """ self.Request.open() return self def __exit__(self, exc_type, exc_val, exc_tb): - """ - Internal use only. (handles scope 'with') - """ + """ + Internal use only. (handles scope 'with') + """ self.Request.close() def __call__(self, *args, **kwargs): - """ - Enable the use of the object to directly invoke the RPC. + """ + Enable the use of the object to directly invoke the RPC. example: - with RPC(bus,service) as myrpc: + with RPC(bus,service) as myrpc: result=myrpc(request) - - """ - timeout= kwargs.pop("timeout",self.timeout) - - - Content=args_as_content(*args,**kwargs) - HasArgs,HasKwArgs = analyze_args(args,kwargs) + + """ + timeout = kwargs.pop("timeout", self.timeout) + Content = args_as_content(*args, **kwargs) + HasArgs, HasKwArgs = analyze_args(args, kwargs) # create unique reply address for this rpc call - options={'create':'always','delete':'receiver'} - ReplyAddress= "reply." + str(uuid.uuid4()) + options = {'create':'always','delete':'receiver'} + ReplyAddress = "reply.%s" % (str(uuid.uuid4())) if self.BusName is None: - Reply = FromBus(ReplyAddress+" ; "+str(options)) + Reply = FromBus("%s ; %s" %(ReplyAddress,str(options))) else: - Reply = FromBus(self.BusName + "/" + ReplyAddress) + Reply = FromBus("%s/%s" % (self.BusName, ReplyAddress)) with Reply: MyMsg = RequestMessage(Content, ReplyAddress , has_args=HasArgs, has_kwargs=HasKwArgs) MyMsg.ttl = timeout @@ -117,7 +115,7 @@ class RPC(): if isinstance(answer, ReplyMessage) is False: # if we come here we had a Time-Out status["state"] = "ERROR" - status["errmsg"] = "Incorrect messagetype (" + str(type(answer)) + ") received." + status["errmsg"] = "Incorrect messagetype (%s) received." % (str(type(answer))) status["backtrace"] = "" raise RPCException(status) diff --git a/LCS/Messaging/python/messaging/Service.py b/LCS/Messaging/python/messaging/Service.py index c849d02dc349cc6d45bc8d216091fa40224192a5..1c759817b8d78fd4eb6923dec9e1d58a7833b97b 100644 --- a/LCS/Messaging/python/messaging/Service.py +++ b/LCS/Messaging/python/messaging/Service.py @@ -62,7 +62,7 @@ class MessageHandlerInterface(object): def handle_message(self, msg): "Function the should handle the received message and return a result." - raise Exception("OOPS! YOU ENDED UP IN THE MESSAGE HANDLER OF THE ABSTRACT BASE CLASS!") + raise NotImplementedError("OOPS! YOU ENDED UP IN THE MESSAGE HANDLER OF THE ABSTRACT BASE CLASS!") def finalize_handling(self, successful): "Called in the main loop after the result was send back to the requester." @@ -250,7 +250,7 @@ class Service(object): reply_msg.backtrace = backtrace # show the message content if required by the verbose flag. - if self.verbose is True: + if self.verbose == True: reply_msg.show() # send the result to the RPC client