Пример #1
0
    def test_dyndeps_alias(self):

        s_dyndeps.addDynAlias('unit_test_woot', woot)

        self.eq(s_dyndeps.getDynLocal('unit_test_woot'), woot)
        self.eq(s_dyndeps.tryDynFunc('unit_test_woot', 20, y=40), 60)

        self.eq(s_dyndeps.delDynAlias('unit_test_woot'), woot)
        self.none(s_dyndeps.getDynLocal('unit_test_woot'))

        self.raises(NoSuchDyn, s_dyndeps.tryDynFunc, 'unit_test_woot', 20, y=40)
Пример #2
0
def getCellCtor(dirn, conf=None):
    '''
    Find the ctor option for a cell and resolve the function.
    '''
    ctor = None

    if conf is not None:
        ctor = conf.get('ctor')

    path = s_common.genpath(dirn, 'config.json')

    if ctor is None and os.path.isfile(path):
        subconf = s_common.jsload(path)
        ctor = subconf.get('ctor')

    if ctor is None:
        raise s_common.ReqConfOpt(mesg='Missing ctor, cannot divide',
                                  name='ctor')

    func = s_dyndeps.getDynLocal(ctor)
    if func is None:
        raise s_common.NoSuchCtor(mesg='Cannot resolve ctor',
                                  name=ctor)

    return ctor, func
Пример #3
0
        def setauthmod(event):
            valu = event[1].get('valu')
            if valu == None:
                self.setAuthModule(None)
                return

            name,args,kwargs = valu

            auth = s_dyndeps.getDynLocal(name)(*args,**kwargs)
            self.setAuthModule( auth )
Пример #4
0
        def setauthmod(event):
            valu = event[1].get('valu')
            if valu == None:
                self.setAuthModule(None)
                return

            name, args, kwargs = valu

            auth = s_dyndeps.getDynLocal(name)(*args, **kwargs)
            self.setAuthModule(auth)
Пример #5
0
    def _loadApiObject(self, name, ctor, *args, **kwargs):
        meth = s_dyndeps.getDynLocal(ctor)
        if meth == None:
            raise NoSuchCtor(ctor)

        obj = meth(*args, **kwargs)
        self.objs[name] = obj

        self.loadHttpPaths(obj)

        return obj
Пример #6
0
    def _loadApiObject(self, name, ctor, *args, **kwargs):
        meth = s_dyndeps.getDynLocal(ctor)
        if meth == None:
            raise NoSuchCtor(ctor)

        obj = meth(*args,**kwargs)
        self.objs[name] = obj

        self.loadHttpPaths(obj)

        return obj
Пример #7
0
def getSynMixins(subsys, name):
    '''
    Return a list of mixin classes for the given subsystem class.

    Example:

        for clas in getSynMixins('telepath','foo.bar.Baz'):
            dostuff()

    '''
    names = mixins[subsys].get(name, ())
    if not names:
        return ()
    return [s_dyndeps.getDynLocal(name) for name in names]
Пример #8
0
def getCellCtor(dirn, conf=None):
    '''
    Find the ctor option for a Cell and resolve the function.

    Args:
        dirn (str): The path to the Cell directory. This may contain the the
         ctor in the ``config.json`` file.
        conf (dict): Configuration dictionary for the cell. This may contain
         the ctor in the ``ctor`` key.

    Returns:
        ((str, function)): The python path to the ctor function and the resolved function.

    Raises:
        ReqConfOpt: If the ctor cannot be resolved from the cell path or conf
        NoSuchCtor: If the ctor function cannot be resolved.
    '''
    ctor = None

    if conf is not None:
        ctor = conf.get('ctor')

    path = s_common.genpath(dirn, 'config.json')

    if ctor is None and os.path.isfile(path):
        subconf = s_common.jsload(path)
        ctor = subconf.get('ctor')

    if ctor is None:
        raise s_common.ReqConfOpt(mesg='Missing ctor, cannot divide',
                                  name='ctor')

    func = s_dyndeps.getDynLocal(ctor)
    if func is None:
        raise s_common.NoSuchCtor(mesg='Cannot resolve ctor', name=ctor)

    return ctor, func
Пример #9
0
 def test_dyndeps_dynloc(self):
     self.assertIsNone( s_dyndeps.getDynLocal('synapse.tests.test_dyndeps.gronk') )
     self.assertIsNotNone( s_dyndeps.getDynLocal('synapse.tests.test_dyndeps.hehe') )
Пример #10
0
    def _loadNeuShare(self, path, name, args, kwargs):
        func = s_dyndeps.getDynLocal(name)
        if func == None:
            raise Exception('No Such Func: %s' % (name,))

        self.addSharedObject( path, func(*args,**kwargs) )
Пример #11
0
 def test_dyndeps_dynloc(self):
     self.assertIsNone(
         s_dyndeps.getDynLocal('synapse.tests.test_dyndeps.gronk'))
     self.assertIsNotNone(
         s_dyndeps.getDynLocal('synapse.tests.test_dyndeps.hehe'))
Пример #12
0
 def test_dyndeps_dynloc(self):
     self.none(s_dyndeps.getDynLocal('synapse.tests.test_dyndeps.gronk'))
     self.nn(s_dyndeps.getDynLocal('synapse.tests.test_dyndeps.hehe'))
Пример #13
0
    def _loadNeuShare(self, path, name, args, kwargs):
        func = s_dyndeps.getDynLocal(name)
        if func == None:
            raise Exception('No Such Func: %s' % (name, ))

        self.addSharedObject(path, func(*args, **kwargs))