mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-27 00:46:34 +00:00
use open() as context manager (#9579)
* use open() as context manager * add changelog frag
This commit is contained in:
@@ -154,11 +154,8 @@ def main():
|
||||
changed, reason = existing_line.opts.remove(opts)
|
||||
|
||||
if changed and not module.check_mode:
|
||||
try:
|
||||
f = open(path, 'wb')
|
||||
with open(path, 'wb') as f:
|
||||
f.write(to_bytes(crypttab, errors='surrogate_or_strict'))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
module.exit_json(changed=changed, msg=reason, **module.params)
|
||||
|
||||
@@ -173,12 +170,9 @@ class Crypttab(object):
|
||||
os.makedirs(os.path.dirname(path))
|
||||
open(path, 'a').close()
|
||||
|
||||
try:
|
||||
f = open(path, 'r')
|
||||
with open(path, 'r') as f:
|
||||
for line in f.readlines():
|
||||
self._lines.append(Line(line))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def add(self, line):
|
||||
self._lines.append(line)
|
||||
|
||||
Reference in New Issue
Block a user