Passed
Push — master ( df1182...461010 )
by Fabio
01:14
created

benedict.dicts.utility.UtilityDict.clone()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 1
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 flatten(self, separator='_'):
32
        return utility_util.flatten(self, separator)
33
34
    def merge(self, other, *args):
35
        dicts = [other] + list(args)
36
        for d in dicts:
37
            utility_util.merge(self, d)
38
39
    def remove(self, keys):
40
        for key in keys:
41
            try:
42
                del self[key]
43
            except KeyError:
44
                continue
45
46
    def subset(self, keys):
47
        d = self.__class__()
48
        for key in keys:
49
            d[key] = self.get(key, None)
50
        return d
51