def force_encoding(encoding=None):
    """Validates an encoding value.

    If `encoding` is None use `locale.getdefaultlocale`:func:.  If that is
    also none, return 'UTF-8'.

    .. versionadded:: 1.2.0

    .. versionchanged:: 1.8.0 migrated to 'future.codecs'

    .. versionchanged:: 1.8.7 Stop using `locale.getpreferrededencoding`:func:
       and improve documentation.

    """
    import locale
    return encoding or locale.getdefaultlocale()[1] or 'UTF-8'
