Service Requests

if failure.origin() == "netsvc" and \ failure.error() == netsvc.SERVER_METHOD_UNAVAILABLE:

# method didn’t exist

As an alternative to using the "conversationId()" member function to obtain the conversation id of the failed request, if the callback accepts a single argument, the conversation id will be passed as an argument to the callback function.

class Client(netsvc.Service): def __init__(self,name):

netsvc.Service.__init__(self,"","") service = self.serviceEndPoint("SMS") if service:

id = service.uptime() self.processResponse(self.uptimeResponse,id) self.processFailure(self.uptimeFailure,id)

def uptimeResponse(self,result): print result

def uptimeFailure(self,id): failure = self.currentFailure()

if failure.origin() == "netsvc" and \ failure.error() == netsvc.SERVER_METHOD_UNAVAILABLE:

# method didn’t exist

This ability to have details of the failure supplied as arguments to the callback function also extends to the contents of the failure object if the callback function accepts an additional four parameters in ad- dition to that for the conversation id.

class Client(netsvc.Service): def __init__(self,name):

netsvc.Service.__init__(self,"","") service = self.serviceEndPoint("SMS") if service:

id = service.uptime() self.processResponse(self.uptimeResponse,id) self.processFailure(self.uptimeFailure,id)

def uptimeResponse(self,result): print result

def uptimeFailure(self,id,error,description,origin,details):

if origin == "netsvc" and error == netsvc.SERVER_METHOD_UNAVAILABLE:

# method didn’t exist

These are not keyword arguments, but positional parameters which the code which calls the callback function supplies or not based on the number of arguments the callback accepts. In other words, the callback must accept the appropriate number of arguments as necessary and in the specified order.

62

Page 62
Image 62
Python Python Manual, 7.0pl5 manual Service Requests