Skip to content

Commit

Permalink
[py]: Enable co-operative multi inheritance with super() throughout (
Browse files Browse the repository at this point in the history
…#10773)

* [py]: Enable multi co-operative inheritance with `super()` throughout

* [py]: Fix `_URL` param in firefox extension and indentation
  • Loading branch information
symonk authored Jun 15, 2022
1 parent 1b1058a commit 40c16bb
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion py/selenium/webdriver/chromium/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class ChromiumRemoteConnection(RemoteConnection):
def __init__(self, remote_server_addr, vendor_prefix, browser_name, keep_alive=True, ignore_proxy=False):
RemoteConnection.__init__(self, remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
self.browser_name = browser_name
self._commands["launchApp"] = ('POST', '/session/$sessionId/chromium/launch_app')
self._commands["setPermissions"] = ('POST', '/session/$sessionId/permissions')
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/chromium/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, executable_path: str, port: int = 0, service_args: List[str]
if not start_error_message:
raise AttributeError("start_error_message should not be empty")

service.Service.__init__(self, executable_path, port=port, env=env, start_error_message=start_error_message)
super().__init__(executable_path, port=port, env=env, start_error_message=start_error_message)

def command_line_args(self) -> List[str]:
return ["--port=%d" % self.port] + self.service_args
5 changes: 2 additions & 3 deletions py/selenium/webdriver/chromium/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def __init__(self, browser_name, vendor_prefix,
self.service.start()

try:
RemoteWebDriver.__init__(
self,
super().__init__(
command_executor=ChromiumRemoteConnection(
remote_server_addr=self.service.service_url,
browser_name=browser_name, vendor_prefix=vendor_prefix,
Expand Down Expand Up @@ -231,7 +230,7 @@ def quit(self) -> None:
that is started when starting the ChromiumDriver
"""
try:
RemoteWebDriver.quit(self)
super().quit()
except Exception:
# We don't care about the message because something probably has gone wrong
pass
Expand Down
3 changes: 1 addition & 2 deletions py/selenium/webdriver/firefox/extension_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def __init__(self, host, firefox_profile, firefox_binary=None, timeout=30):

self.binary.launch_browser(self.profile, timeout=timeout)
_URL = "http://%s:%d/hub" % (HOST, PORT)
RemoteConnection.__init__(
self, _URL, keep_alive=True)
super().__init__(_URL, keep_alive=True)

def quit(self, sessionId=None):
self.execute(Command.QUIT, {'sessionId': sessionId})
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/firefox/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FirefoxRemoteConnection(RemoteConnection):
browser_name = DesiredCapabilities.FIREFOX['browserName']

def __init__(self, remote_server_addr, keep_alive=True, ignore_proxy=False):
RemoteConnection.__init__(self, remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)

self._commands["GET_CONTEXT"] = ('GET', '/session/$sessionId/moz/context')
self._commands["SET_CONTEXT"] = ("POST", "/session/$sessionId/moz/context")
Expand Down
3 changes: 1 addition & 2 deletions py/selenium/webdriver/firefox/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
"""
log_file = open(log_path, "a+") if log_path else None

service.Service.__init__(
self, executable_path, port=port, log_file=log_file, env=env)
super().__init__(executable_path, port=port, log_file=log_file, env=env)
self.service_args = service_args or []

# Set a port for CDP
Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/firefox/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
executor = FirefoxRemoteConnection(
remote_server_addr=self.service.service_url,
ignore_proxy=options._ignore_local_proxy)
RemoteWebDriver.__init__(
self,
super().__init__(
command_executor=executor,
options=options,
keep_alive=True)
Expand All @@ -185,7 +184,7 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
def quit(self) -> None:
"""Quits the driver and close every associated window."""
try:
RemoteWebDriver.quit(self)
super().quit()
except Exception:
# We don't care about the message because something probably has gone wrong
pass
Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/ie/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from selenium.webdriver.common import service


DEFAULT_EXECUTABLE_PATH = 'IEDriverServer.exe'


Expand Down Expand Up @@ -50,8 +49,8 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
if log_file:
self.service_args.append("--log-file=%s" % log_file)

service.Service.__init__(self, executable_path, port=port,
start_error_message="Please download from https://www.selenium.dev/downloads/ and read up at https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver")
super().__init__(executable_path, port=port,
start_error_message="Please download from https://www.selenium.dev/downloads/ and read up at https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver")

def command_line_args(self) -> List[str]:
return ["--port=%d" % self.port] + self.service_args
5 changes: 2 additions & 3 deletions py/selenium/webdriver/ie/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ def __init__(self, executable_path=DEFAULT_EXECUTABLE_PATH, capabilities=None,

self.iedriver.start()

RemoteWebDriver.__init__(
self,
super().__init__(
command_executor=self.iedriver.service_url,
options=options,
keep_alive=keep_alive)
self._is_remote = False

def quit(self) -> None:
RemoteWebDriver.quit(self)
super().quit()
self.iedriver.stop()

def create_options(self) -> Options:
Expand Down
3 changes: 1 addition & 2 deletions py/selenium/webdriver/safari/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class SafariRemoteConnection(RemoteConnection):
browser_name = DesiredCapabilities.SAFARI['browserName']

def __init__(self, remote_server_addr, keep_alive=True, ignore_proxy=False):
RemoteConnection.__init__(self, remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)

super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
self._commands["GET_PERMISSIONS"] = ('GET', '/session/$sessionId/apple/permissions')
self._commands["SET_PERMISSIONS"] = ('POST', '/session/$sessionId/apple/permissions')
self._commands["ATTACH_DEBUGGER"] = ('POST', '/session/$sessionId/apple/attach_debugger')
2 changes: 1 addition & 1 deletion py/selenium/webdriver/safari/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
log = PIPE
if quiet:
log = open(os.devnull, 'w')
service.Service.__init__(self, executable_path, port, log)
super().__init__(executable_path, port, log)

def command_line_args(self):
return ["-p", "%s" % self.port] + self.service_args
Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/safari/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def __init__(self, port=0, executable_path=DEFAULT_EXECUTABLE_PATH, reuse_servic
executor = SafariRemoteConnection(remote_server_addr=self.service.service_url,
keep_alive=keep_alive)

RemoteWebDriver.__init__(
self,
super().__init__(
command_executor=executor,
options=options,
desired_capabilities=desired_capabilities)
Expand All @@ -104,7 +103,7 @@ def quit(self):
that is started when starting the SafariDriver
"""
try:
RemoteWebDriver.quit(self)
super().quit()
except http_client.BadStatusLine:
pass
finally:
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/webkitgtk/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
- log_path : Path for the WebKitGTKDriver service to log to
"""
log_file = open(log_path, "wb") if log_path else None
service.Service.__init__(self, executable_path, port, log_file)
super().__init__(executable_path, port, log_file)

def command_line_args(self):
return ["-p", "%d" % self.port]
Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/webkitgtk/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def __init__(self, executable_path=DEFAULT_EXECUTABLE_PATH,
self.service = Service(executable_path, port=port, log_path=service_log_path)
self.service.start()

RemoteWebDriver.__init__(
self,
super().__init__(
command_executor=self.service.service_url,
desired_capabilities=desired_capabilities,
keep_alive=keep_alive)
Expand All @@ -69,7 +68,7 @@ def quit(self):
that is started when starting the WebKitGTKDriver
"""
try:
RemoteWebDriver.quit(self)
super().quit()
except http_client.BadStatusLine:
pass
finally:
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/wpewebkit/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
- log_path : Path for the WPEWebKitDriver service to log to
"""
log_file = open(log_path, "wb") if log_path else None
service.Service.__init__(self, executable_path, port, log_file)
super().__init__(executable_path, port, log_file)

def command_line_args(self):
return ["-p", "%d" % self.port]
Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/wpewebkit/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def __init__(self, executable_path=DEFAULT_EXECUTABLE_PATH,
self.service = Service(executable_path, port=port, log_path=service_log_path)
self.service.start()

RemoteWebDriver.__init__(
self,
super().__init__(
command_executor=self.service.service_url,
desired_capabilities=desired_capabilities)
self._is_remote = False
Expand All @@ -64,7 +63,7 @@ def quit(self):
that is started when starting the WPEWebKitDriver
"""
try:
RemoteWebDriver.quit(self)
super().quit()
except http_client.BadStatusLine:
pass
finally:
Expand Down

0 comments on commit 40c16bb

Please sign in to comment.