lib/subl/settings.py
def validate_settings(settings):
    '''
    Checks `settings` for invalid/missing values. May raise `SettingsError`.
    This only checks for type-mismatches and missing settings. It does not
    check anything on the file system, as that could block.
    If there are no issues, this returns without doing anything. Otherwise,
    this will raise an exception of type `SettingsError`.
    '''
    if not isinstance(settings, Settings):
        raise TypeError('settings must be Settings: %r' % (settings))

    ycmd_root_directory = settings.ycmd_root_directory

    ycmd_default_settings_path = settings.ycmd_default_settings_path
    ycmd_python_binary_path = settings.ycmd_python_binary_path
    ycmd_language_whitelist = settings.ycmd_language_whitelist
    ycmd_language_blacklist = settings.ycmd_language_blacklist
    ycmd_language_filetype = settings.ycmd_language_filetype
    ycmd_idle_suicide_seconds = settings.ycmd_idle_suicide_seconds
    ycmd_check_interval_seconds = settings.ycmd_check_interval_seconds
    ycmd_log_level = settings.ycmd_log_level
    ycmd_log_file = settings.ycmd_log_file
    ycmd_keep_logs = settings.ycmd_keep_logs
    ycmd_force_semantic_completion = \
        settings.ycmd_force_semantic_completion
    sublime_ycmd_log_level = settings.sublime_ycmd_log_level
    sublime_ycmd_log_file = settings.sublime_ycmd_log_file
    sublime_ycmd_background_threads = \
        settings.sublime_ycmd_background_threads

    # required settings
    if not ycmd_root_directory:
        raise SettingsError(
            'ycmd root directory must be provided, got: %r' %
            (ycmd_root_directory),
            type=SettingsError.MISSING,
            key='ycmd_root_directory', value=ycmd_root_directory,
        )

    # types
    def _desc_from_key(key):
        ''' Calculates a description from a settings key. '''
        return key.replace('_', ' ')

    def check_str(key, value, optional=True):
        if optional and value is None:
            return

        if not isinstance(value, str):
            raise SettingsError(
                '%s must be a str: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )

    def check_bool(key, value, optional=True):
        if optional and value is None:
            return

        if not (value is True or value is False):
            raise SettingsError(
                '%s must be a bool: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )

    def check_int(key, value, optional=True):
        if optional and value is None:
            return

        if not isinstance(value, int):
            raise SettingsError(
                '%s must be an int: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )

    def check_list_str(key, value, optional=True):
        if optional and value is None:
            return

        if not isinstance(value, (list, tuple)):
            raise SettingsError(
                '%s must be a list: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )

        bad_items = list(v for v in value if not isinstance(v, str))
        if not bad_items:
            # everything is valid
            return

        raise SettingsError(
            '%s must have str entries: [ %s ]' % (
                _desc_from_key(key),
                ', '.join('%r' % (v,) for v in bad_items),
            ),
            type=SettingsError.TYPE, key=key, value=value,
        )

    def check_dict_str(key, value, optional=True):
        if optional and value is None:
            return

        if not isinstance(value, (dict)):
            raise SettingsError(
                '%s must be a dict: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )

        bad_keys = list(
            k for k in value if not isinstance(value.get(k, None), str)
        )
        if not bad_keys:
            # everything is valid
            return

        raise SettingsError(
            '%s must have str entries: { %s }' % (
                _desc_from_key(key),
                ', '.join('%r: %r' % (k, value[k]) for k in bad_keys),
            ),
            type=SettingsError.TYPE, key=key, value=value,
        )

    check_str('ycmd_root_directory', ycmd_root_directory)
    check_str('ycmd_default_settings_path', ycmd_default_settings_path)
    check_str('ycmd_python_binary_path', ycmd_python_binary_path)
    check_list_str('ycmd_language_whitelist', ycmd_language_whitelist)
    check_list_str('ycmd_language_blacklist', ycmd_language_blacklist)
    check_dict_str('ycmd_language_filetype', ycmd_language_filetype)
    check_int('ycmd_idle_suicide_seconds', ycmd_idle_suicide_seconds)
    check_int('ycmd_check_interval_seconds', ycmd_check_interval_seconds)
    check_str('ycmd_log_level', ycmd_log_level)
    check_bool('ycmd_log_file', ycmd_log_file)
    check_bool('ycmd_keep_logs', ycmd_keep_logs)
    check_bool(
        'ycmd_force_semantic_completion', ycmd_force_semantic_completion,
    )
    check_str('sublime_ycmd_log_level', sublime_ycmd_log_level)
    check_str('sublime_ycmd_log_file', sublime_ycmd_log_file)
    check_int(
        'sublime_ycmd_background_threads', sublime_ycmd_background_threads,
    )

    Checks `settings` for invalid/missing values. May raise `SettingsError`.
    This only checks for type-mismatches and missing settings. It does not
    check anything on the file system, as that could block.
    If there are no issues, this returns without doing anything. Otherwise,
    this will raise an exception of type `SettingsError`.
    
Checks `settings` for invalid/missing values.
Checks ` settings ` for invalid / missing values .
def validate_settings(settings):
    if not isinstance(settings, Settings):
        raise TypeError('settings must be Settings: %r' % (settings))
    ycmd_root_directory = settings.ycmd_root_directory
    ycmd_default_settings_path = settings.ycmd_default_settings_path
    ycmd_python_binary_path = settings.ycmd_python_binary_path
    ycmd_language_whitelist = settings.ycmd_language_whitelist
    ycmd_language_blacklist = settings.ycmd_language_blacklist
    ycmd_language_filetype = settings.ycmd_language_filetype
    ycmd_idle_suicide_seconds = settings.ycmd_idle_suicide_seconds
    ycmd_check_interval_seconds = settings.ycmd_check_interval_seconds
    ycmd_log_level = settings.ycmd_log_level
    ycmd_log_file = settings.ycmd_log_file
    ycmd_keep_logs = settings.ycmd_keep_logs
    ycmd_force_semantic_completion = \
        settings.ycmd_force_semantic_completion
    sublime_ycmd_log_level = settings.sublime_ycmd_log_level
    sublime_ycmd_log_file = settings.sublime_ycmd_log_file
    sublime_ycmd_background_threads = \
        settings.sublime_ycmd_background_threads
    if not ycmd_root_directory:
        raise SettingsError(
            'ycmd root directory must be provided, got: %r' %
            (ycmd_root_directory),
            type=SettingsError.MISSING,
            key='ycmd_root_directory', value=ycmd_root_directory,
        )
    def _desc_from_key(key):
        return key.replace('_', ' ')
    def check_str(key, value, optional=True):
        if optional and value is None:
            return
        if not isinstance(value, str):
            raise SettingsError(
                '%s must be a str: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )
    def check_bool(key, value, optional=True):
        if optional and value is None:
            return
        if not (value is True or value is False):
            raise SettingsError(
                '%s must be a bool: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )
    def check_int(key, value, optional=True):
        if optional and value is None:
            return
        if not isinstance(value, int):
            raise SettingsError(
                '%s must be an int: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )
    def check_list_str(key, value, optional=True):
        if optional and value is None:
            return
        if not isinstance(value, (list, tuple)):
            raise SettingsError(
                '%s must be a list: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )
        bad_items = list(v for v in value if not isinstance(v, str))
        if not bad_items:
            return
        raise SettingsError(
            '%s must have str entries: [ %s ]' % (
                _desc_from_key(key),
                ', '.join('%r' % (v,) for v in bad_items),
            ),
            type=SettingsError.TYPE, key=key, value=value,
        )
    def check_dict_str(key, value, optional=True):
        if optional and value is None:
            return
        if not isinstance(value, (dict)):
            raise SettingsError(
                '%s must be a dict: %r' % (_desc_from_key(key), value),
                type=SettingsError.TYPE, key=key, value=value,
            )
        bad_keys = list(
            k for k in value if not isinstance(value.get(k, None), str)
        )
        if not bad_keys:
            return
        raise SettingsError(
            '%s must have str entries: { %s }' % (
                _desc_from_key(key),
                ', '.join('%r: %r' % (k, value[k]) for k in bad_keys),
            ),
            type=SettingsError.TYPE, key=key, value=value,
        )
    check_str('ycmd_root_directory', ycmd_root_directory)
    check_str('ycmd_default_settings_path', ycmd_default_settings_path)
    check_str('ycmd_python_binary_path', ycmd_python_binary_path)
    check_list_str('ycmd_language_whitelist', ycmd_language_whitelist)
    check_list_str('ycmd_language_blacklist', ycmd_language_blacklist)
    check_dict_str('ycmd_language_filetype', ycmd_language_filetype)
    check_int('ycmd_idle_suicide_seconds', ycmd_idle_suicide_seconds)
    check_int('ycmd_check_interval_seconds', ycmd_check_interval_seconds)
    check_str('ycmd_log_level', ycmd_log_level)
    check_bool('ycmd_log_file', ycmd_log_file)
    check_bool('ycmd_keep_logs', ycmd_keep_logs)
    check_bool(
        'ycmd_force_semantic_completion', ycmd_force_semantic_completion,
    )
    check_str('sublime_ycmd_log_level', sublime_ycmd_log_level)
    check_str('sublime_ycmd_log_file', sublime_ycmd_log_file)
    check_int(
        'sublime_ycmd_background_threads', sublime_ycmd_background_threads,
    )
def validate_settings ( settings ) : if not isinstance ( settings , Settings ) : raise TypeError ( 'settings must be Settings: %r' % ( settings ) ) ycmd_root_directory = settings . ycmd_root_directory ycmd_default_settings_path = settings . ycmd_default_settings_path ycmd_python_binary_path = settings . ycmd_python_binary_path ycmd_language_whitelist = settings . ycmd_language_whitelist ycmd_language_blacklist = settings . ycmd_language_blacklist ycmd_language_filetype = settings . ycmd_language_filetype ycmd_idle_suicide_seconds = settings . ycmd_idle_suicide_seconds ycmd_check_interval_seconds = settings . ycmd_check_interval_seconds ycmd_log_level = settings . ycmd_log_level ycmd_log_file = settings . ycmd_log_file ycmd_keep_logs = settings . ycmd_keep_logs ycmd_force_semantic_completion = settings . ycmd_force_semantic_completion sublime_ycmd_log_level = settings . sublime_ycmd_log_level sublime_ycmd_log_file = settings . sublime_ycmd_log_file sublime_ycmd_background_threads = settings . sublime_ycmd_background_threads if not ycmd_root_directory : raise SettingsError ( 'ycmd root directory must be provided, got: %r' % ( ycmd_root_directory ) , type = SettingsError . MISSING , key = 'ycmd_root_directory' , value = ycmd_root_directory , ) def _desc_from_key ( key ) : ''' Calculates a description from a settings key. ''' return key . replace ( '_' , ' ' ) def check_str ( key , value , optional = True ) : if optional and value is None : return if not isinstance ( value , str ) : raise SettingsError ( '%s must be a str: %r' % ( _desc_from_key ( key ) , value ) , type = SettingsError . TYPE , key = key , value = value , ) def check_bool ( key , value , optional = True ) : if optional and value is None : return if not ( value is True or value is False ) : raise SettingsError ( '%s must be a bool: %r' % ( _desc_from_key ( key ) , value ) , type = SettingsError . TYPE , key = key , value = value , ) def check_int ( key , value , optional = True ) : if optional and value is None : return if not isinstance ( value , int ) : raise SettingsError ( '%s must be an int: %r' % ( _desc_from_key ( key ) , value ) , type = SettingsError . TYPE , key = key , value = value , ) def check_list_str ( key , value , optional = True ) : if optional and value is None : return if not isinstance ( value , ( list , tuple ) ) : raise SettingsError ( '%s must be a list: %r' % ( _desc_from_key ( key ) , value ) , type = SettingsError . TYPE , key = key , value = value , ) bad_items = list ( v for v in value if not isinstance ( v , str ) ) if not bad_items : return raise SettingsError ( '%s must have str entries: [ %s ]' % ( _desc_from_key ( key ) , ', ' . join ( '%r' % ( v , ) for v in bad_items ) , ) , type = SettingsError . TYPE , key = key , value = value , ) def check_dict_str ( key , value , optional = True ) : if optional and value is None : return if not isinstance ( value , ( dict ) ) : raise SettingsError ( '%s must be a dict: %r' % ( _desc_from_key ( key ) , value ) , type = SettingsError . TYPE , key = key , value = value , ) bad_keys = list ( k for k in value if not isinstance ( value . get ( k , None ) , str ) ) if not bad_keys : return raise SettingsError ( '%s must have str entries: { %s }' % ( _desc_from_key ( key ) , ', ' . join ( '%r: %r' % ( k , value [ k ] ) for k in bad_keys ) , ) , type = SettingsError . TYPE , key = key , value = value , ) check_str ( 'ycmd_root_directory' , ycmd_root_directory ) check_str ( 'ycmd_default_settings_path' , ycmd_default_settings_path ) check_str ( 'ycmd_python_binary_path' , ycmd_python_binary_path ) check_list_str ( 'ycmd_language_whitelist' , ycmd_language_whitelist ) check_list_str ( 'ycmd_language_blacklist' , ycmd_language_blacklist ) check_dict_str ( 'ycmd_language_filetype' , ycmd_language_filetype ) check_int ( 'ycmd_idle_suicide_seconds' , ycmd_idle_suicide_seconds ) check_int ( 'ycmd_check_interval_seconds' , ycmd_check_interval_seconds ) check_str ( 'ycmd_log_level' , ycmd_log_level ) check_bool ( 'ycmd_log_file' , ycmd_log_file ) check_bool ( 'ycmd_keep_logs' , ycmd_keep_logs ) check_bool ( 'ycmd_force_semantic_completion' , ycmd_force_semantic_completion , ) check_str ( 'sublime_ycmd_log_level' , sublime_ycmd_log_level ) check_str ( 'sublime_ycmd_log_file' , sublime_ycmd_log_file ) check_int ( 'sublime_ycmd_background_threads' , sublime_ycmd_background_threads , )
Checks `settings` for invalid/missing values.
Checks ` settings ` for invalid / missing values .
'''
    Checks `settings` for invalid/missing values. May raise `SettingsError`.
    This only checks for type-mismatches and missing settings. It does not
    check anything on the file system, as that could block.
    If there are no issues, this returns without doing anything. Otherwise,
    this will raise an exception of type `SettingsError`.
    ''' # required settings # types ''' Calculates a description from a settings key. ''' # everything is valid # everything is valid
settings