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