- config = Config()
- self.auth = auth
- self.cainfo = cainfo
- self.errors = []
- self.trace = []
- self.calls = {}
- self.multicall = False
- self.url = config.manifold_url
- self.proxy = xmlrpclib.Server(self.url, verbose=False, allow_none=True)
-
- def __getattr__(self, methodName):
- def func(*args, **kwds):
- result=getattr(self.proxy, methodName)(self.auth, *args, **kwds)
- ### debug
- if debug:
- print '===> backend call',methodName, self.auth, self.url,'->',
- if not result: print "no/empty result"
- elif isinstance (result,str): print "result is '%s'"%result
- elif isinstance (result,list): print "result is a %d-elts list"%len(result)
- else: print "dont know how to display result"
- ###
- return result
- return func
-
- # 4amine : xxx
- def send_manifold_query (self, manifold_query):
- (action,method)= (manifold_query.action,manifold_query.method)
- if action=='get':
- return self.proxy.Get(self.auth, method, manifold_query.filters, {}, manifold_query.fields)
- # xxx...
- elif action=='others':
- return None
+ def __repr__ (self): return "ManifoldAPI[%s]"%self.url
+
+ def _print_value (self, value):
+ print "+++",'value',
+ if isinstance (value,list): print "[%d]"%len(value),
+ elif isinstance (value,dict): print "{%d}"%len(value),
+ print mytruncate (value,80)
+
+ # a one-liner to give a hint of what the return value looks like
+ def _print_result (self, result):
+ if not result: print "[no/empty result]"
+ elif isinstance (result,str): print "result is '%s'"%result
+ elif isinstance (result,list): print "result is a %d-elts list"%len(result)
+ elif isinstance (result,dict):
+ print "result is a dict with %d keys : %s"%(len(result),result.keys())
+ for (k,v) in result.iteritems():
+ if v is None: continue
+ if k=='value': self._print_value(v)
+ else: print '+++',k,':',mytruncate (v,30)
+ else: print "[dont know how to display result] %s"%result
+
+ # how to display a call
+ def _repr_query (self,methodName, query):
+ try: action=query['action']
+ except: action="???"
+ try: subject=query['object']
+ except: subject="???"
+ # most of the time, we run 'forward'
+ if methodName=='forward': return "forward(%s(%s))"%(action,subject)
+ else: return "%s(%s)"%(action,subject)
+
+ # xxx temporary code for scaffolding a ManifolResult on top of an API that does not expose error info
+ # as of march 2013 we work with an API that essentially either returns the value, or raises
+ # an xmlrpclib.Fault exception with always the same 8002 code
+ # since most of the time we're getting this kind of issues for expired sessions
+ # (looks like sessions are rather short-lived), for now the choice is to map these errors on
+ # a SESSION_EXPIRED code
+ def __getattr__(self, methodName):
+ def func(*args, **kwds):
+ # shorthand
+ def repr(): return self._repr_query (methodName, args[0])
+ try:
+ if debug:
+ start,msg = mytime()
+ print "====>",msg,"ManifoldAPI.%s"%repr(),"url",self.url
+ # No password in the logs
+ logAuth = copy.copy(self.auth)
+ for obfuscate in ['Authring','session']:
+ if obfuscate in logAuth: logAuth[obfuscate]="XXX"
+ if debug_deep: print "=> auth",logAuth
+ if debug_deep: print "=> args",args,"kwds",kwds
+ annotations = {
+ 'authentication': self.auth
+ }
+ args += (annotations,)
+ result=getattr(self.server, methodName)(*args, **kwds)
+ print "%s%r" %(methodName, args)
+
+ if debug:
+ print '<= result=',
+ self._print_result(result)
+ end,msg = mytime(start)
+ print "<====",msg,"backend call %s returned"%(repr())