Changeset 2592
- Timestamp:
- Dec 14, 2009, 8:50:43 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-base/python/invirt/common.py
r2551 r2592 9 9 pass 10 10 11 class struct( object):11 class struct(dict): 12 12 'A simple namespace object.' 13 13 def __init__(self, d = {}, __prefix = None, **kwargs): 14 'd is the dictionary or the items-iterable to update my __dict__ with.' 15 dct = {} 16 dct.update(d) 17 dct.update(kwargs) 18 self.__dict__.update(dct) 19 self.__keys = set(dct) 14 super(struct, self).__init__(d) 20 15 self.__prefix = __prefix 16 self.update(kwargs) 21 17 def __getattr__(self, key): 22 # XX ideally these would point a frame higher on the stack.23 prefix = self.__prefix24 if prefix is not None:25 raise InvirtConfigError('missing configuration variable %s%s'26 % (prefix, key))27 else:28 raise AttributeError("anonymous struct has no member '%s'"29 % (key,))30 def __iter__(self):31 for i in self.__keys:32 yield i18 try: 19 return self[key] 20 except KeyError: 21 # XX ideally these would point a frame higher on the stack. 22 prefix = self.__prefix 23 if prefix is not None: 24 raise InvirtConfigError('missing configuration variable %s%s' 25 % (prefix, key)) 26 else: 27 raise AttributeError("anonymous struct has no member '%s'" 28 % (key,)) 33 29 34 30 def dicts2struct(x, prefix = None):
Note: See TracChangeset
for help on using the changeset viewer.