# Buggy code
def valid_locale_fallback(desired_locale=None):
    """Provide a default fallback_locale, a string that locale.setlocale will accept.

    If desired_locale is provided must be of type str for py2x compatibility
    """
    # Whenever fallbacks change, adjust test TestHarcodedFallbacksWork
    candidates_windows = [str("English"), str("C")]
    candidates_posix = [str("en_US.utf8"), str("C")]
    candidates = candidates_windows if sys.platform == "win32" else candidates_posix
    if desired_locale:
        candidates = list(candidates)
        candidates.insert(0, desired_locale)
    found_valid = False
    for locale_n in candidates:
        found_valid = is_valid_locale(locale_n)
        if found_valid:
            break
    if not found_valid:
        msg = "Could not find a valid fallback locale, tried: {0}"
        utils.LOGGER.warn(msg.format(candidates))
    elif desired_locale and (desired_locale != locale_n):
        msg = "Desired fallback locale {0} could not be set, using: {1}"
        utils.LOGGER.warn(msg.format(desired_locale, locale_n))
    return locale_n


# Traceback (UnicodeDecodeError)
[2015-10-07T18:13:19Z] WARNING: Nikola: Could not guess locale for language de, using locale C
[2015-10-07T18:13:20Z] ERROR: yapsy: Unable to import plugin: /usr/home/wayne/nikola/blog.cle.ar.it/plugins/ping/ping
Traceback (most recent call last):
File "/usr/home/wayne/nikola/lib/python3.5/site-packages/yapsy/PluginManager.py", line 488, in loadPlugins
candidate_module = imp.load_module(plugin_module_name,plugin_file,candidate_filepath+".py",("py","r",imp.PY_SOURCE))
File "/usr/local/lib/python3.5/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/usr/local/lib/python3.5/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 658, in exec_module
File "<frozen importlib._bootstrap_external>", line 763, in get_code
File "/usr/local/lib/python3.5/imp.py", line 156, in get_data
return file.read()
File "/usr/local/lib/python3.5/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 37: ordinal not in range(128)

# Fixed code
def valid_locale_fallback(desired_locale=None):
    """Provide a default fallback_locale, a string that locale.setlocale will accept.

    If desired_locale is provided must be of type str for py2x compatibility
    """
    # Whenever fallbacks change, adjust test TestHarcodedFallbacksWork
    candidates_windows = [str("English"), str("C")]
    candidates_posix = [str("en_US.UTF-8"), str("C")]
    candidates = candidates_windows if sys.platform == "win32" else candidates_posix
    if desired_locale:
        candidates = list(candidates)
        candidates.insert(0, desired_locale)
    found_valid = False
    for locale_n in candidates:
        found_valid = is_valid_locale(locale_n)
        if found_valid:
            break
    if not found_valid:
        msg = "Could not find a valid fallback locale, tried: {0}"
        utils.LOGGER.warn(msg.format(candidates))
    elif desired_locale and (desired_locale != locale_n):
        msg = "Desired fallback locale {0} could not be set, using: {1}"
        utils.LOGGER.warn(msg.format(desired_locale, locale_n))
    return locale_n