[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture - metaConfigure.py:1.2.12.2

Rakesh Naidu rnaidu@zeomega.com
Mon, 21 Oct 2002 10:56:26 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv4756/Zope3-Bangalore-TTW-Branch/lib/python/Zope/App/ComponentArchitecture

Modified Files:
      Tag: Zope3-Bangalore-TTW-Branch
	metaConfigure.py 
Log Message:
update of metaconfiguration files with actions for interfaces


=== Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py 1.2.12.1 => 1.2.12.2 === (525/625 lines abridged)
--- Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py:1.2.12.1	Mon Oct 21 10:38:42 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py	Mon Oct 21 10:55:56 2002
@@ -1,339 +1,283 @@
-##############################################################################
-#
-# 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.
-# 
-##############################################################################
-
-from Zope.Configuration.Exceptions import ConfigurationError
-from Zope.Security.Proxy import Proxy
-from Zope.ComponentArchitecture import getService, getServiceManager
-from Zope.Configuration import namespace
-from Interface import Interface
-from Zope.Configuration.Action import Action
-
-from Zope.Security.Proxy import Proxy
-from Zope.Security.Checker \
-     import InterfaceChecker, CheckerPublic, NamesChecker, Checker
-
-from Zope.ComponentArchitecture.GlobalServiceManager \
-     import UndefinedService
-
-# I prefer the indirection (using getService and getServiceManager vs.
-# directly importing the various services)  not only because it makes
-# unit tests easier, but also because it reinforces that the services
-# should always be obtained through the
-# IPlacefulComponentArchitecture interface methods
-
-# But these services aren't placeful! And we need to get at things that
-# normal service clients don't need!   Jim
-
-
-
-def handler(serviceName, methodName, *args, **kwargs):
-    method=getattr(getService(None, serviceName), methodName)
-    method(*args, **kwargs)
-
-def managerHandler(methodName, *args, **kwargs):
-    method=getattr(getServiceManager(None), methodName)
-    method(*args, **kwargs)
-

[-=- -=- -=- 525 lines omitted -=- -=- -=-]

+        for stype, interface in service_manager.getServiceDefinitions():
+            if stype == serviceType:
+                break
+        else:
+            raise UndefinedService(serviceType)
+
+        if permission == 'Zope.Public':
+            permission = CheckerPublic
+    
+        checker = InterfaceChecker(interface, permission)
+
+        try:
+            component.__Security_checker__ = checker
+        except: # too bad exceptions aren't more predictable
+            component = Proxy(component, checker)
+
+    service_manager.provideService(serviceType, component)
+    
+def service(_context, serviceType, component=None, permission=None, factory=None):
+    if factory:
+        if component:
+            raise TypeError("Can't specify factory and component.")
+
+        component = _context.resolve(factory)()
+    else:
+        component = _context.resolve(component)
+
+    return [
+        Action(
+            discriminator = ('service', serviceType),        
+            callable = provideService,
+            args = (serviceType, component, permission),
+            )
+        ]
+
+def skin(_context, name, layers, type):
+    type = _context.resolve(type)
+    if ',' in layers:
+        raise TypeError("Commas are not allowed in layer names.")
+
+    layers = layers.strip().split()
+    return [
+        Action(
+            discriminator = ('skin', name, type),
+            callable = handler,
+            args = ('Skins','defineSkin',name, type, layers)
+            )
+        ]
+
+