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

benedict.core.dump._encoder()   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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