Skip to content

Commit 3cc35c8

Browse files
committed
Fix review comments
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 9aede55 commit 3cc35c8

File tree

8 files changed

+54
-36
lines changed

8 files changed

+54
-36
lines changed

py/selenium/webdriver/chrome/remote_connection.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
18+
from typing import Optional
1819

1920
from selenium.webdriver import DesiredCapabilities
2021
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
@@ -28,8 +29,8 @@ def __init__(
2829
self,
2930
remote_server_addr: str,
3031
keep_alive: bool = True,
31-
ignore_proxy: typing.Optional[bool] = False,
32-
client_config: ClientConfig = None,
32+
ignore_proxy: Optional[bool] = False,
33+
client_config: Optional[ClientConfig] = None,
3334
) -> None:
3435
super().__init__(
3536
remote_server_addr=remote_server_addr,

py/selenium/webdriver/chromium/remote_connection.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
from typing import Optional
18+
1719
from selenium.webdriver.remote.client_config import ClientConfig
1820
from selenium.webdriver.remote.remote_connection import RemoteConnection
1921

@@ -25,8 +27,8 @@ def __init__(
2527
vendor_prefix: str,
2628
browser_name: str,
2729
keep_alive: bool = True,
28-
ignore_proxy: bool = False,
29-
client_config: ClientConfig = None,
30+
ignore_proxy: Optional[bool] = False,
31+
client_config: Optional[ClientConfig] = None,
3032
) -> None:
3133
super().__init__(
3234
remote_server_addr=remote_server_addr,

py/selenium/webdriver/edge/remote_connection.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
18+
from typing import Optional
1819

1920
from selenium.webdriver import DesiredCapabilities
2021
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
@@ -28,8 +29,8 @@ def __init__(
2829
self,
2930
remote_server_addr: str,
3031
keep_alive: bool = True,
31-
ignore_proxy: typing.Optional[bool] = False,
32-
client_config: ClientConfig = None,
32+
ignore_proxy: Optional[bool] = False,
33+
client_config: Optional[ClientConfig] = None,
3334
) -> None:
3435
super().__init__(
3536
remote_server_addr=remote_server_addr,

py/selenium/webdriver/firefox/remote_connection.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
18+
from typing import Optional
1819

1920
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2021
from selenium.webdriver.remote.client_config import ClientConfig
@@ -28,8 +29,8 @@ def __init__(
2829
self,
2930
remote_server_addr: str,
3031
keep_alive: bool = True,
31-
ignore_proxy: typing.Optional[bool] = False,
32-
client_config: ClientConfig = None,
32+
ignore_proxy: Optional[bool] = False,
33+
client_config: Optional[ClientConfig] = None,
3334
) -> None:
3435
super().__init__(
3536
remote_server_addr=remote_server_addr,

py/selenium/webdriver/remote/client_config.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717
import base64
1818
import os
19+
from typing import Optional
1920
from urllib import parse
2021

2122
from selenium.webdriver.common.proxy import Proxy
@@ -28,10 +29,10 @@ def __init__(
2829
remote_server_addr: str,
2930
keep_alive: bool = True,
3031
proxy: Proxy = Proxy(raw={"proxyType": ProxyType.SYSTEM}),
31-
username: str = None,
32-
password: str = None,
32+
username: Optional[str] = None,
33+
password: Optional[str] = None,
3334
auth_type: str = "Basic",
34-
token: str = None,
35+
token: Optional[str] = None,
3536
) -> None:
3637
self.remote_server_addr = remote_server_addr
3738
self.keep_alive = keep_alive
@@ -46,7 +47,7 @@ def remote_server_addr(self) -> str:
4647
return self._remote_server_addr
4748

4849
@remote_server_addr.setter
49-
def remote_server_addr(self, value: str):
50+
def remote_server_addr(self, value: str) -> None:
5051
self._remote_server_addr = value
5152

5253
@property
@@ -110,12 +111,12 @@ def token(self) -> str:
110111
def token(self, value: str) -> None:
111112
self._token = value
112113

113-
def get_proxy_url(self) -> str:
114+
def get_proxy_url(self) -> Optional[str]:
114115
proxy_type = self.proxy.proxy_type
115116
remote_add = parse.urlparse(self.remote_server_addr)
116-
if proxy_type == ProxyType.DIRECT:
117+
if proxy_type is ProxyType.DIRECT:
117118
return None
118-
if proxy_type == ProxyType.SYSTEM:
119+
if proxy_type is ProxyType.SYSTEM:
119120
_no_proxy = os.environ.get("no_proxy", os.environ.get("NO_PROXY"))
120121
if _no_proxy:
121122
for entry in map(str.strip, _no_proxy.split(",")):
@@ -130,18 +131,18 @@ def get_proxy_url(self) -> str:
130131
"https_proxy" if self.remote_server_addr.startswith("https://") else "http_proxy",
131132
os.environ.get("HTTPS_PROXY" if self.remote_server_addr.startswith("https://") else "HTTP_PROXY"),
132133
)
133-
if proxy_type == ProxyType.MANUAL:
134+
if proxy_type is ProxyType.MANUAL:
134135
return self.proxy.sslProxy if self.remote_server_addr.startswith("https://") else self.proxy.http_proxy
135136
return None
136137

137-
def get_auth_header(self):
138+
def get_auth_header(self) -> Optional[dict]:
138139
auth_type = self.auth_type.lower()
139140
if auth_type == "basic" and self.username and self.password:
140141
credentials = f"{self.username}:{self.password}"
141-
encoded_credentials = base64.b64encode(credentials.encode()).decode()
142+
encoded_credentials = base64.b64encode(credentials.encode("utf-8")).decode("utf-8")
142143
return {"Authorization": f"Basic {encoded_credentials}"}
143-
elif auth_type == "bearer" and self.token:
144+
if auth_type == "bearer" and self.token:
144145
return {"Authorization": f"Bearer {self.token}"}
145-
elif auth_type == "oauth" and self.token:
146+
if auth_type == "oauth" and self.token:
146147
return {"Authorization": f"OAuth {self.token}"}
147148
return None

py/selenium/webdriver/remote/remote_connection.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import string
2323
import warnings
2424
from base64 import b64encode
25+
from typing import Optional
2526
from urllib import parse
2627

2728
import certifi
@@ -252,28 +253,28 @@ def __init__(
252253
self,
253254
remote_server_addr: str,
254255
keep_alive: bool = True,
255-
ignore_proxy: bool = False,
256-
client_config: ClientConfig = None,
256+
ignore_proxy: Optional[bool] = False,
257+
client_config: Optional[ClientConfig] = None,
257258
):
258259
self._client_config = client_config or ClientConfig(remote_server_addr, keep_alive)
259260

260261
if remote_server_addr:
261262
warnings.warn(
262-
"setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead",
263+
"setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance instead",
263264
DeprecationWarning,
264265
stacklevel=2,
265266
)
266267

267268
if not keep_alive:
268269
warnings.warn(
269-
"setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead",
270+
"setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance instead",
270271
DeprecationWarning,
271272
stacklevel=2,
272273
)
273274

274275
if ignore_proxy:
275276
warnings.warn(
276-
"setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead",
277+
"setting keep_alive in RemoteConnection() is deprecated, set in ClientConfig instance instead",
277278
DeprecationWarning,
278279
stacklevel=2,
279280
)

py/selenium/webdriver/remote/webdriver.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,21 @@ def _create_caps(caps):
9797

9898

9999
def get_remote_connection(
100-
capabilities,
101-
command_executor,
102-
keep_alive,
103-
ignore_local_proxy,
104-
client_config=None,
100+
capabilities: dict,
101+
command_executor: Union[str, RemoteConnection],
102+
keep_alive: bool,
103+
ignore_local_proxy: bool,
104+
client_config: Optional[ClientConfig] = None,
105105
) -> RemoteConnection:
106+
if ignore_local_proxy:
107+
warnings.warn(
108+
"Passing 'ignore_local_proxy' as keyword argument is deprecated, "
109+
"instead, create a Proxy instance with ProxyType.DIRECT to ignore proxy settings, "
110+
"pass the proxy instance into a ClientConfig constructor, "
111+
"pass the client config instance into the Webdriver constructor",
112+
DeprecationWarning,
113+
stacklevel=2,
114+
)
106115
from selenium.webdriver.chrome.remote_connection import ChromeRemoteConnection
107116
from selenium.webdriver.edge.remote_connection import EdgeRemoteConnection
108117
from selenium.webdriver.firefox.remote_connection import FirefoxRemoteConnection
@@ -183,7 +192,7 @@ def __init__(
183192
keep_alive: bool = True,
184193
file_detector: Optional[FileDetector] = None,
185194
options: Optional[Union[BaseOptions, List[BaseOptions]]] = None,
186-
client_config: ClientConfig = None,
195+
client_config: Optional[ClientConfig] = None,
187196
) -> None:
188197
"""Create a new driver that will issue commands using the wire
189198
protocol.

py/selenium/webdriver/safari/remote_connection.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from typing import Optional
19+
1820
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
1921
from selenium.webdriver.remote.client_config import ClientConfig
2022
from selenium.webdriver.remote.remote_connection import RemoteConnection
@@ -27,8 +29,8 @@ def __init__(
2729
self,
2830
remote_server_addr: str,
2931
keep_alive: bool = True,
30-
ignore_proxy: bool = False,
31-
client_config: ClientConfig = None,
32+
ignore_proxy: Optional[bool] = False,
33+
client_config: Optional[ClientConfig] = None,
3234
) -> None:
3335
super().__init__(
3436
remote_server_addr=remote_server_addr,

0 commit comments

Comments
 (0)