Completed
Push — master ( ad01fe...01a50b )
by Fabio
03:50
created

benedict.dicts.benedict.from_yaml()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nop 2
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.dicts.utility import UtilityDict
7
8
9
def benediction(method):
10
    def wrapper(*args, **kwargs):
11
        value = method(*args, **kwargs)
12
        return benedict.cast(value)
13
    return wrapper
14
15
16
class benedict(IODict, KeypathDict, ParseDict, UtilityDict):
17
18
    def __init__(self, *args, **kwargs):
19
        super(benedict, self).__init__(*args, **kwargs)
20
21
    @classmethod
22
    def cast(cls, value):
23
        if isinstance(value, dict) and not isinstance(value, cls):
24
            return cls(value)
25
        else:
26
            return value
27
28
    @benediction
29
    def clone(self):
30
        return super(benedict, self).clone()
31
32
    @benediction
33
    def copy(self):
34
        return super(benedict, self).copy()
35
36
    @benediction
37
    def deepcopy(self):
38
        return super(benedict, self).deepcopy()
39
40
    @benediction
41
    def filter(self, predicate):
42
        return super(benedict, self).filter(predicate)
43
44
    @benediction
45
    def flatten(self, separator='_'):
46
        return super(benedict, self).flatten(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_json(s, **kwargs):
56
        return IODict.from_json(s, **kwargs)
57
58
    @staticmethod
59
    @benediction
60
    def from_toml(s, **kwargs):
61
        return IODict.from_toml(s, **kwargs)
62
63
    @staticmethod
64
    @benediction
65
    def from_xml(s, **kwargs):
66
        return IODict.from_xml(s, **kwargs)
67
68
    @staticmethod
69
    @benediction
70
    def from_yaml(s, **kwargs):
71
        return IODict.from_yaml(s, **kwargs)
72
73
    @benediction
74
    def __getitem__(self, key):
75
        return super(benedict, self).__getitem__(key)
76
77
    @benediction
78
    def get(self, key, default=None):
79
        return super(benedict, self).get(key, default)
80
81
    @benediction
82
    def get_dict(self, key, default=None):
83
        return super(benedict, self).get_dict(key, default)
84
85
    def get_list(self, key, default=None, separator=','):
86
        values = super(benedict, self).get_list(key, default, separator)
87
        values = [benedict.cast(value) for value in values]
88
        return values
89
90
    @benediction
91
    def get_list_item(self, key, index=0, default=None, separator=','):
92
        return super(benedict, self).get_list_item(
93
            key, index, default, separator)
94
95
    @benediction
96
    def get_phonenumber(self, key, country_code=None, default=''):
97
        return super(benedict, self).get_phonenumber(
98
            key, country_code, default)
99
100
    @benediction
101
    def pop(self, key, default=None):
102
        return super(benedict, self).pop(key, default)
103
104
    @benediction
105
    def setdefault(self, key, default=None):
106
        return super(benedict, self).setdefault(key, default)
107
108
    @benediction
109
    def subset(self, keys):
110
        return super(benedict, self).subset(keys)
111