Skip to content

Instantly share code, notes, and snippets.

@theodox
Last active August 29, 2015 14:01
Show Gist options
  • Save theodox/7909dc38454011727f70 to your computer and use it in GitHub Desktop.
Save theodox/7909dc38454011727f70 to your computer and use it in GitHub Desktop.
# usess the same imports as WebFinder.py
class WebLoader(object):
'''
Import loader (see http://pymotw.com/2/sys/imports.html for background)
which loads modules cached by a WebFinder using imp.load_source
'''
def __init__(self, url, filepath, name):
self.url = url
self.name = name
self.file = filepath
return
def load_module(self, fullname):
if fullname in sys.modules:
mod = sys.modules[fullname]
return mod
# bail now so we don't mislead users
# if mod was found somewhere else!
else:
mod = sys.modules.setdefault(fullname, imp.load_source(fullname, self.file))
mod.__file__ = self.file
mod.__name__ = fullname
mod.__path__ = [self.url]
mod.__loader__ = self
mod.__package__ = '.'.join(fullname.split('.')[:-1])
return mod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment