def lookup(self, hostname):
class SubDict(MutableMapping):<EOL><INDENT>def __init__(self, hostname, entries, hostkeys):<EOL><INDENT>self._hostname = hostname<EOL>self._entries = entries<EOL>self._hostkeys = hostkeys<EOL><DEDENT>def __iter__(self):<EOL><INDENT>for k in self.keys():<EOL><INDENT>yield k<EOL><DEDENT><DEDENT>def __len__(self):<EOL><INDENT>return len(self.keys())<EOL><DEDENT>def __delitem__(self, key):<EOL><INDENT>for e in list(self._entries):<EOL><INDENT>if e.key.get_name() == key:<EOL><INDENT>self._entries.remove(e)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise KeyError(key)<EOL><DEDENT><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 [<EOL>e.key.get_name()<EOL>for e in self._entries<EOL>if e.key is not None<EOL>]<EOL><DEDENT><DEDENT>entries = []<EOL>for e in self._entries:<EOL><INDENT>if self._hostname_matches(hostname, e):<EOL><INDENT>entries.append(e)<EOL><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,
``None`` is returned.  Otherwise a dictionary of keytype to key is
returned.  The keytype will be either ``"ssh-rsa"`` or ``"ssh-dss"``.

:param str hostname: the hostname (or IP) to lookup
:return: dict of `str` -> `.PKey` keys associated with this host
    (or ``None``)