bugfix
This commit is contained in:
parent
f442a9873e
commit
9c01d7fb98
@ -11,36 +11,69 @@ def multiDict2Dict(md):
|
|||||||
ns[k] = [ov,v]
|
ns[k] = [ov,v]
|
||||||
return ns
|
return ns
|
||||||
|
|
||||||
class DictObject(dict):
|
class DictObject:
|
||||||
def __init__(self,**args):
|
def __init__(self,**kw):
|
||||||
try:
|
self.__dict__['kwargs'] = {}
|
||||||
dict.__init__(self,**args)
|
for k,v in kw.items():
|
||||||
for k,v in self.items():
|
self.kwargs.update({k:self.__DOitem(v)})
|
||||||
self.__setattr__(k,self._DOitem(v))
|
|
||||||
except Exception as e:
|
def __getattr__(self, name):
|
||||||
print("DictObject.__init__()",e,args)
|
x = self.__dict__.get(name,None)
|
||||||
raise e
|
if x:
|
||||||
|
return x
|
||||||
|
|
||||||
|
b = self.__dict__.get('kwargs',None)
|
||||||
|
if not b:
|
||||||
|
print('Error:kwargs not in __dict__')
|
||||||
|
raise Exception('kwargs not in __dict__')
|
||||||
|
return b.get(name,None)
|
||||||
|
|
||||||
|
def __getitem__(self,name):
|
||||||
|
x = self.__dict__.get(name,None)
|
||||||
|
if x is not None:
|
||||||
|
return x
|
||||||
|
|
||||||
|
x = self.kwargs.get(name,None)
|
||||||
|
return x
|
||||||
|
|
||||||
|
def __setitem__(self,name,value):
|
||||||
|
self.kwargs[name] = value
|
||||||
|
|
||||||
|
def __delattr__(self,name):
|
||||||
|
self.kwargs.pop(name)
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
return self.kwargs.copy()
|
||||||
|
|
||||||
|
def update(self,d):
|
||||||
|
self.kwargs.update(d)
|
||||||
|
|
||||||
|
def keys(self):
|
||||||
|
return self.kwargs.keys()
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return self.kwargs.items()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def isMe(self,name):
|
def isMe(self,name):
|
||||||
return name == 'DictObject'
|
return name == 'DictObject'
|
||||||
|
|
||||||
def __getattr__(self,name):
|
def __DOArray(self,a):
|
||||||
if name in self:
|
b = [ self.__DOitem(i) for i in a ]
|
||||||
return self[name]
|
|
||||||
return None
|
|
||||||
|
|
||||||
def __setattr__(self,name,v):
|
|
||||||
self[name] = v
|
|
||||||
|
|
||||||
def _DOArray(self,a):
|
|
||||||
b = [ self._DOitem(i) for i in a ]
|
|
||||||
return b
|
return b
|
||||||
|
|
||||||
def _DOitem(self, i):
|
def __DOitem(self, i):
|
||||||
if type(i) is type({}):
|
if isinstance(i,DictObject):
|
||||||
return DictObject(**i)
|
return i
|
||||||
|
if isinstance(i,dict):
|
||||||
|
try:
|
||||||
|
d = DictObject(**i)
|
||||||
|
return d
|
||||||
|
except Exception as e:
|
||||||
|
print("****************",i,"*******dictObject.py")
|
||||||
|
raise e
|
||||||
if type(i) is type([]):
|
if type(i) is type([]):
|
||||||
return self._DOArray(i)
|
return self.__DOArray(i)
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def dictObjectFactory(_klassName__,**kwargs):
|
def dictObjectFactory(_klassName__,**kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user