Show More
@@ -83,6 +83,20 b' class Config(dict):' | |||||
83 | # This sets self.__dict__ = self, but it has to be done this way |
|
83 | # This sets self.__dict__ = self, but it has to be done this way | |
84 | # because we are also overriding __setattr__. |
|
84 | # because we are also overriding __setattr__. | |
85 | dict.__setattr__(self, '__dict__', self) |
|
85 | dict.__setattr__(self, '__dict__', self) | |
|
86 | self._ensure_subconfig() | |||
|
87 | ||||
|
88 | def _ensure_subconfig(self): | |||
|
89 | """ensure that sub-dicts that should be Config objects are | |||
|
90 | ||||
|
91 | casts dicts that are under section keys to Config objects, | |||
|
92 | which is necessary for constructing Config objects from dict literals. | |||
|
93 | """ | |||
|
94 | for key in self: | |||
|
95 | obj = self[key] | |||
|
96 | if self._is_section_key(key) \ | |||
|
97 | and isinstance(obj, dict) \ | |||
|
98 | and not isinstance(obj, Config): | |||
|
99 | dict.__setattr__(self, key, Config(obj)) | |||
86 |
|
100 | |||
87 | def _merge(self, other): |
|
101 | def _merge(self, other): | |
88 | to_update = {} |
|
102 | to_update = {} |
General Comments 0
You need to be logged in to leave comments.
Login now