| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import typing |
| 6 |
from importlib import import_module |
| 7 |
|
| 8 |
if typing.TYPE_CHECKING: |
| 9 |
from .bad_request_error import BadRequestError |
| 10 |
from .conflict_error import ConflictError |
| 11 |
from .content_too_large_error import ContentTooLargeError |
| 12 |
from .forbidden_error import ForbiddenError |
| 13 |
from .gone_error import GoneError |
| 14 |
from .internal_server_error import InternalServerError |
| 15 |
from .not_found_error import NotFoundError |
| 16 |
from .payment_required_error import PaymentRequiredError |
| 17 |
from .precondition_failed_error import PreconditionFailedError |
| 18 |
from .service_unavailable_error import ServiceUnavailableError |
| 19 |
from .too_many_requests_error import TooManyRequestsError |
| 20 |
from .unauthorized_error import UnauthorizedError |
| 21 |
_dynamic_imports: typing.Dict[str, str] = { |
| 22 |
"BadRequestError": ".bad_request_error", |
| 23 |
"ConflictError": ".conflict_error", |
| 24 |
"ContentTooLargeError": ".content_too_large_error", |
| 25 |
"ForbiddenError": ".forbidden_error", |
| 26 |
"GoneError": ".gone_error", |
| 27 |
"InternalServerError": ".internal_server_error", |
| 28 |
"NotFoundError": ".not_found_error", |
| 29 |
"PaymentRequiredError": ".payment_required_error", |
| 30 |
"PreconditionFailedError": ".precondition_failed_error", |
| 31 |
"ServiceUnavailableError": ".service_unavailable_error", |
| 32 |
"TooManyRequestsError": ".too_many_requests_error", |
| 33 |
"UnauthorizedError": ".unauthorized_error", |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
def __getattr__(attr_name: str) -> typing.Any: |
| 38 |
module_name = _dynamic_imports.get(attr_name) |
| 39 |
if module_name is None: |
| 40 |
raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}") |
| 41 |
try: |
| 42 |
module = import_module(module_name, __package__) |
| 43 |
if module_name == f".{attr_name}": |
| 44 |
return module |
| 45 |
else: |
| 46 |
return getattr(module, attr_name) |
| 47 |
except ImportError as e: |
| 48 |
raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e |
| 49 |
except AttributeError as e: |
| 50 |
raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e |
| 51 |
|
| 52 |
|
| 53 |
def __dir__(): |
| 54 |
lazy_attrs = list(_dynamic_imports.keys()) |
| 55 |
return sorted(lazy_attrs) |
| 56 |
|
| 57 |
|
| 58 |
__all__ = [ |
| 59 |
"BadRequestError", |
| 60 |
"ConflictError", |
| 61 |
"ContentTooLargeError", |
| 62 |
"ForbiddenError", |
| 63 |
"GoneError", |
| 64 |
"InternalServerError", |
| 65 |
"NotFoundError", |
| 66 |
"PaymentRequiredError", |
| 67 |
"PreconditionFailedError", |
| 68 |
"ServiceUnavailableError", |
| 69 |
"TooManyRequestsError", |
| 70 |
"UnauthorizedError", |
| 71 |
] |