[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator - CompositeWidget.py:1.2 Errors.py:1.2 Field.py:1.2 FieldRegistry.py:1.2 Form.py:1.2 ICompositeWidget.py:1.2 IField.py:1.2 IInstanceFactory.py:1.2 IPropertyFieldAdapter.py:1.2 ISimpleRegistry.py:1.2 IValidator.py:1.2 IWidget.py:1.2 PropertyFieldAdapter.py:1.2 SimpleRegistry.py:1.2 Validator.py:1.2 ValidatorRegistry.py:1.2 Widget.py:1.2 __init__.py:1.2 formulator-meta.zcml:1.2 formulator.zcml:1.2 metaConfigure.py:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:28:51 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/Formulator

Added Files:
	CompositeWidget.py Errors.py Field.py FieldRegistry.py Form.py 
	ICompositeWidget.py IField.py IInstanceFactory.py 
	IPropertyFieldAdapter.py ISimpleRegistry.py IValidator.py 
	IWidget.py PropertyFieldAdapter.py SimpleRegistry.py 
	Validator.py ValidatorRegistry.py Widget.py __init__.py 
	formulator-meta.zcml formulator.zcml metaConfigure.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.


=== Zope3/lib/python/Zope/App/Formulator/CompositeWidget.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from ICompositeWidget import ICompositeWidget
+from Widget import Widget
+
+
+class CompositeWidget(Widget):
+    """ """
+
+    __implements__ = Widget.__implements__, ICompositeWidget
+
+    # Page template that is ised to lay out sub-widgets
+    template = None
+
+    # List of Sub-Widgets
+    widgets = None
+
+
+    def render(self, REQUEST):
+        """ """
+        return apply(self.template, (REQUEST,))
+
+
+    def render_hidden(self, REQUEST):
+        """ """
+        return apply(self.template, (REQUEST,), {'hidden': 1})
+
+
+    def setWidget(self, name, widget):
+        """ """
+        if self.widgets is None:
+            self.widgets = {}
+
+        self.widgets[name] = widget
+
+
+    def getWidget(self, name, _default=None):
+        """ """
+        if name in self.widgets.keys():
+            return self.widgets[name]
+        else:
+            return _default
+
+
+    def getWidgets(self):
+        """ """
+        return self.widgets


=== Zope3/lib/python/Zope/App/Formulator/Errors.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+"""
+Exception Classes for Formulator
+
+$Id$
+"""
+
+# These classes are placed here so that they can be imported into TTW Python
+# scripts. To do so, add the following line to your Py script:
+# from Products.Formulator.Errors import ValidationError, FormValidationError
+
+
+class FormValidationError(Exception):
+
+    def __init__(self, errors, result):
+        Exception.__init__(self, "Form Validation Error")
+        self.errors = errors
+        self.result = result
+        
+
+class ValidationError(Exception):
+    
+    def __init__(self, errorKey, field):
+        Exception.__init__(self, errorKey)
+        self.errorKey = errorKey
+        self.fieldId = field.id
+        self.field = field
+        self.errorText = field.getErrorMessage(errorKey)
+


=== Zope3/lib/python/Zope/App/Formulator/Field.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from Persistence import Persistent
+from IField import IField
+from Zope.App.Formulator.Errors import ValidationError
+from IInstanceFactory import IInstanceFactory
+
+
+class Field(Persistent):
+    """Base class of all fields.
+    A field is an object consisting of a widget and a validator.
+    """
+
+    __implements__ = (
+        IField,
+        IInstanceFactory
+        )
+
+    propertyNames = ('id', 'validator', 'default', 'title', 'description',
+                     'required')
+
+    id = None
+    validator = None
+    default = None
+    title = 'Field Title'
+    description = 'Field Description'
+    required = 0
+
+
+    def __init__(self, context=None, **kw):
+        self.realize(context)
+
+        for name in self.propertyNames:
+            if name in kw.keys():
+                setattr(self, name, kw[name])
+
+
+    def getErrorMessage(self, name):
+        try:
+            return self.validator.getMessage(name)
+        except KeyError:
+            if name in self.validator.messageNames:
+                return getattr(self.validator, name)
+            else:
+                return "Unknown error: %s" % name
+
+
+    ############################################################
+    # Implementation methods for interface
+    # Zope.App.Formulator.IField.
+
+    def getValidator(self):
+        '''See interface IField'''
+        return self.validator
+
+
+    def hasValue(self, id):
+        '''See interface IField'''
+        if id in self.propertyNames:
+            return 1
+        else:
+            return 0
+
+
+    def getValue(self, id, _default=None):
+        '''See interface IField'''
+        if id in self.propertyNames:
+            return getattr(self, id)
+        else:
+            return _default
+
+
+    def isRequired(self):
+        '''See interface IField'''
+        return hasattr(self, 'required') and getattr(self, 'required')
+
+
+    def getErrorNames(self):
+        '''See interface IField'''
+        return self.validator.messageNames
+
+
+    def getTales(self, id):
+        '''See interface IField'''
+        raise NotImplemented
+
+
+    def isTALESAvailable(self):
+        '''See interface IField'''
+        raise NotImplemented
+
+
+    def getOverride(self, id):
+        '''See interface IField'''
+        raise NotImplemented
+
+    #
+    ############################################################
+
+
+    ############################################################
+    # Implementation methods for interface
+    # Zope.App.Formulator.IInstanceFactory.
+
+    def __call__(self, context):
+        '''See interface IInstanceFactory'''
+        self.realize(context)
+        return self
+
+    def realize(self, context):
+        '''See interface IInstanceFactory'''
+        self.context = context
+    #
+    ############################################################


=== Zope3/lib/python/Zope/App/Formulator/FieldRegistry.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+
+from SimpleRegistry import SimpleRegistry
+from ISimpleRegistry import ISimpleRegistry
+from IField import IField
+
+class IFieldRegistry(ISimpleRegistry):
+    """
+    The Field Registry manages a list of all the fields available in Zope. A
+    registry is useful at this point, since fields can be initialized and
+    registered by many places.
+
+    Note that it does not matter whether we have classes or instances as
+    fields. If the fields are instances, they must implement
+    IInstanceFactory.
+    """
+    pass
+
+
+class FieldRegistry(SimpleRegistry):
+    """ """
+
+    __implements__ =  (IFieldRegistry,)
+
+
+
+FieldRegistry = FieldRegistry(IField)
+registerField = FieldRegistry.register
+getField = FieldRegistry.get


=== Zope3/lib/python/Zope/App/Formulator/Form.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from Zope.Publisher.Browser.BrowserView import BrowserView
+#from IForm import IForm
+from Zope.ComponentArchitecture import getView
+from Zope.App.Formulator.IPropertyFieldAdapter import IPropertyFieldAdapter
+from Zope.App.Formulator.Errors import ValidationError
+from Zope.ComponentArchitecture import getAdapter
+
+
+class Form(BrowserView):
+    """Form base class.
+    """
+
+    name = 'Form Name'     # for use by javascript
+    title = 'This is a form'
+    description = ''
+    method = 'post'
+    enctype = ''
+
+    _fieldViewNames = []
+    template = None
+
+
+    def __init__(self, *args):
+        """Initialize form.
+        """
+        super(Form, self).__init__(*args)
+        self._widgets = []
+        
+
+    def index(self, REQUEST, **kw):
+        """ """
+        return apply(self.template, (REQUEST,), kw)
+
+
+    def action(self, REQUEST):
+        """ """
+        errors = []
+        values = {}
+        for widget in self.getFieldViews(REQUEST):
+            value = widget.getValueFromRequest(REQUEST)
+            field = widget.context
+            try:
+                values[field.id] = field.getValidator().validate(field, value)
+            except ValidationError, err:
+                errors.append(err)
+
+        if errors == []:
+            for widget in self.getFieldViews(REQUEST):
+                field = widget.context
+                getAdapter(field, IPropertyFieldAdapter
+                           ).setPropertyInContext(values[field.id])
+
+        return self.index(REQUEST, errors=errors)
+
+
+    def getFieldViews(self, REQUEST):
+        """ """
+        views = []
+        context = self.context
+        for name in self._fieldViewNames:
+            views.append(getView(context, name, REQUEST))
+        return views


=== Zope3/lib/python/Zope/App/Formulator/ICompositeWidget.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from IWidget import IWidget
+
+
+class ICompositeWidget(IWidget):
+    """ """


=== Zope3/lib/python/Zope/App/Formulator/IField.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+from Zope.ComponentArchitecture.IContextDependent import IContextDependent
+
+class IField(IContextDependent):
+    """
+    """
+
+    def getValidator():
+        """Return the validator of this field."""
+
+
+    def hasValue(id):
+        """Return true if the field defines such a value.
+        """
+
+
+    def getValue(id):
+        """Get value for id."""
+
+
+    def getOverride(id):
+        """Get override method for id (not wrapped)."""
+
+
+    def getTales(id):
+        """Get tales expression method for id."""
+    
+
+    def isRequired():
+        """Check whether this field is required (utility function)
+        """    
+
+
+    def getErrorNames():
+        """Get error messages.
+        """
+
+
+    def isTALESAvailable():
+        """Return true only if TALES is available.
+        """


=== Zope3/lib/python/Zope/App/Formulator/IInstanceFactory.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from Zope.ComponentArchitecture.IContextDependent import IContextDependent
+
+class IInstanceFactory(IContextDependent):
+    """
+    If the Instance Factory is implemented by an object, then this object
+    can be used as factory for other components, such as Views.
+    """
+
+    def realize(context):
+        """
+        Relaizes an instance in a particular context/evironment. This
+        method basically replaces __init__(context) for class-based
+        factories.
+        """
+
+
+    def __call__(context):
+        """
+        Basically calls realize(context). However it must be implemented
+        too, so that the factory is callable This method has to return the
+        produced object.
+        """


=== Zope3/lib/python/Zope/App/Formulator/IPropertyFieldAdapter.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+
+from Interface import Interface
+
+
+class IPropertyFieldAdapter(Interface):
+    """
+    """
+
+    def setPropertyInContext(value):
+        """ """
+
+
+    def getPropertyInContext():
+        """ """


=== Zope3/lib/python/Zope/App/Formulator/ISimpleRegistry.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+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.
+        """


=== Zope3/lib/python/Zope/App/Formulator/IValidator.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from Interface import Interface
+
+
+class IValidator(Interface):
+    """A field validator provides the functionality to verify the
+       input data on the server. 
+
+       This class will be initialized as a singleton.
+    """
+
+    def validate(field, value):
+        """Validate the value, knowing the field.
+        """
+
+    def raiseError(errorKey, field):
+        """Raises the error, if the validation fails.
+        """


=== Zope3/lib/python/Zope/App/Formulator/IWidget.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+from Zope.ComponentArchitecture.IContextDependent import IContextDependent
+
+class IWidget(IContextDependent):
+    """Generically describes the behavior of a widget.
+
+    The widget defines a list of propertyNames, which describes
+    what properties of the widget are available to use for
+    constructing the widget render output.
+
+    Note that this level must be still presentation independent.
+    """
+
+    def getValue(name):
+        """Look up a Widget setting (value) by name."""
+
+    def render():
+        """Render the widget. This will return the representation the
+           client will understand."""
+
+    def render_hidden():
+        """Render the widget as a hidden field. This will return the
+           representation the client will understand."""


=== Zope3/lib/python/Zope/App/Formulator/PropertyFieldAdapter.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from IPropertyFieldAdapter import IPropertyFieldAdapter
+from Zope.App.Formulator.Errors import ValidationError
+
+class PropertyFieldAdapter:
+    """ """
+
+    __implements__ = IPropertyFieldAdapter
+
+
+    def __init__(self, context):
+        """ """
+        self.context = context
+
+
+    def setPropertyInContext(self, value):
+        """ """
+        field = self.context
+        method = getattr(field.context,
+                        'set'+field.id[0].capitalize()+field.id[1:], None)
+        apply(method, (value,))
+
+
+    def getPropertyInContext(self):
+        """ """
+        field = self.context
+        method = getattr(field.context,
+                        'get'+field.id[0].capitalize()+field.id[1:], None)
+        return apply(method, ())


=== Zope3/lib/python/Zope/App/Formulator/SimpleRegistry.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from Zope.Configuration.name import resolve
+from 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
+        
+
+    ############################################################
+    # Implementation methods for interface
+    # Zope.App.Formulator.ISimpleRegistry
+
+    def register(self, name, object):
+        '''See interface 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 ISimpleRegistry'''
+        if name in self.objects.keys():
+            return self.objects[name]
+        else:
+            return None
+
+    #
+    ############################################################


=== Zope3/lib/python/Zope/App/Formulator/Validator.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from Zope.App.Formulator.Errors import ValidationError
+from IValidator import IValidator
+from IInstanceFactory import IInstanceFactory
+
+class Validator:
+    """Validates input and possibly transforms it to output.
+    """
+
+    __implements__ = (
+        IValidator,
+        IInstanceFactory
+        )
+    
+    propertyNames = ['externalValidator']
+    externalValidator = None
+    
+    messageNames = ['externalValidatorFailed']
+    externalValidatorFailed = "The input failed the external validator."
+
+
+    def __init__(self, **kw):
+        """Initialize the Validator."""
+        for name in self.propertyNames:
+            if name in kw.keys():
+                setattr(self, name, kw[name])
+
+                
+    def getMessage(self, name):
+        """ """
+        if name in self.messageNames:
+            return getattr(self, name)
+
+
+    ############################################################
+    # Implementation methods for interface
+    # Zope.App.Formulator.IValidator.
+
+    def raiseError(self, errorKey, field):
+        '''See interface IValidator'''
+        raise ValidationError(errorKey, field)
+
+
+    def validate(self, field, value):
+        '''See interface IValidator'''
+        pass
+    #
+    ############################################################
+
+
+    ############################################################
+    # Implementation methods for interface
+    # Zope.App.Formulator.IInstanceFactory.
+
+    def __call__(self, context):
+        '''See interface IInstanceFactory'''
+        self.realize(context)
+        return self
+
+    def realize(self, context):
+        '''See interface IInstanceFactory'''
+        self.context = context
+    #
+    ############################################################


=== Zope3/lib/python/Zope/App/Formulator/ValidatorRegistry.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+
+from SimpleRegistry import SimpleRegistry
+from ISimpleRegistry import ISimpleRegistry
+from IValidator import IValidator
+
+class IValidatorRegistry(ISimpleRegistry):
+    """
+
+    Note that it does not matter whether we have classes or instances as
+    validators. If the validaotrs are instances, they must implement
+    IInstanceFactory.
+    """
+    pass
+
+
+class ValidatorRegistry(SimpleRegistry):
+    """ """
+
+    __implements__ =  (IValidatorRegistry,)
+
+
+
+ValidatorRegistry = ValidatorRegistry(IValidator)
+registerValidator = ValidatorRegistry.register
+getValidator = ValidatorRegistry.get


=== Zope3/lib/python/Zope/App/Formulator/Widget.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+from IWidget import IWidget
+
+
+class Widget(object):
+    """I do not know what will be in this class, but it provides
+    an extra layer.
+    """
+
+    __implements__ = IWidget
+
+    propertyNames = []
+
+
+    def __init__(self, field, request=None):
+        """ """
+        # XXX: the rest of the framework expects the arguments to
+        #      be (context, request). The request argument is not
+        #      used in this class.
+        self.context = field
+
+    def getValue(self, name):
+        """ """
+        if name in self.propertyNames:
+            return getattr(self, name, None)
+
+
+    def render(self):
+        """ """
+        raise NotImplemented
+
+
+    def render_hidden(self):
+        """ """
+        raise NotImplemented


=== Zope3/lib/python/Zope/App/Formulator/__init__.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from FieldRegistry import registerField, getField
+from ValidatorRegistry import registerValidator, getValidator


=== Zope3/lib/python/Zope/App/Formulator/formulator-meta.zcml 1.1 => 1.2 ===
+
+  <directives namespace="http://namespaces.zope.org/formulator">
+
+    <directive name="registerField" attributes="name field"
+       handler="Zope.App.Formulator.metaConfigure.field" />
+
+    <directive name="registerValidator" attributes="name validator"
+       handler="Zope.App.Formulator.metaConfigure.validator" />
+
+  </directives>
+
+</zopeConfigure>


=== Zope3/lib/python/Zope/App/Formulator/formulator.zcml 1.1 => 1.2 ===
+   xmlns='http://namespaces.zope.org/zope'
+   xmlns:security='http://namespaces.zope.org/security'
+>
+
+  <include package="Zope.App.Formulator" file="formulator-meta.zcml" />
+
+  <include package="Zope.App.Formulator.Fields" file="fields.zcml" />
+  <include package="Zope.App.Formulator.Validators" file="validators.zcml" />
+  <include package="Zope.App.Formulator.Widgets" file="widgets.zcml" />
+
+  <adapter factory="Zope.App.Formulator.PropertyFieldAdapter."
+           provides="Zope.App.Formulator.IPropertyFieldAdapter."
+           for="Zope.App.Formulator.IField." />
+
+  <content class=".Field.">
+    <security:require
+        permission="Zope.View" 
+        interface=".IField." />
+  </content>
+  
+  <content class=".Form.">
+    <security:require
+        permission="Zope.View" 
+        attributes="index action getFieldViews getContext" />
+  </content>
+
+</zopeConfigure>


=== Zope3/lib/python/Zope/App/Formulator/metaConfigure.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from Zope.Configuration.Action import Action
+from FieldRegistry import registerField
+from ValidatorRegistry import registerValidator
+
+def field(_context, name, field):
+    """
+    Note that most applications return an actual Action at this point;
+    however, the field registry is requred during the startup, so we
+    need to initialize it now.
+    """
+    field = _context.resolve(field)
+    registerField(name, field)
+    return []
+
+
+def validator(_context, name, validator):
+    """
+    Note that most applications return an actual Action at this point;
+    however, the validator registry is requred during the startup, so we
+    need to initialize it now.
+    """
+    validator = _context.resolve(validator)
+    registerValidator(name, validator)
+    return []
+