Skip to content
Snippets Groups Projects
Commit a557f0d3 authored by Jan Rinze Peterzon's avatar Jan Rinze Peterzon
Browse files

Task #8531: brush up messaging python code to adhere to style guide.

parent b5547e8e
Branches
Tags
No related merge requests found
...@@ -41,11 +41,11 @@ class RPC(): ...@@ -41,11 +41,11 @@ class RPC():
As a side-effect the sender and session are destroyed. As a side-effect the sender and session are destroyed.
""" """
def __init__(self, service, **kwargs ): #busname=None, timeout=None, ForwardExceptions=None, Verbose=None): def __init__(self, service, **kwargs ):
""" """
Initialize an Remote procedure call using: Initialize an Remote procedure call using:
service= <str> Service Name service= <str> Service Name
bus= <str> Bus Name busname= <str> Bus Name
timeout= <float> Time to wait in seconds before the call is considered a failure. timeout= <float> Time to wait in seconds before the call is considered a failure.
Verbose= <bool> If True output extra logging to stdout. Verbose= <bool> If True output extra logging to stdout.
...@@ -60,9 +60,9 @@ class RPC(): ...@@ -60,9 +60,9 @@ class RPC():
if self.BusName is None: if self.BusName is None:
self.Request = ToBus(self.ServiceName) self.Request = ToBus(self.ServiceName)
else: else:
self.Request = ToBus(self.BusName + "/" + self.ServiceName) self.Request = ToBus("%s/%s" % (self.BusName, self.ServiceName))
if len(kwargs): 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): def __enter__(self):
""" """
...@@ -88,17 +88,15 @@ class RPC(): ...@@ -88,17 +88,15 @@ class RPC():
""" """
timeout = kwargs.pop("timeout", self.timeout) timeout = kwargs.pop("timeout", self.timeout)
Content = args_as_content(*args, **kwargs) Content = args_as_content(*args, **kwargs)
HasArgs, HasKwArgs = analyze_args(args, kwargs) HasArgs, HasKwArgs = analyze_args(args, kwargs)
# create unique reply address for this rpc call # create unique reply address for this rpc call
options = {'create':'always','delete':'receiver'} options = {'create':'always','delete':'receiver'}
ReplyAddress= "reply." + str(uuid.uuid4()) ReplyAddress = "reply.%s" % (str(uuid.uuid4()))
if self.BusName is None: if self.BusName is None:
Reply = FromBus(ReplyAddress+" ; "+str(options)) Reply = FromBus("%s ; %s" %(ReplyAddress,str(options)))
else: else:
Reply = FromBus(self.BusName + "/" + ReplyAddress) Reply = FromBus("%s/%s" % (self.BusName, ReplyAddress))
with Reply: with Reply:
MyMsg = RequestMessage(Content, ReplyAddress , has_args=HasArgs, has_kwargs=HasKwArgs) MyMsg = RequestMessage(Content, ReplyAddress , has_args=HasArgs, has_kwargs=HasKwArgs)
MyMsg.ttl = timeout MyMsg.ttl = timeout
...@@ -117,7 +115,7 @@ class RPC(): ...@@ -117,7 +115,7 @@ class RPC():
if isinstance(answer, ReplyMessage) is False: if isinstance(answer, ReplyMessage) is False:
# if we come here we had a Time-Out # if we come here we had a Time-Out
status["state"] = "ERROR" status["state"] = "ERROR"
status["errmsg"] = "Incorrect messagetype (" + str(type(answer)) + ") received." status["errmsg"] = "Incorrect messagetype (%s) received." % (str(type(answer)))
status["backtrace"] = "" status["backtrace"] = ""
raise RPCException(status) raise RPCException(status)
......
...@@ -62,7 +62,7 @@ class MessageHandlerInterface(object): ...@@ -62,7 +62,7 @@ class MessageHandlerInterface(object):
def handle_message(self, msg): def handle_message(self, msg):
"Function the should handle the received message and return a result." "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): def finalize_handling(self, successful):
"Called in the main loop after the result was send back to the requester." "Called in the main loop after the result was send back to the requester."
...@@ -250,7 +250,7 @@ class Service(object): ...@@ -250,7 +250,7 @@ class Service(object):
reply_msg.backtrace = backtrace reply_msg.backtrace = backtrace
# show the message content if required by the verbose flag. # show the message content if required by the verbose flag.
if self.verbose is True: if self.verbose == True:
reply_msg.show() reply_msg.show()
# send the result to the RPC client # send the result to the RPC client
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment