def METHOD_NAME(builder, docname, maxdepth=-1):
    """Return a TOC nodetree -- for use on the same page only!"""
    env = builder.env
    if maxdepth < 0:
        maxdepth = env.metadata[docname].get('tocdepth', 0)
    toctree = TocTree(env)
    try:
        toc = env.tocs[docname].deepcopy()
        toctree._toctree_prune(toc, 2, maxdepth)
    except KeyError:
        # the document does not exist anymore: return a dummy node that
        # renders to nothing
        return nodes.paragraph()
    sphinx_nodes.process_only_nodes(toc, builder.tags)
    for node in toc.traverse(nodes.reference):
        node['refuri'] = node['anchorname'] or '#'
    return toc