2015-07-15 21:48:30 +00:00
|
|
|
Callable providers
|
|
|
|
------------------
|
|
|
|
|
|
|
|
``Callable`` provider is a provider that wraps particular callable with
|
|
|
|
some injections. Every call of this provider returns result of call of initial
|
|
|
|
callable.
|
|
|
|
|
|
|
|
``Callable`` provider uses ``KwArg`` injections. ``KwArg`` injections are
|
|
|
|
done by passing injectable values as keyword arguments during call time.
|
|
|
|
|
|
|
|
Context keyword arguments have higher priority than ``KwArg`` injections.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
.. image:: /images/callable.png
|
|
|
|
:width: 100%
|
|
|
|
:align: center
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
2015-07-15 23:39:21 +00:00
|
|
|
"""`Callable` providers example."""
|
|
|
|
|
|
|
|
from passlib.hash import sha256_crypt
|
2015-07-15 21:48:30 +00:00
|
|
|
|
|
|
|
from objects.providers import Callable
|
|
|
|
from objects.injections import KwArg
|
|
|
|
|
|
|
|
|
2015-07-15 23:39:21 +00:00
|
|
|
# Password hasher and verifier providers (hash function could be changed
|
|
|
|
# anytime (for example, to sha512) without any changes in client's code):
|
|
|
|
password_hasher = Callable(sha256_crypt.encrypt,
|
|
|
|
KwArg('salt_size', 16),
|
|
|
|
KwArg('rounds', 10000))
|
|
|
|
password_verifier = Callable(sha256_crypt.verify)
|
2015-07-15 21:48:30 +00:00
|
|
|
|
2015-07-15 23:39:21 +00:00
|
|
|
# Making some asserts (client's code):
|
|
|
|
hashed_password = password_hasher('super secret')
|
|
|
|
assert password_verifier('super secret', hashed_password)
|