1 # Manifold API Python interface
4 from myslice.config import Config
8 class SessionExpired (Exception):
9 def __init__ (self,message):
12 return "<SessionExpired: %s>"%self.message
16 def __init__(self, auth=None, cainfo=None):
24 self.multicall = False
25 self.url = config.manifold_url
26 self.server = xmlrpclib.Server(self.url, verbose=False, allow_none=True)
28 def __getattr__(self, methodName):
29 def func(*args, **kwds):
31 result=getattr(self.server, methodName)(self.auth, *args, **kwds)
33 print '===> backend call',methodName, self.auth, self.url,'->',
34 if not result: print "no/empty result"
35 elif isinstance (result,str): print "result is '%s'"%result
36 elif isinstance (result,list): print "result is a %d-elts list"%len(result)
37 else: print "dont know how to display result"
39 except xmlrpclib.Fault, error:
40 ### xxx this is very rough for now
41 # until we have some agreement about how the API calls should return error conditions
42 # in some less unpolite way than this anoanymous exception, we assume it's a problem with the session
43 # that needs to be refreshed
44 if error.faultCode == 8002:
45 reason="most likely your session has expired"
46 reason += " (the manifold API has no unambiguous error reporting mechanism yet)"
47 raise SessionExpired(reason)
48 except Exception,error:
49 print "ManifoldAPI: unexpected exception",error
53 def send_manifold_query (self, manifold_query):
54 (action,subject)= (manifold_query.action,manifold_query.subject)
56 # use self.Get rather than self.server.Get so we catch exceptions as per __getattr__
57 return self.Get(self.auth, subject, manifold_query.filters, {}, manifold_query.fields)
60 print "WARNING: ManifoldAPI.send_manifold_query: only 'get' implemented for now"