From 99d5c521d1bde97f7f95ddd97e803c601e076bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 9 Oct 2025 09:54:18 +0200 Subject: [PATCH] use 'encoding="utf-8"' when opening files in text mode (#8376) --- gallery_dl/cookies.py | 2 +- gallery_dl/extractor/common.py | 4 ++-- gallery_dl/extractor/recursive.py | 2 +- gallery_dl/formatter.py | 6 +++--- gallery_dl/postprocessor/ugoira.py | 4 ++-- gallery_dl/ytdl.py | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gallery_dl/cookies.py b/gallery_dl/cookies.py index 6c19e233..ba719acc 100644 --- a/gallery_dl/cookies.py +++ b/gallery_dl/cookies.py @@ -241,7 +241,7 @@ def _firefox_cookies_database(browser_name, profile=None, container=None): os.path.dirname(path), "containers.json") try: - with open(containers_path) as fp: + with open(containers_path, encoding="utf-8") as fp: identities = util.json_loads(fp.read())["identities"] except OSError: _log_error("Unable to read Firefox container database at '%s'", diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 728fc8a5..34e65c5c 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -541,7 +541,7 @@ class Extractor(): elif isinstance(cookies_source, str): path = util.expand_path(cookies_source) try: - with open(path) as fp: + with open(path, encoding="utf-8") as fp: cookies = util.cookiestxt_load(fp) except ValueError as exc: self.log.warning("cookies: Invalid Netscape cookies.txt file " @@ -599,7 +599,7 @@ class Extractor(): path_tmp = path + ".tmp" try: - with open(path_tmp, "w") as fp: + with open(path_tmp, "w", encoding="utf-8") as fp: util.cookiestxt_store(fp, self.cookies) os.replace(path_tmp, path) except OSError as exc: diff --git a/gallery_dl/extractor/recursive.py b/gallery_dl/extractor/recursive.py index 4762fa57..c553fec6 100644 --- a/gallery_dl/extractor/recursive.py +++ b/gallery_dl/extractor/recursive.py @@ -22,7 +22,7 @@ class RecursiveExtractor(Extractor): url = self.url.partition(":")[2] if url.startswith("file://"): - with open(url[7:]) as fp: + with open(url[7:], encoding="utf-8") as fp: page = fp.read() else: page = self.request(text.ensure_http_scheme(url)).text diff --git a/gallery_dl/formatter.py b/gallery_dl/formatter.py index cc9af11f..f9088d74 100644 --- a/gallery_dl/formatter.py +++ b/gallery_dl/formatter.py @@ -259,7 +259,7 @@ class TemplateFormatter(StringFormatter): """Read format_string from file""" def __init__(self, path, default=NONE, fmt=format): - with open(util.expand_path(path)) as fp: + with open(util.expand_path(path), encoding="utf-8") as fp: format_string = fp.read() StringFormatter.__init__(self, format_string, default, fmt) @@ -268,7 +268,7 @@ class TemplateFStringFormatter(FStringFormatter): """Read f-string from file""" def __init__(self, path, default=NONE, fmt=None): - with open(util.expand_path(path)) as fp: + with open(util.expand_path(path), encoding="utf-8") as fp: fstring = fp.read() FStringFormatter.__init__(self, fstring, default, fmt) @@ -277,7 +277,7 @@ class TemplateJinjaFormatter(JinjaFormatter): """Generate text by evaluating a Jinja template""" def __init__(self, path, default=NONE, fmt=None): - with open(util.expand_path(path)) as fp: + with open(util.expand_path(path), encoding="utf-8") as fp: source = fp.read() JinjaFormatter.__init__(self, source, default, fmt) diff --git a/gallery_dl/postprocessor/ugoira.py b/gallery_dl/postprocessor/ugoira.py index 33ebb75c..1a55e22c 100644 --- a/gallery_dl/postprocessor/ugoira.py +++ b/gallery_dl/postprocessor/ugoira.py @@ -386,7 +386,7 @@ class UgoiraPP(PostProcessor): content.append("") ffconcat = tempdir + "/ffconcat.txt" - with open(ffconcat, "w") as fp: + with open(ffconcat, "w", encoding="utf-8") as fp: fp.write("\n".join(content)) return ffconcat @@ -401,7 +401,7 @@ class UgoiraPP(PostProcessor): content.append("") timecodes = tempdir + "/timecodes.tc" - with open(timecodes, "w") as fp: + with open(timecodes, "w", encoding="utf-8") as fp: fp.write("\n".join(content)) return timecodes diff --git a/gallery_dl/ytdl.py b/gallery_dl/ytdl.py index 02964982..b7ee1caf 100644 --- a/gallery_dl/ytdl.py +++ b/gallery_dl/ytdl.py @@ -31,7 +31,7 @@ def construct_YoutubeDL(module, obj, user_opts, system_opts=None): module.YoutubeDL.deprecation_warning = util.false if cfg := config("config-file"): - with open(util.expand_path(cfg)) as fp: + with open(util.expand_path(cfg), encoding="utf-8") as fp: contents = fp.read() argv = shlex.split(contents, comments=True)