@classmethod
def _validate_key(cls, key):
    """Emit a warning or raise an exception if key is invalid. Returns key."""
    if isinstance(key, str):
        if '.' in key:
            from ..errors import InvalidKeyError
            raise InvalidKeyError("keys may not contain dots ('.'): {}".
                format(key))
        else:
            return key
    elif isinstance(key, cls.VALID_KEY_TYPES):
        return cls._validate_key(str(key))
    else:
        from ..errors import KeyTypeError
        raise KeyTypeError('keys must be str, int, bool or None, not {}'.
            format(type(key).__name__))
