示例#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
文件: neuron.py 项目: piggum/synapse
        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
文件: neuron.py 项目: drstrng/synapse
        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
文件: mixins.py 项目: thpatel/synapse
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
文件: neuron.py 项目: piggum/synapse
    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
文件: neuron.py 项目: drstrng/synapse
    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))