This commit is contained in:
yumoqing 2024-04-11 18:00:59 +08:00
parent b3ec0416e1
commit 55e6b5d316
2 changed files with 11 additions and 9 deletions

View File

@ -18,19 +18,17 @@ class ArgsConvert(object):
def convert(self,obj,namespace,default=''):
""" obj can be a string,[],or dictionary """
if type(obj) == type(''):
if isinstance(obj, str):
return self.convertString(obj,namespace,default)
if type(obj) == type([]):
if isinstance(obj, list):
ret = []
for o in obj:
ret.append(self.convert(o,namespace,default))
return ret
if type(obj) == type({}):
ret = {}
for k in obj.keys():
ret.update({k:self.convert(obj.get(k),namespace,default)})
if isinstance(obj, dict):
ret = DictObject()
ret.update({k:self.convert(v,namespace,default) for k,v in obj.items()})
return ret
# print( type(obj),"not converted")
return obj
def findAllVariables(self,src):
@ -62,7 +60,7 @@ class ArgsConvert(object):
dl = s.split(arg)
var = self.getVarName(arg)
v = self.getVarValue(var,namespace,default)
if type(v) != type(u''):
if not isinstance(v, str):
if len(args) == 1 and s.startswith(self.preString) and s.endswith(self.subfixString):
return v
v = str(v)
@ -156,7 +154,7 @@ if __name__ == '__main__':
'a':12,
'b':'of',
'c':'abc',
u'':'is',
'':'is',
'd':{
'a':'doc',
'b':'gg',

View File

@ -64,6 +64,10 @@ class DictObject(dict):
"""
self[attr] = value
def get(self, k, defv=None):
v = super().get(k, defv)
return self.__DOitem(v)
def copy(self):
return self.__DOitem(super().copy())