From: Marc Fiuczynski Date: Wed, 20 May 2009 22:16:11 +0000 (+0000) Subject: cleaner approach to wrapping the 'call' X-Git-Tag: PLCAPI-4.3-15~17 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=faf9e02002f0da92e3e9ae0c9a5cf96da4218280;p=plcapi.git cleaner approach to wrapping the 'call' --- diff --git a/PLC/Legacy/NodeNetworks.py b/PLC/Legacy/NodeNetworks.py index 7fec8d3f..b5596470 100644 --- a/PLC/Legacy/NodeNetworks.py +++ b/PLC/Legacy/NodeNetworks.py @@ -37,9 +37,9 @@ for legacyname in methods: # GetNodes update # first replace the call method so we can translate fields c = getattr(v42legacy.import_deep("PLC.Methods.GetNodes"),"GetNodes") -# rename call to newcall so we can still invoke +# rename call to __origcall so we can still invoke original = getattr(c,"call") -setattr(c,"newcall",original) +setattr(c,"__origcall",original) # 4.2 legacy support; update node_fields to include nodenetwork_ids from PLC.Parameter import Parameter, Mixed, python_type @@ -71,14 +71,13 @@ newreturns = [node_fields] setattr(c,"returns",newreturns) def GetNodesCall(self, auth, node_filter = None, return_fields = None): - global original # convert nodenetwork_ids -> interface_ids if node_filter <> None and \ node_filter.has_key('nodenetwork_ids') and \ not node_filter.has_key('interface_ids'): node_filter['interface_ids']=node_filter['nodenetwork_ids'] - nodes = original(self,auth,node_filter,return_fields) + nodes = self.__origcall(auth,node_filter,return_fields) # add in a interface_ids -> nodenetwork_ids for node in nodes: diff --git a/PLC/Legacy/v42legacy.py b/PLC/Legacy/v42legacy.py index fdf316f8..dc04f565 100644 --- a/PLC/Legacy/v42legacy.py +++ b/PLC/Legacy/v42legacy.py @@ -21,6 +21,7 @@ def patch (arg,rename): def make_class (legacyname,newname,path,v42rename,v43rename): # locate new class newclass=getattr(import_deep(path+newname),newname) + setattr(newclass,"__origcall",getattr(newclass,"call")) # create class for legacy name legacyclass = type(legacyname,(newclass,), {"__doc__":"Legacy method - please use %s instead"%newname}) @@ -33,7 +34,7 @@ def make_class (legacyname,newname,path,v42rename,v43rename): # print "%s: self.caller = %s, self=%s" % (legacyname,self.caller,self) newargs=[patch(x,v42rename) for x in args] newkwds=dict ( [ (k,patch(v,v42rename)) for (k,v) in kwds.iteritems() ] ) - results = getattr(newclass,"call")(self,auth,*newargs,**newkwds) + results = self.__origcall(auth,*newargs,**newkwds) return patch(results,v43rename) setattr(legacyclass,"call",wrapped_call)