[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture - Service.py:1.1.6.1 IComponentArchitecture.py:1.1.2.8 __init__.py:1.1.6.8
Jim Fulton
jim@zope.com
Wed, 26 Dec 2001 17:04:07 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv19995
Modified Files:
Tag: Zope-3x-branch
IComponentArchitecture.py __init__.py
Added Files:
Tag: Zope-3x-branch
Service.py
Log Message:
added basic service implementation
=== Added File Zope3/lib/python/Zope/ComponentArchitecture/Service.py ===
##############################################################################
#
# Copyright (c) 2001 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: Service.py,v 1.1.6.1 2001/12/26 22:04:07 jim Exp $
"""
from Zope.Exceptions import DuplicationError, NotFoundError
class UndefinedService(Exception):
"""An attempt to register a service that has not been defined
"""
class InvalidService(Exception):
"""An attempt to register a service that doesn't implement the required interface
"""
class ServiceManager:
"""service manager"""
def __init__(self):
self.__defs = {}
self.__services = {}
def defineService(self, name, interface):
"""Define a new service"""
if name in self.__defs:
raise DuplicationError(name)
self.__defs[name] = interface
def provideService(self, name, component):
"""provide a service implementation"""
if name in self.__services:
raise DuplicationError(name)
if name not in self.__defs:
raise UndefinedService(name)
if not self.__defs[name].isImplementedBy(component):
raise InvalidService(name, component, self.__defs[name])
self.__services[name] = component
def getService(self, object, name):
"""retrieve a service implementation"""
try:
return self.__services[name]
except KeyError:
return NotFoundError(name)
def _clear(self):
self.__init__()
serviceManager = ServiceManager()
defineService = serviceManager.defineService
provideService = serviceManager.provideService
getService = serviceManager.getService
_clear = serviceManager._clear
=== Zope3/lib/python/Zope/ComponentArchitecture/IComponentArchitecture.py 1.1.2.7 => 1.1.2.8 ===
raised if the factory component can't be found.
"""
-
+
+ def defineService(name, interface):
+ """Define a new service"""
+
+ def provideService(name, component):
+ """provide a service implementation"""
+
+ def getService(object, name):
+ """retrieve a service implementation"""
+
=== Zope3/lib/python/Zope/ComponentArchitecture/__init__.py 1.1.6.7 => 1.1.6.8 ===
from hooks import provideView, getView
from hooks import provideFactory, createObject
+from Service import defineService, provideService, getService
def _clear():
from hooks import _clear
+ _clear()
+ from Service import _clear
_clear()