Example #1
0
def _loadModuleFromVerifiedHashSource(hashFinder, modName, modClass):
    hRoot = hashFinder.hashRoot()
    pkg = importlib.import_module(hRoot)
    impModName = modName if modName.startswith(hRoot + '.') else (hRoot + '.' + modName)
    try:
        m = importlib.import_module(impModName, hRoot)
    except (BadZipFile, SyntaxError) as ex:
        raise ImportError(str(ex))
    return getattr(m, modClass)
Example #2
0
def _loadModuleFromVerifiedHashSource(hashFinder, modName, modClass):
    hRoot = hashFinder.hashRoot()
    pkg = importlib.import_module(hRoot)
    #impModName = modName if modName.startswith(hRoot + '.') else (hRoot + '.' + modName)
    impModName = modName if modName.startswith(hRoot) else (hRoot + modName)
    try:
        m = importlib.import_module(impModName, hRoot)
    except (BadZipFile, SyntaxError) as ex:
        raise ImportError('Source hash %s: %s' % (hRoot, str(ex)))
    return getattr(m, modClass)
Example #3
0
 def _startupActorSys(self, currentSystemBase, systemBase, capabilities, logDefs):
     self.systemAddress = ActorAddress('/ActorSys')
     self.capabilities = capabilities or dict()
     if 'logging' in self.capabilities:
         import logging
         logging('Thespian').warning('logging specification moved from capabilities to an explicit argument.')
     if systemBase is None:
         systemBase = currentSystemBase
         if systemBase is None:
             import thespian.system.simpleSystemBase
             systemBase = thespian.system.simpleSystemBase.ActorSystemBase(self, logDefs = logDefs)
     elif isinstance(systemBase, str):
         import sys
         if sys.version_info < (2,7):
             import thespian.importlib as importlib
         else:
             import importlib
         # n.b. let standard import exception indicate a missing/unknown systemBase
         module = importlib.import_module('thespian.system.%s'%systemBase)
         sbc = getattr(module, 'ActorSystemBase')
         if currentSystemBase and id(currentSystemBase.__class__) == id(sbc):
             systemBase = currentSystemBase
         else:
             systemBase = sbc(self, logDefs = logDefs)
     elif systemBase and currentSystemBase:
         if id(systemBase.__class__) == id(currentSystemBase.__class__):
             systemBase = currentSystemBase
     # else systemBase should be a valid object already
     self._systemBase = systemBase
     return systemBase
Example #4
0
def actualActorClass(actorClass, sourceHashLoader=None):
    # the actorClass can either be a class object already or
    # it can be a string.  If it's the latter, get the actual
    # class object corresponding to the string.
    if isStr(actorClass):
        # actorClass is a module-qualified object reference
        # (e.g. "thespian.test.testLoadSource.BarActor').
        classModule, adot, className = actorClass.rpartition('.')
        if not classModule:
            # Caller passed an unqualified name string.  The name is
            # presumably in the same file context as the caller, and
            # for some systemBases (those that share the same process)
            # it might be possible to walk up the call frames and find
            # the right context, but that is not universally possible
            # (esp. for multi-process configurations), so this is
            # *always* disallowed.
            raise InvalidActorSpecification(actorClass)
        else:
            import thespian.importlib as importlib
            if sourceHashLoader:
                actorClass = sourceHashLoader(classModule, className)
            else:
                m = importlib.import_module(classModule)
                actorClass = getattr(m, className)
    return actorClass
Example #5
0
def _loadModuleFromVerifiedHashSource(hashFinder, modName, modClass):
    import thespian.importlib as importlib
    hRoot = hashFinder.hashRoot()
    impModName = modName if modName.startswith(hRoot + '.') else ('.' +
                                                                  modName)
    m = importlib.import_module(impModName, hRoot)
    return getattr(m, modClass)
