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 <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Oct 17, 2024
1 parent 9aede55 commit 9f21342
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 37 deletions.
7 changes: 4 additions & 3 deletions py/selenium/webdriver/chrome/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import typing

from typing import Optional

from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
Expand All @@ -28,8 +29,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: 4 additions & 2 deletions py/selenium/webdriver/chromium/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Optional

from selenium.webdriver.remote.client_config import ClientConfig
from selenium.webdriver.remote.remote_connection import RemoteConnection

Expand All @@ -25,8 +27,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
7 changes: 4 additions & 3 deletions py/selenium/webdriver/edge/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import typing

from typing import Optional

from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
Expand All @@ -28,8 +29,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
7 changes: 4 additions & 3 deletions py/selenium/webdriver/firefox/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import typing

from typing import Optional

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.client_config import ClientConfig
Expand All @@ -28,8 +29,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
27 changes: 14 additions & 13 deletions py/selenium/webdriver/remote/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
import base64
import os
from typing import Optional
from urllib import parse

from selenium.webdriver.common.proxy import Proxy
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,
auth_type: str = "Basic",
token: str = None,
username: Optional[str] = None,
password: Optional[str] = None,
auth_type: Optional[str] = "Basic",
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 @@ -22,6 +22,7 @@
import string
import warnings
from base64 import b64encode
from typing import Optional
from urllib import parse

import certifi
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 remote_server_addr 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 ignore_proxy in RemoteConnection() is deprecated, set in ClientConfig instance instead",
DeprecationWarning,
stacklevel=2,
)
Expand Down
12 changes: 6 additions & 6 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def _create_caps(caps):


def get_remote_connection(
capabilities,
command_executor,
keep_alive,
ignore_local_proxy,
client_config=None,
capabilities: dict,
command_executor: Union[str, RemoteConnection],
keep_alive: bool,
ignore_local_proxy: bool,
client_config: Optional[ClientConfig] = None,
) -> RemoteConnection:
from selenium.webdriver.chrome.remote_connection import ChromeRemoteConnection
from selenium.webdriver.edge.remote_connection import EdgeRemoteConnection
Expand Down 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
6 changes: 4 additions & 2 deletions py/selenium/webdriver/safari/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.client_config import ClientConfig
from selenium.webdriver.remote.remote_connection import RemoteConnection
Expand All @@ -27,8 +29,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 9f21342

Please sign in to comment.