1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Backed out [16356] due to later rejection of #16182.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16426 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Andrew Godwin
2011-06-17 09:47:08 +00:00
parent 222a5ed69e
commit 838a16ec20
2 changed files with 20 additions and 24 deletions

View File

@@ -158,12 +158,8 @@ class Signer(object):
class TimestampSigner(Signer):
def __init__(self, *args, **kwargs):
self.time_func = kwargs.pop('time', time.time)
super(TimestampSigner, self).__init__(*args, **kwargs)
def timestamp(self):
return baseconv.base62.encode(int(self.time_func() * 10000))
return baseconv.base62.encode(int(time.time()))
def sign(self, value):
value = smart_str('%s%s%s' % (value, self.sep, self.timestamp()))
@@ -172,10 +168,10 @@ class TimestampSigner(Signer):
def unsign(self, value, max_age=None):
result = super(TimestampSigner, self).unsign(value)
value, timestamp = result.rsplit(self.sep, 1)
timestamp = baseconv.base62.decode(timestamp) / 10000.0
timestamp = baseconv.base62.decode(timestamp)
if max_age is not None:
# Check timestamp is not older than max_age
age = self.time_func() - timestamp
age = time.time() - timestamp
if age > max_age:
raise SignatureExpired(
'Signature age %s > %s seconds' % (age, max_age))