mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-10-31 16:07:51 +03:00 
			
		
		
		
	* Add single container prototype * Add multiple containers prototype * Add integration tests * Implement from_*() methods and add tests * Prototype inline injections * Add integration test for inline providers * Refactor integration tests * Add integration test for reordered schema * Remove unused imports from tests * Refactor schema module * Update tests to match latest schemas * Add mypy_boto3_s3 to the test requirements * Add boto3 to the test requirements * Add set_provides for Callable, Factory, and Singleton providers * Fix warnings in tests * Add typing stubs for Callable, Factory, and Singleton .set_provides() attributes * Fix singleton children to have optional provides * Implement provider to provider resolving * Fix pypy3 tests * Implement boto3 session use case and add tests * Implement lazy initialization and improve copying for Callable, Factory, Singleton, and Coroutine providers * Fix Python 2 tests * Add region name for boto3 integration example * Remove f-strings from set_provides() * Fix schema flake8 errors * Implement lazy initialization and improve copying for Delegate provider * Implement lazy initialization and improve copying for Object provider * Speed up wiring tests * Implement lazy initialization and improve copying for FactoryAggregate provider * Implement lazy initialization and improve copying for Selector provider * Implement lazy initialization and improve copying for Dependency provider * Implement lazy initialization and improve copying for Resource provider * Implement lazy initialization and improve copying for Configuration provider * Implement lazy initialization and improve copying for ProvidedInstance provider * Implement lazy initialization and improve copying for AttributeGetter provider * Implement lazy initialization and improve copying for ItemGetter provider * Implement lazy initialization and improve copying for MethodCaller provder * Update changelog * Fix typing in wiring module * Fix wiring module loader uninstallation issue * Fix provided instance providers error handing in asynchronous mode Co-authored-by: Roman Mogylatov <rmk@Romans-MacBook-Pro.local>
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| """Services module."""
 | |
| 
 | |
| import logging
 | |
| import sqlite3
 | |
| from typing import Dict
 | |
| 
 | |
| from mypy_boto3_s3 import S3Client
 | |
| 
 | |
| 
 | |
| class BaseService:
 | |
| 
 | |
|     def __init__(self) -> None:
 | |
|         self.logger = logging.getLogger(
 | |
|             f'{__name__}.{self.__class__.__name__}',
 | |
|         )
 | |
| 
 | |
| 
 | |
| class UserService(BaseService):
 | |
| 
 | |
|     def __init__(self, db: sqlite3.Connection) -> None:
 | |
|         self.db = db
 | |
|         super().__init__()
 | |
| 
 | |
|     def get_user(self, email: str) -> Dict[str, str]:
 | |
|         self.logger.debug('User %s has been found in database', email)
 | |
|         return {'email': email, 'password_hash': '...'}
 | |
| 
 | |
| 
 | |
| class AuthService(BaseService):
 | |
| 
 | |
|     def __init__(self, db: sqlite3.Connection, token_ttl: int) -> None:
 | |
|         self.db = db
 | |
|         self.token_ttl = token_ttl
 | |
|         super().__init__()
 | |
| 
 | |
|     def authenticate(self, user: Dict[str, str], password: str) -> None:
 | |
|         assert password is not None
 | |
|         self.logger.debug(
 | |
|             'User %s has been successfully authenticated',
 | |
|             user['email'],
 | |
|         )
 | |
| 
 | |
| 
 | |
| class PhotoService(BaseService):
 | |
| 
 | |
|     def __init__(self, db: sqlite3.Connection, s3: S3Client) -> None:
 | |
|         self.db = db
 | |
|         self.s3 = s3
 | |
|         super().__init__()
 | |
| 
 | |
|     def upload_photo(self, user: Dict[str, str], photo_path: str) -> None:
 | |
|         self.logger.debug(
 | |
|             'Photo %s has been successfully uploaded by user %s',
 | |
|             photo_path,
 | |
|             user['email'],
 | |
|         )
 |