Skip to content

Commit 6b4b9f8

Browse files
committed
[py]: use cls for class methods; be explicit with open(..., encoding=...)
1 parent 32d2a50 commit 6b4b9f8

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

py/selenium/webdriver/firefox/extension_connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def connect(self):
6565
{'desiredCapabilities': DesiredCapabilities.FIREFOX})
6666

6767
@classmethod
68-
def connect_and_quit(self):
68+
def connect_and_quit(cls):
6969
"""Connects to an running browser and quit immediately."""
70-
self._request('%s/extensions/firefox/quit' % _URL)
70+
cls._request('%s/extensions/firefox/quit' % _URL)
7171

7272
@classmethod
73-
def is_connectable(self):
73+
def is_connectable(cls):
7474
"""Tries to connect to the extension but do not retrieve context."""
75-
utils.is_connectable(self.profile.port)
75+
utils.is_connectable(cls.profile.port)
7676

7777

7878
class ExtensionConnectionError(Exception):

py/selenium/webdriver/firefox/firefox_profile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, profile_directory=None):
5959
DeprecationWarning, stacklevel=2)
6060
if not FirefoxProfile.DEFAULT_PREFERENCES:
6161
with open(os.path.join(os.path.dirname(__file__),
62-
WEBDRIVER_PREFERENCES)) as default_prefs:
62+
WEBDRIVER_PREFERENCES), encoding='utf-8') as default_prefs:
6363
FirefoxProfile.DEFAULT_PREFERENCES = json.load(default_prefs)
6464

6565
self.default_preferences = copy.deepcopy(
@@ -180,7 +180,7 @@ def _write_user_prefs(self, user_prefs):
180180
"""
181181
writes the current user prefs dictionary to disk
182182
"""
183-
with open(self.userPrefs, "w") as f:
183+
with open(self.userPrefs, "w", encoding='utf-8') as f:
184184
for key, value in user_prefs.items():
185185
f.write(f'user_pref("{key}", {json.dumps(value)});\n')
186186

@@ -189,7 +189,7 @@ def _read_existing_userjs(self, userjs):
189189

190190
PREF_RE = re.compile(r'user_pref\("(.*)",\s(.*)\)')
191191
try:
192-
with open(userjs) as f:
192+
with open(userjs, encoding='utf-8') as f:
193193
for usr in f:
194194
matches = re.search(PREF_RE, usr)
195195
try:
@@ -322,10 +322,10 @@ def parse_manifest_json(content):
322322
elif os.path.isdir(addon_path):
323323
manifest_json_filename = os.path.join(addon_path, 'manifest.json')
324324
if os.path.exists(manifest_json_filename):
325-
with open(manifest_json_filename) as f:
325+
with open(manifest_json_filename, encoding='utf-8') as f:
326326
return parse_manifest_json(f.read())
327327

328-
with open(os.path.join(addon_path, 'install.rdf')) as f:
328+
with open(os.path.join(addon_path, 'install.rdf'), encoding='utf-8') as f:
329329
manifest = f.read()
330330
else:
331331
raise OSError('Add-on path is neither an XPI nor a directory: %s' % addon_path)

py/selenium/webdriver/firefox/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
4646
in the services' environment.
4747
4848
"""
49-
log_file = open(log_path, "a+") if log_path else None
49+
log_file = open(log_path, "a+", encoding='utf-8') if log_path else None
5050

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

py/selenium/webdriver/firefox/webdriver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def install_addon(self, path, temporary=False) -> str:
245245
driver.install_addon('/path/to/firebug.xpi')
246246
"""
247247

248-
if (os.path.isdir(path)):
248+
if os.path.isdir(path):
249249
fp = BytesIO()
250250
path_root = len(path) + 1 # account for trailing slash
251251
with zipfile.ZipFile(fp, 'w', zipfile.ZIP_DEFLATED) as zipped:

py/selenium/webdriver/safari/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
5454
self.quiet = quiet
5555
log = PIPE
5656
if quiet:
57-
log = open(os.devnull, 'w')
57+
log = open(os.devnull, 'w', encoding='utf-8')
5858
super().__init__(executable_path, port, log)
5959

6060
def command_line_args(self):

0 commit comments

Comments
 (0)