michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # Taken from Paver's paver.options module. michael@0: michael@0: class Bunch(dict): michael@0: """A dictionary that provides attribute-style access.""" michael@0: michael@0: def __repr__(self): michael@0: keys = self.keys() michael@0: keys.sort() michael@0: args = ', '.join(['%s=%r' % (key, self[key]) for key in keys]) michael@0: return '%s(%s)' % (self.__class__.__name__, args) michael@0: michael@0: def __getitem__(self, key): michael@0: item = dict.__getitem__(self, key) michael@0: if callable(item): michael@0: return item() michael@0: return item michael@0: michael@0: def __getattr__(self, name): michael@0: try: michael@0: return self[name] michael@0: except KeyError: michael@0: raise AttributeError(name) michael@0: michael@0: __setattr__ = dict.__setitem__ michael@0: michael@0: def __delattr__(self, name): michael@0: try: michael@0: del self[name] michael@0: except KeyError: michael@0: raise AttributeError(name)