def METHOD_NAME(torrent, path):
    """
    `torrent` must be a Torrent instance and `path` must be a sequence of nested
    directory names in the tree `torrent['files']`
    Empty strings in `path` are ignored (like `ls foo//bar///baz` also works).
    If `torrent` is a single-file torrent or any item in `path[:-1]` points to a
    leaf or doesn't exist, return None.  Otherwise, return the subtree or
    file/leaf that `path` points to.  (To clarify: the last item in `path` may
    not exist, in which case its parent tree is returned.)
    """
    tree = torrent['files'][torrent['name']]
    if tree.nodetype == 'leaf':
        # `torrent` is single-file torrent
        return None
    else:
        for i,part in enumerate(path):
            if part:
                subtree = tree.get(part)
                is_last_part = i == len(path) - 1
                if subtree is None:
                    if not is_last_part:
                        return None
                elif subtree.nodetype == 'leaf' and is_last_part:
                    return subtree
                elif subtree.nodetype == 'parent':
                    tree = subtree
                else:
                    # An item in `path[:-1]` points to a leaf.  We can't use
                    # files as subtrees.
                    return None
        return tree