[Zope3-checkins] CVS: Zope3/src/zope/app/component - service.py:1.1.2.1

Jim Fulton jim at zope.com
Mon Aug 4 12:34:26 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/component
In directory cvs.zope.org:/tmp/cvs-serv26080/src/zope/app/component

Added Files:
      Tag: zcml-interface-field-branch
	service.py 
Log Message:
Provides some initial machinery for creatiing and setting up global
service managers. Someday, there might be multiple global service
managers per process.


=== Added File Zope3/src/zope/app/component/service.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Global service management

This module provides access to and management of global service managers.

For now, this is experimental and used only to simplify testing.
Eventually, perhaps, it could be used to to allow multiple global
service managers per process and allow us to get away from having
services be stuck in module globals.

$Id: service.py,v 1.1.2.1 2003/08/04 15:34:20 jim Exp $
"""

from zope.app.services import servicenames
from zope.component import resource
from zope.component import service, utility, adapter, factory, skin, view
import zope.app.component.globalinterfaceservice
import zope.app.interfaces.component
import zope.component.interfaces

services = {
    servicenames.Utilities: (
       zope.component.interfaces.IUtilityService,
       utility.GlobalUtilityService,
       ),
    servicenames.Adapters: (
       zope.component.interfaces.IAdapterService,
       adapter.GlobalAdapterService,
       ),
    servicenames.Factories: (
       zope.component.interfaces.IFactoryService,
       factory.GlobalFactoryService,
       ),
    servicenames.Skins: (
       zope.component.interfaces.ISkinService,
       skin.GlobalSkinService,
       ),
    servicenames.Views: (
       zope.component.interfaces.IViewService,
       view.GlobalViewService,
       ),
    servicenames.Resources: (
       zope.component.interfaces.IResourceService,
       resource.GlobalResourceService,
       ),
    servicenames.Interfaces: (
       zope.app.interfaces.component.IInterfaceService,
       zope.app.component.globalinterfaceservice.InterfaceService,
       ),
    }


def globalServiceManager(*names):
    """Create a global service manager with selected services configured

    If no services are provided, all services will be configured.

    >>> sm = globalServiceManager()
    >>> sm.getService(servicenames.Utilities).__class__.__name__
    'GlobalUtilityService'
    >>> sm.getService(servicenames.Views).__class__.__name__
    'GlobalViewService'

    >>> sm = globalServiceManager(servicenames.Utilities)
    >>> sm.getService(servicenames.Utilities).__class__.__name__
    'GlobalUtilityService'
    >>> sm.getService(servicenames.Views).__class__.__name__
    Traceback (most recent call last):
    ComponentLookupError: Views
    
    """

    if not names:
        names = services

    sm = service.GlobalServiceManager()
    for name in names:
        i, f = services[name]
        sm.defineService(name, i)
        sm.provideService(name, f())
        
    return sm




More information about the Zope3-Checkins mailing list