diff --git a/src/python/dm/common/utility/dictUtility.py b/src/python/dm/common/utility/dictUtility.py new file mode 100755 index 0000000000000000000000000000000000000000..3e357d6d58bff6996e058d33f6b048a2a19ea78f --- /dev/null +++ b/src/python/dm/common/utility/dictUtility.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +import copy + +class DictUtility: + + @classmethod + def deepCopy(cls, dict, includeKeys=[], excludeKeys=[]): + dict2 = copy.deepcopy(dict) + if len(includeKeys): + for key in dict2.keys(): + if not key in includeKeys: + del dict2[key] + elif len(excludeKeys): + for key in excludeKeys: + if dict2.has_key(key): + del dict2[key] + return dict2 + +####################################################################### +# Testing. +if __name__ == '__main__': + print DictUtility.deepCopy({'k1': '1', 'k2' : '2'}, excludeKeys=['k1']) + print DictUtility.deepCopy({'k1': '1', 'k2' : '2'}, includeKeys=['k1']) + print DictUtility.deepCopy({'k1': '1', 'k2' : '2'}) +