Completed
Push — master ( 827a28...9f02a5 )
by Asif
03:06 queued 45s
created

pysmartprice.ComplexEncoder.default()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 5
rs 9.4285
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