summaryrefslogtreecommitdiff
path: root/paramiko/hostkeys.py
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-11-19 08:56:53 -0800
committerScott Maxwell <scott@codecobblers.com>2013-11-19 08:56:53 -0800
commit2da5f1fb4565d1e6dc72672f640dac44b122d235 (patch)
tree341373c292485f1417933551cc5c425d17fbbd44 /paramiko/hostkeys.py
parent7471515fffd2315f7330c5e1dd42f353982ded6c (diff)
downloadparamiko-2da5f1fb4565d1e6dc72672f640dac44b122d235.tar.gz
Use 'with' for opening most file and SFTPFIle objects
Diffstat (limited to 'paramiko/hostkeys.py')
-rw-r--r--paramiko/hostkeys.py10
1 files changed, 2 insertions, 8 deletions
diff --git a/paramiko/hostkeys.py b/paramiko/hostkeys.py
index 16f7f901..cf586a29 100644
--- a/paramiko/hostkeys.py
+++ b/paramiko/hostkeys.py
@@ -172,8 +172,7 @@ class HostKeys (MutableMapping):
@raise IOError: if there was an error reading the file
"""
- f = open(filename, 'r')
- try:
+ with open(filename, 'r') as f:
for lineno, line in enumerate(f):
line = line.strip()
if (len(line) == 0) or (line[0] == '#'):
@@ -186,8 +185,6 @@ class HostKeys (MutableMapping):
e.hostnames.remove(h)
if len(e.hostnames):
self._entries.append(e)
- finally:
- f.close()
def save(self, filename):
"""
@@ -203,14 +200,11 @@ class HostKeys (MutableMapping):
@since: 1.6.1
"""
- f = open(filename, 'w')
- try:
+ with open(filename, 'w') as f:
for e in self._entries:
line = e.to_line()
if line:
f.write(line)
- finally:
- f.close()
def lookup(self, hostname):
"""