|
@@ -66,68 +66,24 @@ class AttributeDictionary(object):
|
|
|
def __setstate__(self, state):
|
|
|
super(AttributeDictionary, self).__setattr__("_dict", state)
|
|
|
|
|
|
-class ParamsAttributeDictionary(object):
|
|
|
+class ParamsAttributeDictionary(AttributeDictionary):
|
|
|
"""
|
|
|
This class can store user parameters
|
|
|
- and support some features necessary for substitution to work.
|
|
|
+ and it supports some features necessary for substitution to work.
|
|
|
"""
|
|
|
def __init__(self, substitutor, *args, **kwargs):
|
|
|
- d = kwargs
|
|
|
- if len(args)==1:
|
|
|
- d = args[0]
|
|
|
- super(ParamsAttributeDictionary, self).__setattr__("_dict", d)
|
|
|
- super(ParamsAttributeDictionary, self).__setattr__("substitutor", substitutor)
|
|
|
-
|
|
|
- def __setattr__(self, name, value):
|
|
|
- self[name] = value
|
|
|
-
|
|
|
- def __setitem__(self, name, value):
|
|
|
- self._dict[name] = self._convert_value(value)
|
|
|
+ super(ParamsAttributeDictionary, self).__init__(*args, **kwargs)
|
|
|
+ super(AttributeDictionary, self).__setattr__("substitutor", substitutor)
|
|
|
|
|
|
def __getitem__(self, name):
|
|
|
val = self.substitutor.get_subdict(name, self._dict)
|
|
|
return self._convert_value(val)
|
|
|
|
|
|
- def _convert_value(self, value):
|
|
|
- if isinstance(value, dict) and not isinstance(value, ParamsAttributeDictionary):
|
|
|
- return ParamsAttributeDictionary(self.substitutor, value)
|
|
|
- return value
|
|
|
-
|
|
|
def copy(self):
|
|
|
- return self.__class__(self._dict.copy())
|
|
|
-
|
|
|
- def update(self, *args, **kwargs):
|
|
|
- self._dict.update(*args, **kwargs)
|
|
|
-
|
|
|
- def items(self):
|
|
|
- return self._dict.items()
|
|
|
-
|
|
|
- def values(self):
|
|
|
- return self._dict.values()
|
|
|
-
|
|
|
- def keys(self):
|
|
|
- return self._dict.keys()
|
|
|
-
|
|
|
- def pop(self, *args, **kwargs):
|
|
|
- return self._dict.pop(*args, **kwargs)
|
|
|
-
|
|
|
- def get(self, *args, **kwargs):
|
|
|
- return self._dict.get(*args, **kwargs)
|
|
|
-
|
|
|
- def __repr__(self):
|
|
|
- return self._dict.__repr__()
|
|
|
+ return ParamsAttributeDictionary(self.substitutor, self._dict)
|
|
|
|
|
|
def __unicode__(self):
|
|
|
- return self._dict.__unicode__()
|
|
|
-
|
|
|
- def __str__(self):
|
|
|
- return self._dict.__str__()
|
|
|
-
|
|
|
- def __iter__(self):
|
|
|
- return self._dict.__iter__()
|
|
|
-
|
|
|
- def __getstate__(self):
|
|
|
- return self._dict
|
|
|
-
|
|
|
- def __setstate__(self, state):
|
|
|
- super(ParamsAttributeDictionary, self).__setattr__("_dict", state)
|
|
|
+ if isinstance(self._dict, str):
|
|
|
+ return self._dict.__unicode__()
|
|
|
+ else:
|
|
|
+ return str(self._dict)
|