def save_host_keys(self, filename):
<EOL>if self._host_keys_filename is not None:<EOL><INDENT>self.load_host_keys(self._host_keys_filename)<EOL><DEDENT>with open(filename, "<STR_LIT:w>") as f:<EOL><INDENT>for hostname, keys in self._host_keys.items():<EOL><INDENT>for keytype, key in keys.items():<EOL><INDENT>f.write(<EOL>"<STR_LIT>".format(<EOL>hostname, keytype, key.get_base64()<EOL>)<EOL>)<EOL><DEDENT><DEDENT><DEDENT>
Save the host keys back to a file.  Only the host keys loaded with
`load_host_keys` (plus any added directly) will be saved -- not any
host keys loaded with `load_system_host_keys`.

:param str filename: the filename to save to

:raises: ``IOError`` -- if the file could not be written