X Tutup
Skip to content

Commit 3bc830a

Browse files
author
Alex Stapleton
committed
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.
1 parent cd6aec2 commit 3bc830a

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

pylibs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import patch_urandom_bug

pylibs/patch_urandom_bug.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
import os
3+
4+
if not hasattr(os, 'urandom'):
5+
# There's some annoying bug with Vim builds on OS X that breaks os.urandom.
6+
# To work around this we temporarily patch it out and then hack in a
7+
# totally insecure version of os.urandom.
8+
9+
def raise_notimpl(*args):
10+
"""Force random to fallback to using time for a seed"""
11+
raise NotImplementedError()
12+
os.urandom = raise_notimpl
13+
14+
import random
15+
import cStringIO
16+
17+
def crappy_urandom_for_macports_bug(n):
18+
"""Totally fail way of generating some random bytes"""
19+
buf = cStringIO.StringIO()
20+
for i in xrange(n):
21+
buf.write(chr(random.randint(0, 255)))
22+
return buf.getvalue()
23+
os.urandom = crappy_urandom_for_macports_bug

pylibs/pymode/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import patch_urandom_bug

pylibs/ropevim.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""ropevim, a vim mode for using rope refactoring library"""
2+
import patch_urandom_bug
23
import glob
34
import os
45
import tempfile

0 commit comments

Comments
 (0)
X Tutup