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")
|
os.path.dirname(path), "containers.json")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(containers_path) as fp:
|
with open(containers_path, encoding="utf-8") as fp:
|
||||||
identities = util.json_loads(fp.read())["identities"]
|
identities = util.json_loads(fp.read())["identities"]
|
||||||
except OSError:
|
except OSError:
|
||||||
_log_error("Unable to read Firefox container database at '%s'",
|
_log_error("Unable to read Firefox container database at '%s'",
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ class Extractor():
|
|||||||
elif isinstance(cookies_source, str):
|
elif isinstance(cookies_source, str):
|
||||||
path = util.expand_path(cookies_source)
|
path = util.expand_path(cookies_source)
|
||||||
try:
|
try:
|
||||||
with open(path) as fp:
|
with open(path, encoding="utf-8") as fp:
|
||||||
cookies = util.cookiestxt_load(fp)
|
cookies = util.cookiestxt_load(fp)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
self.log.warning("cookies: Invalid Netscape cookies.txt file "
|
self.log.warning("cookies: Invalid Netscape cookies.txt file "
|
||||||
@@ -599,7 +599,7 @@ class Extractor():
|
|||||||
|
|
||||||
path_tmp = path + ".tmp"
|
path_tmp = path + ".tmp"
|
||||||
try:
|
try:
|
||||||
with open(path_tmp, "w") as fp:
|
with open(path_tmp, "w", encoding="utf-8") as fp:
|
||||||
util.cookiestxt_store(fp, self.cookies)
|
util.cookiestxt_store(fp, self.cookies)
|
||||||
os.replace(path_tmp, path)
|
os.replace(path_tmp, path)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class RecursiveExtractor(Extractor):
|
|||||||
url = self.url.partition(":")[2]
|
url = self.url.partition(":")[2]
|
||||||
|
|
||||||
if url.startswith("file://"):
|
if url.startswith("file://"):
|
||||||
with open(url[7:]) as fp:
|
with open(url[7:], encoding="utf-8") as fp:
|
||||||
page = fp.read()
|
page = fp.read()
|
||||||
else:
|
else:
|
||||||
page = self.request(text.ensure_http_scheme(url)).text
|
page = self.request(text.ensure_http_scheme(url)).text
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ class TemplateFormatter(StringFormatter):
|
|||||||
"""Read format_string from file"""
|
"""Read format_string from file"""
|
||||||
|
|
||||||
def __init__(self, path, default=NONE, fmt=format):
|
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()
|
format_string = fp.read()
|
||||||
StringFormatter.__init__(self, format_string, default, fmt)
|
StringFormatter.__init__(self, format_string, default, fmt)
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ class TemplateFStringFormatter(FStringFormatter):
|
|||||||
"""Read f-string from file"""
|
"""Read f-string from file"""
|
||||||
|
|
||||||
def __init__(self, path, default=NONE, fmt=None):
|
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()
|
fstring = fp.read()
|
||||||
FStringFormatter.__init__(self, fstring, default, fmt)
|
FStringFormatter.__init__(self, fstring, default, fmt)
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ class TemplateJinjaFormatter(JinjaFormatter):
|
|||||||
"""Generate text by evaluating a Jinja template"""
|
"""Generate text by evaluating a Jinja template"""
|
||||||
|
|
||||||
def __init__(self, path, default=NONE, fmt=None):
|
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()
|
source = fp.read()
|
||||||
JinjaFormatter.__init__(self, source, default, fmt)
|
JinjaFormatter.__init__(self, source, default, fmt)
|
||||||
|
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ class UgoiraPP(PostProcessor):
|
|||||||
content.append("")
|
content.append("")
|
||||||
|
|
||||||
ffconcat = tempdir + "/ffconcat.txt"
|
ffconcat = tempdir + "/ffconcat.txt"
|
||||||
with open(ffconcat, "w") as fp:
|
with open(ffconcat, "w", encoding="utf-8") as fp:
|
||||||
fp.write("\n".join(content))
|
fp.write("\n".join(content))
|
||||||
return ffconcat
|
return ffconcat
|
||||||
|
|
||||||
@@ -401,7 +401,7 @@ class UgoiraPP(PostProcessor):
|
|||||||
content.append("")
|
content.append("")
|
||||||
|
|
||||||
timecodes = tempdir + "/timecodes.tc"
|
timecodes = tempdir + "/timecodes.tc"
|
||||||
with open(timecodes, "w") as fp:
|
with open(timecodes, "w", encoding="utf-8") as fp:
|
||||||
fp.write("\n".join(content))
|
fp.write("\n".join(content))
|
||||||
return timecodes
|
return timecodes
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ def construct_YoutubeDL(module, obj, user_opts, system_opts=None):
|
|||||||
module.YoutubeDL.deprecation_warning = util.false
|
module.YoutubeDL.deprecation_warning = util.false
|
||||||
|
|
||||||
if cfg := config("config-file"):
|
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()
|
contents = fp.read()
|
||||||
argv = shlex.split(contents, comments=True)
|
argv = shlex.split(contents, comments=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user