Ejemplo n.º 1
0
def getParents(obj):
    """Returns a list starting with the given object's parent followed by
    each of its parents.

    Raises a TypeError if the context doesn't go all the way down to
    a containment root.
    """
    if IContainmentRoot.providedBy(obj):
        return []

    
    parents = []
    w = obj
    while 1:
        w = w.__parent__
        if w is None:
            break
        parents.append(w)

    if parents and IContainmentRoot.providedBy(parents[-1]):
        return parents

    raise TypeError("Not enough context information to get all parents")
Ejemplo n.º 2
0
def getParent(obj):
    """Returns the container the object was traversed via.

    Returns None if the object is a containment root.
    Raises TypeError if the object doesn't have enough context to get the
    parent.
    """
    
    if IContainmentRoot.providedBy(obj):
        return None
    
    parent = getattr(obj, '__parent__', None)
    if parent is not None:
        return parent

    raise TypeError("Not enough context information to get parent", obj)