ComplexEncoder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 6
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A default() 0 5 2
1
import json
2
3
4
class ComplexEncoder(json.JSONEncoder):
5
    def default(self, obj):
6
        if hasattr(obj, 'jsonable'):
7
            return obj.dumptojson
8
        else:
9
            return json.JSONEncoder.default(self, obj)
10
11
12
class SmartPriceBase(object):
13
    def __init__(self, params):
14
        self.__dict__.update(params)
15
16
    def jsonable(self):
17
        return self.__dict__
18
19
    @property
20
    def dumptojson(self):
21
        return json.loads(
22
            json.dumps(
23
                self.jsonable(),
24
                cls=ComplexEncoder,
25
                # sort_keys=True,
26
                indent=4,
27
                separators=(',', ': '))
28
        )
29
30
31
class SmartPriceResult(SmartPriceBase):
32
    pass
33
34
35
class SmartPriceSeller(SmartPriceBase):
36
    pass
37