mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 01:47:36 +03:00 
			
		
		
		
	Replacing callable provider documentation examples with literalincludes
This commit is contained in:
		
							parent
							
								
									a822f9e6d2
								
							
						
					
					
						commit
						cbe7069227
					
				| 
						 | 
					@ -19,26 +19,8 @@ Example:
 | 
				
			||||||
    :width: 100%
 | 
					    :width: 100%
 | 
				
			||||||
    :align: center
 | 
					    :align: center
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. code-block:: python
 | 
					.. literalinclude:: ../../examples/providers/callable_injections.py
 | 
				
			||||||
 | 
					   :language: python
 | 
				
			||||||
    """`Callable` providers example."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    from passlib.hash import sha256_crypt
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    from objects.providers import Callable
 | 
					 | 
				
			||||||
    from objects.injections import KwArg
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # 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)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Making some asserts (client's code):
 | 
					 | 
				
			||||||
    hashed_password = password_hasher('super secret')
 | 
					 | 
				
			||||||
    assert password_verifier('super secret', hashed_password)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
Callable providers delegation
 | 
					Callable providers delegation
 | 
				
			||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | 
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | 
				
			||||||
| 
						 | 
					@ -53,21 +35,5 @@ delegation* section for example.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Example:
 | 
					Example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. code-block:: python
 | 
					.. literalinclude:: ../../examples/providers/callable_delegation.py
 | 
				
			||||||
 | 
					   :language: python
 | 
				
			||||||
    """`Callable` providers delegation example."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    import sys
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    from objects.providers import Callable
 | 
					 | 
				
			||||||
    from objects.providers import Delegate
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Some callable provider and few delegates of it:
 | 
					 | 
				
			||||||
    callable_provider = Callable(sys.exit)
 | 
					 | 
				
			||||||
    callable_provider_delegate1 = callable_provider.delegate()
 | 
					 | 
				
			||||||
    callable_provider_delegate2 = Delegate(callable_provider)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Making some asserts:
 | 
					 | 
				
			||||||
    assert callable_provider_delegate1() is callable_provider
 | 
					 | 
				
			||||||
    assert callable_provider_delegate2() is callable_provider
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user