__init__.py 738 B

1234567891011121314151617181920212223242526
  1. """
  2. A utility class with convenience classes.
  3. """
  4. class Bunch(object):
  5. """
  6. A convenience class to allow dict keys to be represented as object fields.
  7. The end result is that this allows a dict to be to be represented the same
  8. as a database class, thus the two become interchangeable as a data source.
  9. """
  10. def __init__(self, **kwargs):
  11. self.__dict__.update(kwargs)
  12. def __repr__(self):
  13. """
  14. Return the contents of the dict in a printable representation
  15. """
  16. return str(self.__dict__)
  17. def get(self, key, default=None):
  18. """
  19. Returns a value for the given key, if found or `'default` otherwise.
  20. """
  21. return self.__dict__.get(key, default)