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

pysmartprice.SmartPriceBase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %
Metric Value
dl 0
loc 16
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonable() 0 2 1
A dumptojson() 0 9 1
A __init__() 0 2 1
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