# Path: lib/util/format.py
# def base64_encode(data):
#     '''
#     Encodes the given `data` in base-64. The result will either be a `str`,
#     or `bytes`, depending on the input type (same as input type).
#     '''
#     assert isinstance(data, (str, bytes)), \
#         'data must be str or bytes: %r' % (data)
# 
#     is_str = isinstance(data, str)
#     if is_str:
#         data = str_to_bytes(data)
# 
#     encoded = base64.b64encode(data)
# 
#     if is_str:
#         encoded = bytes_to_str(encoded)
# 
#     return encoded
# 
# Path: lib/util/fs.py
# def is_directory(path):
#     '''
#     Returns true if the supplied `path` refers to a valid directory, and
#     false otherwise.
#     '''
#     if not isinstance(path, str):
#         raise TypeError('path must be a str: %r' % (path))
#     return os.path.exists(path) and os.path.isdir(path)
# 
# def is_file(path):
#     '''
#     Returns true if the supplied `path` refers to a valid plain file, and
#     false otherwise.
#     '''
#     if not isinstance(path, str):
#         raise TypeError('path must be a str: %r' % (path))
#     return os.path.exists(path) and os.path.isfile(path)
# 
# def load_json_file(path, encoding='utf-8'):
#     '''
#     Returns a `dict` generated by reading the file at `path`, and then parsing
#     it as JSON. This will throw if the file does not exist, cannot be read, or
#     cannot be parsed as JSON.
#     The `encoding` parameter is used when initially reading the file.
#     '''
#     if not isinstance(path, str):
#         raise TypeError('path must be a str: %r' % (path))
#     if not isinstance(encoding, str):
#         raise TypeError('encoding must be a str: %r' % (encoding))
# 
#     path = resolve_env(path)
#     if not is_file(path):
#         logger.warning('path does not seem to refer to a valid file: %s', path)
#         # but fall through and try anyway
# 
#     logger.debug(
#         'attempting to parse file with path, encoding: %s, %s', path, encoding,
#     )
#     with open(path, encoding=encoding) as file_handle:
#         file_data = json.load(file_handle)
# 
#     logger.debug('successfully parsed json file')
#     return file_data
# 
# Path: lib/util/str.py
# def bytes_to_str(data):
#     '''
#     Converts `data` to `str`.
# 
#     If data is a `bytes`, it is decoded into `str`.
#     If data is `str`, it is returned as-is.
#     '''
#     assert isinstance(data, (str, bytes)), \
#         'data must be str or bytes: %r' % (data)
#     if isinstance(data, str):
#         # already str, yay
#         return data
#     return data.decode()


import logging
import os
from ..util.format import base64_encode
from ..util.fs import (
    is_directory,
    is_file,
    load_json_file,
)
from ..util.str import bytes_to_str
        logger.warning(
            'ycmd settings template is missing the '
            'filetype_whitelist placeholder'
        )
    ycmd_settings['filetype_whitelist'] = {}
    ycmd_settings['filetype_whitelist']['*'] = 1

    # BLACKLIST
    # Disable for nothing. This plugin will decide what to ignore.
    if 'filetype_blacklist' not in ycmd_settings:
        logger.warning(
            'ycmd settings template is missing the '
            'filetype_blacklist placeholder'
        )
    ycmd_settings['filetype_blacklist'] = {}

    # HMAC
    # Pass in the hmac parameter. It needs to be base-64 encoded first.
    if 'hmac_secret' not in ycmd_settings:
        logger.warning(
            'ycmd settings template is missing the hmac_secret placeholder'
        )

    if not isinstance(hmac_secret, bytes):
        logger.warning(
            'hmac secret was not passed in as binary, it might be incorrect'
        )
    else:
        logger.debug('converting hmac secret to base64')
        hmac_secret_binary = hmac_secret

# Path: lib/util/format.py
# def base64_encode(data):
#     '''
#     Encodes the given `data` in base-64. The result will either be a `str`,
#     or `bytes`, depending on the input type (same as input type).
#     '''
#     assert isinstance(data, (str, bytes)), \
#         'data must be str or bytes: %r' % (data)
# 
#     is_str = isinstance(data, str)
#     if is_str:
#         data = str_to_bytes(data)
# 
#     encoded = base64.b64encode(data)
# 
#     if is_str:
#         encoded = bytes_to_str(encoded)
# 
#     return encoded
# 
# Path: lib/util/fs.py
# def is_directory(path):
#     '''
#     Returns true if the supplied `path` refers to a valid directory, and
#     false otherwise.
#     '''
#     if not isinstance(path, str):
#         raise TypeError('path must be a str: %r' % (path))
#     return os.path.exists(path) and os.path.isdir(path)
# 
# def is_file(path):
#     '''
#     Returns true if the supplied `path` refers to a valid plain file, and
#     false otherwise.
#     '''
#     if not isinstance(path, str):
#         raise TypeError('path must be a str: %r' % (path))
#     return os.path.exists(path) and os.path.isfile(path)
# 
# def load_json_file(path, encoding='utf-8'):
#     '''
#     Returns a `dict` generated by reading the file at `path`, and then parsing
#     it as JSON. This will throw if the file does not exist, cannot be read, or
#     cannot be parsed as JSON.
#     The `encoding` parameter is used when initially reading the file.
#     '''
#     if not isinstance(path, str):
#         raise TypeError('path must be a str: %r' % (path))
#     if not isinstance(encoding, str):
#         raise TypeError('encoding must be a str: %r' % (encoding))
# 
#     path = resolve_env(path)
#     if not is_file(path):
#         logger.warning('path does not seem to refer to a valid file: %s', path)
#         # but fall through and try anyway
# 
#     logger.debug(
#         'attempting to parse file with path, encoding: %s, %s', path, encoding,
#     )
#     with open(path, encoding=encoding) as file_handle:
#         file_data = json.load(file_handle)
# 
#     logger.debug('successfully parsed json file')
#     return file_data
# 
# Path: lib/util/str.py
# def bytes_to_str(data):
#     '''
#     Converts `data` to `str`.
# 
#     If data is a `bytes`, it is decoded into `str`.
#     If data is `str`, it is returned as-is.
#     '''
#     assert isinstance(data, (str, bytes)), \
#         'data must be str or bytes: %r' % (data)
#     if isinstance(data, str):
#         # already str, yay
#         return data
#     return data.decode()


# Path: lib/ycmd/settings.py
import logging
import os
from ..util.format import base64_encode
from ..util.fs import (
    is_directory,
    is_file,
    load_json_file,
)
from ..util.str import bytes_to_str

        logger.warning(
            'ycmd settings template is missing the '
            'filetype_whitelist placeholder'
        )
    ycmd_settings['filetype_whitelist'] = {}
    ycmd_settings['filetype_whitelist']['*'] = 1

    # BLACKLIST
    # Disable for nothing. This plugin will decide what to ignore.
    if 'filetype_blacklist' not in ycmd_settings:
        logger.warning(
            'ycmd settings template is missing the '
            'filetype_blacklist placeholder'
        )
    ycmd_settings['filetype_blacklist'] = {}

    # HMAC
    # Pass in the hmac parameter. It needs to be base-64 encoded first.
    if 'hmac_secret' not in ycmd_settings:
        logger.warning(
            'ycmd settings template is missing the hmac_secret placeholder'
        )

    if not isinstance(hmac_secret, bytes):
        logger.warning(
            'hmac secret was not passed in as binary, it might be incorrect'
        )
    else:
        logger.debug('converting hmac secret to base64')
        hmac_secret_binary = hmac_secret

        hmac_secret_encoded = base64_encode(hmac_secret_binary)