57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"default plugin for storage: 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
|
|
#
|
|
# ____________________________________________________________
|
|
from tiramisu.i18n import _
|
|
from tiramisu.error import ConfigError
|
|
|
|
|
|
class Setting(object):
|
|
pass
|
|
|
|
|
|
setting = Setting()
|
|
_list_sessions = []
|
|
|
|
|
|
def list_sessions():
|
|
return _list_sessions
|
|
|
|
|
|
def delete_session(session_id):
|
|
raise ConfigError(_('dictionary storage cannot delete session'))
|
|
|
|
|
|
class Storage(object):
|
|
__slots__ = ('session_id', 'values', 'settings')
|
|
storage = 'dictionary'
|
|
|
|
def __init__(self, session_id, persistent):
|
|
if session_id in _list_sessions:
|
|
raise ValueError(_('session already used'))
|
|
if persistent:
|
|
raise ValueError(_('a dictionary cannot be persistent'))
|
|
self.session_id = session_id
|
|
_list_sessions.append(self.session_id)
|
|
|
|
def __del__(self):
|
|
try:
|
|
_list_sessions.remove(self.session_id)
|
|
except AttributeError:
|
|
pass
|