3 from PLC.Method import Method
4 from PLC.Auth import Auth
7 # apply rename on list (columns) or dict (filter) args
8 def patch (arg,rename):
9 if isinstance(arg,list):
10 for i in range(0,len(arg)):
11 arg[i] = patch(arg[i],rename)
13 if isinstance(arg,dict):
14 return dict ( [ (rename(k),v) for (k,v) in arg.iteritems() ] )
17 def make_class (legacyname,newname,path,import_deep,v42rename,v43rename):
19 newclass=getattr(import_deep(path+newname),newname)
20 setattr(newclass,"__origcall",getattr(newclass,"call"))
21 # create class for legacy name
22 legacyclass = type(legacyname,(newclass,),
23 {"__doc__":"Legacy method - please use %s instead"%newname})
24 for internal in ["roles","accepts","returns"]:
25 setattr(legacyclass,internal,getattr(newclass,internal))
26 # turn off type checking, as introspection code fails on wrapped_call
27 setattr(legacyclass,"skip_typecheck",True)
29 def wrapped_call (self,auth,*args, **kwds):
30 #print "%s: self.caller = %s, auth=%s, self.api=%s, self=%s" % (legacyname,self.caller,auth,self.api,self)
31 if not hasattr(self,"auth"):
33 if self.auth == None and auth <> None:
37 a = PLC.Auth.map_auth(auth)
38 a.check(self,auth,*args)
40 newargs=[patch(x,v42rename) for x in args]
41 newkwds=dict ( [ (k,patch(v,v42rename)) for (k,v) in kwds.iteritems() ] )
42 results = self.__origcall(auth,*newargs,**newkwds)
43 return patch(results,v43rename)
44 setattr(legacyclass,"call",wrapped_call)