Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_resource(self, res_name: str, t: Optional[Type] = None) -> Any:
logger.trace(f"Loading resource {res_name} of type {t}")
# FIXME: Actually returns obj of type `t`, but python is bad
loader, name = split_resource_name(res_name)
if t is None:
return self(_fwd.registry.get_named(loader, ResourceLoader))(name)
else:
return self(_fwd.registry.get_named(loader, ResourceLoader[t]))(name)
def load_modules(self):
import importlib.util
for i in self.modules:
spec = importlib.util.spec_from_file_location("ciphey.module_load_site", i)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
logger.debug(f"Loaded modules {_fwd.registry.get_all_names()}")
def get_targeted(
self, target: str, type_constraint: Type = None
) -> Optional[Union[Dict[Type, Set[Type]], Set[Type]]]:
x = self._targets.get(target)
if x is None or type_constraint is None:
return x
return x.get(type_constraint)
def get_all_names(self) -> List[str]:
return list(self._names.keys())
def __str__(self):
return f"ciphey.iface.Registry {{_reg: {self._reg}, _names: {self._names}, _targets: {self._targets}}}"
_fwd.registry = Registry()
return self(_fwd.registry.get_named(loader, ResourceLoader[t]))(name)
def __str__(self):
return str({
"verbosity": self.verbosity,
"searcher": self.searcher,
"params": self.params,
"format": self.format,
"modules": self.modules,
"checker": self.checker,
"default_dist": self.default_dist,
"timeout": self.timeout
})
_fwd.config = Config