1 # -*- coding: utf-8 -*-
2 "default plugin for cache: 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 # ____________________________________________________________
22 from os.path import basename, splitext, join
27 class Setting(object):
35 def _gen_filename(name):
36 return join(setting.dir_database, '{0}.{1}'.format(name,
42 for filename in glob(_gen_filename('*')):
43 names.append(basename(splitext(filename)[0]))
47 def delete_session(session_id):
48 unlink(_gen_filename(session_id))
51 class Storage(object):
52 __slots__ = ('_conn', '_cursor', 'persistent', '_session_id')
55 def __init__(self, session_id, persistent):
56 self.persistent = persistent
57 self._session_id = session_id
58 self._conn = sqlite3.connect(_gen_filename(self._session_id))
59 self._conn.text_factory = str
60 self._cursor = self._conn.cursor()
62 def execute(self, sql, params=None, commit=True):
65 self._cursor.execute(sql, params)
69 def select(self, sql, params=None, only_one=True):
70 self.execute(sql, params=params, commit=False)
72 return self._cursor.fetchone()
74 return self._cursor.fetchall()
79 if not self.persistent:
80 delete_session(self._session_id)