def read_key_value_pairs(filepath):
    """Reads key value pairs from a file.
    Format:
    [key]:value

    :param filepath: file to read from
    :type filepath: str
    :return: The key value pairs stored in a dictionary and the leftover string before the first pair.
    :return: tuple(dict[str,str],str)
    """
    pre_string = ''
    d = dict()
    with open(filepath, 'r+', encoding='utf-8') as f:
        pairs = f.read().split('\n[')

        if len(pairs) != 0:
            if pairs[0][0] != '[':
                pre_string = pairs[0]
                pairs.pop(0)
            else:
                pairs[0] = pairs[0][1:]

        for p in pairs:
            if len(p.split(']:')) != 2:
                continue
            key = p.split(']:')[0].strip()
            value = p.split(']:')[1]
            d[key] = value
    return d, pre_string