Back to index

plone3  3.1.7
Functions
five.localsitemanager.utils Namespace Reference

Functions

def get_parent

Function Documentation

Returns the container the object was traversed via.  This
is a version of zope.traversing.api.getParent that is designed to
handle acquisition as well.

Returns None if the object is a containment root.
Raises TypeError if the object doesn't have enough context to get the
parent.

Definition at line 6 of file utils.py.

00006 
00007 def get_parent(obj):
00008     """Returns the container the object was traversed via.  This
00009     is a version of zope.traversing.api.getParent that is designed to
00010     handle acquisition as well.
00011 
00012     Returns None if the object is a containment root.
00013     Raises TypeError if the object doesn't have enough context to get the
00014     parent.
00015     """
00016     
00017     if IContainmentRoot.providedBy(obj):
00018         return None
00019     
00020     parent = getattr(obj, '__parent__', None)
00021     if parent is not None:
00022         return parent
00023 
00024     parent = aq_parent(aq_inner(obj))
00025     if parent is not None:
00026         return parent
00027 
00028     raise TypeError("Not enough context information to get parent", obj)

Here is the caller graph for this function: