Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for Mount API#1362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
69cbc1c492e742618e56ec827d028c5eb57b5dbfd89dc09eacd607835d0ac3bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -87,7 +87,7 @@ def __init__( | ||
| cookies: CookieTypes = None, | ||
| timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG, | ||
| max_redirects: int = DEFAULT_MAX_REDIRECTS, | ||
| event_hooks: typing.Dict[str, typing.List[typing.Callable]] = None, | ||
| event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None, | ||
| base_url: URLTypes = "", | ||
| trust_env: bool = True, | ||
| ): | ||
| @@ -561,11 +561,12 @@ def __init__( | ||
| cert: CertTypes = None, | ||
| http2: bool = False, | ||
| proxies: ProxiesTypes = None, | ||
| mounts: typing.Mapping[str, httpcore.SyncHTTPTransport] = None, | ||
| timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG, | ||
| limits: Limits = DEFAULT_LIMITS, | ||
| pool_limits: Limits = None, | ||
| max_redirects: int = DEFAULT_MAX_REDIRECTS, | ||
| event_hooks: typing.Dict[str, typing.List[typing.Callable]] = None, | ||
| event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None, | ||
| base_url: URLTypes = "", | ||
| transport: httpcore.SyncHTTPTransport = None, | ||
| app: typing.Callable = None, | ||
| @@ -611,7 +612,7 @@ def __init__( | ||
| app=app, | ||
| trust_env=trust_env, | ||
| ) | ||
| self._proxies: typing.Dict[ | ||
| self._mounts: typing.Dict[ | ||
| URLPattern, typing.Optional[httpcore.SyncHTTPTransport] | ||
| ] = { | ||
| URLPattern(key): None | ||
| @@ -626,7 +627,12 @@ def __init__( | ||
| ) | ||
| for key, proxy in proxy_map.items() | ||
| } | ||
| self._proxies = dict(sorted(self._proxies.items())) | ||
| if mounts is not None: | ||
| self._mounts.update( | ||
| {URLPattern(key): transport for key, transport in mounts.items()} | ||
| ) | ||
| self._mounts = dict(sorted(self._mounts.items())) | ||
| def _init_transport( | ||
| self, | ||
| @@ -681,7 +687,7 @@ def _transport_for_url(self, url: URL) -> httpcore.SyncHTTPTransport: | ||
| Returns the transport instance that should be used for a given URL. | ||
| This will either be the standard connection pool, or a proxy. | ||
| """ | ||
| for pattern, transport in self._proxies.items(): | ||
| for pattern, transport in self._mounts.items(): | ||
| ||
| if pattern.matches(url): | ||
| return self._transport if transport is None else transport | ||
| @@ -1109,17 +1115,17 @@ def close(self) -> None: | ||
| self._state = ClientState.CLOSED | ||
| self._transport.close() | ||
| for proxy in self._proxies.values(): | ||
| if proxy is not None: | ||
| proxy.close() | ||
| for transport in self._mounts.values(): | ||
| if transport is not None: | ||
| transport.close() | ||
| def __enter__(self: T) -> T: | ||
| self._state = ClientState.OPENED | ||
| self._transport.__enter__() | ||
| for proxy in self._proxies.values(): | ||
| if proxy is not None: | ||
| proxy.__enter__() | ||
| for transport in self._mounts.values(): | ||
| if transport is not None: | ||
| transport.__enter__() | ||
| return self | ||
| def __exit__( | ||
| @@ -1131,9 +1137,9 @@ def __exit__( | ||
| self._state = ClientState.CLOSED | ||
| self._transport.__exit__(exc_type, exc_value, traceback) | ||
| for proxy in self._proxies.values(): | ||
| if proxy is not None: | ||
| proxy.__exit__(exc_type, exc_value, traceback) | ||
| for transport in self._mounts.values(): | ||
| if transport is not None: | ||
| transport.__exit__(exc_type, exc_value, traceback) | ||
| def __del__(self) -> None: | ||
| self.close() | ||
| @@ -1198,11 +1204,12 @@ def __init__( | ||
| cert: CertTypes = None, | ||
| http2: bool = False, | ||
| proxies: ProxiesTypes = None, | ||
| mounts: typing.Mapping[str, httpcore.AsyncHTTPTransport] = None, | ||
| timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG, | ||
| limits: Limits = DEFAULT_LIMITS, | ||
| pool_limits: Limits = None, | ||
| max_redirects: int = DEFAULT_MAX_REDIRECTS, | ||
| event_hooks: typing.Dict[str, typing.List[typing.Callable]] = None, | ||
| event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None, | ||
| base_url: URLTypes = "", | ||
| transport: httpcore.AsyncHTTPTransport = None, | ||
| app: typing.Callable = None, | ||
| @@ -1249,7 +1256,7 @@ def __init__( | ||
| trust_env=trust_env, | ||
| ) | ||
| self._proxies: typing.Dict[ | ||
| self._mounts: typing.Dict[ | ||
| URLPattern, typing.Optional[httpcore.AsyncHTTPTransport] | ||
| ] = { | ||
| URLPattern(key): None | ||
| @@ -1264,7 +1271,11 @@ def __init__( | ||
| ) | ||
| for key, proxy in proxy_map.items() | ||
| } | ||
| self._proxies = dict(sorted(self._proxies.items())) | ||
| if mounts is not None: | ||
| self._mounts.update( | ||
| {URLPattern(key): transport for key, transport in mounts.items()} | ||
| ) | ||
| self._mounts = dict(sorted(self._mounts.items())) | ||
| def _init_transport( | ||
| self, | ||
| @@ -1319,7 +1330,7 @@ def _transport_for_url(self, url: URL) -> httpcore.AsyncHTTPTransport: | ||
| Returns the transport instance that should be used for a given URL. | ||
| This will either be the standard connection pool, or a proxy. | ||
| """ | ||
| for pattern, transport in self._proxies.items(): | ||
| for pattern, transport in self._mounts.items(): | ||
| if pattern.matches(url): | ||
| return self._transport if transport is None else transport | ||
| @@ -1499,7 +1510,7 @@ async def _send_single_request( | ||
| await timer.async_start() | ||
| with map_exceptions(HTTPCORE_EXC_MAP, request=request): | ||
| (status_code, headers, stream, ext,) = await transport.arequest( | ||
| (status_code, headers, stream, ext) = await transport.arequest( | ||
| request.method.encode(), | ||
| request.url.raw, | ||
| headers=request.headers.raw, | ||
| @@ -1750,15 +1761,15 @@ async def aclose(self) -> None: | ||
| self._state = ClientState.CLOSED | ||
| await self._transport.aclose() | ||
| for proxy in self._proxies.values(): | ||
| for proxy in self._mounts.values(): | ||
| if proxy is not None: | ||
| await proxy.aclose() | ||
| async def __aenter__(self: U) -> U: | ||
| self._state = ClientState.OPENED | ||
| await self._transport.__aenter__() | ||
| for proxy in self._proxies.values(): | ||
| for proxy in self._mounts.values(): | ||
| if proxy is not None: | ||
| await proxy.__aenter__() | ||
| return self | ||
| @@ -1772,7 +1783,7 @@ async def __aexit__( | ||
| self._state = ClientState.CLOSED | ||
| await self._transport.__aexit__(exc_type, exc_value, traceback) | ||
| for proxy in self._proxies.values(): | ||
| for proxy in self._mounts.values(): | ||
| if proxy is not None: | ||
| await proxy.__aexit__(exc_type, exc_value, traceback) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that the mounts overrides proxies? Like:
Do we need to outline it somewhere?