def _key_from_filepath(self, filename, klass, password):
cert_suffix = "<STR_LIT>"<EOL>if filename.endswith(cert_suffix):<EOL><INDENT>key_path = filename[: -len(cert_suffix)]<EOL>cert_path = filename<EOL><DEDENT>else:<EOL><INDENT>key_path = filename<EOL>cert_path = filename + cert_suffix<EOL><DEDENT>key = klass.from_private_key_file(key_path, password)<EOL>msg = "<STR_LIT>".format(<EOL>hexlify(key.get_fingerprint()), key_path<EOL>)<EOL>self._log(DEBUG, msg)<EOL>if os.path.isfile(cert_path):<EOL><INDENT>key.load_certificate(cert_path)<EOL>self._log(DEBUG, "<STR_LIT>".format(cert_path))<EOL><DEDENT>return key<EOL>
Attempt to derive a `.PKey` from given string path ``filename``:

- If ``filename`` appears to be a cert, the matching private key is
  loaded.
- Otherwise, the filename is assumed to be a private key, and the
  matching public cert will be loaded if it exists.