Merge pull request #1562 from richboss/dev_urandom
don't write to /dev/urandom on Windows platforms
This commit is contained in:
+14
-12
@@ -17,6 +17,7 @@ import random
|
|||||||
import inspect
|
import inspect
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
@@ -299,19 +300,20 @@ def initialize_urandom():
|
|||||||
try:
|
try:
|
||||||
os.urandom(1)
|
os.urandom(1)
|
||||||
have_urandom = True
|
have_urandom = True
|
||||||
try:
|
if sys.platform != 'win32':
|
||||||
# try to add process-specific entropy
|
|
||||||
frandom = open('/dev/urandom', 'wb')
|
|
||||||
try:
|
try:
|
||||||
if PY2:
|
# try to add process-specific entropy
|
||||||
frandom.write(''.join(chr(t) for t in ctokens))
|
frandom = open('/dev/urandom', 'wb')
|
||||||
else:
|
try:
|
||||||
frandom.write(bytes([]).join(bytes([t]) for t in ctokens))
|
if PY2:
|
||||||
finally:
|
frandom.write(''.join(chr(t) for t in ctokens))
|
||||||
frandom.close()
|
else:
|
||||||
except IOError:
|
frandom.write(bytes([]).join(bytes([t]) for t in ctokens))
|
||||||
# works anyway
|
finally:
|
||||||
pass
|
frandom.close()
|
||||||
|
except IOError:
|
||||||
|
# works anyway
|
||||||
|
pass
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
have_urandom = False
|
have_urandom = False
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|||||||
Reference in New Issue
Block a user