@classmethod
def get_parent_of(cls, segment, root_segment):
    """Return the segment immediately containing segment.

        NB: This is recursive.

        Args:
            segment: The segment to look for.
            root_segment: Some known parent of the segment
                we're looking for (although likely not the
                direct parent in question).

        """
    if segment in root_segment.segments:
        return root_segment
    elif root_segment.segments:
        for sub in root_segment.segments:
            p = cls.get_parent_of(segment, sub)
            if p:
                return p
    return None
