def _load(self): q = SqlQuery(self._db, 'sessions', SESSION_TABLE) result = q.select({'id': self.id}) r = result.fetchone() if r: data = str(base64.b64decode(r[1])) return pickle.loads(data)
def _cleanup(self): # pylint: disable=protected-access table = SqlQuery(self._db, 'sessions', SESSION_TABLE)._table # pylint: disable=no-value-for-parameter d = table.delete().where(table.c.expiration_time <= datetime.datetime.now()) return d.execute().rowcount
def _save(self, expiration_time): q = None try: q = SqlQuery(self._db, 'sessions', SESSION_TABLE, trans=True) q.delete({'id': self.id}) data = pickle.dumps((self._data, expiration_time), self._proto) q.insert((self.id, base64.b64encode(data), expiration_time)) q.commit() except Exception: # pylint: disable=broad-except if q: q.rollback() raise
def _delete(self): q = SqlQuery(self._db, 'sessions', SESSION_TABLE) q.delete({'id': self.id})
def _exists(self): q = SqlQuery(self._db, 'sessions', SESSION_TABLE) result = q.select({'id': self.id}) return True if result.fetchone() else False