Changeset 6730 for TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/utils/__init__.py
- Timestamp:
- 16/03/10 08:37:55 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/utils/__init__.py
r5870 r6730 76 76 77 77 return super(TypedList, self).append(item) 78 79 class RestrictedKeyNamesDict(dict): 80 """Utility class for holding a constrained list of key names 81 """ 82 83 def __init__(self, *arg, **kw): 84 """Alter standard dict() initialisation to fix key names set at 85 initialisation 86 """ 87 super(RestrictedKeyNamesDict, self).__init__(*arg, **kw) 88 self.__keyNames = self.keys() 89 90 def __setitem__(self, key, val): 91 if key not in self.__keyNames: 92 raise KeyError('Key name %r not recognised. Valid key names ' 93 'are: %r' % (key, self.__keyNames)) 94 95 dict.__setitem__(self, key, val) 96 97 def update(self, d, **kw): 98 for dictArg in (d, kw): 99 for k in dictArg: 100 if k not in self.__keyNames: 101 raise KeyError('Key name "%s" not recognised. Valid ' 102 'key names are: %s' % 103 self.__keyNames) 104 105 dict.update(self, d, **kw)
Note: See TracChangeset
for help on using the changeset viewer.