benedict.core.dump.dump()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 13
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 13
rs 9.75
c 0
b 0
f 0
cc 3
nop 2
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