| Total Complexity | 15 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | |||
| 3 | from benedict.utils import utility_util |
||
| 4 | |||
| 5 | |||
| 6 | class UtilityDict(dict): |
||
| 7 | |||
| 8 | def __init__(self, *args, **kwargs): |
||
| 9 | super(UtilityDict, self).__init__(*args, **kwargs) |
||
| 10 | |||
| 11 | def clean(self, strings=True, dicts=True, lists=True): |
||
| 12 | utility_util.clean(self, strings=strings, dicts=dicts, lists=lists) |
||
| 13 | |||
| 14 | def clone(self): |
||
| 15 | return utility_util.clone(self) |
||
| 16 | |||
| 17 | def deepcopy(self): |
||
| 18 | return self.clone() |
||
| 19 | |||
| 20 | def deepupdate(self, other, *args): |
||
| 21 | self.merge(other, *args) |
||
| 22 | |||
| 23 | def dump(self, data=None): |
||
| 24 | return utility_util.dump(data or self) |
||
| 25 | |||
| 26 | def filter(self, predicate): |
||
| 27 | if not callable(predicate): |
||
| 28 | raise ValueError('predicate argument must be a callable.') |
||
| 29 | return utility_util.filter(self, predicate) |
||
| 30 | |||
| 31 | def merge(self, other, *args): |
||
| 32 | dicts = [other] + list(args) |
||
| 33 | for d in dicts: |
||
| 34 | utility_util.merge(self, d) |
||
| 35 | |||
| 36 | def remove(self, keys): |
||
| 37 | for key in keys: |
||
| 38 | try: |
||
| 39 | del self[key] |
||
| 40 | except KeyError: |
||
| 41 | continue |
||
| 42 | |||
| 43 | def subset(self, keys): |
||
| 44 | d = self.__class__() |
||
| 45 | for key in keys: |
||
| 46 | d[key] = self.get(key, None) |
||
| 47 | return d |
||
| 48 |