From 080bece2586d348b9791892cd6e5670a7afdb1a9 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Fri, 12 Oct 2012 09:41:52 +0200 Subject: [PATCH] Assure that host entries in known_hosts files do not duplicate endlessly if keys from known_hosts are loaded via HostKeys.load() more than once (e.g. for refreshing the list of known hosts during runtime). --- paramiko/hostkeys.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/paramiko/hostkeys.py b/paramiko/hostkeys.py index da5b66c..27b9fef 100644 --- a/paramiko/hostkeys.py +++ b/paramiko/hostkeys.py @@ -168,7 +168,12 @@ class HostKeys (UserDict.DictMixin): continue e = HostKeyEntry.from_line(line) if e is not None: - self._entries.append(e) + _hostnames = e.hostnames + for h in _hostnames: + if self.check(h, e.key): + e.hostnames.remove(h) + if len(e.hostnames): + self._entries.append(e) f.close() def save(self, filename):