[Zope3-checkins] CVS: Zope3/src/zope/component - __init__.py:1.22
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Mar 9 07:41:15 EST 2004
Update of /cvs-repository/Zope3/src/zope/component
In directory cvs.zope.org:/tmp/cvs-serv10985/src/zope/component
Modified Files:
__init__.py
Log Message:
Added getFactoriesFor() function, since there is not compact equivalent to it
anywhere.
Added deprecation warnings to getFactory and queryFactory, since they are
replaced by getUtility and queryUtility. Jim said, that there is not need to
deprecate them; if we decide that, then we should just remove the deprecation
warning. I changed all of the Zope code to use getUtility and queryUtility
though.
=== Zope3/src/zope/component/__init__.py 1.21 => 1.22 ===
--- Zope3/src/zope/component/__init__.py:1.21 Fri Mar 5 21:50:18 2004
+++ Zope3/src/zope/component/__init__.py Tue Mar 9 07:41:15 2004
@@ -18,11 +18,10 @@
import sys
import warnings
from zope.interface import moduleProvides, Interface
-from zope.component.interfaces import IComponentArchitecture
+from zope.component.interfaces import IComponentArchitecture, IFactory
from zope.component.exceptions import ComponentLookupError
from zope.component.service import serviceManager
from zope.component.servicenames import Adapters, Presentation
-from zope.component.servicenames import Factories
# Try to be hookable. Do so in a try/except to avoid a hard dependence
try:
@@ -164,19 +163,31 @@
return adapters.querySubscriptionMultiAdapter(objects, interface, name,
default)
-# Factory service
+# Factories
def createObject(context, name, *args, **kwargs):
- return getService(context, Factories).createObject(name, *args, **kwargs)
+ return getUtility(context, IFactory, name)(*args, **kwargs)
+
+def getFactoryInterfaces(context, name):
+ return getUtility(context, IFactory, name).getInterfaces()
+
+def getFactoriesFor(context, interface):
+ utils = getService(context, 'Utilities')
+ return [(name, factory) \
+ for iface, name, factory in utils.getRegisteredMatching(IFactory) \
+ if interface in tuple(factory.getInterfaces())]
def getFactory(context, name):
- return getService(context, Factories).getFactory(name)
+ warnings.warn(
+ "Use getUtility(context, IFactory, name) instead of getFactory(...)",
+ DeprecationWarning, 2)
+ return getUtility(context, IFactory, name)
def queryFactory(context, name, default=None):
- return getService(context, Factories).queryFactory(name, default)
-
-def getFactoryInterfaces(context, name):
- return getService(context, Factories).getInterfaces(name)
+ warnings.warn(
+ "Use getUtility(context, IFactory, name) instead of getFactory(...)",
+ DeprecationWarning, 2)
+ return queryUtility(context, IFactory, name)
# Presentation service
More information about the Zope3-Checkins
mailing list