Skip to content

Commit

Permalink
pylint: Fix unspecified-encoding
Browse files Browse the repository at this point in the history
Pylint 2.10 introduced new checker unspecified-encoding:
> Added unspecified-encoding: Emitted when open() is called without
  specifying an encoding

https://pylint.pycqa.org/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-10-0
pylint-dev/pylint#3826
https://www.python.org/dev/peps/pep-0597/

Fixes: freeipa#244
Signed-off-by: Stanislav Levin <slev@altlinux.org>
  • Loading branch information
stanislavlevin committed Feb 15, 2022
1 parent 77330e8 commit 727ea5c
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/ipaclustercheck/ipa/plugin.py
Expand Up @@ -92,7 +92,7 @@ def load_files(self, dir):
fname = join(dir, file)
logger.debug("Reading %s", fname)
try:
with open(fname, 'r') as fd:
with open(fname, 'r', encoding="utf-8") as fd:
data = fd.read()
except Exception as e:
logger.error("Unable to read %s: %s", fname, e)
Expand Down
2 changes: 1 addition & 1 deletion src/ipahealthcheck/core/core.py
Expand Up @@ -409,7 +409,7 @@ def run_healthcheck(self):

if 'infile' in options and options.infile:
try:
with open(options.infile, 'r') as f:
with open(options.infile, 'r', encoding="utf-8") as f:
raw_data = f.read()

json_data = json.loads(raw_data)
Expand Down
2 changes: 1 addition & 1 deletion src/ipahealthcheck/core/output.py
Expand Up @@ -61,7 +61,7 @@ def render(self, results):
def write_file(self, output):
"""Write the output to a file or sys.stdout"""
if self.filename:
with open(self.filename, 'w') as fd:
with open(self.filename, 'w', encoding="utf-8") as fd:
fd.write(output)
else:
sys.stdout.write(output)
Expand Down
2 changes: 1 addition & 1 deletion src/ipahealthcheck/ipa/certs.py
Expand Up @@ -173,7 +173,7 @@ def get_dogtag_cert_password():
"""
ca_passwd = None
token = 'internal'
with open(paths.PKI_TOMCAT_PASSWORD_CONF, 'r') as f:
with open(paths.PKI_TOMCAT_PASSWORD_CONF, 'r', encoding="utf-8") as f:
for line in f:
(tok, pin) = line.split('=', 1)
if token == tok:
Expand Down
2 changes: 1 addition & 1 deletion src/ipahealthcheck/ipa/proxy.py
Expand Up @@ -22,7 +22,7 @@ def read_ipa_pki_proxy():
Split out to make it easier to mock
"""
with open(paths.HTTPD_IPA_PKI_PROXY_CONF, "r") as fd:
with open(paths.HTTPD_IPA_PKI_PROXY_CONF, "r", encoding="utf-8") as fd:
lines = fd.readlines()

return lines
Expand Down
4 changes: 2 additions & 2 deletions src/ipahealthcheck/system/filesystemspace.py
Expand Up @@ -13,10 +13,10 @@

def in_container():
"""Determine if we're running in a container."""
with open('/proc/1/sched', 'r') as sched:
with open('/proc/1/sched', 'r', encoding="utf-8") as sched:
data_sched = sched.readline()

with open('/proc/self/cgroup', 'r') as cgroup:
with open('/proc/self/cgroup', 'r', encoding="utf-8") as cgroup:
data_cgroup = cgroup.readline()

checks = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_options.py
Expand Up @@ -28,7 +28,7 @@ def test_options_merge(mock_parse, mock_run, mock_service):
mock_parse.return_value = options
fd, config_path = tempfile.mkstemp()
os.close(fd)
with open(config_path, "w") as fd:
with open(config_path, "w", encoding="utf-8") as fd:
fd.write('[default]\n')
fd.write('output_type=human\n')
fd.write('indent=5\n')
Expand Down
8 changes: 4 additions & 4 deletions tests/test_suppress.py
Expand Up @@ -76,7 +76,7 @@ def test_suppress_none(mock_find, mock_parse, mock_service):

fd, config_path = tempfile.mkstemp()
os.close(fd)
with open(config_path, "w") as fd:
with open(config_path, "w", encoding="utf-8") as fd:
fd.write('[default]\n')

try:
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_suppress_source(mock_find, mock_parse, mock_service):

fd, config_path = tempfile.mkstemp()
os.close(fd)
with open(config_path, "w") as fd:
with open(config_path, "w", encoding="utf-8") as fd:
fd.write('[default]\n')
fd.write('[excludes]\n')
fd.write('source=test_suppress\n')
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_suppress_check(mock_find, mock_parse, mock_service):

fd, config_path = tempfile.mkstemp()
os.close(fd)
with open(config_path, "w") as fd:
with open(config_path, "w", encoding="utf-8") as fd:
fd.write('[default]\n')
fd.write('[excludes]\n')
fd.write('check=PluginOne\n')
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_suppress_key(mock_find, mock_parse, mock_service):

fd, config_path = tempfile.mkstemp()
os.close(fd)
with open(config_path, "w") as fd:
with open(config_path, "w", encoding="utf-8") as fd:
fd.write('[default]\n')
fd.write('[excludes]\n')
fd.write('key=test2\n')
Expand Down

0 comments on commit 727ea5c

Please sign in to comment.