changeset 56:6ebd2d10fc03 default tip

stub embedding fetch
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 02 Dec 2011 17:41:12 -0800
parents 2dfdff7549b2
children
files example.py
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example.py	Fri Dec 02 17:41:12 2011 -0800
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+"""
+http://k0s.org/geekcode                                      tmp/code       file
+#https://github.com/mozilla/mozbase/tarball/master#mozprofile tmp/mozprofile tar
+#http://k0s.org/mozilla/hg/fetch#fetch.py                     tmp/fetch.py   hg
+git://github.com/mozautomation/mozmill.git#jsbridge          tmp/jsbridge   git
+"""
+
+# example embedding fetch
+
+def require(url):
+    """
+    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)[-1]
+    dest = tempfile.mkstemp(suffix='.py', prefix=module)
+    f = file(dest, 'w')
+    f.write(contents)
+    f.close()
+    return imp.load_source(module, dest)