Skip to content

Commit 8129896

Browse files
committed
This change didn't make it into the last commit. Allow the user to
override the time column in the database by setting the __timestamp item in the call to set. This should make expiration of CSRF otk's work correctly for the rdbms backend.
1 parent 5bbde12 commit 8129896

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

roundup/backends/sessions_rdbms.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
class. It's now also used for One Time Key handling too.
66
"""
77
__docformat__ = 'restructuredtext'
8-
98
import os, time
109
from cgi import escape
1110

@@ -50,6 +49,12 @@ def getall(self, infoid):
5049
return eval(res[0])
5150

5251
def set(self, infoid, **newvalues):
52+
""" Store all newvalues under key infoid with a timestamp in database.
53+
54+
If newvalues['__timestamp'] exists and is representable as a floating point number
55+
(i.e. could be generated by time.time()), that value is used for the <name>_time
56+
column in the database.
57+
"""
5358
c = self.cursor
5459
n = self.name
5560
a = self.db.arg
@@ -67,9 +72,18 @@ def set(self, infoid, **newvalues):
6772
a, n, a)
6873
args = (repr(values), infoid)
6974
else:
75+
if '__timestamp' in newvalues:
76+
try:
77+
# __timestamp must be represntable as a float. Check it.
78+
timestamp = float(newvalues['__timestamp'])
79+
except ValueError:
80+
timestamp = time.time()
81+
else:
82+
timestamp = time.time()
83+
7084
sql = 'insert into %ss (%s_key, %s_time, %s_value) '\
7185
'values (%s, %s, %s)'%(n, n, n, n, a, a, a)
72-
args = (infoid, time.time(), repr(values))
86+
args = (infoid, timestamp, repr(values))
7387
c.execute(sql, args)
7488

7589
def list(self):

0 commit comments

Comments
 (0)