[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZMI - metaConfigure.py:1.1.2.9

Stephan Richter srichter@cbu.edu
Tue, 2 Apr 2002 17:26:46 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/ZMI
In directory cvs.zope.org:/tmp/cvs-serv22467

Added Files:
      Tag: Zope-3x-branch
	metaConfigure.py 
Log Message:
Issue 54: Resolve

Cleaned up the ZMI namespace quiet a bit:

- Removed the deprecated provideClass directive from the Code.
- Added "class" attribute to factoryFromClass to the "zmi" and "service"
  namespace.
- Changed existing directives to reflect this change.
- Corrected tests.


=== Zope3/lib/python/Zope/App/ZMI/metaConfigure.py 1.1.2.8 => 1.1.2.9 ===
+#
+# 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.
+# 
+##############################################################################
+""" ZMI Addable Registration
+
+$Id$
+"""
+
+
+from Zope.Configuration.Action import Action
+from Zope.ComponentArchitecture.IFactory import IFactory
+from Zope.ComponentArchitecture import provideFactory
+import Addable
+
+class ClassFactory:
+    __implements__ = IFactory
+
+    def __init__(self, _class, permission):
+        self.__permission__ = permission
+        self._class = _class
+
+    def __call__(self):
+        return self._class()
+
+
+def provideClass(registry, qualified_name, _class, permission,
+                 title, description=''):
+    """Provide simple class setup
+
+    - create a component
+
+    - Register as addable
+
+    - register a factory
+
+    - set component permission
+    """
+    factory = ClassFactory(_class, permission)
+    provideFactory(qualified_name, factory)
+    registry.provideAddable(qualified_name, title, description)
+
+
+def ServiceClassDir(_context, name, class_, permission_id, title,
+                    description=''):
+    return [
+        Action(
+            discriminator = name,
+            callable = provideClass,
+            args = (Addable.ServiceAddables, name, _context.resolve(class_),
+                    permission_id, title, description)
+             )
+        ]
+
+
+def ContentClassDir(_context, name, class_, permission_id, title,
+                    description=''):
+    return [
+        Action(
+            discriminator = name,
+            callable = provideClass,
+            args = (Addable.ContentAddables, name, _context.resolve(class_),
+                    permission_id, title, description)
+            )
+        ]