changeset 513:c30cd6473984

.emacs
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 17 Sep 2013 19:24:26 -0700
parents 68635bbb3d3e
children 1303f1f90a90
files .emacs
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.emacs	Mon Sep 09 13:15:31 2013 -0700
+++ b/.emacs	Tue Sep 17 19:24:26 2013 -0700
@@ -168,6 +168,25 @@
     main()")
 ;; TODO: take directly from MakeItSo
 
+(fset 'python-require "def require(url):
+    # http://k0s.org/hg/config/file/68635bbb3d3e/python/require.py
+    # import a module from the web
+    # url should be like scheme://host.name/path/to/module.py
+
+    import imp
+    import os
+    import tempfile
+    import urllib2
+    contents = urllib2.urlopen(url).read()
+    filename = url.rsplit('/', 1)[-1]
+    module = filename.rsplit('.', 1)[0]
+    dest = tempfile.mkstemp(suffix='.py', prefix=module)
+    f = file(dest, 'w')
+    f.write(contents)
+    f.close()
+    return imp.load_source(module, dest)
+")
+
 (fset 'mozbase-test "#!/usr/bin/env python
 
 # This Source Code Form is subject to the terms of the Mozilla Public