1 # -*- coding: utf-8 -*-
2 "default plugin for value: 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
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # ____________________________________________________________
21 from tiramisu.storage.dictionary.storage import Cache
25 __slots__ = ('_values',)
27 def __init__(self, storage):
28 """init plugin means create values storage
31 # should init cache too
32 super(Values, self).__init__()
35 def setvalue(self, path, value, owner):
36 """set value for a path
37 a specified value must be associated to an owner
39 self._values[path] = (owner, value)
41 def getvalue(self, path):
42 """get value for a path
43 return: only value, not the owner
45 return self._values[path][1]
47 def hasvalue(self, path):
48 """if path has a value
51 return path in self._values
53 def resetvalue(self, path):
54 """remove value means delete value in storage
56 del(self._values[path])
58 def get_modified_values(self):
59 """return all values in a dictionary
60 example: {'path1': (owner, 'value1'), 'path2': (owner, 'value2')}
65 def setowner(self, path, owner):
66 """change owner for a path
68 self._values[path] = (owner, self._values[path][1])
70 def getowner(self, path, default):
71 """get owner for a path
74 return self._values.get(path, (default, None))[0]