get self.caller to work
authorMarc Fiuczynski <mef@cs.princeton.edu>
Thu, 21 May 2009 01:45:09 +0000 (01:45 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Thu, 21 May 2009 01:45:09 +0000 (01:45 +0000)
PLC/Legacy/NodeNetworks.py
PLC/Legacy/Types.py
PLC/Legacy/v42legacy.py

index b559647..f5a42e4 100644 (file)
@@ -6,6 +6,13 @@ import v42legacy
 import sys
 current_module=sys.modules[__name__]
 
+def import_deep(name):
+    mod = __import__(name)
+    components = name.split('.')
+    for comp in components[1:]:
+        mod = getattr(mod, comp)
+    return mod
+
 methods = [
     "AddNodeNetwork",
     "AddNodeNetworkSetting",
@@ -32,11 +39,11 @@ for legacyname in methods:
     # new method name
     newname=legacyname.replace("NodeNetwork","Interface").replace("Setting","Tag")
     path = "PLC.Methods."
-    setattr(current_module,legacyname,v42legacy.make_class(legacyname,newname,path,v42rename,v43rename))
+    setattr(current_module,legacyname,v42legacy.make_class(legacyname,newname,path,import_deep,v42rename,v43rename))
 
 # GetNodes update
 # first replace the call method so we can translate fields
-c = getattr(v42legacy.import_deep("PLC.Methods.GetNodes"),"GetNodes")
+c = getattr(import_deep("PLC.Methods.GetNodes"),"GetNodes")
 # rename call to __origcall so we can still invoke
 original = getattr(c,"call")
 setattr(c,"__origcall",original)
index 9828730..c0dd316 100644 (file)
@@ -6,6 +6,13 @@ import v42legacy
 import sys
 current_module=sys.modules[__name__]
 
+def import_deep(name):
+    mod = __import__(name)
+    components = name.split('.')
+    for comp in components[1:]:
+        mod = getattr(mod, comp)
+    return mod
+
 v42_to_v43_methodmap = {
     "AddSliceAttributeType"         : "AddTagType",
     "DeleteSliceAttributeType"      : "DeleteTagType",
@@ -30,4 +37,4 @@ for legacyname in methods:
     # new method name
     newname=v42_to_v43_methodmap[legacyname]
     path = "PLC.Methods."
-    setattr(current_module,legacyname,v42legacy.make_class(legacyname,newname,path,v42rename,v43rename))
+    setattr(current_module,legacyname,v42legacy.make_class(legacyname,newname,path,import_deep,v42rename,v43rename))
index dc04f56..5e6cdae 100644 (file)
@@ -1,11 +1,8 @@
 # $Id: $
 
-def import_deep(name):
-    mod = __import__(name)
-    components = name.split('.')
-    for comp in components[1:]:
-        mod = getattr(mod, comp)
-    return mod
+from PLC.Method import Method
+from PLC.Auth import Auth
+import PLC.Auth
 
 # apply rename on list (columns) or dict (filter) args
 def patch (arg,rename):
@@ -17,8 +14,7 @@ def patch (arg,rename):
         return dict ( [ (rename(k),v) for (k,v) in arg.iteritems() ] )
     return rename(arg)
 
-
-def make_class (legacyname,newname,path,v42rename,v43rename):
+def make_class (legacyname,newname,path,import_deep,v42rename,v43rename):
     # locate new class
     newclass=getattr(import_deep(path+newname),newname)
     setattr(newclass,"__origcall",getattr(newclass,"call"))
@@ -31,7 +27,16 @@ def make_class (legacyname,newname,path,v42rename,v43rename):
     setattr(legacyclass,"skip_typecheck",True)
     # rewrite call
     def wrapped_call (self,auth,*args, **kwds):
-       # print "%s: self.caller = %s, self=%s" % (legacyname,self.caller,self)
+       #print "%s: self.caller = %s, auth=%s, self.api=%s, self=%s" % (legacyname,self.caller,auth,self.api,self)
+        if not hasattr(self,"auth"):
+            self.auth = None
+        if self.auth == None and auth <> None:
+            self.auth = auth
+
+        if self.auth <> None:
+            a = PLC.Auth.map_auth(auth)
+            a.check(self,auth,*args)
+
         newargs=[patch(x,v42rename) for x in args]
         newkwds=dict ( [ (k,patch(v,v42rename)) for (k,v) in kwds.iteritems() ] )
         results = self.__origcall(auth,*newargs,**newkwds)