def _canonicalize_extension(ext):
    """Returns a transformed ext that has a uniform pattern.
    Specifically, if ``ext`` has a leading . then it is simply returned.
    If ``ext`` doesn't have a leading . then it is prepended.
    Exceptions to this are if ``ext`` is ``None`` or "". If ``ext``
    is "" then "" is return. If ``ext`` is None then None is returned.

    :param ext: The extension to canonicalize.
    :returns: The canonicalized extension.

    """
    if ext is None or ext == "" or ext.startswith("."):
        return ext
    return "." + ext