2
0

__init__.py 683 B

12345678910111213141516171819202122
  1. from copy import deepcopy
  2. from .alfred import AlfredParser
  3. from .graphite import GraphitePush
  4. __all__ = [ 'AlfredParser', 'GraphitePush', 'dict_merge' ]
  5. def dict_merge(a, b):
  6. '''recursively merges dict's. not just simple a['key'] = b['key'], if
  7. both a and bhave a key who's value is a dict then dict_merge is called
  8. on both values and the result stored in the returned dictionary.'''
  9. if not isinstance(b, dict):
  10. return b
  11. result = deepcopy(a)
  12. for k, v in b.iteritems():
  13. if k in result and isinstance(result[k], dict):
  14. result[k] = dict_merge(result[k], v)
  15. else:
  16. result[k] = deepcopy(v)
  17. return result