def start(cntx, resources, url): full_name = 'quactrl.rest.' + class_name Resource = get_class(full_name) app = App() app.add_resource(Resource(), name) app.run()
def construct_device_container(dev_definitions): devices = DynamicContainer() for definition in dev_definitions: provider = _providers[definition['strategy']]( get_class(definition['class']), ) setattr(devices, definition['name'],) return devices
def Device(self): if not hasattr(self, '_Device'): device_class = self.pars.get('device_class') self._Device = None if device_class is not None: self._Device = get_class(device_class) if device_class else None self.kwargs = self.pars.get('kwargs', {}) return self._Device
def Device(self): if not hasattr(self, '_Device'): device_class = self.pars.get('device_class') if device_class is None: self._Device, self.kwargs = self._find_Device() else: self._Device = get_class(device_class) self.kwargs = self.pars.get('kwargs', {}) return self._Device
def __init__(self, module_name, connection_string=None, **kwargs): super().__init__() self.connection_string = connection_string self.module_name = 'quactrl.data.' + module_name self.db = get_class('{}.Db'.format(self.module_name))( connection_string, **kwargs) self.Session = providers.ThreadLocalSingleton(self.db.Session) self._load_repos()
def _inject_provider(self, dev_name): if not hasattr(self, dev_name): config = self._devices[dev_name] Provider = self._providers[config['strategy']] DeviceClass = get_class(config['class']) args = config.get('args', []) for index, value in enumerate(args): if type(value) is str and value and value[0] == '>': args[index] = self._inject_provider(value[1:]) kwargs = config.get('kwargs', {}) for key in kwargs.keys(): value = kwargs[key] if type(value) is str and value and value[0] == '>': kwargs[key] = self._inject_provider(value[1:]) setattr(self, dev_name, Provider(DeviceClass, *args, **kwargs)) return getattr(self, dev_name)
def test_get_class(): assert get_class('tests.unit.helpers.test_init.FakeClass') == FakeClass
def _create_device(self, pars): class_name = pars.pop('class_name') Device = get_class(class_name) return Device(**pars)
def _get_class(self, name): full_class_name = '{}.{}Repo'.format(self.module_name, name) ResultClass = get_class(full_class_name) return ResultClass