Back to index

plone3  3.1.7
interface.py
Go to the documentation of this file.
00001 from zope.interface import Interface, implements
00002 from zope.dottedname.resolve import resolve
00003 
00004 from plone.memoize.view import memoize
00005 
00006 from Acquisition import aq_base
00007 from Products.Five.browser import BrowserView
00008 
00009 from interfaces import IInterfaceInformation
00010 
00011 def resolveInterface(dotted_name):
00012     klass = resolve(dotted_name)
00013     if not issubclass(klass, Interface):
00014         raise ValueError, '%r is not a valid Interface.' % dotted_name
00015     return klass
00016 
00017 class InterfaceInformation(BrowserView):
00018     implements(IInterfaceInformation)
00019     
00020     @memoize
00021     def provides(self, dotted_name):
00022         iface = resolveInterface(dotted_name)
00023         return iface.providedBy(aq_base(self.context))
00024 
00025     @memoize
00026     def class_provides(self, dotted_name):
00027         iface = resolveInterface(dotted_name)
00028         return iface.providedBy(aq_base(self.context).__class__)