Skip to content
Permalink
Browse files

Make it so that we can use config.Foo.Bar instead of config.Foo["Bar"].

  • Loading branch information...
wsanchez committed Nov 11, 2008
1 parent 244ce79 commit da7824dee4a865b0ace92a1793f58f5d280c3653
Showing with 37 additions and 0 deletions.
  1. +37 −0 twistedcaldav/config.py
@@ -14,6 +14,14 @@
# limitations under the License.
##

__all__ = [
"defaultConfigFile",
"defaultConfig",
"Config",
"ConfigurationError",
"config",
]

import os
import copy
import re
@@ -353,12 +361,41 @@
"EnableKeepAlive": True,
}

class ConfigDict (dict):
def __init__(self, mapping=None):
if mapping is not None:
for key, value in mapping.iteritems():
self[key] = value

def __repr__(self):
return "*" + dict.__repr__(self)

def __setitem__(self, key, value):
if type(value) is dict:
dict.__setitem__(self, key, ConfigDict(value))
else:
dict.__setitem__(self, key, value)

def __setattr__(self, attr, value):
if attr[0] == "_":
dict.__setattr__(self, attr, value)
else:
self[attr] = value

def __getattr__(self, attr):
if attr in self:
return self[attr]
else:
return dict.__getattr__(self, attr)

class Config (object):
"""
@DynamicAttrs
"""
def __init__(self, defaults):
if not isinstance(defaults, ConfigDict):
defaults = ConfigDict(defaults)

self.setDefaults(defaults)
self._data = copy.deepcopy(self._defaults)
self._configFile = None

0 comments on commit da7824d

Please sign in to comment.
You can’t perform that action at this time.