ztfy/utils/traversing.py
changeset 14 c5b819c782dd
parent 7 1d29e2389bd3
child 15 2c187bbb521f
equal deleted inserted replaced
13:6eddd17108b1 14:c5b819c782dd
    30 def getParent(context, interface=Interface, allow_context=True):
    30 def getParent(context, interface=Interface, allow_context=True):
    31     """Get first parent of the given context that implements given interface"""
    31     """Get first parent of the given context that implements given interface"""
    32     if allow_context:
    32     if allow_context:
    33         parent = context
    33         parent = context
    34     else:
    34     else:
    35         parent = zapi.getParent(context)
    35         parent = getattr(context, '__parent__', None)
    36     while parent is not None:
    36     while parent is not None:
    37         if interface.providedBy(parent):
    37         if interface.providedBy(parent):
    38             return interface(parent)
    38             return interface(parent)
    39         parent = zapi.getParent(parent)
    39         parent = getattr(parent, '__parent__', None)
    40     return None
    40     return None