osbuild: explicit encodings for open()
Provides explicit encodings for all calls to `open()`, this is a newer pylint warning but also just makes sense to do.
This commit is contained in:
parent
42552e0436
commit
3703328751
8 changed files with 22 additions and 22 deletions
|
|
@ -25,7 +25,7 @@ def replace(target, patterns):
|
|||
finder = [(re.compile(p), s) for p, s in patterns]
|
||||
newfile = target + ".replace"
|
||||
|
||||
with open(target, "r") as i, open(newfile, "w") as o:
|
||||
with open(target, "r", encoding="utf8") as i, open(newfile, "w", encoding="utf8") as o:
|
||||
for line in i:
|
||||
for p, s in finder:
|
||||
line = p.sub(s, line)
|
||||
|
|
@ -95,7 +95,7 @@ class Script:
|
|||
dirname = os.path.dirname(target)
|
||||
os.makedirs(dirname, exist_ok=True)
|
||||
print(f"append '{target}' '{data}'")
|
||||
with open(target, "a", encoding="utf-8") as f:
|
||||
with open(target, "a", encoding="utf8") as f:
|
||||
f.write(bytes(data, "utf8").decode("unicode_escape"))
|
||||
f.write("\n")
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ def brace_expand_line(line):
|
|||
def render_template(path, args):
|
||||
"""Render a template at `path` with arguments `args`"""
|
||||
|
||||
with open(path, "r") as f:
|
||||
with open(path, "r", encoding="utf8") as f:
|
||||
data = f.read()
|
||||
|
||||
tlp = mako.template.Template(text=data, filename=path)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ def parse_files(*paths):
|
|||
|
||||
path = next((p for p in paths if os.path.exists(p)), None)
|
||||
if path:
|
||||
with open(path) as f:
|
||||
with open(path, encoding="utf8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class Treefile:
|
|||
fd, name = tempfile.mkstemp(suffix=".json",
|
||||
text=True)
|
||||
|
||||
with os.fdopen(fd, "w+") as f:
|
||||
with os.fdopen(fd, "w+", encoding="utf8") as f:
|
||||
self.dump(f)
|
||||
|
||||
yield name
|
||||
|
|
@ -120,7 +120,7 @@ def rev_parse(repo: PathLike, ref: str) -> str:
|
|||
repo = repo.decode("utf8")
|
||||
|
||||
r = subprocess.run(["ostree", "rev-parse", ref, f"--repo={repo}"],
|
||||
encoding="utf-8",
|
||||
encoding="utf8",
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False)
|
||||
|
|
@ -141,7 +141,7 @@ def show(repo: PathLike, checksum: str) -> str:
|
|||
repo = repo.decode("utf8")
|
||||
|
||||
r = subprocess.run(["ostree", "show", f"--repo={repo}", checksum],
|
||||
encoding="utf-8",
|
||||
encoding="utf8",
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False)
|
||||
|
|
@ -188,7 +188,7 @@ class PasswdLike:
|
|||
if not os.path.isfile(path):
|
||||
return ret
|
||||
|
||||
with open(path, "r") as p:
|
||||
with open(path, "r", encoding="utf8") as p:
|
||||
ret.db = cls._passwd_lines_to_dict(p.readlines())
|
||||
return ret
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ class PasswdLike:
|
|||
if not os.path.isfile(path):
|
||||
return
|
||||
|
||||
with open(path, "r") as p:
|
||||
with open(path, "r", encoding="utf8") as p:
|
||||
additional_passwd_dict = self._passwd_lines_to_dict(p.readlines())
|
||||
for name, passwd_line in additional_passwd_dict.items():
|
||||
if name not in self.db:
|
||||
|
|
@ -206,7 +206,7 @@ class PasswdLike:
|
|||
|
||||
def dump_to_file(self, path: PathLike):
|
||||
"""Write the current database to a file"""
|
||||
with open(path, "w") as p:
|
||||
with open(path, "w", encoding="utf8") as p:
|
||||
p.writelines(list(self.db.values()))
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -250,13 +250,13 @@ class SubIdsDB:
|
|||
|
||||
def read_from(self, path: PathLike) -> int:
|
||||
"""Read a file and add the entries to the database"""
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(path, "r", encoding="utf8") as f:
|
||||
return self.read(f)
|
||||
|
||||
def write_to(self, path: PathLike) -> None:
|
||||
"""Write the database to a file"""
|
||||
data = self.dumps()
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
with open(path, "w", encoding="utf8") as f:
|
||||
f.write(data)
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class Subscriptions:
|
|||
"""Read redhat.repo file and process the list of repositories in there."""
|
||||
ret = cls(None)
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
with open("/etc/yum.repos.d/redhat.repo", "r") as fp:
|
||||
with open("/etc/yum.repos.d/redhat.repo", "r", encoding="utf8") as fp:
|
||||
ret = cls.parse_repo_file(fp)
|
||||
|
||||
with contextlib.suppress(RuntimeError):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue