code: def _check_valid_key(self, key):
          
          if not isinstance(key, key_type):
              raise ValueError('%r is not a valid key type' % key)
          if not VALID_KEY_RE.match(key):
              raise ValueError('%r contains illegal characters' % key)
docs: Checks if a key is valid and raises a ValueError if its not.
  
          When in need of checking a key for validity, always use this
          method if possible.
  
          :param key: The key to be checked