[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Annotation - AttributeAnnotations.py:1.1.2.1 IAnnotatable.py:1.1.2.1 IAnnotations.py:1.1.2.1 IAttributeAnnotatable.py:1.1.2.1 __init__.py:1.1.2.1 annotation.zcml:1.1.2.1

Steve Alexander steve@cat-box.net
Sun, 26 May 2002 12:10:26 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Annotation
In directory cvs.zope.org:/tmp/cvs-serv3979/lib/python/Zope/App/OFS/Annotation

Added Files:
      Tag: Zope-3x-branch
	AttributeAnnotations.py IAnnotatable.py IAnnotations.py 
	IAttributeAnnotatable.py __init__.py annotation.zcml 
Log Message:
Changed MementoBag to Annotations as per collector issue 66
http://collector.zope.org/Zope3-dev/66

Note that this will break pre-existing __memobag__ attributes in
persistent objects.


=== Added File Zope3/lib/python/Zope/App/OFS/Annotation/AttributeAnnotations.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.
# 
##############################################################################
"""

$Id: AttributeAnnotations.py,v 1.1.2.1 2002/05/26 16:10:25 stevea Exp $
"""

from Persistence.BTrees.OOBTree import OOBTree
from IAnnotations import IAnnotations

class AttributeAnnotations:

    """
    Store annotations in the __annotations__ attribute on a
    IAttributeAnnotatable object.
    """
    
    __implements__ = IAnnotations

    def __init__(self,obj):
        self.obj = obj
        
    def __getitem__(self, key):
        annotations = getattr(self.obj, '__annotations__', {})
        return annotations[key]
        
    def get(self, key, default=None):
        try:
            return self.obj.__annotations__.get(key, default)
        except AttributeError:
            return default

    def __getattr__(self,attr):
        try:
            return getattr(self.obj.__annotations__, attr)
        except AttributeError:
            if not hasattr(self.obj, '__annotations__'):
                annotations = self.obj.__annotations__ = OOBTree()
                return getattr(annotations, attr)
            raise
            


=== Added File Zope3/lib/python/Zope/App/OFS/Annotation/IAnnotatable.py ===
##############################################################################
#
# Copyright (c) 2001 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
#
##############################################################################
"""

$Id: IAnnotatable.py,v 1.1.2.1 2002/05/26 16:10:25 stevea Exp $
"""
from Interface import Interface
from Interface.Attribute import Attribute

class IAnnotatable(Interface):
    """
    Marker interface for objects that support storing annotations.
    
    This interface says "There exists an adapter to an IAnnotations
    for an object that implements IAnnotatable".
    
    Classes should not directly declare that they implement this interface.
    Instead they should implement an interface derived from this one, which
    details how the annotations are to be stored, such as
    IAttributeAnnotatable.
    """


=== Added File Zope3/lib/python/Zope/App/OFS/Annotation/IAnnotations.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.
# 
##############################################################################
"""

$Id: IAnnotations.py,v 1.1.2.1 2002/05/26 16:10:25 stevea Exp $
"""
from Interface import Interface

class IAnnotations(Interface):
    """
    Annotations store arbitrary application data under package unique keys
    """

    def __getitem__(key):
        """
        Return the annotation stored under key.

        Raises KeyError if key not found.
        """

    def get(key, default=None):
        """
        Return the annotation stored under key, returning default if not found.
        """

    def __setitem__(key, memento):
        """
        Store annotation under key.

        In order to avoid key collisions, users of this interface must
        use their dotted package name as part of the key name.
        """

    def __delitem__(key):
        """
        Removes the annotation stored under key.

        Raises a KeyError if the key is not found.
        """


=== Added File Zope3/lib/python/Zope/App/OFS/Annotation/IAttributeAnnotatable.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.
# 
##############################################################################
"""

$Id: IAttributeAnnotatable.py,v 1.1.2.1 2002/05/26 16:10:25 stevea Exp $
"""
from IAnnotatable import IAnnotatable
from Interface.Attribute import Attribute

class IAttributeAnnotatable(IAnnotatable):
    """
    Marker interface giving permission for an IAnnotations adapter to store
    data in an an attribute named __annotations__.
    """

    __annotations__ = Attribute(
        """
        This attribute may be used by an IAnnotations adapter to
        store pickleable data in.  The object implementing this
        interface promises not to touch the attribute other than
        to persist it.
        """)


=== Added File Zope3/lib/python/Zope/App/OFS/Annotation/__init__.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.
# 
##############################################################################
 


=== Added File Zope3/lib/python/Zope/App/OFS/Annotation/annotation.zcml ===
<zopeConfigure
    xmlns='http://namespaces.zope.org/zope'
>

<adapter
    factory=".AttributeAnnotations."
    provides=".IAnnotations."
    for=".IAttributeAnnotatable." />

</zopeConfigure>