From 3bc830ac8d87916dfee030edc9e90741ab71b3a9 Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Thu, 7 Feb 2013 12:13:56 +0000 Subject: [PATCH] Really awful hack to work around tempfile wanting os.urandom to exist. This is awful but makes python-mode actually work for me on OS X with MacPorts. --- pylibs/__init__.py | 1 + pylibs/patch_urandom_bug.py | 23 +++++++++++++++++++++++ pylibs/pymode/__init__.py | 1 + pylibs/ropevim.py | 1 + 4 files changed, 26 insertions(+) create mode 100644 pylibs/patch_urandom_bug.py 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