[Zope3-checkins] CVS: Zope3/src/zope/component - factory.py:1.6
interfaces.py:1.19
Garrett Smith
garrett at mojave-corp.com
Thu Jan 8 15:48:52 EST 2004
Update of /cvs-repository/Zope3/src/zope/component
In directory cvs.zope.org:/tmp/cvs-serv3742/src/zope/component
Modified Files:
factory.py interfaces.py
Log Message:
Added factory 'info' to the factory service. This can be used to lookup
title and description for registered factories. Prior to this change, factory
title and description defined in ZCML was discarded.
This change is per an exchange back in May:
http://mail.zope.org/pipermail/zope3-dev/2003-May/006915.html
Note that only the factory info portion of the proposed change is
implemented in this commit. The ability to enumerate registered factories
was implemented earlier.
=== Zope3/src/zope/component/factory.py 1.5 => 1.6 ===
--- Zope3/src/zope/component/factory.py:1.5 Mon Aug 25 10:14:08 2003
+++ Zope3/src/zope/component/factory.py Thu Jan 8 15:48:22 2004
@@ -18,26 +18,40 @@
from zope.interface.verify import verifyObject
from zope.interface import implements
from zope.component.interfaces import IFactory
+from zope.component.interfaces import IFactoryInfo
from zope.component.interfaces import IFactoryService
from zope.component.exceptions import ComponentLookupError
class IGlobalFactoryService(IFactoryService):
- def provideFactory(name, factory):
+ def provideFactory(name, factory, info=None):
"""Provide a factory for the given name.
+
+ If specified, info must implement IFactoryInfo.
"""
+class FactoryInfo:
+
+ implements(IFactoryInfo)
+
+ def __init__(self, title, description):
+ self.title = title
+ self.description = description
+
class GlobalFactoryService:
implements(IGlobalFactoryService)
def __init__(self):
- self.__factories={}
+ self.__factories = {}
+ self.__info = {}
- def provideFactory(self, name, factory):
+ def provideFactory(self, name, factory, info=None):
"""See IGlobalFactoryService interface"""
verifyObject(IFactory, factory)
self.__factories[name] = factory
+ if info is not None:
+ self.__info[name] = info
def createObject(self, name, *args, **kwargs):
"""See IFactoryService interface"""
@@ -74,6 +88,9 @@
"""See IFactoryService interface"""
return [(n, f) for n, f in self.__factories.items() \
if iface in f.getInterfaces()] or default
+
+ def getFactoryInfo(self, name):
+ return self.__info.get(name)
_clear = __init__
=== Zope3/src/zope/component/interfaces.py 1.18 => 1.19 ===
--- Zope3/src/zope/component/interfaces.py:1.18 Mon Dec 22 10:10:34 2003
+++ Zope3/src/zope/component/interfaces.py Thu Jan 8 15:48:22 2004
@@ -292,12 +292,18 @@
def getInterfaces():
"""Get the interfaces implemented by the factory
-
Return the interface(s) that objects created by this factory
will implement.
-
"""
+class IFactoryInfo(Interface):
+ """Additional information about a factory."""
+
+ title = Attribute("The factory title.")
+
+ description = Attribute("A brief description of the factory.")
+
+
class IFactoryService(Interface):
def createObject(name, *args, **kwargs):
@@ -308,7 +314,6 @@
A ComponentLookupError will be raised if the factory component
can't be found.
-
"""
def getFactory(name):
@@ -339,6 +344,13 @@
that create objects which implement the given interface
If no factory is found, the default value is returned.
+ """
+
+ def getFactoryInfo(name):
+ """Returns information about the specified factory.
+
+ Return value implements IFactoryInfo or is None if information
+ about the factory is not available.
"""
class IUtilityService(Interface):
More information about the Zope3-Checkins
mailing list