def load_security_services(self, configuration): if configuration.security is not None: if configuration.security.authentication is not None: if configuration.security.authentication.classname is not None: try: classobject = ClassLoader.instantiate_class( configuration.security.authentication.classname) self._authentication = classobject( configuration.security.authentication) except Exception as excep: YLogger.exception(self, "Failed to load security services", excep) else: YLogger.debug(self, "No authentication configuration defined") if configuration.security.authorisation is not None: if configuration.security.authorisation.classname is not None: try: classobject = ClassLoader.instantiate_class( configuration.security.authorisation.classname) self._authorisation = classobject( configuration.security.authorisation) except Exception as excep: YLogger.exception( self, "Failed to instatiate authorisation class", excep) else: YLogger.debug(self, "No authorisation configuration defined") else: YLogger.debug( self, "No security configuration defined, running open...")
def test_instantiate_module_class(self): loader = ClassLoader() self.assertIsNotNone(loader) meta_class = loader.instantiate_class("programrtest.utils.classes.testclass.TestClass") self.assertIsNotNone(meta_class) new_class = meta_class() self.assertIsNotNone(new_class) self.assertTrue(new_class.test_method())
def preload_services(cls, services_config): YLogger.debug(None, "In preload_services in ServiceFactory") loader = ClassLoader() for service_name in services_config.services(): name = service_name.upper() service_config = services_config.service(service_name) YLogger.debug(None, "Preloading service [%s] -> [%s]", name, service_config.classname) meta_class = loader.instantiate_class(service_config.classname) new_class = meta_class(service_config) ServiceFactory.services[name] = new_class
def resolve_to_string(self, client_context): data = self.resolve_children_to_string(client_context) new_class = ClassLoader.instantiate_class(self._path) instance = new_class() resolved = instance.execute(client_context, data) YLogger.debug(client_context, "[%s] resolved to [%s]", self.to_string(), resolved) return resolved
def load_nlp(self): # print("self.configuration.nlp.classname: {}".format(self.configuration.nlp.classname)) # print("self.configuration: {}".format(self.configuration)) if self.configuration and self.configuration.nlp.classname: nlp = ClassLoader.instantiate_class( self.configuration.nlp.classname) return nlp(self.configuration.nlp) else: #todo change this to handle when it's none return None
def load_oob_processors(self, configuration): if configuration.oob is not None: if configuration.oob.default() is not None: try: YLogger.info(self, "Loading default oob") classobject = ClassLoader.instantiate_class( configuration.oob.default().classname) self._default_oob = classobject() except Exception as excep: YLogger.exception(self, "Failed to load OOB Processor", excep) for oob_name in configuration.oob.oobs(): try: YLogger.info(self, "Loading oob: %s", oob_name) classobject = ClassLoader.instantiate_class( configuration.oob.oob(oob_name).classname) self._oob[oob_name] = classobject() except Exception as excep: YLogger.exception(self, "Failed to load OOB", excep)
def load_renderer(self): try: if self.get_client_configuration().renderer is not None: clazz = ClassLoader.instantiate_class( self.get_client_configuration().renderer.renderer) return clazz(self) except Exception as e: YLogger.exception(None, "Failed to load config specified renderer", e) return self.get_default_renderer()
def load(self, filename, *args, **kw): YLogger.debug(self, "Loading processors from file [%s]", filename) count = 0 try: with open(filename, "r", encoding="utf-8") as file: for line in file: line = line.strip() if line: if line[0] != '#': new_class = ClassLoader.instantiate_class(line) if new_class is not None: self.processors.append(new_class(*args, **kw)) count += 1 except FileNotFoundError: YLogger.error(self, "File not found [%s]", filename) return count
def process_config_line(self, line): if self.valid_config_line(line): splits = line.split("=") node_name = splits[0].strip() if node_name in self._nodes_config: YLogger.error(self, "Node already exists in config [%s]", line) return class_name = splits[1].strip() YLogger.debug(self, "Pre-instantiating %s Node [%s]", self._type, class_name) try: self._nodes_config[node_name] = ClassLoader.instantiate_class( class_name) except Exception as e: YLogger.exception( self, "Failed pre-instantiating %s Node [%s]" % (self._type, class_name), e)
def initiate_spellchecker(self): # TODO Move this to Spelling bass class if self.configuration is not None: if self.configuration.spelling.classname is not None: try: YLogger.info(self, "Loading spelling checker from class [%s]", self.configuration.spelling.classname) spell_class = ClassLoader.instantiate_class( self.configuration.spelling.classname) self._spell_checker = spell_class( self.configuration.spelling) except Exception as excep: YLogger.exception(self, "Failed to initiate spellcheker", excep) else: YLogger.warning( self, "No configuration setting for spelling checker!")
def add_dynamic_map(self, name, classname, config_file): self._dynamic_maps[name.upper()] = (ClassLoader.instantiate_class(classname))(config_file)