Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firefox_profile.py: use with statement in zipfile as Python 2.x support is dropped #14489

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions py/selenium/webdriver/firefox/firefox_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,11 @@ def parse_manifest_json(content):

try:
if zipfile.is_zipfile(addon_path):
# Bug 944361 - We cannot use 'with' together with zipFile because
# it will cause an exception thrown in Python 2.6.
# TODO: use with statement when Python 2.x is no longer supported
try:
compressed_file = zipfile.ZipFile(addon_path, "r")
with zipfile.ZipFile(addon_path, "r") as compressed_file:
if "manifest.json" in compressed_file.namelist():
return parse_manifest_json(compressed_file.read("manifest.json"))

manifest = compressed_file.read("install.rdf")
finally:
compressed_file.close()
elif os.path.isdir(addon_path):
manifest_json_filename = os.path.join(addon_path, "manifest.json")
if os.path.exists(manifest_json_filename):
Expand Down
Loading