Exemplo n.º 1
0
    def register(self, app: App) -> None:
        for name, hasher in self.hashers.items():
            hasher_class = import_string(hasher)
            app.singleton(
                hasher_class,
                hasher_class,
                aliases=f"hasher.{name}",
                tags=["password_hasher"],
            )

        app.alias(f"hasher.{self.default}", PasswordHasher)
Exemplo n.º 2
0
 def test_imports_module(self):
     var = import_string("tests")
     assert isinstance(var, types.ModuleType)
Exemplo n.º 3
0
 def test_raises_if_string_malformed(self):
     with pytest.raises(ImportError):
         import_string("tests.test_utils.")
Exemplo n.º 4
0
 def test_raises_if_no_attribute(self):
     with pytest.raises(ImportError):
         import_string("tests.test_utils.invalid_import")
Exemplo n.º 5
0
 def test_returns_argument_if_not_string(self):
     a = 1
     var = import_string(a)
     assert var == a
Exemplo n.º 6
0
 def test_imports_using_string(self):
     var = import_string("tests.test_utils.variable_to_import")
     assert var == variable_to_import
Exemplo n.º 7
0
 def include(self, module_name: str, callback: str = "configure") -> None:
     fn_path = module_name + "." + callback
     fn = import_string(fn_path)
     fn(self)
Exemplo n.º 8
0
 def factory(app: App) -> Authenticator:
     options_ = options or {}
     provider = app.get(f"user_provider.{user_provider}")
     cls = import_string(klass)
     return cls(provider, **options_)
Exemplo n.º 9
0
 def _jinja_renderer(self, env: jinja2.Environment) -> JinjaRenderer:
     processors = [
         import_string(cp) if isinstance(cp, str) else cp
         for cp in self.context_processors
     ]
     return JinjaRenderer(env, processors)