diff --git a/pylibs/__init__.py b/pylibs/__init__.py index e69de29b..6710cfa7 100644 --- a/pylibs/__init__.py +++ b/pylibs/__init__.py @@ -0,0 +1 @@ +import patch_urandom_bug diff --git a/pylibs/patch_urandom_bug.py b/pylibs/patch_urandom_bug.py new file mode 100644 index 00000000..1eab2ce3 --- /dev/null +++ b/pylibs/patch_urandom_bug.py @@ -0,0 +1,23 @@ + +import os + +if not hasattr(os, 'urandom'): + # There's some annoying bug with Vim builds on OS X that breaks os.urandom. + # To work around this we temporarily patch it out and then hack in a + # totally insecure version of os.urandom. + + def raise_notimpl(*args): + """Force random to fallback to using time for a seed""" + raise NotImplementedError() + os.urandom = raise_notimpl + + import random + import cStringIO + + def crappy_urandom_for_macports_bug(n): + """Totally fail way of generating some random bytes""" + buf = cStringIO.StringIO() + for i in xrange(n): + buf.write(chr(random.randint(0, 255))) + return buf.getvalue() + os.urandom = crappy_urandom_for_macports_bug diff --git a/pylibs/pymode/__init__.py b/pylibs/pymode/__init__.py index e69de29b..6710cfa7 100644 --- a/pylibs/pymode/__init__.py +++ b/pylibs/pymode/__init__.py @@ -0,0 +1 @@ +import patch_urandom_bug diff --git a/pylibs/ropevim.py b/pylibs/ropevim.py index b2d150c4..4b3cc6d8 100644 --- a/pylibs/ropevim.py +++ b/pylibs/ropevim.py @@ -1,4 +1,5 @@ """ropevim, a vim mode for using rope refactoring library""" +import patch_urandom_bug import glob import os import tempfile