Use a context handler for file handling in paramiko_ssh.Connection. (#65624)

pull/65902/head
Mads Jensen 6 years ago committed by ansibot
parent d3e9ef3c35
commit ec34235e2e

@ -0,0 +1,2 @@
bugfixes:
- paramiko_ssh - optimized file handling by using a context manager.

@ -517,7 +517,7 @@ class Connection(ConnectionBase):
path = os.path.expanduser("~/.ssh") path = os.path.expanduser("~/.ssh")
makedirs_safe(path) makedirs_safe(path)
f = open(filename, 'w') with open(filename, 'w') as f:
for hostname, keys in iteritems(self.ssh._host_keys): for hostname, keys in iteritems(self.ssh._host_keys):
@ -535,8 +535,6 @@ class Connection(ConnectionBase):
if added_this_time: if added_this_time:
f.write("%s %s %s\n" % (hostname, keytype, key.get_base64())) f.write("%s %s %s\n" % (hostname, keytype, key.get_base64()))
f.close()
def reset(self): def reset(self):
self.close() self.close()
self._connect() self._connect()

Loading…
Cancel
Save