-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[py] implement configurable configuration class for the http client #13286
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a57423a
[py] implement configurable configuration class for the http client
titusfortner 3bc1889
fix private method access in tests
titusfortner d6f16e7
Merge branch 'trunk' into py_client_config_new
diemol 5600cc7
Merge branch 'trunk' into py_client_config_new
VietND96 3d209cb
[py] get auth header from client config
VietND96 35995bc
Merge branch 'trunk' into py_client_config_new
VietND96 9aede55
Merge branch 'trunk' into py_client_config_new
VietND96 9f21342
Fix review comments
VietND96 dbe23c5
Merge remote-tracking branch 'origin/trunk' into py_client_config_new
VietND96 3dd1b39
Update ClientConfig with more kwargs
VietND96 247d7dd
Merge branch 'trunk' into py_client_config_new
VietND96 0fe4410
Merge branch 'trunk' into py_client_config_new
AutomatedTester File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| import os | ||
| from urllib import parse | ||
|
|
||
| from selenium.webdriver.common.proxy import Proxy | ||
| from selenium.webdriver.common.proxy import ProxyType | ||
|
|
||
|
|
||
| class ClientConfig: | ||
| def __init__( | ||
| self, | ||
| remote_server_addr: str, | ||
| keep_alive: bool = True, | ||
| proxy=None, | ||
VietND96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) -> None: | ||
| self.remote_server_addr = remote_server_addr | ||
| self.keep_alive = keep_alive | ||
| self.proxy = proxy | ||
|
|
||
| @property | ||
| def remote_server_addr(self) -> str: | ||
| return self._remote_server_addr | ||
|
|
||
| @remote_server_addr.setter | ||
| def remote_server_addr(self, value: str): | ||
VietND96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self._remote_server_addr = value | ||
|
|
||
| @property | ||
| def keep_alive(self) -> bool: | ||
| """:Returns: The keep alive value.""" | ||
| return self._keep_alive | ||
|
|
||
| @keep_alive.setter | ||
| def keep_alive(self, value: bool) -> None: | ||
| """Toggles the keep alive value. | ||
| :Args: | ||
| - value: whether to keep the http connection alive | ||
| """ | ||
| self._keep_alive = value | ||
|
|
||
| @property | ||
| def proxy(self) -> Proxy: | ||
| """:Returns: The proxy used for communicating to the driver/server.""" | ||
|
|
||
| self._proxy = self._proxy or Proxy(raw={"proxyType": ProxyType.SYSTEM}) | ||
VietND96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return self._proxy | ||
|
|
||
| @proxy.setter | ||
| def proxy(self, proxy: Proxy) -> None: | ||
| """Provides the information for communicating with the driver or | ||
| server. | ||
| :Args: | ||
| - value: the proxy information to use to communicate with the driver or server | ||
| """ | ||
| self._proxy = proxy | ||
|
|
||
| def get_proxy_url(self): | ||
VietND96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if self.proxy.proxy_type == ProxyType.DIRECT: | ||
| return None | ||
| elif self.proxy.proxy_type == ProxyType.SYSTEM: | ||
| _no_proxy = os.environ.get("no_proxy", os.environ.get("NO_PROXY")) | ||
| if _no_proxy: | ||
| for npu in _no_proxy.split(","): | ||
VietND96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| npu = npu.strip() | ||
| if npu == "*": | ||
| return None | ||
| n_url = parse.urlparse(npu) | ||
| remote_add = parse.urlparse(self.remote_server_addr) | ||
| if n_url.netloc: | ||
| if remote_add.netloc == n_url.netloc: | ||
| return None | ||
| else: | ||
| if n_url.path in remote_add.netloc: | ||
| return None | ||
| if self.remote_server_addr.startswith("https://"): | ||
| return os.environ.get("https_proxy", os.environ.get("HTTPS_PROXY")) | ||
VietND96 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if self.remote_server_addr.startswith("http://"): | ||
| return os.environ.get("http_proxy", os.environ.get("HTTP_PROXY")) | ||
| elif self.proxy.proxy_type == ProxyType.MANUAL: | ||
| if self.remote_server_addr.startswith("https://"): | ||
| return self.proxy.sslProxy | ||
| elif self.remote_server_addr.startswith("http://"): | ||
| return self.proxy.http_proxy | ||
| else: | ||
| return None | ||
| else: | ||
| return None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.