|
24 | 24 | # |
25 | 25 | # -------------------------------------------------------------------------- |
26 | 26 |
|
| 27 | +import sys |
27 | 28 | from ._base import HttpTransport, HttpRequest, HttpResponse |
28 | 29 | from ._requests_basic import RequestsTransport, RequestsTransportResponse |
29 | 30 |
|
|
35 | 36 | 'RequestsTransportResponse', |
36 | 37 | ] |
37 | 38 |
|
38 | | -#pylint: disable=unused-import |
39 | | - |
| 39 | +# pylint: disable=unused-import, redefined-outer-name |
40 | 40 | try: |
41 | 41 | from ._base_async import AsyncHttpTransport, AsyncHttpResponse |
42 | 42 | from ._requests_asyncio import AsyncioRequestsTransport, AsyncioRequestsTransportResponse |
|
47 | 47 | 'AsyncioRequestsTransportResponse' |
48 | 48 | ]) |
49 | 49 |
|
50 | | - try: |
51 | | - from ._requests_trio import TrioRequestsTransport, TrioRequestsTransportResponse |
| 50 | + if sys.version_info >= (3, 7): |
52 | 51 | __all__.extend([ |
53 | 52 | 'TrioRequestsTransport', |
54 | | - 'TrioRequestsTransportResponse' |
55 | | - ]) |
56 | | - except ImportError: |
57 | | - pass # Trio not installed |
58 | | - |
59 | | - try: |
60 | | - from ._aiohttp import AioHttpTransport, AioHttpTransportResponse |
61 | | - __all__.extend([ |
| 53 | + 'TrioRequestsTransportResponse', |
62 | 54 | 'AioHttpTransport', |
63 | 55 | 'AioHttpTransportResponse', |
64 | 56 | ]) |
65 | | - except ImportError: |
66 | | - pass # Aiohttp not installed |
| 57 | + |
| 58 | + def __dir__(): |
| 59 | + return __all__ |
| 60 | + |
| 61 | + def __getattr__(name): |
| 62 | + if name == 'AioHttpTransport': |
| 63 | + try: |
| 64 | + from ._aiohttp import AioHttpTransport |
| 65 | + return AioHttpTransport |
| 66 | + except ImportError: |
| 67 | + raise ImportError("aiohttp package is not installed") |
| 68 | + if name == 'AioHttpTransportResponse': |
| 69 | + try: |
| 70 | + from ._aiohttp import AioHttpTransportResponse |
| 71 | + return AioHttpTransportResponse |
| 72 | + except ImportError: |
| 73 | + raise ImportError("aiohttp package is not installed") |
| 74 | + if name == 'TrioRequestsTransport': |
| 75 | + try: |
| 76 | + from ._requests_trio import TrioRequestsTransport |
| 77 | + return TrioRequestsTransport |
| 78 | + except ImportError: |
| 79 | + raise ImportError("trio package is not installed") |
| 80 | + if name == 'TrioRequestsTransportResponse': |
| 81 | + try: |
| 82 | + from ._requests_trio import TrioRequestsTransportResponse |
| 83 | + return TrioRequestsTransportResponse |
| 84 | + except ImportError: |
| 85 | + raise ImportError("trio package is not installed") |
| 86 | + return name |
| 87 | + |
| 88 | + else: |
| 89 | + try: |
| 90 | + from ._requests_trio import TrioRequestsTransport, TrioRequestsTransportResponse |
| 91 | + __all__.extend([ |
| 92 | + 'TrioRequestsTransport', |
| 93 | + 'TrioRequestsTransportResponse' |
| 94 | + ]) |
| 95 | + except ImportError: |
| 96 | + pass # Trio not installed |
| 97 | + |
| 98 | + try: |
| 99 | + from ._aiohttp import AioHttpTransport, AioHttpTransportResponse |
| 100 | + __all__.extend([ |
| 101 | + 'AioHttpTransport', |
| 102 | + 'AioHttpTransportResponse', |
| 103 | + ]) |
| 104 | + except ImportError: |
| 105 | + pass # Aiohttp not installed |
67 | 106 | except (ImportError, SyntaxError): |
68 | 107 | pass # Asynchronous pipelines not supported. |
0 commit comments