Passed
Push — master ( f980db...1c4121 )
by Fabio
01:20
created

benedict.dicts.benedict.unique()   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.dicts.io import IODict
4
from benedict.dicts.keypath import KeypathDict
5
from benedict.dicts.parse import ParseDict
6
from benedict.utils import dict_util
7
8
9
def benediction(method):
10
    def wrapper(*args, **kwargs):
11
        value = method(*args, **kwargs)
12
        if isinstance(value, dict) and not isinstance(value, benedict):
13
            return benedict(value)
14
        return value
15
    return wrapper
16
17
18
class benedict(IODict, KeypathDict, ParseDict):
19
20
    def __init__(self, *args, **kwargs):
21
        super(benedict, self).__init__(*args, **kwargs)
22
23
    def clean(self, strings=True, dicts=True, lists=True):
24
        dict_util.clean(self, strings=strings, dicts=dicts, lists=lists)
25
26
    def clone(self):
27
        return dict_util.clone(self)
28
29
    @benediction
30
    def copy(self):
31
        return super(benedict, self).copy()
32
33
    def deepcopy(self):
34
        return self.clone()
35
36
    def deepupdate(self, other, *args):
37
        self.merge(other, *args)
38
39
    def dump(self, data=None):
40
        return dict_util.dump(data or self)
41
42
    def filter(self, predicate):
43
        return dict_util.filter(self, predicate)
44
45
    def flatten(self, separator='_'):
46
        return dict_util.flatten(self, separator)
47
48
    @classmethod
49
    @benediction
50
    def fromkeys(cls, sequence, value=None):
51
        return KeypathDict.fromkeys(sequence, value)
52
53
    @staticmethod
54
    @benediction
55
    def from_base64(s, format='json', **kwargs):
56
        return IODict.from_base64(s, format, **kwargs)
57
58
    @staticmethod
59
    @benediction
60
    def from_json(s, **kwargs):
61
        return IODict.from_json(s, **kwargs)
62
63
    @staticmethod
64
    @benediction
65
    def from_toml(s, **kwargs):
66
        return IODict.from_toml(s, **kwargs)
67
68
    @staticmethod
69
    @benediction
70
    def from_xml(s, **kwargs):
71
        return IODict.from_xml(s, **kwargs)
72
73
    @staticmethod
74
    @benediction
75
    def from_yaml(s, **kwargs):
76
        return IODict.from_yaml(s, **kwargs)
77
78
    def invert(self, flat=False):
79
        return dict_util.invert(self, flat)
80
81
    def items_sorted_by_keys(self, reverse=False):
82
        return dict_util.items_sorted_by_keys(self, reverse=reverse)
83
84
    def items_sorted_by_values(self, reverse=False):
85
        return dict_util.items_sorted_by_values(self, reverse=reverse)
86
87
    def merge(self, other, *args):
88
        dict_util.merge(self, other, *args)
89
90
    def move(self, key_src, key_dest):
91
        dict_util.move(self, key_src, key_dest)
92
93
    def remove(self, keys, *args):
94
        dict_util.remove(self, keys, *args)
95
96
    def subset(self, keys, *args):
97
        return dict_util.subset(self, keys, *args)
98
99
    def swap(self, key1, key2):
100
        dict_util.swap(self, key1, key2)
101
102
    def unique(self):
103
        dict_util.unique(self)
104