| |
@@ -11,10 +11,6 @@
|
| |
etcd = None
|
| |
import json
|
| |
import time
|
| |
- try:
|
| |
- import cPickle as pickle
|
| |
- except ImportError:
|
| |
- import pickle
|
| |
|
| |
SESSION_TABLE = {'columns': ['id', 'data', 'expiration_time'],
|
| |
'primary_key': ('id', ),
|
| |
@@ -85,13 +81,20 @@
|
| |
r = result.fetchone()
|
| |
if r:
|
| |
data = str(base64.b64decode(r[1]))
|
| |
- return pickle.loads(data)
|
| |
+ if not data.startswith('['):
|
| |
+ # This is a pre-upgrade pickle'd session. Just invalidate.
|
| |
+ self._delete()
|
| |
+ return
|
| |
+ value, exp_time = json.loads(data)
|
| |
+ exp_dt = datetime.datetime.utcfromtimestamp(exp_time)
|
| |
+ return value, exp_dt
|
| |
|
| |
def _save(self, expiration_time):
|
| |
+ expiration_time = int(time.mktime(expiration_time.timetuple()))
|
| |
q = SqlQuery(self._db, 'sessions', SESSION_TABLE, trans=True)
|
| |
with q:
|
| |
q.delete({'id': self.id})
|
| |
- data = pickle.dumps((self._data, expiration_time), self._proto)
|
| |
+ data = json.dumps((self._data, expiration_time))
|
| |
q.insert((self.id, base64.b64encode(data), expiration_time))
|
| |
|
| |
def _delete(self):
|
| |
Do note that this does not currently pass, and I will open another PR to change away from using pickle's for storing sessions.