2013-08-14 23:06:31 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# ____________________________________________________________
|
2013-08-20 22:45:11 +02:00
|
|
|
from tiramisu.i18n import _
|
2013-08-25 21:57:11 +02:00
|
|
|
from tiramisu.error import ConfigError
|
|
|
|
|
|
|
|
|
2013-08-26 21:48:42 +02:00
|
|
|
class Setting(object):
|
2013-09-10 21:04:12 +02:00
|
|
|
"""Dictionary storage has no particular setting.
|
|
|
|
"""
|
2013-08-26 21:48:42 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
setting = Setting()
|
2013-08-27 09:46:52 +02:00
|
|
|
_list_sessions = []
|
2013-08-26 21:48:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def list_sessions():
|
2013-08-27 09:46:52 +02:00
|
|
|
return _list_sessions
|
2013-08-25 21:57:11 +02:00
|
|
|
|
|
|
|
|
2013-08-26 21:48:42 +02:00
|
|
|
def delete_session(session_id):
|
2013-08-25 21:57:11 +02:00
|
|
|
raise ConfigError(_('dictionary storage cannot delete session'))
|
2013-08-20 22:45:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Storage(object):
|
2013-09-06 23:15:28 +02:00
|
|
|
__slots__ = ('session_id', 'values', 'settings')
|
2013-08-25 20:49:24 +02:00
|
|
|
storage = 'dictionary'
|
|
|
|
|
2013-08-27 09:46:52 +02:00
|
|
|
def __init__(self, session_id, persistent):
|
|
|
|
if session_id in _list_sessions:
|
|
|
|
raise ValueError(_('session already used'))
|
|
|
|
if persistent:
|
2013-08-20 22:45:11 +02:00
|
|
|
raise ValueError(_('a dictionary cannot be persistent'))
|
2013-08-27 09:46:52 +02:00
|
|
|
self.session_id = session_id
|
|
|
|
_list_sessions.append(self.session_id)
|
|
|
|
|
|
|
|
def __del__(self):
|
2013-08-27 11:39:32 +02:00
|
|
|
try:
|
|
|
|
_list_sessions.remove(self.session_id)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|