timeplus.base
base
This module defines base class of resources.
:copyright: (c) 2022 by Timeplus
:license: Apache2, see LICENSE for more details.
View Source
0""" 1base 2 3This module defines base class of resources. 4:copyright: (c) 2022 by Timeplus 5:license: Apache2, see LICENSE for more details. 6""" 7 8 9class Base: 10 """ 11 Base class for API related object 12 """ 13 14 def __init__(self): 15 self._data = {} 16 17 def prop(self, name, *args): 18 if len(args) == 0: 19 return self._get(name) 20 elif len(args) == 1: 21 return self._set(name, args[0]) 22 else: 23 raise Exception("invalid number of arguments") 24 25 def _set(self, key, value): 26 if isinstance(value, Base): 27 self._data[key] = value.data() 28 else: 29 self._data[key] = value 30 return self 31 32 def _get(self, key): 33 return self._data[key] 34 35 def data(self): 36 return self._data 37 38 def id(self): 39 return self._get("id")
View Source
10class Base: 11 """ 12 Base class for API related object 13 """ 14 15 def __init__(self): 16 self._data = {} 17 18 def prop(self, name, *args): 19 if len(args) == 0: 20 return self._get(name) 21 elif len(args) == 1: 22 return self._set(name, args[0]) 23 else: 24 raise Exception("invalid number of arguments") 25 26 def _set(self, key, value): 27 if isinstance(value, Base): 28 self._data[key] = value.data() 29 else: 30 self._data[key] = value 31 return self 32 33 def _get(self, key): 34 return self._data[key] 35 36 def data(self): 37 return self._data 38 39 def id(self): 40 return self._get("id")
Base class for API related object