32 lines
788 B
Python
32 lines
788 B
Python
import plugin
|
|
class ReadOnlyError(Exception):
|
|
pass
|
|
|
|
class DictData(plugin.JSONData):
|
|
def __init__(self,filename,**kwargs):
|
|
plugin.JSONData.__init__(self,kwargs)
|
|
self.filename = filename
|
|
self.load(self.filename)
|
|
def __getitem__(self,k):
|
|
self.load(self.filename)
|
|
return self.value[k]
|
|
def __setitem__(self,k,v):
|
|
self.value[k]=v
|
|
self.save(self.filename)
|
|
def __contains__(self,k):
|
|
return k in self.value
|
|
def get(self,k,default=None):
|
|
return self.value.get(k,default)
|
|
|
|
class ReadOnlyDictData(DictData):
|
|
def __setitem__(self,k,v):
|
|
raise ReadOnlyError("Cannot set item {} to {}".format(k,v))
|
|
|
|
class Numerical(ReadOnlyDictData):
|
|
def load(self,filename):
|
|
super(Numerical,self).load(filename)
|
|
n = {}
|
|
for k in self.value:
|
|
n[int(k)]=self.value[k]
|
|
self.value = n
|