Completed
Push — master ( c396a1...0e306d )
by Fabio
03:31
created

benedict.core.dump.dump()   A

Complexity

Conditions 3

Size

Total Lines 16
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 16
rs 9.65
c 0
b 0
f 0
cc 3
nop 2
1
# -*- coding: utf-8 -*-
2
3
from benedict.serializers import JSONSerializer
4
5
6
def dump(obj, **kwargs):
7
    serializer = JSONSerializer()
8
    options = {
9
        'indent': 4,
10
        'sort_keys': True,
11
    }
12
    options.update(**kwargs)
13
    try:
14
        output = serializer.encode(obj, **options)
15
        return output
16
    except TypeError as error:
17
        sort_keys = options.pop('sort_keys', False)
18
        if sort_keys:
19
            output = serializer.encode(obj, **options)
20
            return output
21
        raise error
22