# HG changeset patch # User Jeff Hammel # Date 1322876472 28800 # Node ID 6ebd2d10fc033e3e961a91967caa26c876b1f94b # Parent 2dfdff7549b285b06b262b9e2866d627b00f0b5a stub embedding fetch diff -r 2dfdff7549b2 -r 6ebd2d10fc03 example.py --- /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)