コード例 #1
0
ファイル: sourceLoader.py プロジェクト: jfasenfest/Thespian
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)
コード例 #2
0
ファイル: sourceLoader.py プロジェクト: trumanw/Thespian
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)
コード例 #3
0
ファイル: actors.py プロジェクト: mathewraj/Thespian
 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
コード例 #4
0
ファイル: utilis.py プロジェクト: thomcost/Thespian
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
コード例 #5
0
ファイル: sourceLoader.py プロジェクト: thomcost/Thespian
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)
コード例 #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
コード例 #7
0
ファイル: utilis.py プロジェクト: thomcost/Thespian
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
コード例 #8
0
ファイル: actors.py プロジェクト: thomcost/Thespian
    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
コード例 #9
0
ファイル: actors.py プロジェクト: thomcost/Thespian
 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
コード例 #10
0
ファイル: sourceLoader.py プロジェクト: thomcost/Thespian
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)