def find_parent(obj, which): if isinstance(obj, mutable.Document): return None if mutable.istype(obj.parent, which): return obj.parent else: return find_parent(obj.parent, which)
def find_parent_deep(obj, which): if isinstance(obj, mutable.Document): return None if mutable.istype(obj.parent, which): while mutable.isinside(obj.parent, which): obj = obj.parent return obj.parent else: return find_parent(obj.parent, which)