[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/AddableService - Addable.py:1.1.2.1 GlobalAddableService.py:1.1.2.1 IAddable.py:1.1.2.1 IAddableService.py:1.1.2.1 __init__.py:1.1.2.1 addable-service.zcml:1.1.2.1 hooks.py:1.1.2.1

Gary Poster garyposter@earthlink.net
Mon, 22 Apr 2002 15:03:23 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/AddableService
In directory cvs.zope.org:/tmp/cvs-serv31509/App/OFS/Services/AddableService

Added Files:
      Tag: Zope-3x-branch
	Addable.py GlobalAddableService.py IAddable.py 
	IAddableService.py __init__.py addable-service.zcml hooks.py 
Log Message:
1. As per ZopeTop discussion, moved Addable out of ZMI into the Services folder, and turned it into a true service (this involved a lot of small changes, particularly in the folders and a number of tests) and gave it some hooks
2. used SteveA's ContextWrapper.ContextMethod to make the ServiceManager and Services placefully look up to parent placeful equivalents
3. Made Event into a more standard service, and gave it some hooks
4. Built the beginning of a placeful EventService (will need tests, and views, and EventChannels, and more meat; just wanted to check this in for now)
5. made it so you can't add an item to a folder with a blank string id, and updated the folder interface
6. some typos fixed here and there
7. a few more tests here and there

I'm checking this in then checking it out again to check my work; also tagged previous version as gary-service_update.



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

Revision information: $Id: Addable.py,v 1.1.2.1 2002/04/22 19:03:22 poster Exp $
"""

"Keep track of add-menu contents"

from IAddable import IAddable

class Addable(object):
    
    __implements__=IAddable

    def __init__(self, id, title, description, icon=None, marker_interface=None):
        self.__id = id
        self.title = title
        self.description = description
        self.icon = icon
        if marker_interface:
            if hasattr(self, "__implements__"): 
                # not checking to see if already there...
                self.__implements__ = marker_interface, self.__implements__
            else: self.__implements__=marker_interface

    def __getid(self): return self.__id
    
    id=property(__getid)
    
    def __eq__(self, other):
        try:
            i, t, d = other.id, other.title, other.description
        except AttributeError:
            return 0
        
        return self.id == i and self.title == t and self.description == d

    

=== Added File Zope3/lib/python/Zope/App/OFS/Services/AddableService/GlobalAddableService.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.
# 
##############################################################################
"""
generic AddableContentService

$Id: GlobalAddableService.py,v 1.1.2.1 2002/04/22 19:03:22 poster Exp $
"""
from Zope.ComponentArchitecture import getService
from IAddableService import IAddableService
from Addable import Addable

class GlobalAddableService: # file system
    
    __implements__=IAddableService

    def provideAddable(self, id, title, description, marker_interface=None):
        self.__reg.append(Addable(id, title, description, marker_interface=marker_interface))

    def getAddables(self, ob):
        return self.__reg[:]
    
    def _clear(self):
        self.__reg = []

    __init__ = _clear

addableContent=GlobalAddableService()
addableServices=GlobalAddableService()


def _clear():
    addableContent._clear()
    addableServices._clear()


# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
from Zope.Testing.CleanUp import addCleanUp
addCleanUp(_clear)
del addCleanUp

=== Added File Zope3/lib/python/Zope/App/OFS/Services/AddableService/IAddable.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.
# 
##############################################################################
"""Keep track of add-menu contents

Revision information: $Id: IAddable.py,v 1.1.2.1 2002/04/22 19:03:22 poster Exp $
"""

from Interface import Interface
from Interface.Attribute import Attribute


class IAddable(Interface):
    """objects that present a more human-readable front to factories."""
    
    def __init__(id, title, description, icon, createViewMarkers):
        """attributes as below, with createViewMarkers going into
        __mutable_implements__ (see IMutableInterfaceClass)"""
    
    id = Attribute (
        """the name that the factory services should recognize to create
        this kind of object.
        
        read-only, set in __init__.""")
    
    title = Attribute (
        """the human readable name for this type of addable: has no
        further significance
        
        read-write""")
    
    description = Attribute(
        """the human readable description for this type of addable: has
        no further significance.
        
        read-write""")
    
    icon = Attribute(
        """the icon for this addable type; implementation TBA (i.e.,
        name for view resource, actual image object, etc. unknown at
        this time)
        
        read-write""")

    

=== Added File Zope3/lib/python/Zope/App/OFS/Services/AddableService/IAddableService.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.
# 
##############################################################################
"""
generic AddableService

$Id: IAddableService.py,v 1.1.2.1 2002/04/22 19:03:22 poster Exp $
"""
from Interface import Interface

class IAddableService(Interface):
    """The common denominator for all addables services.  Addables are
    the """
    
    def getAddables(container):
        """returns the addables available from this service for the
        service's context, as limited by what factory names are also
        available in the same context, and as further limited by what
        addables and factories are registered to be added to the
        interfaces implemented by the container"""
    
    def provideAddable(name, addable):
        """adds addable to service, associated with name
        
        raises DuplicateError if name is already used in this service"""



=== Added File Zope3/lib/python/Zope/App/OFS/Services/AddableService/__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.
# 
##############################################################################
""" Addables """
from hooks import getAddableContent, getAddableServices

=== Added File Zope3/lib/python/Zope/App/OFS/Services/AddableService/addable-service.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=".Addable+"
                         permission_id="Zope.Public"
  		         interface=".IAddable+" />

<serviceType name='AddableContent' 
             interface='.IAddableService+' />
             
<service name='AddableContent'
         component='.GlobalAddableService.addableContent' />
             
<serviceType name='AddableServices' 
             interface='.IAddableService+' />

<service name='AddableServices'
         component='.GlobalAddableService.addableServices' />

<hookable module=".hooks" name="getAddableContent" />
<hookable module=".hooks" name="getAddableServices" />

</zopeConfigure>


=== Added File Zope3/lib/python/Zope/App/OFS/Services/AddableService/hooks.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.
# 
##############################################################################
"""
generic AddableContentService

$Id: hooks.py,v 1.1.2.1 2002/04/22 19:03:22 poster Exp $
"""
from Zope.ComponentArchitecture import getService

# hookables

def getAddableContent(context):
    """return the list of content addables for the given context"""
    return getAddableContent_hook(context)

def getAddableServices(context):
    """return the list  of service addables for the given context"""
    return getAddableServices_hook(context)

# hooks (rely on getService for placeful functionality)

def getAddableContent_hook(context):
    """return the list of content addables for the given context"""
    return getService(context, 'AddableContent').getAddables(context)

def getAddableServices_hook(context):
    """return the list  of service addables for the given context"""
    return getService(context, 'AddableServices').getAddables(context)