def lookup(self, hostname):
class SubDict (UserDict.DictMixin):<EOL><INDENT>def __init__(self, hostname, entries, hostkeys):<EOL><INDENT>self._hostname = hostname<EOL>self._entries = entries<EOL>self._hostkeys = hostkeys<EOL><DEDENT>def __getitem__(self, key):<EOL><INDENT>for e in self._entries:<EOL><INDENT>if e.key.get_name() == key:<EOL><INDENT>return e.key<EOL><DEDENT><DEDENT>raise KeyError(key)<EOL><DEDENT>def __setitem__(self, key, val):<EOL><INDENT>for e in self._entries:<EOL><INDENT>if e.key is None:<EOL><INDENT>continue<EOL><DEDENT>if e.key.get_name() == key:<EOL><INDENT>e.key = val<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>e = HostKeyEntry([hostname], val)<EOL>self._entries.append(e)<EOL>self._hostkeys._entries.append(e)<EOL><DEDENT><DEDENT>def keys(self):<EOL><INDENT>return [e.key.get_name() for e in self._entries if e.key is not None]<EOL><DEDENT><DEDENT>entries = []<EOL>for e in self._entries:<EOL><INDENT>for h in e.hostnames:<EOL><INDENT>if (h.startswith('<STR_LIT>') and (self.hash_host(hostname, h) == h)) or (h == hostname):<EOL><INDENT>entries.append(e)<EOL><DEDENT><DEDENT><DEDENT>if len(entries) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>return SubDict(hostname, entries, self)<EOL>
Find a hostkey entry for a given hostname or IP.  If no entry is found,
C{None} is returned.  Otherwise a dictionary of keytype to key is
returned.  The keytype will be either C{"ssh-rsa"} or C{"ssh-dss"}.

@param hostname: the hostname (or IP) to lookup
@type hostname: str
@return: keys associated with this host (or C{None})
@rtype: dict(str, L{PKey})