def _normalize_key(self, key, unknown_ok=True):
        """Return the normalized version of KEY.
        KEY may be a frameid (a string), or a Frame class object.
        If KEY corresponds to a registered frameid, then that frameid is returned.
        Otherwise, either KeyError is raised, or KEY is returned verbatim, 
        depending on the value of UNKNOWN_OK.
        """
        if Frames.is_frame_class(key):
            key = key.frameid
        if isinstance(key, str):
            if not self._is_frame_id(key):
                raise KeyError("{0}: Invalid frame id".format(key))
            if key not in self.known_frames:
                if unknown_ok:
                    warn("{0}: Unknown frame id".format(key), UnknownFrameWarning)
                else:
                    raise KeyError("{0}: Unknown frame id".format(key))
        return key