cleaner approach to wrapping the 'call'
authorMarc Fiuczynski <mef@cs.princeton.edu>
Wed, 20 May 2009 22:16:11 +0000 (22:16 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Wed, 20 May 2009 22:16:11 +0000 (22:16 +0000)
PLC/Legacy/NodeNetworks.py
PLC/Legacy/v42legacy.py

index 7fec8d3..b559647 100644 (file)
@@ -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:
index fdf316f..dc04f56 100644 (file)
@@ -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)