1 # -*- coding: utf-8 -*-
2 "default plugin for setting: set it in a simple dictionary"
3 # Copyright (C) 2013 Team tiramisu (see AUTHORS for all contributors)
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by the
7 # Free Software Foundation, either version 3 of the License, or (at your
8 # option) any later version.
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # ____________________________________________________________
19 from ..util import Cache
22 class Settings(Cache):
23 __slots__ = ('_properties', '_permissives')
25 def __init__(self, session_id, storage):
26 # properties attribute: the name of a property enables this property
27 # key is None for global properties
29 # permissive properties
30 self._permissives = {}
31 super(Settings, self).__init__(storage)
34 def setproperties(self, path, properties):
35 self._properties[path] = properties
37 def getproperties(self, path, default_properties):
38 return self._properties.get(path, set(default_properties))
40 def hasproperties(self, path):
41 return path in self._properties
43 def reset_all_properties(self):
44 self._properties.clear()
46 def delproperties(self, path):
47 if path in self._properties:
48 del(self._properties[path])
50 def setpermissive(self, path, permissive):
51 self._permissives[path] = frozenset(permissive)
53 def getpermissive(self, path=None):
54 return self._permissives.get(path, frozenset())
56 def get_modified_properties(self):
57 """return all modified settings in a dictionary
58 example: {'path1': set(['prop1', 'prop2'])}
60 return copy(self._properties)
62 def get_modified_permissives(self):
63 """return all modified permissives in a dictionary
64 example: {'path1': set(['perm1', 'perm2'])}
66 return copy(self._permissives)