From: Greg Brockman Date: Fri, 22 Jan 2010 14:45:09 +0000 (-0500) Subject: Removed invirt-web-afs-apache X-Git-Tag: 0.0.29~1 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-base.git/commitdiff_plain/30641d7872dd5f494c965b4d9f01e8d8910dc4f4?ds=sidebyside Removed invirt-web-afs-apache svn path=/trunk/packages/invirt-base/; revision=2920 --- diff --git a/debian/changelog b/debian/changelog index 928fc71..dda2cdb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-base (0.0.29) unstable; urgency=low + + * Added a safestructs for doing config without raising. + + -- Greg Brockman Tue, 19 Jan 2010 23:49:19 -0500 + invirt-base (0.0.28) unstable; urgency=low * Completely remove the invirt.authz Python package - it will be diff --git a/python/invirt/common.py b/python/invirt/common.py index e4f7c25..77b8da5 100644 --- a/python/invirt/common.py +++ b/python/invirt/common.py @@ -10,24 +10,28 @@ class InvirtConfigError(AttributeError): class struct(dict): 'A simple namespace object.' - def __init__(self, d = {}, __prefix = None, **kwargs): + def __init__(self, d = {}, __prefix = None, __default=None, **kwargs): super(struct, self).__init__(d) self.__prefix = __prefix + self.__default = __default self.update(kwargs) def __getattr__(self, key): try: return self[key] except KeyError: - # XX ideally these would point a frame higher on the stack. - prefix = self.__prefix - if prefix is not None: - raise InvirtConfigError('missing configuration variable %s%s' - % (prefix, key)) + if self.__default is None: + # XX ideally these would point a frame higher on the stack. + prefix = self.__prefix + if prefix is not None: + raise InvirtConfigError('missing configuration variable ' + '%s%s' % (prefix, key)) + else: + raise AttributeError("anonymous struct has no member '%s'" + % (key,)) else: - raise AttributeError("anonymous struct has no member '%s'" - % (key,)) + return struct({}, '', self.__default) -def dicts2struct(x, prefix = None): +def dicts2struct(x, prefix = None, default = None): """ Given a tree of lists/dicts, perform a deep traversal to transform all the dicts to structs. @@ -37,13 +41,15 @@ def dicts2struct(x, prefix = None): else: def newprefix(k): return prefix if type(x) == dict: - return struct(((k, dicts2struct(v, newprefix(k))) + return struct(((k, dicts2struct(v, newprefix(k), default)) for k,v in x.iteritems()), - prefix) + prefix, + default) elif type(x) == list: - return [dicts2struct(v, newprefix(i)) for i, v in enumerate(x)] + return [dicts2struct(v, newprefix(i), default) + for i, v in enumerate(x)] elif x is None: - return struct({}, prefix) + return struct({}, prefix, default) else: return x diff --git a/python/invirt/config.py b/python/invirt/config.py index bcd2423..039ca3d 100644 --- a/python/invirt/config.py +++ b/python/invirt/config.py @@ -141,5 +141,6 @@ def load(force_refresh = False): dicts = load() structs = dicts2struct(dicts, '') +safestructs = dicts2struct(dicts, '', '') # vim:et:sw=4:ts=4