# Buggy code
def validate_config_values(app):
    # type: (Sphinx) -> None
    if app.config.latex_toplevel_sectioning not in (None, "part", "chapter", "section"):
        logger.warning(
            "invalid latex_toplevel_sectioning, ignored: %s",
            app.config.latex_toplevel_sectioning,
        )
        app.config.latex_toplevel_sectioning = None  # type: ignore

    if "footer" in app.config.latex_elements:
        if "postamble" in app.config.latex_elements:
            logger.warning(
                "latex_elements['footer'] conflicts with "
                "latex_elements['postamble'], ignored."
            )
        else:
            warnings.warn(
                "latex_elements['footer'] is deprecated. "
                "Use latex_elements['preamble'] instead.",
                RemovedInSphinx17Warning,
            )
            app.config.latex_elements["postamble"] = app.config.latex_elements["footer"]

    if app.config.latex_keep_old_macro_names:
        warnings.warn(
            "latex_keep_old_macro_names is deprecated. "
            "LaTeX markup since Sphinx 1.4.5 uses only prefixed macro names.",
            RemovedInSphinx17Warning,
        )


# Traceback (UnicodeDecodeError)
# Sphinx version: 1.5.6
# Python version: 2.7.13 (CPython)                                                            # Docutils version: 0.13.1 release
# Jinja2 version: 2.9.6                                                                       # Last messages:
#   materijali/spamassasin-spam-filter                                                        #   materijali/bind9-dns-sustav
#   materijali/avahi-zeroconf                                                                 #   materijali/screen-tmux-multipleksiranje-terminala
#   kolegiji/RM-RiTeh                                                                         #   kolegiji/NRM-RiTeh
#   materijali/index                                                                          #
#   resolving references...                                                                   #   writing...
# Loaded extensions:                                                                          #   sphinx.ext.mathjax (1.5.6) from /usr/lib/python2.7/dist-packages/sphinx/ext/mathjax.pyc
#   sphinx.ext.graphviz (1.5.6) from /usr/lib/python2.7/dist-packages/sphinx/ext/graphviz.pyc #   sphinx.ext.todo (1.5.6) from /usr/lib/python2.7/dist-packages/sphinx/ext/todo.pyc
#   alabaster (0.7.8) from /usr/lib/python2.7/dist-packages/alabaster/__init__.pyc            Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/cmdline.py", line 296, in main                    app.build(opts.force_all, filenames)
File "/usr/lib/python2.7/dist-packages/sphinx/application.py", line 333, in build               self.builder.build_update()
File "/usr/lib/python2.7/dist-packages/sphinx/builders/__init__.py", line 246, in build_update
self.build(['__all__'], to_build)                                                           File "/usr/lib/python2.7/dist-packages/sphinx/builders/__init__.py", line 322, in build
self.write(docnames, list(updated_docnames), method)                                        File "/usr/lib/python2.7/dist-packages/sphinx/builders/latex.py", line 130, in write
docwriter.write(doctree, destination)                                                       File "/usr/lib/python2.7/dist-packages/docutils/writers/__init__.py", line 80, in write
self.translate()                                                                            File "/usr/lib/python2.7/dist-packages/sphinx/writers/latex.py", line 162, in translate
self.output = visitor.astext()                                                              File "/usr/lib/python2.7/dist-packages/sphinx/writers/latex.py", line 576, in astext
return LaTeXRenderer().render(DEFAULT_TEMPLATE, self.elements)                              File "/usr/lib/python2.7/dist-packages/sphinx/util/template.py", line 25, in render
return self.env.get_template(template_name).render(context)                                 File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)                                    File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)                                                            File "/usr/share/sphinx/templates/latex/content.tex_t", line 51, in top-level template code
<%= printindex %>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 13: ordinal not in range(128)

# Fixed code
def validate_config_values(app):
    # type: (Sphinx) -> None
    if app.config.latex_toplevel_sectioning not in (None, "part", "chapter", "section"):
        logger.warning(
            "invalid latex_toplevel_sectioning, ignored: %s",
            app.config.latex_toplevel_sectioning,
        )
        app.config.latex_toplevel_sectioning = None  # type: ignore

    if "footer" in app.config.latex_elements:
        if "postamble" in app.config.latex_elements:
            logger.warning(
                "latex_elements['footer'] conflicts with "
                "latex_elements['postamble'], ignored."
            )
        else:
            warnings.warn(
                "latex_elements['footer'] is deprecated. "
                "Use latex_elements['preamble'] instead.",
                RemovedInSphinx17Warning,
            )
            app.config.latex_elements["postamble"] = app.config.latex_elements["footer"]

    if app.config.latex_keep_old_macro_names:
        warnings.warn(
            "latex_keep_old_macro_names is deprecated. "
            "LaTeX markup since Sphinx 1.4.5 uses only prefixed macro names.",
            RemovedInSphinx17Warning,
        )

    for document in app.config.latex_documents:
        try:
            text_type(document[2])
        except UnicodeDecodeError:
            raise ConfigError(
                "Invalid latex_documents.title found (might contain non-ASCII chars. "
                'Please use u"..." notation instead): %r' % (document,)
            )

        try:
            text_type(document[3])
        except UnicodeDecodeError:
            raise ConfigError(
                "Invalid latex_documents.author found (might contain non-ASCII chars. "
                'Please use u"..." notation instead): %r' % (document,)
            )