mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
*: pylint: Explicitly specify encoding when open a file
This is recommended by PEP-0597: https://peps.python.org/pep-0597/ Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
05815bc992
commit
3c7bc4a192
49 files changed
+165
-138
No files matched your search
+4
-3
@@ -106,7 +106,7 @@ class YAMLFile(object):
|
||||
self.yaml.preserve_quotes = True
|
||||
|
||||
def __enter__(self):
|
||||
with open(self.yaml_file, 'r') as intro_conf:
|
||||
with open(self.yaml_file, 'r', encoding='utf-8') as intro_conf:
|
||||
if not self.is_file_empty():
|
||||
self.conf = self.yaml.load(intro_conf)
|
||||
else:
|
||||
@@ -116,7 +116,7 @@ class YAMLFile(object):
|
||||
|
||||
def __exit__(self, type_, value, traceback):
|
||||
if not traceback:
|
||||
with open(self.yaml_file, 'w') as intro_conf:
|
||||
with open(self.yaml_file, 'w', encoding='utf-8') as intro_conf:
|
||||
self.yaml.dump(self.conf, intro_conf)
|
||||
|
||||
def is_file_empty(self):
|
||||
@@ -140,7 +140,8 @@ def generate_password(size=32):
|
||||
def grep(pattern, file_name):
|
||||
"""Return lines of a file matching a pattern."""
|
||||
return [
|
||||
line.rstrip() for line in open(file_name) if re.search(pattern, line)
|
||||
line.rstrip() for line in open(file_name, encoding='utf-8')
|
||||
if re.search(pattern, line)
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user