10
|
1 def require(url):
|
|
2 """
|
|
3 import a module from the web
|
|
4 url should be like scheme://host.name/path/to/module.py
|
|
5 """
|
|
6 import imp
|
|
7 import os
|
|
8 import tempfile
|
|
9 import urllib2
|
|
10 contents = urllib2.urlopen(url).read()
|
|
11 filename = url.rsplit('/', 1)[-1]
|
|
12 module = filename.rsplit('.', 1)[-1]
|
|
13 dest = tempfile.mktemp(suffix='.py', prefix=module)
|
|
14 f = file(dest, 'w')
|
|
15 f.write(contents)
|
|
16 f.close()
|
|
17 return imp.load_source(module, dest)
|
|
18
|
|
19 # TODO: make an equivalent method for a tarball
|