Example #6
0
 def _startupActorSys(self, currentSystemBase, systemBase, capabilities,
                      logDefs):
     self.systemAddress = ActorAddress('/ActorSys')
     self.capabilities = capabilities or dict()
     if 'logging' in self.capabilities:
         import logging
         logging('Thespian').warning(
             'logging specification moved from capabilities to an explicit argument.'
         )
     if systemBase is None:
         systemBase = currentSystemBase
         if systemBase is None:
             import thespian.system.simpleSystemBase
             systemBase = thespian.system.simpleSystemBase.ActorSystemBase(
                 self, logDefs=logDefs)
     elif isinstance(systemBase, str):
         import sys
         if sys.version_info < (2, 7):
             import thespian.importlib as importlib
         else:
             import importlib
         # n.b. let standard import exception indicate a missing/unknown systemBase
         module = importlib.import_module('thespian.system.%s' % systemBase)
         sbc = getattr(module, 'ActorSystemBase')
         if currentSystemBase and id(
                 currentSystemBase.__class__) == id(sbc):
             systemBase = currentSystemBase
         else:
             systemBase = sbc(self, logDefs=logDefs)
     elif systemBase and currentSystemBase:
         if id(systemBase.__class__) == id(currentSystemBase.__class__):
             systemBase = currentSystemBase
     # else systemBase should be a valid object already
     self._systemBase = systemBase
     return systemBase
Example #7
0
def actualActorClass(actorClass, sourceHashLoader=None):
    # the actorClass can either be a class object already or
    # it can be a string.  If it's the latter, get the actual
    # class object corresponding to the string.
    if isStr(actorClass):
        # actorClass is a module-qualified object reference
        # (e.g. "thespian.test.testLoadSource.BarActor').
        classModule, adot, className = actorClass.rpartition('.')
        if not classModule:
            # Caller passed an unqualified name string.  The name is
            # presumably in the same file context as the caller, and
            # for some systemBases (those that share the same process)
            # it might be possible to walk up the call frames and find
            # the right context, but that is not universally possible
            # (esp. for multi-process configurations), so this is
            # *always* disallowed.
            raise InvalidActorSpecification(actorClass)
        else:
            import thespian.importlib as importlib
            if sourceHashLoader:
                actorClass = sourceHashLoader(classModule, className)
            else:
                m = importlib.import_module(classModule)
                actorClass = getattr(m, className)
    return actorClass
Example #8
0
    def __init__(self, systemBase=None, capabilities=None, logDefs=None):
        self.systemAddress = ActorAddress("/ActorSys")
        self.capabilities = capabilities or dict()
        if "logging" in self.capabilities:
            import logging

            logging("Thespian").warning("logging specification moved from capabilities to an explicit argument.")
        if systemBase is None:
            systemBase = getattr(self.__class__, "systemBase", None)
            if systemBase is None:
                import thespian.system.simpleSystemBase

                systemBase = thespian.system.simpleSystemBase.ActorSystemBase(self, logDefs)
        elif isinstance(systemBase, str):
            import thespian.importlib as importlib

            # n.b. let standard import exception indicate a missing/unknown systemBase
            module = importlib.import_module("thespian.system.%s" % systemBase)
            systemBase = getattr(module, "ActorSystemBase")(self, logDefs)
        # else systemBase should be a valid object already
        self._systemBase = systemBase
        if getattr(self.__class__, "systemBase", None) is None:
            # Set the Singleton systemBase
            self.__class__.systemBase = systemBase
Example #9
0
 def __init__(self, systemBase=None, capabilities=None, logDefs=None):
     self.systemAddress = ActorAddress('/ActorSys')
     self.capabilities = capabilities or dict()
     if 'logging' in self.capabilities:
         import logging
         logging('Thespian').warning(
             'logging specification moved from capabilities to an explicit argument.'
         )
     if systemBase is None:
         systemBase = getattr(self.__class__, 'systemBase', None)
         if systemBase is None:
             import thespian.system.simpleSystemBase
             systemBase = thespian.system.simpleSystemBase.ActorSystemBase(
                 self, logDefs)
     elif isinstance(systemBase, str):
         import thespian.importlib as importlib
         # n.b. let standard import exception indicate a missing/unknown systemBase
         module = importlib.import_module('thespian.system.%s' % systemBase)
         systemBase = getattr(module, 'ActorSystemBase')(self, logDefs)
     # else systemBase should be a valid object already
     self._systemBase = systemBase
     if getattr(self.__class__, 'systemBase', None) is None:
         # Set the Singleton systemBase
         self.__class__.systemBase = systemBase
Example #10
0
def _loadModuleFromVerifiedHashSource(hashFinder, modName, modClass):
    import thespian.importlib as importlib
    hRoot = hashFinder.hashRoot()
    impModName = modName if modName.startswith(hRoot + '.') else ('.' + modName)
    m = importlib.import_module(impModName, hRoot)
    return getattr(m, modClass)