Commits

Anonymous committed 0392e53

[svn] fix python 2.3 compatibility: use random.randrange when random.getrandbits is
not available

  • Participants
  • Parent commits ae2dc56

Comments (0)

Files changed (1)

File webhelpers/rails/secure_form_tag.py

     already exist."""
     session = get_session()
     if not token_key in session:
-        session[token_key] = str(random.getrandbits(128))
+        try:
+            token = str(random.getrandbits(128))
+        except AttributeError: # Python < 2.4
+            token = str(random.randrange(2**128))
+        session[token_key] = token
         if hasattr(session, 'save'):
             session.save()
     return session[token_key]