예제 #1
0
def tryDynLocal(name):
    '''
    Dynamically import a module and return a module local or raise an exception.
    '''
    if name.find('.') == -1:
        raise s_exc.NoSuchDyn(name=name)

    modname, objname = name.rsplit('.', 1)
    mod = tryDynMod(modname)
    item = getattr(mod, objname, s_common.novalu)
    if item is s_common.novalu:
        raise s_exc.NoSuchDyn(name=name)
    return item
예제 #2
0
def tryDynMod(name):
    '''
    Dynamically import a python module or exception.
    '''
    try:
        return importlib.import_module(name)
    except ModuleNotFoundError:
        raise s_exc.NoSuchDyn(name=name)