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)
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
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 )
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)
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
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
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]
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
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') )
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) )
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'))
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'))
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))