benedict.core.dump   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 15
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A dump() 0 13 3
1
from benedict.serializers import JSONSerializer
2
3
4
def dump(obj, **kwargs):
5
    serializer = JSONSerializer()
6
    options = {"indent": 4, "sort_keys": True}
7
    options.update(**kwargs)
8
    try:
9
        output = serializer.encode(obj, **options)
10
        return output
11
    except TypeError as error:
12
        sort_keys = options.pop("sort_keys", False)
13
        if sort_keys:
14
            output = serializer.encode(obj, **options)
15
            return output
16
        raise error
17