<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _real_key(self, key):
 """ Return the normalized key to be used for the internal dictionary, from the input key. """

        if key is not None:
            try:
                return key.lower()
            except AttributeError:
                raise TypeError(
                    _format("NocaseDict key {0!A} must be a string, "
                            "but is {1}", key, type(key)))

        if self.allow_unnamed_keys:
            return None

        raise TypeError(
            _format("NocaseDict key None (unnamed key) is not "
                    "allowed for this object"))