[Zodb-checkins] CVS: Zope3/src/zope/interface - declarations.py:1.1 __init__.py:1.4

Jim Fulton jim at zope.com
Fri Apr 18 19:13:03 EDT 2003


Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv8556/src/zope/interface

Modified Files:
	__init__.py 
Added Files:
	declarations.py 
Log Message:
In prepration for the upcoming interface changes, I added some
new functions for making interface assertions on instances.  

Rather than:

  class C:

     __class_implements__ = I1, I2

use:

  class C:

     classProvides(I1, I2)

rather than:

__implements__ = I1, I2

use:

moduleProvides(I1, I2)

rather than:

someinstance.__implements__ = I1, I2

use:

directlyProvides(I1, I2)

Note that interface assertions on persistent objects should be aboided
since the internal representation will change.

Continue to make assertions about the interfaces that class instances
implement the same way:

  class C:

     __implements__ = I1, I2


I also modified the core software to use the new spellings.



=== Added File Zope3/src/zope/interface/declarations.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Interfaces declarations, forward comptability versions

$Id: declarations.py,v 1.1 2003/04/18 22:12:32 jim Exp $
"""

import sys
from types import ClassType
_ClassTypes = ClassType, type
del ClassType

def directlyProvides(object, *interfaces):
    if isinstance(object, _ClassTypes):
        object.__class_implements__ = interfaces
    else:
        object.__implements__ = interfaces

def classProvides(*interfaces):
    f = sys._getframe(1)
    locals = f.f_locals
    if f.f_globals is locals or "__module__" not in locals:
        raise TypeError("classProvides can only be used in a class definition")
    if "__class_implements__" in locals:
        raise TypeError("classProvides can only be used once "
                        "in a class definition")
    locals["__class_implements__"] = interfaces

def moduleProvides(*interfaces):
    f = sys._getframe(1)
    locals = f.f_locals
    if f.f_globals is not locals or "__name__" not in locals:
        raise TypeError(
            "classProvides can only be used in a module definition")
    if "__implements__" in locals:
        raise TypeError("moduleProvides can only be used once "
                        "in a module definition")
    locals["__implements__"] = interfaces


=== Zope3/src/zope/interface/__init__.py 1.3 => 1.4 ===
--- Zope3/src/zope/interface/__init__.py:1.3	Wed Dec 25 13:30:40 2002
+++ Zope3/src/zope/interface/__init__.py	Fri Apr 18 18:12:32 2003
@@ -77,3 +77,5 @@
 del _wire
 
 from zope.interface.interface import Attribute
+from zope.interface.declarations import directlyProvides
+from zope.interface.declarations import classProvides, moduleProvides




More information about the Zodb-checkins mailing list