use 'encoding="utf-8"' when opening files in text mode (#8376)
This commit is contained in:
@@ -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'",
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user