[Zope3-checkins] CVS: Zope3/src/zope/app/services - configuration.py:1.20 service.py:1.16
Jim Fulton
jim@zope.com
Mon, 24 Mar 2003 06:10:10 -0500
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv21429/src/zope/app/services
Modified Files:
configuration.py service.py
Log Message:
Fixed a bug in configuration handling.
You should (and now do) get an error if you try to register a
configuration and there is no *local*, meaning in this site, service
to register with. You now get an understandable (I hope) error
telling you to add a local service.
=== Zope3/src/zope/app/services/configuration.py 1.19 => 1.20 ===
--- Zope3/src/zope/app/services/configuration.py:1.19 Sun Mar 23 17:35:41 2003
+++ Zope3/src/zope/app/services/configuration.py Mon Mar 24 06:09:39 2003
@@ -23,6 +23,7 @@
from zope.app.interfaces.container import IAddNotifiable, IDeleteNotifiable
from zope.app.interfaces.container import IZopeWriteContainer
from zope.app.interfaces.dependable import IDependable, DependencyError
+
from zope.app.interfaces.services.configuration import IConfigurationManager
from zope.app.interfaces.services.configuration import IConfigurationRegistry
from zope.app.interfaces.services.configuration \
@@ -37,6 +38,7 @@
from zope.app.interfaces.services.configuration import IUseConfiguration
from zope.app.interfaces.services.configuration \
import NoConfigurationManagerError
+from zope.app.interfaces.services.configuration import NoLocalServiceError
from zope.app.interfaces.services.configuration import Unregistered
from zope.app.interfaces.services.configuration import Registered, Active
@@ -62,7 +64,9 @@
return self
configuration = inst
- service = queryService(configuration, self.service)
+
+ sm = getServiceManager(configuration)
+ service = sm.queryLocalService(self.service)
# XXX The following may fail; there's a subtle bug here when
# the returned service isn't in the same service manager as
# the one owning the configuration.
@@ -79,7 +83,10 @@
def __set__(self, inst, value):
configuration = inst
- service = queryService(configuration, self.service)
+
+ sm = getServiceManager(configuration)
+ service = sm.queryLocalService(self.service)
+
registry = service and service.queryConfigurationsFor(configuration)
if value == Unregistered:
@@ -88,8 +95,11 @@
else:
if not service:
- # raise an error
- service = getService(configuration, self.service)
+ raise NoLocalServiceError(
+ "This configuration change cannot be performed because "
+ "there isn't a corresponding %s service defined in this "
+ "site. To proceed, first add a local %s service."
+ % (self.service, self.service))
if registry is None:
registry = service.createConfigurationsFor(configuration)
=== Zope3/src/zope/app/services/service.py 1.15 => 1.16 ===
--- Zope3/src/zope/app/services/service.py:1.15 Sun Mar 23 11:45:44 2003
+++ Zope3/src/zope/app/services/service.py Mon Mar 24 06:09:39 2003
@@ -123,6 +123,34 @@
getService = ContextMethod(getService)
+ def queryLocalService(wrapped_self, name, default=None):
+ "See IServiceManager"
+
+ # This is rather tricky. Normally, getting a service requires
+ # the use of other services, like the adapter service. We
+ # need to be careful not to get into an infinate recursion by
+ # getting out getService to be called while looking up
+ # services, so we'll
+
+ if name == 'Services':
+ return wrapped_self # We are the service service
+
+ if not getattr(wrapped_self, '_v_calling', 0):
+
+ wrapped_self._v_calling = 1
+ try:
+ service = wrapped_self.queryActiveComponent(name)
+ if service is not None:
+ return service
+
+ finally:
+ wrapped_self._v_calling = 0
+
+ return default
+
+ queryLocalService = ContextMethod(queryLocalService)
+
+
def getInterfaceFor(wrapped_self, service_type):
"See IServiceService"
for type, interface in wrapped_self.getServiceDefinitions():