76 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
"default plugin for value: set it in a simple dictionary"
# Copyright (C) 2013 Team tiramisu (see AUTHORS for all contributors)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ____________________________________________________________
#FIXME
from tiramisu.plugins.dictionary.cache import Cache
class Values(Cache):
__slots__ = ('_values',)
def __init__(self, config_id):
"""init plugin means create values storage
"""
self._values = {}
# should init cache too
super(Values, self).__init__()
# value
def setvalue(self, opt, value, owner):
"""set value for an option
a specified value must be associated to an owner
"""
self._values[opt] = (owner, value)
def getvalue(self, opt):
"""get value for an option
return: only value, not the owner
"""
return self._values[opt][1]
def hasvalue(self, opt):
"""if opt has a value
return: boolean
"""
return opt in self._values
def resetvalue(self, opt):
"""remove value means delete value in storage
"""
del(self._values[opt])
def get_modified_values(self):
"""return all values in a dictionary
example: {option1: (owner, 'value1'), option2: (owner, 'value2')}
"""
return self._values
# owner
def setowner(self, opt, owner):
"""change owner for an option
"""
self._values[opt] = (owner, self._values[opt][1])
def getowner(self, opt, default):
"""get owner for an option
return: owner object
"""
return self._values.get(opt, (default, None))[0]