[Zope3-checkins] CVS: Zope3/lib/python/Zope/StartUp - ISimpleRegistry.py:1.1 SimpleRegistry.py:1.1 RequestFactoryRegistry.py:1.3 ServerTypeRegistry.py:1.3
Stephan Richter
srichter@cbu.edu
Fri, 19 Jul 2002 09:12:35 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/StartUp
In directory cvs.zope.org:/tmp/cvs-serv24805/lib/python/Zope/StartUp
Modified Files:
RequestFactoryRegistry.py ServerTypeRegistry.py
Added Files:
ISimpleRegistry.py SimpleRegistry.py
Log Message:
Okay, I finished the Forms work. Schema and Forms completely replace the
old Formulator code now. I have switched all the Content objects to using
Schema + Forms; especially the SQL Script has an interesting demo on how
to write your custom fields.
However, I am not satisfied with all my design decisions. There is still
a lot of work to be done in Converters and Widgets. Please contact Martijn
and/or me if you would like to help.
=== Added File Zope3/lib/python/Zope/StartUp/ISimpleRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""
$Id: ISimpleRegistry.py,v 1.1 2002/07/19 13:12:34 srichter Exp $
"""
from Interface import Interface
class ISimpleRegistry(Interface):
"""
The Simple Registry is minimal collection of registered objects. This can
be useful, when it is expected that objects of a particular type are added
from many places in the system (through 3rd party products for example).
A good example for this are the Formulator fields. While the basic types
are defined inside the Formulator tree, other parties might add many
more later on in their products, so it is useful to provide a registry via
ZCML that allows to collect these items.
There is only one constraint on the objects. They all must implement a
particular interface specified during the initialization of the registry.
Note that it does not matter whether we have classes or instances as
objects. If the objects are instances, they must implement simply
IInstanceFactory.
"""
def register(name, object):
"""
Registers the object under the id name.
"""
def getF(name):
"""
This returns the object with id name.
"""
=== Added File Zope3/lib/python/Zope/StartUp/SimpleRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""
$Id: SimpleRegistry.py,v 1.1 2002/07/19 13:12:34 srichter Exp $
"""
from Zope.Configuration.name import resolve
from Zope.StartUp.ISimpleRegistry import ISimpleRegistry
from types import StringTypes, ListType, TupleType
ListTypes = (TupleType, ListType)
class ZopeDuplicateRegistryEntryError(Exception):
"""
This Error is raised when the user tries to add an object with
a name that already exists in the registry. Therefore,
overwriting is not allowed.
"""
def __init__(self, name):
"""Initializes Error"""
self.name = name
def __str__(self):
"""Returns string representation of Error"""
return "The name '%s' is already defined in this registry." \
%self.name
class ZopeIllegalInterfaceError(Exception):
"""This Error is thrown, when the passed object does not implement
the specified interface."""
def __init__(self, name, interface):
"""Initalize Error"""
self.name = name
self.interface = interface
def __str__(self):
"""Returns string representation of Error"""
return ( "The object with name " + self.name + " does not implement "
"the interface " + self.interface.__name__ + "." )
class SimpleRegistry:
""" """
__implements__ = (ISimpleRegistry,)
def __init__(self, interface):
"""Initialize registry"""
self.objects = {}
self.interface = interface
def register(self, name, object):
'''See interface Zope.App.Formulator.ISimpleRegistry.ISimpleRegistry'''
if name in self.objects.keys():
raise ZopeDuplicateRegistryEntryError(name)
# XXX Find the right Interface tools to do that; unfortunately,
# I have not found them
# Check whether the object implements the right interface.
# Note, that we do *not* know whether the object is an instance
# or a class (or worse a Persistent class)
if hasattr(object, '__implements__') and \
( self.interface == object.__implements__ or \
( type(object.__implements__) in ListTypes and
self.interface in object.__implements__ ) ):
self.objects[name] = object
else:
raise ZopeIllegalInterfaceError(name, self.interface)
return []
def get(self, name):
'''See interface Zope.App.Formulator.ISimpleRegistry.ISimpleRegistry'''
if name in self.objects.keys():
return self.objects[name]
else:
return None
=== Zope3/lib/python/Zope/StartUp/RequestFactoryRegistry.py 1.2 => 1.3 ===
#
##############################################################################
"""
-
$Id$
"""
-
-
-from Zope.App.Formulator.SimpleRegistry import SimpleRegistry
-from Zope.App.Formulator.ISimpleRegistry import ISimpleRegistry
+from Zope.StartUp.SimpleRegistry import SimpleRegistry
+from Zope.StartUp.ISimpleRegistry import ISimpleRegistry
from RequestFactory import IRequestFactory
class IRequestFactoryRegistry(ISimpleRegistry):
@@ -36,7 +33,6 @@
class RequestFactoryRegistry(SimpleRegistry):
""" """
-
__implements__ = (IRequestFactoryRegistry,)
=== Zope3/lib/python/Zope/StartUp/ServerTypeRegistry.py 1.2 => 1.3 ===
#
##############################################################################
"""
-
$Id$
"""
-
-
-from Zope.App.Formulator.SimpleRegistry import SimpleRegistry
-from Zope.App.Formulator.ISimpleRegistry import ISimpleRegistry
+from Zope.StartUp.SimpleRegistry import SimpleRegistry
+from Zope.StartUp.ISimpleRegistry import ISimpleRegistry
from ServerType import IServerType
class IServerTypeRegistry(ISimpleRegistry):
@@ -35,10 +32,8 @@
class ServerTypeRegistry(SimpleRegistry):
- """ """
-
+ """Registry for the various Server types"""
__implements__ = (IServerTypeRegistry,)
-
ServerTypeRegistry = ServerTypeRegistry(IServerType)