[Checkins] SVN: zope.interface/branches/tlotze-component-API/src/zope/interface/interface.py added adapt and utility methods to interfaces as a kind of prototype
Thomas Lotze
tl at gocept.com
Mon Dec 14 05:36:24 EST 2009
Log message for revision 106479:
added adapt and utility methods to interfaces as a kind of prototype
Changed:
U zope.interface/branches/tlotze-component-API/src/zope/interface/interface.py
-=-
Modified: zope.interface/branches/tlotze-component-API/src/zope/interface/interface.py
===================================================================
--- zope.interface/branches/tlotze-component-API/src/zope/interface/interface.py 2009-12-14 10:35:24 UTC (rev 106478)
+++ zope.interface/branches/tlotze-component-API/src/zope/interface/interface.py 2009-12-14 10:36:24 UTC (rev 106479)
@@ -689,9 +689,32 @@
#print '>', self, other, c > 0, c
return c > 0
+ def adapt(self, *obj, **options):
+ default = options.pop('default', _marker)
+ for hook in component_hooks:
+ adapter = hook(self, obj, **options)
+ if adapter is not None:
+ return adapter
+ if default is not _marker:
+ return default
+ raise TypeError('Could not adapt', obj, self, options)
+ def utility(self, **options):
+ default = options.pop('default', _marker)
+ for hook in component_hooks:
+ utility = hook(self, (), **options)
+ if utility is not None:
+ return utility
+ if default is not _marker:
+ return default
+ raise TypeError('Could not find utility', self, options)
+
+
Interface = InterfaceClass("Interface", __module__ = 'zope.interface')
+component_hooks = []
+
+
class Attribute(Element):
"""Attribute descriptions
"""
More information about the checkins
mailing list