Use a context handler for file handling in paramiko_ssh.Connection. (#65624)
This commit is contained in:
parent
d3e9ef3c35
commit
ec34235e2e
2 changed files with 14 additions and 14 deletions
2
changelogs/fragments/65624-paramiko-ctx-man.yml
Normal file
2
changelogs/fragments/65624-paramiko-ctx-man.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- paramiko_ssh - optimized file handling by using a context manager.
|
|
@ -517,25 +517,23 @@ class Connection(ConnectionBase):
|
|||
path = os.path.expanduser("~/.ssh")
|
||||
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):
|
||||
|
||||
for keytype, key in iteritems(keys):
|
||||
for keytype, key in iteritems(keys):
|
||||
|
||||
# was f.write
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if not added_this_time:
|
||||
f.write("%s %s %s\n" % (hostname, keytype, key.get_base64()))
|
||||
# was f.write
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if not added_this_time:
|
||||
f.write("%s %s %s\n" % (hostname, keytype, key.get_base64()))
|
||||
|
||||
for hostname, keys in iteritems(self.ssh._host_keys):
|
||||
for hostname, keys in iteritems(self.ssh._host_keys):
|
||||
|
||||
for keytype, key in iteritems(keys):
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if added_this_time:
|
||||
f.write("%s %s %s\n" % (hostname, keytype, key.get_base64()))
|
||||
|
||||
f.close()
|
||||
for keytype, key in iteritems(keys):
|
||||
added_this_time = getattr(key, '_added_by_ansible_this_time', False)
|
||||
if added_this_time:
|
||||
f.write("%s %s %s\n" % (hostname, keytype, key.get_base64()))
|
||||
|
||||
def reset(self):
|
||||
self.close()
|
||||
|
|
Loading…
Reference in a new issue