Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Oct 17, 2024
1 parent 9aede55 commit 448437d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 31 deletions.
6 changes: 3 additions & 3 deletions py/selenium/webdriver/chrome/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions py/selenium/webdriver/chromium/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/edge/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/firefox/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
25 changes: 13 additions & 12 deletions py/selenium/webdriver/remote/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
from typing import Optional


class ClientConfig:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(",")):
Expand All @@ -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
11 changes: 6 additions & 5 deletions py/selenium/webdriver/remote/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import urllib3

from selenium import __version__
from typing import Optional

from . import utils
from .client_config import ClientConfig
Expand Down Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions py/selenium/webdriver/safari/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down

0 comments on commit 448437d

Please sign in to comment.