1# --------------------------------------------------------------------------
2#
3# Copyright (c) Microsoft Corporation. All rights reserved.
4#
5# The MIT License (MIT)
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the ""Software""), to
9# deal in the Software without restriction, including without limitation the
10# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11# sell copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23# IN THE SOFTWARE.
24#
25# --------------------------------------------------------------------------
26from typing import List, Optional, Any
27from ._base import HttpTransport, HttpRequest, HttpResponse
28from ._base_async import AsyncHttpTransport, AsyncHttpResponse
29
30# pylint: disable=undefined-all-variable
31
32__all__ = [
33 "HttpTransport",
34 "HttpRequest",
35 "HttpResponse",
36 "RequestsTransport",
37 "RequestsTransportResponse",
38 "AsyncHttpTransport",
39 "AsyncHttpResponse",
40 "AsyncioRequestsTransport",
41 "AsyncioRequestsTransportResponse",
42 "TrioRequestsTransport",
43 "TrioRequestsTransportResponse",
44 "AioHttpTransport",
45 "AioHttpTransportResponse",
46]
47
48# pylint: disable= no-member, too-many-statements
49
50
51def __dir__() -> List[str]:
52 return __all__
53
54
55# To do nice overloads, need https://github.com/python/mypy/issues/8203
56
57
58def __getattr__(name: str):
59 transport: Optional[Any] = None
60 if name == "AsyncioRequestsTransport":
61 try:
62 from ._requests_asyncio import AsyncioRequestsTransport
63
64 transport = AsyncioRequestsTransport
65 except ImportError as err:
66 raise ImportError("requests package is not installed") from err
67 if name == "AsyncioRequestsTransportResponse":
68 try:
69 from ._requests_asyncio import AsyncioRequestsTransportResponse
70
71 transport = AsyncioRequestsTransportResponse
72 except ImportError as err:
73 raise ImportError("requests package is not installed") from err
74 if name == "RequestsTransport":
75 try:
76 from ._requests_basic import RequestsTransport
77
78 transport = RequestsTransport
79 except ImportError as err:
80 raise ImportError("requests package is not installed") from err
81 if name == "RequestsTransportResponse":
82 try:
83 from ._requests_basic import RequestsTransportResponse
84
85 transport = RequestsTransportResponse
86 except ImportError as err:
87 raise ImportError("requests package is not installed") from err
88 if name == "AioHttpTransport":
89 try:
90 from ._aiohttp import AioHttpTransport
91
92 transport = AioHttpTransport
93 except ImportError as err:
94 raise ImportError("aiohttp package is not installed") from err
95 if name == "AioHttpTransportResponse":
96 try:
97 from ._aiohttp import AioHttpTransportResponse
98
99 transport = AioHttpTransportResponse
100 except ImportError as err:
101 raise ImportError("aiohttp package is not installed") from err
102 if name == "TrioRequestsTransport":
103 try:
104 from ._requests_trio import TrioRequestsTransport
105
106 transport = TrioRequestsTransport
107 except ImportError as ex:
108 if ex.msg.endswith("'requests'"):
109 raise ImportError("requests package is not installed") from ex
110 raise ImportError("trio package is not installed") from ex
111 if name == "TrioRequestsTransportResponse":
112 try:
113 from ._requests_trio import TrioRequestsTransportResponse
114
115 transport = TrioRequestsTransportResponse
116 except ImportError as err:
117 raise ImportError("trio package is not installed") from err
118 if transport:
119 return transport
120 raise AttributeError(f"module 'azure.core.pipeline.transport' has no attribute {name}")