1 # -*- coding: utf-8 -*-
4 from base64 import urlsafe_b64encode
6 from django.utils.hashcompat import sha_constructor
7 from django.conf import settings
10 # Use the system (hardware-based) random number generator if it exists.
11 if hasattr(random, 'SystemRandom'):
12 randrange = random.SystemRandom().randrange
14 randrange = random.randrange
15 MAX_SESSION_KEY = 18446744073709551616L # 2 << 63
18 def get_random_hash(seed):
19 sha_digest = sha_constructor('%s%s%s%s' %
20 (randrange(0, MAX_SESSION_KEY), time.time(), unicode(seed).encode('utf-8', 'replace'),
21 settings.SECRET_KEY)).digest()
22 return urlsafe_b64encode(sha_digest).replace('=', '').replace('_', '-').lower()
28 result.setdefault(tag.category, []).append(tag)