key is now always path and change opt by path dictionary storage

This commit is contained in:
2013-08-21 22:21:50 +02:00
parent 707a215a2c
commit b6bb685ca5
12 changed files with 297 additions and 242 deletions

View File

@ -32,21 +32,21 @@ class Settings(Cache):
super(Settings, self).__init__()
# propertives
def setproperties(self, opt, properties):
self._properties[opt] = properties
def setproperties(self, path, properties):
self._properties[path] = properties
def getproperties(self, opt, default_properties):
return self._properties.get(opt, set(default_properties))
def getproperties(self, path, default_properties):
return self._properties.get(path, set(default_properties))
def hasproperties(self, opt):
return opt in self._properties
def hasproperties(self, path):
return path in self._properties
def reset_all_propertives(self):
self._properties.clear()
def reset_properties(self, opt):
def reset_properties(self, path):
try:
del(self._properties[opt])
del(self._properties[path])
except KeyError:
pass
@ -54,8 +54,8 @@ class Settings(Cache):
return self._properties
# permissive
def setpermissive(self, opt, permissive):
self._permissives[opt] = frozenset(permissive)
def setpermissive(self, path, permissive):
self._permissives[path] = frozenset(permissive)
def getpermissive(self, opt=None):
return self._permissives.get(opt, frozenset())
def getpermissive(self, path=None):
return self._permissives.get(path, frozenset())

View File

@ -36,22 +36,22 @@ class Cache(object):
def __init__(self):
self._cache = {}
def setcache(self, cache_type, opt, val, time):
self._cache[opt] = (val, time)
def setcache(self, cache_type, path, val, time):
self._cache[path] = (val, time)
def getcache(self, cache_type, opt, exp):
value, created = self._cache[opt]
def getcache(self, cache_type, path, exp):
value, created = self._cache[path]
if exp < created:
return True, value
return False, None
def hascache(self, cache_type, opt):
""" option is in the cache
def hascache(self, cache_type, path):
""" path is in the cache
:param cache_type: value | property
:param opt: the key (typically, the option object)
:param path: the path's option
"""
return opt in self._cache
return path in self._cache
def reset_expired_cache(self, cache_type, exp):
keys = self._cache.keys()
@ -66,6 +66,6 @@ class Cache(object):
def get_cached(self, cache_type, context):
"""return all values in a dictionary
example: {option1: ('value1', 'time1'), option2: ('value2', 'time2')}
example: {'path1': ('value1', 'time1'), 'path2': ('value2', 'time2')}
"""
return self._cache

View File

@ -32,43 +32,43 @@ class Values(Cache):
super(Values, self).__init__()
# value
def setvalue(self, opt, value, owner):
"""set value for an option
def setvalue(self, path, value, owner):
"""set value for a path
a specified value must be associated to an owner
"""
self._values[opt] = (owner, value)
self._values[path] = (owner, value)
def getvalue(self, opt):
"""get value for an option
def getvalue(self, path):
"""get value for a path
return: only value, not the owner
"""
return self._values[opt][1]
return self._values[path][1]
def hasvalue(self, opt):
"""if opt has a value
def hasvalue(self, path):
"""if path has a value
return: boolean
"""
return opt in self._values
return path in self._values
def resetvalue(self, opt):
def resetvalue(self, path):
"""remove value means delete value in storage
"""
del(self._values[opt])
del(self._values[path])
def get_modified_values(self):
"""return all values in a dictionary
example: {option1: (owner, 'value1'), option2: (owner, 'value2')}
example: {'path1': (owner, 'value1'), 'path2': (owner, 'value2')}
"""
return self._values
# owner
def setowner(self, opt, owner):
"""change owner for an option
def setowner(self, path, owner):
"""change owner for a path
"""
self._values[opt] = (owner, self._values[opt][1])
self._values[path] = (owner, self._values[path][1])
def getowner(self, opt, default):
"""get owner for an option
def getowner(self, path, default):
"""get owner for a path
return: owner object
"""
return self._values.get(opt, (default, None))[0]
return self._values.get(path, (default, None))[0]