Close all open filehandle (#50544)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde
2019-01-11 20:44:08 +05:30
committed by Brian Coca
parent 94a1d86d70
commit db8702cdb8
21 changed files with 81 additions and 47 deletions

View File

@@ -231,7 +231,9 @@ class ACIModule(object):
self.params['certificate_name'] = os.path.basename(os.path.splitext(self.params['private_key'])[0])
try:
sig_key = load_privatekey(FILETYPE_PEM, open(self.params['private_key'], 'r').read())
with open(self.params['private_key'], 'r') as priv_key_fh:
private_key_content = priv_key_fh.read()
sig_key = load_privatekey(FILETYPE_PEM, private_key_content)
except Exception:
self.module.fail_json(msg='Cannot load private key %s' % self.params['private_key'])

View File

@@ -203,7 +203,8 @@ class NetworkConfig(object):
self._items = self.parse(s)
def loadfp(self, fp):
return self.load(open(fp).read())
with open(fp) as f:
return self.load(f.read())
def parse(self, lines, comment_tokens=None):
toplevel = re.compile(r'\S')