|
|
@ -183,12 +183,17 @@ class SlaveModuleImporter(object):
|
|
|
|
if ret is None:
|
|
|
|
if ret is None:
|
|
|
|
raise ImportError('Master does not have %r' % (fullname,))
|
|
|
|
raise ImportError('Master does not have %r' % (fullname,))
|
|
|
|
|
|
|
|
|
|
|
|
path, data = ret
|
|
|
|
is_pkg, path, data = ret
|
|
|
|
code = compile(zlib.decompress(data), path, 'exec')
|
|
|
|
mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
|
|
|
|
module = imp.new_module(fullname)
|
|
|
|
mod.__file__ = 'master:' + path
|
|
|
|
sys.modules[fullname] = module
|
|
|
|
mod.__loader__ = self
|
|
|
|
eval(code, vars(module), vars(module))
|
|
|
|
if is_pkg:
|
|
|
|
return module
|
|
|
|
mod.__path__ = []
|
|
|
|
|
|
|
|
mod.__package__ = fullname
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
mod.__package__ = fullname.rpartition('.')[0]
|
|
|
|
|
|
|
|
exec zlib.decompress(data) in mod.__dict__
|
|
|
|
|
|
|
|
return mod
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MasterModuleResponder(object):
|
|
|
|
class MasterModuleResponder(object):
|
|
|
@ -203,9 +208,17 @@ class MasterModuleResponder(object):
|
|
|
|
reply_to, fullname = data
|
|
|
|
reply_to, fullname = data
|
|
|
|
LOG.debug('SlaveModuleImporter.GetModule(%r, %r)', reply_to, fullname)
|
|
|
|
LOG.debug('SlaveModuleImporter.GetModule(%r, %r)', reply_to, fullname)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
module = __import__(fullname)
|
|
|
|
module = __import__(fullname, fromlist=['*'])
|
|
|
|
source = zlib.compress(inspect.getsource(module))
|
|
|
|
is_pkg = getattr(module, '__path__', None) is not None
|
|
|
|
self._context.Enqueue(reply_to, (module.__file__, source))
|
|
|
|
path = inspect.getsourcefile(module)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
source = inspect.getsource(module)
|
|
|
|
|
|
|
|
except IOError:
|
|
|
|
|
|
|
|
if not is_pkg:
|
|
|
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
source = '\n'
|
|
|
|
|
|
|
|
compressed = zlib.compress(source)
|
|
|
|
|
|
|
|
self._context.Enqueue(reply_to, (is_pkg, path, compressed))
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
LOG.exception('While importing %r', fullname)
|
|
|
|
LOG.exception('While importing %r', fullname)
|
|
|
|
self._context.Enqueue(reply_to, None)
|
|
|
|
self._context.Enqueue(reply_to, None)
|
|
|
@ -852,7 +865,7 @@ class ExternalContext(object):
|
|
|
|
args = (self,) + args
|
|
|
|
args = (self,) + args
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
obj = __import__(modname)
|
|
|
|
obj = __import__(modname, fromlist=['*'])
|
|
|
|
if klass:
|
|
|
|
if klass:
|
|
|
|
obj = getattr(obj, klass)
|
|
|
|
obj = getattr(obj, klass)
|
|
|
|
fn = getattr(obj, func)
|
|
|
|
fn = getattr(obj, func)
|
|
|
|