Commits

Robert Brewer committed f374cf2

Fix for #489 (secure session key). os.urandom is used when available.

Comments (0)

Files changed (1)

         """Clean up expired sessions."""
         pass
     
-    def generate_id(self):
-        """Return a new session id."""
-        return sha.new('%s' % random.random()).hexdigest()
+    try:
+        os.urandom(20)
+    except (AttributeError, NotImplementedError):
+        # os.urandom not available until Python 2.4. Fall back to random.random.
+        def generate_id(self):
+            """Return a new session id."""
+            return sha.new('%s' % random.random()).hexdigest()
+    else:
+        def generate_id(self):
+            """Return a new session id."""
+            return os.urandom(20).encode('hex')
     
     def save(self):
         """Save session data."""