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

benedict.core.dump   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A dump() 0 16 3
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