|
| 1 | +# This file was auto-generated by Fern from our API Definition. |
| 2 | + |
| 3 | +# isort: skip_file |
| 4 | + |
| 5 | +import typing |
| 6 | +from importlib import import_module |
| 7 | + |
| 8 | +if typing.TYPE_CHECKING: |
| 9 | + from ._api import EventSource, aconnect_sse, connect_sse |
| 10 | + from ._exceptions import SSEError |
| 11 | + from ._models import ServerSentEvent |
| 12 | +_dynamic_imports: typing.Dict[str, str] = { |
| 13 | + "EventSource": "._api", |
| 14 | + "SSEError": "._exceptions", |
| 15 | + "ServerSentEvent": "._models", |
| 16 | + "aconnect_sse": "._api", |
| 17 | + "connect_sse": "._api", |
| 18 | +} |
| 19 | + |
| 20 | + |
| 21 | +def __getattr__(attr_name: str) -> typing.Any: |
| 22 | + module_name = _dynamic_imports.get(attr_name) |
| 23 | + if module_name is None: |
| 24 | + raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}") |
| 25 | + try: |
| 26 | + module = import_module(module_name, __package__) |
| 27 | + if module_name == f".{attr_name}": |
| 28 | + return module |
| 29 | + else: |
| 30 | + return getattr(module, attr_name) |
| 31 | + except ImportError as e: |
| 32 | + raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e |
| 33 | + except AttributeError as e: |
| 34 | + raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e |
| 35 | + |
| 36 | + |
| 37 | +def __dir__(): |
| 38 | + lazy_attrs = list(_dynamic_imports.keys()) |
| 39 | + return sorted(lazy_attrs) |
| 40 | + |
| 41 | + |
| 42 | +__all__ = ["EventSource", "SSEError", "ServerSentEvent", "aconnect_sse", "connect_sse"] |
0 commit comments