From: Marc Fiuczynski Date: Thu, 21 May 2009 01:45:09 +0000 (+0000) Subject: get self.caller to work X-Git-Tag: PLCAPI-4.3-15~14 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=382051072be8e35a57c704f6e3aa4c55f9a43e61;p=plcapi.git get self.caller to work --- diff --git a/PLC/Legacy/NodeNetworks.py b/PLC/Legacy/NodeNetworks.py index b5596470..f5a42e40 100644 --- a/PLC/Legacy/NodeNetworks.py +++ b/PLC/Legacy/NodeNetworks.py @@ -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) diff --git a/PLC/Legacy/Types.py b/PLC/Legacy/Types.py index 98287308..c0dd3161 100644 --- a/PLC/Legacy/Types.py +++ b/PLC/Legacy/Types.py @@ -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)) diff --git a/PLC/Legacy/v42legacy.py b/PLC/Legacy/v42legacy.py index dc04f565..5e6cdae8 100644 --- a/PLC/Legacy/v42legacy.py +++ b/PLC/Legacy/v42legacy.py @@ -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)