[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/AddableService - Addable.py:1.2 GlobalAddableService.py:1.2 IAddable.py:1.2 IAddableService.py:1.2 __init__.py:1.2 addable-service.zcml:1.2 hooks.py:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:28:40 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/AddableService
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/OFS/Services/AddableService
Added Files:
Addable.py GlobalAddableService.py IAddable.py
IAddableService.py __init__.py addable-service.zcml hooks.py
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/App/OFS/Services/AddableService/Addable.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+"Keep track of add-menu contents"
+
+from IAddable import IAddable
+
+class Addable(object):
+
+ __implements__=IAddable
+
+ def __init__(self, id, title, description,
+ for_container=None,
+ creation_markers=None, icon=None):
+ self.__id = id
+ self.title = title
+ self.description = description
+ self.icon = icon
+ self.for_container=for_container
+ if creation_markers:
+ if hasattr(self, "__implements__"):
+ # not checking to see if already there...
+ self.__implements__ = creation_markers, self.__implements__
+ else: self.__implements__=creation_markers
+
+ def __getid(self): return self.__id
+
+ id=property(__getid)
+
+ def __eq__(self, other): # here basically just for unit tests...
+ if not IAddable.isImplementedBy(other):
+ return 0
+ 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
+
+ def __repr__(self): # and for debugging
+ return "<Addable %s (%s)>" % (self.__id, self.title)
+
+
\ No newline at end of file
=== Zope3/lib/python/Zope/App/OFS/Services/AddableService/GlobalAddableService.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+from Zope.ComponentArchitecture import getService, getFactoryInterfaces, \
+ ComponentLookupError
+from IAddableService import IAddableService
+from Addable import Addable
+from Zope.App.OFS.Container.IContainer import IWriteContainer
+from Zope.App.OFS.Container.IContainer import IHomogenousContainer
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
+
+class IGlobalAddableService(IAddableService):
+
+ def provideAddable(self, id, title, description, for_container=None,
+ creation_markers=None):
+ """adds addable to service, associated with id (used in
+ factory service for the class)
+
+ for_container is interface or interface tuple indicating type of
+ container to which this addable can be added (any match in list
+ is sufficient, including subclasses)
+
+ creation_markers are marker interfaces to which one can associate
+ views for this addable (for pre-creation views)
+
+ raises DuplicateError if id is already used in this service"""
+
+def multi_implement_check(interface, object):
+ if type(interface) is tuple:
+ for inter in interface:
+ if multi_implement_check(inter, object):
+ return 1
+ return 0
+ return interface.isImplementedBy(object)
+
+class GlobalAddableService: # file system
+
+ __implements__=IGlobalAddableService
+
+ def provideAddable(self, id, title, description, for_container=None,
+ creation_markers=None):
+ self.__reg.append(Addable(id, title, description,
+ for_container=for_container,
+ creation_markers=creation_markers))
+
+ def getAddables(self, ob, allowed_types=None):
+ clean_object=removeAllProxies(ob)
+ addables=[]
+ for addable in self.__reg:
+ for_c=addable.for_container
+ if not for_c or multi_implement_check(for_c, clean_object):
+
+ try:
+ inter=getFactoryInterfaces(ob, addable.id)
+ except ComponentLookupError:
+ continue
+ if (IHomogenousContainer.isImplementedBy(clean_object)
+ and not
+ ob.isAddable(inter)
+ ):
+ continue
+
+ addables.append(addable)
+ return addables
+
+ 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
=== Zope3/lib/python/Zope/App/OFS/Services/AddableService/IAddable.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+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""")
+
+ for_container = Attribute(
+ """the interfaces of objects that can contain this addable""")
+
+
\ No newline at end of file
=== Zope3/lib/python/Zope/App/OFS/Services/AddableService/IAddableService.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+from Interface import Interface
+
+class IAddableService(Interface):
+ """The common denominator for all addables services. Addables are
+ the Zope-specific front end for the factory service. The
+ functionality relies on the factory service and on the IContainer
+ interface"""
+
+ def getAddables(container):
+ """returns the addables available from this service and its
+ parents for the service's context.
+
+ By default, it is limited by what factory names are also
+ available in the same context; and further limited by what
+ addables and factories are registered to be added to the
+ interfaces implemented by the container; and, if the container
+ implements IWriteContainer, further limited by what interfaces
+ the container supports in its getAddableInterfaces method."""
+
=== Zope3/lib/python/Zope/App/OFS/Services/AddableService/__init__.py 1.1 => 1.2 ===
+#
+# 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 Zope.ComponentArchitecture import getService
+
+def getAddableContent(wrapped_container):
+ """return the list of content addables for the given container"""
+ return getService(wrapped_container,
+ 'AddableContent').getAddables(wrapped_container)
+
+def getAddableServices(wrapped_container):
+ """return the list of service addables for the given container"""
+ return getService(wrapped_container,
+ 'AddableServices').getAddables(wrapped_container)
\ No newline at end of file
=== Zope3/lib/python/Zope/App/OFS/Services/AddableService/addable-service.zcml 1.1 => 1.2 ===
+ 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'
+>
+
+ <content class=".Addable.">
+ <security:allow interface=".IAddable." />
+ </content>
+
+ <serviceType id='AddableContent'
+ interface='.IAddableService.' />
+
+ <service serviceType='AddableContent'
+ component='.GlobalAddableService.addableContent' />
+
+ <serviceType id='AddableServices'
+ interface='.IAddableService.' />
+
+ <service serviceType='AddableServices'
+ component='.GlobalAddableService.addableServices' />
+
+</zopeConfigure>
=== Zope3/lib/python/Zope/App/OFS/Services/AddableService/hooks.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+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)
\ No newline at end of file