[Zope3-checkins] CVS: Zope3/src/zope/interface - declarations.py:1.4
Jim Fulton
jim@zope.com
Tue, 6 May 2003 07:08:31 -0400
Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv14432/zope/interface
Modified Files:
declarations.py
Log Message:
Changed the way declarations are handled for instances of classes
(like ExtensionClasses) that don't support descriptors. Now, when we
get the value that's supposed to be provided by the descriptor, we
check whether we get the right thing and, if not, we simply do the
work of the descriptor ourselves. With this change, you can use most
of the new declaration API with these classes. Note however, that you
can't declare interfaces implemented by these classes.
Also assed an assertion to check a partocular edget case.
=== Zope3/src/zope/interface/declarations.py 1.3 => 1.4 ===
--- Zope3/src/zope/interface/declarations.py:1.3 Sat May 3 12:36:19 2003
+++ Zope3/src/zope/interface/declarations.py Tue May 6 07:08:00 2003
@@ -485,6 +485,8 @@
1
"""
+ only = True
+
def __init__(self, ob):
self.ob = ob
@@ -530,6 +532,11 @@
implements = getattr(c, '__implements__', None)
if implements is not None:
+ assert ((implements.__class__ == tuple)
+ or
+ (InterfaceClass in
+ implements.__class__.__mro__)
+ )
result.append(`implements`)
else:
@@ -606,7 +613,14 @@
# or a descriptor
try:
- r = ob.__providedBy__
+ r = ob.__providedBy__
+
+ # We might have gotten a descriptor from an instance of a
+ # class (like an ExtensionClass) that doesn't support
+ # descriptors. We'll make sure we got one by trying to get
+ # the only attribute, which all specs have.
+ r.only
+
except AttributeError:
# No descriptor, so fall back to a plain object spec
r = ObjectSpecification(ob)
@@ -1124,10 +1138,7 @@
if flags & heap:
cls.__implements__ = v
-
- # Only set up the descriptor if the class supports descriptors
- if isinstance(cls, DescriptorAwareMetaClasses):
- cls.__providedBy__ = _objectSpecificationDescriptor
+ cls.__providedBy__ = _objectSpecificationDescriptor
else:
_implements_reg[cls] = v