Commit 47cbb8d7 authored by Tres Seaver's avatar Tres Seaver

Merge pull request #6 from snordhausen/master

Use os.urandom() to read from /dev/urandom
parents 1997818b ab7dcf4b
...@@ -46,11 +46,9 @@ from ZEO.Exceptions import AuthError ...@@ -46,11 +46,9 @@ from ZEO.Exceptions import AuthError
from ZEO.hash import sha1 from ZEO.hash import sha1
def get_random_bytes(n=8): def get_random_bytes(n=8):
if os.path.exists("/dev/urandom"): try:
f = open("/dev/urandom", 'rb') b = os.urandom(n)
b = f.read(n) except NotImplementedError:
f.close()
else:
L = [chr(random.randint(0, 255)) for i in range(n)] L = [chr(random.randint(0, 255)) for i in range(n)]
b = b"".join(L) b = b"".join(L)
return b return b
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment