| 1 |
import importlib |
| 2 |
import sys |
| 3 |
import typing as t |
| 4 |
|
| 5 |
from .api import ErrorSubdocument, GlobusAPIError |
| 6 |
from .base import GlobusError, GlobusSDKUsageError, ValidationError |
| 7 |
from .err_info import ( |
| 8 |
AuthorizationParameterInfo, |
| 9 |
ConsentRequiredInfo, |
| 10 |
ErrorInfo, |
| 11 |
ErrorInfoContainer, |
| 12 |
) |
| 13 |
from .warnings import RemovedInV5Warning, warn_deprecated |
| 14 |
|
| 15 |
__all__ = ( |
| 16 |
"GlobusError", |
| 17 |
"GlobusSDKUsageError", |
| 18 |
"ValidationError", |
| 19 |
"GlobusAPIError", |
| 20 |
"ErrorSubdocument", |
| 21 |
"NetworkError", |
| 22 |
"GlobusTimeoutError", |
| 23 |
"GlobusConnectionTimeoutError", |
| 24 |
"GlobusConnectionError", |
| 25 |
"convert_request_exception", |
| 26 |
"ErrorInfo", |
| 27 |
"ErrorInfoContainer", |
| 28 |
"AuthorizationParameterInfo", |
| 29 |
"ConsentRequiredInfo", |
| 30 |
"RemovedInV5Warning", |
| 31 |
"warn_deprecated", |
| 32 |
) |
| 33 |
|
| 34 |
# imports from `globus_sdk.exc.convert` are done lazily |
| 35 |
# |
| 36 |
# this ensures that we do not eagerly import `requests` when attempting to use SDK |
| 37 |
# components which do not need it, but which do need errors (e.g., RemovedInV5Warning) |
| 38 |
# and we avoid paying the performance penalty for importing the relevant dependencies |
| 39 |
if t.TYPE_CHECKING: |
| 40 |
from .convert import ( |
| 41 |
GlobusConnectionError, |
| 42 |
GlobusConnectionTimeoutError, |
| 43 |
GlobusTimeoutError, |
| 44 |
NetworkError, |
| 45 |
convert_request_exception, |
| 46 |
) |
| 47 |
else: |
| 48 |
_LAZY_IMPORT_TABLE = { |
| 49 |
"convert": { |
| 50 |
"GlobusConnectionError", |
| 51 |
"GlobusConnectionTimeoutError", |
| 52 |
"GlobusTimeoutError", |
| 53 |
"NetworkError", |
| 54 |
"convert_request_exception", |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
def __getattr__(name: str) -> t.Any: |
| 59 |
for modname, items in _LAZY_IMPORT_TABLE.items(): |
| 60 |
if name in items: |
| 61 |
mod = importlib.import_module("." + modname, __name__) |
| 62 |
value = getattr(mod, name) |
| 63 |
setattr(sys.modules[__name__], name, value) |
| 64 |
return value |
| 65 |
|
| 66 |
raise AttributeError(f"module {__name__} has no attribute {name}") |