예제 #1
0
 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)
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
 def _delete(self):
     q = SqlQuery(self._db, 'sessions', SESSION_TABLE)
     q.delete({'id': self.id})
예제 #5
0
 def _exists(self):
     q = SqlQuery(self._db, 'sessions', SESSION_TABLE)
     result = q.select({'id': self.id})
     return True if result.fetchone() else False