| 136 | from dns.query import _compute_times, _expiration_for_this_attempt, _remaining |
| 137 | |
| 138 | class _NetworkBackend(_CoreAsyncNetworkBackend): |
| 139 | def __init__(self, resolver, local_port, bootstrap_address, family): |
| 140 | super().__init__() |
| 141 | self._local_port = local_port |
| 142 | self._resolver = resolver |
| 143 | self._bootstrap_address = bootstrap_address |
| 144 | self._family = family |
| 145 | if local_port != 0: |
| 146 | raise NotImplementedError( |
| 147 | "the asyncio transport for HTTPX cannot set the local port" |
| 148 | ) |
| 149 | |
| 150 | async def connect_tcp( |
| 151 | self, host, port, timeout=None, local_address=None, socket_options=None |
| 152 | ): # pylint: disable=signature-differs |
| 153 | addresses = [] |
| 154 | _, expiration = _compute_times(timeout) |
| 155 | if dns.inet.is_address(host): |
| 156 | addresses.append(host) |
| 157 | elif self._bootstrap_address is not None: |
| 158 | addresses.append(self._bootstrap_address) |
| 159 | else: |
| 160 | timeout = _remaining(expiration) |
| 161 | family = self._family |
| 162 | if local_address: |
| 163 | family = dns.inet.af_for_address(local_address) |
| 164 | answers = await self._resolver.resolve_name( |
| 165 | host, family=family, lifetime=timeout |
| 166 | ) |
| 167 | addresses = answers.addresses() |
| 168 | for address in addresses: |
| 169 | try: |
| 170 | attempt_expiration = _expiration_for_this_attempt(2.0, expiration) |
| 171 | timeout = _remaining(attempt_expiration) |
| 172 | with anyio.fail_after(timeout): |
| 173 | stream = await anyio.connect_tcp( |
| 174 | remote_host=address, |
| 175 | remote_port=port, |
| 176 | local_host=local_address, |
| 177 | ) |
| 178 | return _CoreAnyIOStream(stream) |
| 179 | except Exception: |
| 180 | pass |
| 181 | raise httpcore.ConnectError |
| 182 | |
| 183 | async def connect_unix_socket( |
| 184 | self, path, timeout=None, socket_options=None |
| 185 | ): # pylint: disable=signature-differs |
| 186 | raise NotImplementedError |
| 187 | |
| 188 | async def sleep(self, seconds): # pylint: disable=signature-differs |
| 189 | await anyio.sleep(seconds) |
| 190 | |
| 191 | class _HTTPTransport(httpx.AsyncHTTPTransport): |
| 192 | def __init__( |
no outgoing calls
no test coverage detected
searching dependent graphs…