This is a "factory" procedure that creates a new canvas.T object.
    Both parameters, <fname> and
    <format>, are optional. Parameter <fname> specifies either the output
    file name or a file object. Parameter <format>, if specified, defines the
    file's format. Its value must be one of "ps", "pdf", "svg", "x11", or
    "png".

    When <fname> is omitted or is None, the output is sent to standard
    output. When <format> is omitted, it is guessed from the <fname>'s
    suffix; failing that, "ps" is selected.

def init(fname=None, format=None):
    """This is a "factory" procedure that creates a new canvas.T object.
    Both parameters, <fname> and
    <format>, are optional. Parameter <fname> specifies either the output
    file name or a file object. Parameter <format>, if specified, defines the
    file's format. Its value must be one of "ps", "pdf", "svg", "x11", or
    "png".

    When <fname> is omitted or is None, the output is sent to standard
    output. When <format> is omitted, it is guessed from the <fname>'s
    suffix; failing that, "ps" is selected."""

    fname = fname or theme.output_file
    format = format or theme.output_format

    if format == None:
        if not isinstance(fname, str):
            format = "ps"
        elif re.search("pdf$", fname):
            format = "pdf"
        elif re.search("png$", fname):
            format = "png"
        elif re.search("svg$", fname):
            format = "svg"
        else:
            format = "ps"

    if format == "ps":
        can = pscanvas.T(fname)
    elif format == "png":
        can = pngcanvas.T(fname)
    elif format == "x11":
        can = x11canvas.T(fname)
    elif format == "svg":
        can = svgcanvas.T(fname)
    elif format == "pdf-uncompressed":
        can = pdfcanvas.T(fname, False)
    else:
        can = pdfcanvas.T(fname, theme.compress_output)
    return can