From bb5d643b83cde30d2fa37aaae21a8d4b225f584b Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 20 Jul 2008 03:04:58 +0000 Subject: - Add find_interface API. --- repoze/bfg/traversal.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'repoze/bfg/traversal.py') diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py index a9f127841..ee66ae887 100644 --- a/repoze/bfg/traversal.py +++ b/repoze/bfg/traversal.py @@ -3,6 +3,7 @@ import urllib from zope.interface import classProvides from zope.interface import implements from zope.location.location import located +from zope.location.location import LocationIterator from zope.location.interfaces import ILocation from repoze.bfg.interfaces import ITraverser @@ -63,3 +64,10 @@ class NaiveTraverser(object): return ob, name, path +def find_interface(context, interface): + """ Return an object providing 'interface' anywhere in the parent + chain of 'context' or None if no object providing that interface + can be found in the parent chain """ + for location in LocationIterator(context): + if interface.providedBy(location): + return location -- cgit v1.2.3