| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import typing |
| 6 |
from importlib import import_module |
| 7 |
|
| 8 |
if typing.TYPE_CHECKING: |
| 9 |
from . import ( |
| 10 |
bot_detection, |
| 11 |
breached_password_detection, |
| 12 |
brute_force_protection, |
| 13 |
captcha, |
| 14 |
phone_provider_protection, |
| 15 |
suspicious_ip_throttling, |
| 16 |
) |
| 17 |
_dynamic_imports: typing.Dict[str, str] = { |
| 18 |
"bot_detection": ".bot_detection", |
| 19 |
"breached_password_detection": ".breached_password_detection", |
| 20 |
"brute_force_protection": ".brute_force_protection", |
| 21 |
"captcha": ".captcha", |
| 22 |
"phone_provider_protection": ".phone_provider_protection", |
| 23 |
"suspicious_ip_throttling": ".suspicious_ip_throttling", |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
def __getattr__(attr_name: str) -> typing.Any: |
| 28 |
module_name = _dynamic_imports.get(attr_name) |
| 29 |
if module_name is None: |
| 30 |
raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}") |
| 31 |
try: |
| 32 |
module = import_module(module_name, __package__) |
| 33 |
if module_name == f".{attr_name}": |
| 34 |
return module |
| 35 |
else: |
| 36 |
return getattr(module, attr_name) |
| 37 |
except ImportError as e: |
| 38 |
raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e |
| 39 |
except AttributeError as e: |
| 40 |
raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e |
| 41 |
|
| 42 |
|
| 43 |
def __dir__(): |
| 44 |
lazy_attrs = list(_dynamic_imports.keys()) |
| 45 |
return sorted(lazy_attrs) |
| 46 |
|
| 47 |
|
| 48 |
__all__ = [ |
| 49 |
"bot_detection", |
| 50 |
"breached_password_detection", |
| 51 |
"brute_force_protection", |
| 52 |
"captcha", |
| 53 |
"phone_provider_protection", |
| 54 |
"suspicious_ip_throttling", |
| 55 |
] |