[CalendarServer-changes] [3364] CalendarServer/trunk/twistedcaldav/config.py
source_changes at macosforge.org
source_changes at macosforge.org
Tue Nov 11 10:52:42 PST 2008
Revision: 3364
http://trac.macosforge.org/projects/calendarserver/changeset/3364
Author: wsanchez at apple.com
Date: 2008-11-11 10:52:42 -0800 (Tue, 11 Nov 2008)
Log Message:
-----------
Make it so that we can use config.Foo.Bar instead of config.Foo["Bar"].
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/config.py
Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py 2008-11-11 18:26:23 UTC (rev 3363)
+++ CalendarServer/trunk/twistedcaldav/config.py 2008-11-11 18:52:42 UTC (rev 3364)
@@ -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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081111/df7dbfd7/attachment.html>
More information about the calendarserver-changes
mailing list