[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container - SampleContainer.py:1.1.2.1 __init__.py:1.1.2.1 container.zcml:1.1.2.1

Jim Fulton jim@zope.com
Mon, 4 Mar 2002 11:46:26 -0500


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

Added Files:
      Tag: Zope-3x-branch
	SampleContainer.py __init__.py container.zcml 
Log Message:
Added base-class framework for container content types, views, and
tests.

Among other things, this provides a framework for building interface
tests that can be subclasses by tests for implementation of the
interfaces.



=== Added File Zope3/lib/python/Zope/App/OFS/Container/SampleContainer.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
# 
##############################################################################
"""
This module provides a sample container implementation.

This is primarily for testing purposes.

It might be useful as a mix-in for some classes, but many classes will
need a very different implementation.

Revision information:
$Id: SampleContainer.py,v 1.1.2.1 2002/03/04 16:46:24 jim Exp $
"""

from Zope.App.OFS.IContainer import IContainer

_marker = object()

class Container(object):

    __implements__ =  IContainer

    def __init__(self):
        self.__data = self._Container__newData()

    def _Container__newData(self):
        """Construct an item-data container

        Subclasses should override this if they want different data.

        The value returned is a mapping object that also has get,
        has_key, keys, items, and values methods.
        """
        return {}

    ############################################################
    # Implementation methods for interface
    # Zope.App.OFS.IContainer

    def objectIds(self):
        '''See interface IReadContainer'''
        return self.__data.keys()

    def getObject(self, name, default=_marker):
        '''See interface IReadContainer'''
        v = self.__data.get(name, default)
        if v is _marker:
            raise KeyError, name
        return v

    def objectValues(self):
        '''See interface IReadContainer'''
        return self.__data.values()

    def objectCount(self):
        '''See interface IReadContainer'''
        return len(self.__data)

    def objectItems(self):
        '''See interface IReadContainer'''
        return self.__data.items()

    def hasObject(self, name):
        '''See interface IReadContainer'''
        return self.__data.has_key(name)

    def setObject(self, name, object):
        '''See interface IWriteContainer'''
        self.__data[name] = object

    def delObject(self, name):
        '''See interface IWriteContainer'''
        del self.__data[name]
    #
    ############################################################


=== Added File Zope3/lib/python/Zope/App/OFS/Container/__init__.py ===
"""Provide generic container support components
"""


=== Added File Zope3/lib/python/Zope/App/OFS/Container/container.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:security='http://namespaces.zope.org/security'
   xmlns:zmi='http://namespaces.zope.org/zmi'
   xmlns:browser='http://namespaces.zope.org/browser'
>

<security:protectClass name="Zope.App.OFS.Folder."
   permission_id="Zope.View">
  <security:instances permission_id="Zope.View" />
  <security:protect
      interface="Zope.ComponentArchitecture.IServiceManagerContainer." 
      permission_id="Zope.ManageServices" />
</security:protectClass>

<security:protectClass name="Zope.App.OFS.Container.ContentsView."
   permission_id="Zope.ManageContent" 
   methods="index, listContentInfo, removeObjects, remove" />

</zopeConfigure>