[Zope-Checkins] CVS: Zope/lib/python/ComponentArchitecture - Content.py:1.1.2.1 Component.py:1.1.2.2 FactoryComponents.py:1.1.2.4 InputToName.py:1.1.2.4 InterfaceComponents.py:1.1.2.5 __init__.py:1.1.2.8
Shane Hathaway
shane@digicool.com
Tue, 7 Aug 2001 11:29:07 -0400
Update of /cvs-repository/Zope/lib/python/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv24307
Modified Files:
Tag: NR-branch
Component.py FactoryComponents.py InputToName.py
InterfaceComponents.py __init__.py
Added Files:
Tag: NR-branch
Content.py
Log Message:
Created simple factories.
=== Added File Zope/lib/python/ComponentArchitecture/Content.py ===
=== Zope/lib/python/ComponentArchitecture/Component.py 1.1.2.1 => 1.1.2.2 ===
'''
'''
+
=== Zope/lib/python/ComponentArchitecture/FactoryComponents.py 1.1.2.3 => 1.1.2.4 ===
from InputToName import InputToNameService, InputToNameComponent, \
GlobalInputToNameRegistry, getRealization, listComponentNames
+from Content import ContentContainer
FACTORY_SERVICE_NAME = 'factories'
@@ -124,4 +125,36 @@
def listFactoryNames(object, inputs=None):
return listComponentNames(FACTORY_SERVICE_NAME, global_reg,
object, inputs)
+
+
+class SimpleFactory:
+
+ __implements__ = FactoryComponent
+
+ def __init__(self, fullname, ui_name, inputs, constructor):
+ self.fullname = fullname
+ self.ui_name = ui_name
+ self.inputs = inputs
+ self.__dict__['constructor'] = constructor # Careful not to bind
+
+ def getInputs(self):
+ return self.inputs
+
+ def getNames(self):
+ return (self.fullname,)
+
+ def getId(self):
+ return self.fullname
+
+ def isEnabled(self):
+ return 1
+
+
+def provideSimpleFactory(klass, ui_name=None, inputs=(ContentContainer,)):
+ fullname = '%s.%s' % (klass.__module__, klass.__name__)
+ if ui_name is None:
+ ui_name = fullname
+ sf = SimpleFactory(fullname, ui_name, inputs, klass)
+ for input in inputs:
+ global_reg.provideRealization(input, fullname, sf)
=== Zope/lib/python/ComponentArchitecture/InputToName.py 1.1.2.3 => 1.1.2.4 ===
lst = list(lst)
result.extend(lst)
- return 0
+ return 0
def listComponentNames(service_name, global_reg, object, inputs=None):
'''
=== Zope/lib/python/ComponentArchitecture/InterfaceComponents.py 1.1.2.4 => 1.1.2.5 ===
return listComponentNames(INTERFACES_SERVICE_NAME, global_reg, object)
+def provideInterface(i, name=None):
+ if name is None:
+ name = i.getName()
+ global_reg.provideRealization(name, i)
+
def flattenInterfaceList(object, interfaces, append):
# Helper for objectImplements().
for i in interfaces:
=== Zope/lib/python/ComponentArchitecture/__init__.py 1.1.2.7 => 1.1.2.8 ===
providePresentation = Presentation.global_reg.provideRealization
+from Content import Content, ContentContainer
+
+import FactoryComponents
+provideSimpleFactory = FactoryComponents.provideSimpleFactory
+
__all__ = (
'getAdapter', 'provideAdapter',
'getPresentation', 'providePresentation',
+ 'Content', 'ContentContainer',
+ 'provideSimpleFactory',
)