Created
April 8, 2013 21:38
-
-
Save PureForm/5340738 to your computer and use it in GitHub Desktop.
Add this to the end of `os.py`. This fixes the "from os import urandom as _urandom ImportError: cannot import name urandom" issue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if not _exists("urandom"): | |
def urandom(n): | |
"""urandom(n) -> str | |
Return a string of n random bytes suitable for cryptographic use. | |
""" | |
try: | |
_urandomfd = open("/dev/urandom", O_RDONLY) | |
except (OSError, IOError): | |
raise NotImplementedError("/dev/urandom (or equivalent) not found") | |
try: | |
bs = b"" | |
while n - len(bs) >= 1: | |
bs += read(_urandomfd, n - len(bs)) | |
finally: | |
close(_urandomfd) | |
return bs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment