mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-31 03:36:41 +03:00
Add container usage for callable provider example
This commit is contained in:
parent
1eb9020a4e
commit
a497cb2527
|
@ -2,17 +2,22 @@
|
||||||
|
|
||||||
import passlib.hash
|
import passlib.hash
|
||||||
|
|
||||||
from dependency_injector import providers
|
from dependency_injector import containers, providers
|
||||||
|
|
||||||
|
|
||||||
password_hasher = providers.Callable(
|
class Container(containers.DeclarativeContainer):
|
||||||
passlib.hash.sha256_crypt.hash,
|
|
||||||
salt_size=16,
|
password_hasher = providers.Callable(
|
||||||
rounds=10000,
|
passlib.hash.sha256_crypt.hash,
|
||||||
)
|
salt_size=16,
|
||||||
password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify)
|
rounds=10000,
|
||||||
|
)
|
||||||
|
|
||||||
|
password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
hashed_password = password_hasher('super secret')
|
container = Container()
|
||||||
assert password_verifier('super secret', hashed_password)
|
|
||||||
|
hashed_password = container.password_hasher('super secret')
|
||||||
|
assert container.password_verifier('super secret', hashed_password)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user