tiramisu/tiramisu/storage/dictionary/storage.py

63 lines
2.0 KiB
Python
Raw Normal View History

2013-08-14 23:06:31 +02:00
# -*- coding: utf-8 -*-
2018-01-26 07:33:47 +01:00
# Copyright (C) 2013-2018 Team tiramisu (see AUTHORS for all contributors)
2013-08-14 23:06:31 +02:00
#
2013-09-22 22:33:09 +02:00
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
2013-08-14 23:06:31 +02:00
#
2013-09-22 22:33:09 +02:00
# 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 Lesser General Public License for more
# details.
2013-08-14 23:06:31 +02:00
#
2013-09-22 22:33:09 +02:00
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2013-08-14 23:06:31 +02:00
# ____________________________________________________________
from ...i18n import _
2017-07-21 18:03:34 +02:00
from ...error import ConfigError, ConflictError
2017-07-21 18:46:11 +02:00
class Setting(object):
2013-09-10 21:04:12 +02:00
"""Dictionary storage has no particular setting.
"""
pass
setting = Setting()
2013-08-27 09:46:52 +02:00
_list_sessions = []
2014-06-19 23:22:39 +02:00
def list_sessions(): # pragma: optional cover
2013-08-27 09:46:52 +02:00
return _list_sessions
2018-09-11 20:11:13 +02:00
def delete_session(session_id): # pragma: optional cover
raise ConfigError(_('dictionary storage cannot delete session'))
2013-08-20 22:45:11 +02:00
class Storage(object):
2013-09-22 20:57:52 +02:00
__slots__ = ('session_id', 'persistent')
storage = 'dictionary'
2013-09-22 20:57:52 +02:00
#if object could be serializable
serializable = True
2013-09-22 20:57:52 +02:00
def __init__(self, session_id, persistent, test=False):
2014-06-19 23:22:39 +02:00
if not test and session_id in _list_sessions: # pragma: optional cover
2017-11-23 16:56:14 +01:00
raise ConflictError(_('session "{}" already used').format(session_id))
2014-06-19 23:22:39 +02:00
if persistent: # pragma: optional cover
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
2013-09-22 20:57:52 +02:00
self.persistent = persistent
2013-08-27 09:46:52 +02:00
_list_sessions.append(self.session_id)
def __del__(self):
try:
_list_sessions.remove(self.session_id)
2014-06-19 23:22:39 +02:00
except AttributeError: # pragma: optional cover
pass
def getsession():
pass