Add read-only dictdata
This commit is contained in:
parent
96985ca2dd
commit
ba4048d6d2
15
dictdata.py
15
dictdata.py
|
@ -1,4 +1,7 @@
|
||||||
import plugin
|
import plugin
|
||||||
|
class ReadOnlyError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class DictData(plugin.JSONData):
|
class DictData(plugin.JSONData):
|
||||||
def __init__(self,filename,**kwargs):
|
def __init__(self,filename,**kwargs):
|
||||||
plugin.JSONData.__init__(self,kwargs)
|
plugin.JSONData.__init__(self,kwargs)
|
||||||
|
@ -14,3 +17,15 @@ class DictData(plugin.JSONData):
|
||||||
return k in self.value
|
return k in self.value
|
||||||
def get(self,k,default=None):
|
def get(self,k,default=None):
|
||||||
return self.value.get(k,default)
|
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
|
||||||
|
|
Loading…
Reference in New Issue