'get the next parent node (including ourself)
which is an instance of the given class'

def getparent(self, cls):

    current = self
    while (current and (not isinstance(current, cls))):
        current = current.parent
    return current
