Repository: matplotlib/matplotlib
File: lib/matplotlib/sphinxext/plot_directive.py (Python)

Code before:
        elif isinstance(fmt, (tuple, list)) and len(fmt) == 2:
            formats.append((str(fmt[0]), int(fmt[1])))
        else:
            raise PlotError('invalid image format "%r" in plot_formats' % fmt)
    return formats


def _parse_srcset(entries):
    """
    Parse srcset for multiples...
    """
    srcset = {}
    for entry in entries:
        entry = entry.strip()
        if len(entry) >= 2:
            mult = entry[:-1]
            srcset[float(mult)] = entry
        else:
            raise ExtensionError(f'srcset argument {entry!r} is invalid.')
    return srcset


def check_output_base_name(env, output_base):
    docname = env.docname

    if '.' in output_base or '/' in output_base:
        raise PlotError(
            f"The image-basename '{output_base}' is invalid. "
            f"It must not contain dots or slashes.")

    for d in env.mpl_plot_image_basenames:
        if output_base in env.mpl_plot_image_basenames[d]:
            if d == docname:
                raise PlotError(
                    f"The image-basename "
                    f"{output_base}' is used multiple times.")
            raise PlotError(f"The image-basename "
                            f"'{output_base}' is used multiple times "
                            f"(it is also used in {env.doc2path(d)}).")

    env.mpl_plot_image_basenames[docname].add(output_base)


def render_figures(code, code_path, output_dir, output_base, context,
                   function_name, config, context_reset=False,
                   close_figs=False,
                   code_includes=None):
    """
    Run a pyplot script and save the images in *output_dir*.

    Save the images under *output_dir* with file names derived from

Review comment (suggestion):
Since this is passed through `Path`, etc., you should also check for `\\`.

Code after:
                formats.append((fmt, default_dpi.get(fmt, 80)))
        elif isinstance(fmt, (tuple, list)) and len(fmt) == 2:
            formats.append((str(fmt[0]), int(fmt[1])))
        else:
            raise PlotError('invalid image format "%r" in plot_formats' % fmt)
    return formats


def _parse_srcset(entries):
    """
    Parse srcset for multiples...
    """
    srcset = {}
    for entry in entries:
        entry = entry.strip()
        if len(entry) >= 2:
            mult = entry[:-1]
            srcset[float(mult)] = entry
        else:
            raise ExtensionError(f'srcset argument {entry!r} is invalid.')
    return srcset


def check_output_base_name(env, output_base):
    docname = env.docname

    if '.' in output_base or '/' in output_base or '\\' in output_base:
        raise PlotError(
            f"The filename-prefix '{output_base}' is invalid. "
            f"It must not contain dots or slashes.")

    for d in env.mpl_plot_image_basenames:
        if output_base in env.mpl_plot_image_basenames[d]:
            if d == docname:
                raise PlotError(
                    f"The filename-prefix {output_base!r} is used multiple times.")
            raise PlotError(f"The filename-prefix {output_base!r} is used multiple"
                            f"times (it is also used in {env.doc2path(d)}).")

    env.mpl_plot_image_basenames[docname].add(output_base)


def render_figures(code, code_path, output_dir, output_base, context,
                   function_name, config, context_reset=False,
                   close_figs=False,
                   code_includes=None):
    """
    Run a pyplot script and save the images in *output_dir*.

    Save the images under *output_dir* with file names derived from
    *output_base*