Skip to content

Commit 448437d

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

File tree

8 files changed

+35
-31
lines changed

8 files changed

+35
-31
lines changed

py/selenium/webdriver/chrome/remote_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
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
1817

1918
from selenium.webdriver import DesiredCapabilities
2019
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
2120
from selenium.webdriver.remote.client_config import ClientConfig
21+
from typing import Optional
2222

2323

2424
class ChromeRemoteConnection(ChromiumRemoteConnection):
@@ -28,8 +28,8 @@ def __init__(
2828
self,
2929
remote_server_addr: str,
3030
keep_alive: bool = True,
31-
ignore_proxy: typing.Optional[bool] = False,
32-
client_config: ClientConfig = None,
31+
ignore_proxy: Optional[bool] = False,
32+
client_config: Optional[ClientConfig] = None,
3333
) -> None:
3434
super().__init__(
3535
remote_server_addr=remote_server_addr,

py/selenium/webdriver/chromium/remote_connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717
from selenium.webdriver.remote.client_config import ClientConfig
1818
from selenium.webdriver.remote.remote_connection import RemoteConnection
19+
from typing import Optional
1920

2021

2122
class ChromiumRemoteConnection(RemoteConnection):
@@ -25,8 +26,8 @@ def __init__(
2526
vendor_prefix: str,
2627
browser_name: str,
2728
keep_alive: bool = True,
28-
ignore_proxy: bool = False,
29-
client_config: ClientConfig = None,
29+
ignore_proxy: Optional[bool] = False,
30+
client_config: Optional[ClientConfig] = None,
3031
) -> None:
3132
super().__init__(
3233
remote_server_addr=remote_server_addr,

py/selenium/webdriver/edge/remote_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
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
1817

1918
from selenium.webdriver import DesiredCapabilities
2019
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
2120
from selenium.webdriver.remote.client_config import ClientConfig
21+
from typing import Optional
2222

2323

2424
class EdgeRemoteConnection(ChromiumRemoteConnection):
@@ -28,8 +28,8 @@ def __init__(
2828
self,
2929
remote_server_addr: str,
3030
keep_alive: bool = True,
31-
ignore_proxy: typing.Optional[bool] = False,
32-
client_config: ClientConfig = None,
31+
ignore_proxy: Optional[bool] = False,
32+
client_config: Optional[ClientConfig] = None,
3333
) -> None:
3434
super().__init__(
3535
remote_server_addr=remote_server_addr,

py/selenium/webdriver/firefox/remote_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
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
1817

1918
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2019
from selenium.webdriver.remote.client_config import ClientConfig
2120
from selenium.webdriver.remote.remote_connection import RemoteConnection
21+
from typing import Optional
2222

2323

2424
class FirefoxRemoteConnection(RemoteConnection):
@@ -28,8 +28,8 @@ def __init__(
2828
self,
2929
remote_server_addr: str,
3030
keep_alive: bool = True,
31-
ignore_proxy: typing.Optional[bool] = False,
32-
client_config: ClientConfig = None,
31+
ignore_proxy: Optional[bool] = False,
32+
client_config: Optional[ClientConfig] = None,
3333
) -> None:
3434
super().__init__(
3535
remote_server_addr=remote_server_addr,

py/selenium/webdriver/remote/client_config.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from selenium.webdriver.common.proxy import Proxy
2222
from selenium.webdriver.common.proxy import ProxyType
23+
from typing import Optional
2324

2425

2526
class ClientConfig:
@@ -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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import urllib3
2929

3030
from selenium import __version__
31+
from typing import Optional
3132

3233
from . import utils
3334
from .client_config import ClientConfig
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(
183183
keep_alive: bool = True,
184184
file_detector: Optional[FileDetector] = None,
185185
options: Optional[Union[BaseOptions, List[BaseOptions]]] = None,
186-
client_config: ClientConfig = None,
186+
client_config: Optional[ClientConfig] = None,
187187
) -> None:
188188
"""Create a new driver that will issue commands using the wire
189189
protocol.

py/selenium/webdriver/safari/remote_connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
1919
from selenium.webdriver.remote.client_config import ClientConfig
2020
from selenium.webdriver.remote.remote_connection import RemoteConnection
21+
from typing import Optional
2122

2223

2324
class SafariRemoteConnection(RemoteConnection):
@@ -27,8 +28,8 @@ def __init__(
2728
self,
2829
remote_server_addr: str,
2930
keep_alive: bool = True,
30-
ignore_proxy: bool = False,
31-
client_config: ClientConfig = None,
31+
ignore_proxy: Optional[bool] = False,
32+
client_config: Optional[ClientConfig] = None,
3233
) -> None:
3334
super().__init__(
3435
remote_server_addr=remote_server_addr,

0 commit comments

Comments
 (0)