From 448437d677d7bf22aaa89ac6941512ec76f956bb Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Thu, 17 Oct 2024 05:38:50 +0000 Subject: [PATCH] Fix review comments Signed-off-by: Viet Nguyen Duc --- .../webdriver/chrome/remote_connection.py | 6 ++--- .../webdriver/chromium/remote_connection.py | 5 ++-- .../webdriver/edge/remote_connection.py | 6 ++--- .../webdriver/firefox/remote_connection.py | 6 ++--- py/selenium/webdriver/remote/client_config.py | 25 ++++++++++--------- .../webdriver/remote/remote_connection.py | 11 ++++---- py/selenium/webdriver/remote/webdriver.py | 2 +- .../webdriver/safari/remote_connection.py | 5 ++-- 8 files changed, 35 insertions(+), 31 deletions(-) diff --git a/py/selenium/webdriver/chrome/remote_connection.py b/py/selenium/webdriver/chrome/remote_connection.py index b3f278fe5c547..48eefbf123779 100644 --- a/py/selenium/webdriver/chrome/remote_connection.py +++ b/py/selenium/webdriver/chrome/remote_connection.py @@ -14,11 +14,11 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing from selenium.webdriver import DesiredCapabilities from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection from selenium.webdriver.remote.client_config import ClientConfig +from typing import Optional class ChromeRemoteConnection(ChromiumRemoteConnection): @@ -28,8 +28,8 @@ def __init__( self, remote_server_addr: str, keep_alive: bool = True, - ignore_proxy: typing.Optional[bool] = False, - client_config: ClientConfig = None, + ignore_proxy: Optional[bool] = False, + client_config: Optional[ClientConfig] = None, ) -> None: super().__init__( remote_server_addr=remote_server_addr, diff --git a/py/selenium/webdriver/chromium/remote_connection.py b/py/selenium/webdriver/chromium/remote_connection.py index cc14a2b00a9f8..b8c7f073bded1 100644 --- a/py/selenium/webdriver/chromium/remote_connection.py +++ b/py/selenium/webdriver/chromium/remote_connection.py @@ -16,6 +16,7 @@ # under the License. from selenium.webdriver.remote.client_config import ClientConfig from selenium.webdriver.remote.remote_connection import RemoteConnection +from typing import Optional class ChromiumRemoteConnection(RemoteConnection): @@ -25,8 +26,8 @@ def __init__( vendor_prefix: str, browser_name: str, keep_alive: bool = True, - ignore_proxy: bool = False, - client_config: ClientConfig = None, + ignore_proxy: Optional[bool] = False, + client_config: Optional[ClientConfig] = None, ) -> None: super().__init__( remote_server_addr=remote_server_addr, diff --git a/py/selenium/webdriver/edge/remote_connection.py b/py/selenium/webdriver/edge/remote_connection.py index b819e66860031..65dfcce04bac6 100644 --- a/py/selenium/webdriver/edge/remote_connection.py +++ b/py/selenium/webdriver/edge/remote_connection.py @@ -14,11 +14,11 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing from selenium.webdriver import DesiredCapabilities from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection from selenium.webdriver.remote.client_config import ClientConfig +from typing import Optional class EdgeRemoteConnection(ChromiumRemoteConnection): @@ -28,8 +28,8 @@ def __init__( self, remote_server_addr: str, keep_alive: bool = True, - ignore_proxy: typing.Optional[bool] = False, - client_config: ClientConfig = None, + ignore_proxy: Optional[bool] = False, + client_config: Optional[ClientConfig] = None, ) -> None: super().__init__( remote_server_addr=remote_server_addr, diff --git a/py/selenium/webdriver/firefox/remote_connection.py b/py/selenium/webdriver/firefox/remote_connection.py index 6dd51524e5243..3e161ea4c67af 100644 --- a/py/selenium/webdriver/firefox/remote_connection.py +++ b/py/selenium/webdriver/firefox/remote_connection.py @@ -14,11 +14,11 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import typing from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.remote.client_config import ClientConfig from selenium.webdriver.remote.remote_connection import RemoteConnection +from typing import Optional class FirefoxRemoteConnection(RemoteConnection): @@ -28,8 +28,8 @@ def __init__( self, remote_server_addr: str, keep_alive: bool = True, - ignore_proxy: typing.Optional[bool] = False, - client_config: ClientConfig = None, + ignore_proxy: Optional[bool] = False, + client_config: Optional[ClientConfig] = None, ) -> None: super().__init__( remote_server_addr=remote_server_addr, diff --git a/py/selenium/webdriver/remote/client_config.py b/py/selenium/webdriver/remote/client_config.py index d00c3b76aff0b..0cea37d3bcbdc 100644 --- a/py/selenium/webdriver/remote/client_config.py +++ b/py/selenium/webdriver/remote/client_config.py @@ -20,6 +20,7 @@ from selenium.webdriver.common.proxy import Proxy from selenium.webdriver.common.proxy import ProxyType +from typing import Optional class ClientConfig: @@ -28,10 +29,10 @@ def __init__( remote_server_addr: str, keep_alive: bool = True, proxy: Proxy = Proxy(raw={"proxyType": ProxyType.SYSTEM}), - username: str = None, - password: str = None, + username: Optional[str] = None, + password: Optional[str] = None, auth_type: str = "Basic", - token: str = None, + token: Optional[str] = None, ) -> None: self.remote_server_addr = remote_server_addr self.keep_alive = keep_alive @@ -46,7 +47,7 @@ def remote_server_addr(self) -> str: return self._remote_server_addr @remote_server_addr.setter - def remote_server_addr(self, value: str): + def remote_server_addr(self, value: str) -> None: self._remote_server_addr = value @property @@ -110,12 +111,12 @@ def token(self) -> str: def token(self, value: str) -> None: self._token = value - def get_proxy_url(self) -> str: + def get_proxy_url(self) -> Optional[str]: proxy_type = self.proxy.proxy_type remote_add = parse.urlparse(self.remote_server_addr) - if proxy_type == ProxyType.DIRECT: + if proxy_type is ProxyType.DIRECT: return None - if proxy_type == ProxyType.SYSTEM: + if proxy_type is ProxyType.SYSTEM: _no_proxy = os.environ.get("no_proxy", os.environ.get("NO_PROXY")) if _no_proxy: for entry in map(str.strip, _no_proxy.split(",")): @@ -130,18 +131,18 @@ def get_proxy_url(self) -> str: "https_proxy" if self.remote_server_addr.startswith("https://") else "http_proxy", os.environ.get("HTTPS_PROXY" if self.remote_server_addr.startswith("https://") else "HTTP_PROXY"), ) - if proxy_type == ProxyType.MANUAL: + if proxy_type is ProxyType.MANUAL: return self.proxy.sslProxy if self.remote_server_addr.startswith("https://") else self.proxy.http_proxy return None - def get_auth_header(self): + def get_auth_header(self) -> Optional[dict]: auth_type = self.auth_type.lower() if auth_type == "basic" and self.username and self.password: credentials = f"{self.username}:{self.password}" - encoded_credentials = base64.b64encode(credentials.encode()).decode() + encoded_credentials = base64.b64encode(credentials.encode("utf-8")).decode("utf-8") return {"Authorization": f"Basic {encoded_credentials}"} - elif auth_type == "bearer" and self.token: + if auth_type == "bearer" and self.token: return {"Authorization": f"Bearer {self.token}"} - elif auth_type == "oauth" and self.token: + if auth_type == "oauth" and self.token: return {"Authorization": f"OAuth {self.token}"} return None diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 3a061ada49aec..c739c3b397eb6 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -28,6 +28,7 @@ import urllib3 from selenium import __version__ +from typing import Optional from . import utils from .client_config import ClientConfig @@ -252,28 +253,28 @@ def __init__( self, remote_server_addr: str, keep_alive: bool = True, - ignore_proxy: bool = False, - client_config: ClientConfig = None, + ignore_proxy: Optional[bool] = False, + client_config: Optional[ClientConfig] = None, ): self._client_config = client_config or ClientConfig(remote_server_addr, keep_alive) if remote_server_addr: warnings.warn( - "setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead", + "setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance instead", DeprecationWarning, stacklevel=2, ) if not keep_alive: warnings.warn( - "setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead", + "setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance instead", DeprecationWarning, stacklevel=2, ) if ignore_proxy: warnings.warn( - "setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead", + "setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance instead", DeprecationWarning, stacklevel=2, ) diff --git a/py/selenium/webdriver/remote/webdriver.py b/py/selenium/webdriver/remote/webdriver.py index 98bb6f66fb255..7aa409333eda8 100644 --- a/py/selenium/webdriver/remote/webdriver.py +++ b/py/selenium/webdriver/remote/webdriver.py @@ -183,7 +183,7 @@ def __init__( keep_alive: bool = True, file_detector: Optional[FileDetector] = None, options: Optional[Union[BaseOptions, List[BaseOptions]]] = None, - client_config: ClientConfig = None, + client_config: Optional[ClientConfig] = None, ) -> None: """Create a new driver that will issue commands using the wire protocol. diff --git a/py/selenium/webdriver/safari/remote_connection.py b/py/selenium/webdriver/safari/remote_connection.py index bafde257a3baa..bf4f6a2176822 100644 --- a/py/selenium/webdriver/safari/remote_connection.py +++ b/py/selenium/webdriver/safari/remote_connection.py @@ -18,6 +18,7 @@ from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.remote.client_config import ClientConfig from selenium.webdriver.remote.remote_connection import RemoteConnection +from typing import Optional class SafariRemoteConnection(RemoteConnection): @@ -27,8 +28,8 @@ def __init__( self, remote_server_addr: str, keep_alive: bool = True, - ignore_proxy: bool = False, - client_config: ClientConfig = None, + ignore_proxy: Optional[bool] = False, + client_config: Optional[ClientConfig] = None, ) -> None: super().__init__( remote_server_addr=remote_server_addr,