[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Validators - BooleanValidator.py:1.1.4.2 DateTimeValidator.py:1.1.4.2 EmailValidator.py:1.1.4.2 FileValidator.py:1.1.4.2 FloatValidator.py:1.1.4.2 IntegerValidator.py:1.1.4.2 ListLinesValidator.py:1.1.4.2 MultiSelectionValidator.py:1.1.4.2 PatternValidator.py:1.1.4.2 SelectionValidator.py:1.1.4.2 StringBaseValidator.py:1.1.4.2 StringValidator.py:1.1.4.2 TextValidator.py:1.1.4.2

Jeremy Hylton jeremy@zope.com
Tue, 4 Jun 2002 12:28:19 -0400


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

Modified Files:
      Tag: Zope-3x-branch
	BooleanValidator.py DateTimeValidator.py EmailValidator.py 
	FileValidator.py FloatValidator.py IntegerValidator.py 
	ListLinesValidator.py MultiSelectionValidator.py 
	PatternValidator.py SelectionValidator.py 
	StringBaseValidator.py StringValidator.py TextValidator.py 
Log Message:
Fix line endings


=== Zope3/lib/python/Zope/App/Formulator/Validators/BooleanValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from Zope.App.Formulator.Validator import Validator
-
-class BooleanValidator(Validator):
-
-    __implements__ = Validator.__implements__
-
-    
-    def validate(self, field, value):
-
-        if value in ['t', 1]:
-            return 1
-
-        if value in ['f', 0, '', None]:
-            return 0
-
-        # XXX Should raise some sort of error
+"""
+
+$Id$
+"""
+
+from Zope.App.Formulator.Validator import Validator
+
+class BooleanValidator(Validator):
+
+    __implements__ = Validator.__implements__
+
+    
+    def validate(self, field, value):
+
+        if value in ['t', 1]:
+            return 1
+
+        if value in ['f', 0, '', None]:
+            return 0
+
+        # XXX Should raise some sort of error


=== Zope3/lib/python/Zope/App/Formulator/Validators/DateTimeValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from StringValidator import StringValidator
-from Zope.Misc.DateTimeParse import parse
-
-
-class DateTimeValidator(StringValidator):
-
-    propertyNames = StringValidator.propertyNames + \
-                    ['required', 'startDateTime', 'endDateTime']
-
-    requiredNotFound = 'Input is required but no input given.'
-    notDateTime = 'You did not enter a valid date and time.'
-    datetimeOutOfRange = 'The date and time you entered were out of range.'
-    
-    def validate(self, field, key, REQUEST):    
-        try:
-            year = field.validate_sub_field('year', REQUEST)
-            month = field.validate_sub_field('month', REQUEST)
-            day = field.validate_sub_field('day', REQUEST)
-            
-            if field.get_value('date_only'):
-                hour = 0
-                minute = 0
-            else:
-                hour = field.validate_sub_field('hour', REQUEST)
-                minute = field.validate_sub_field('minute', REQUEST)
-        except ValidationError:
-            self.raiseError('not_datetime', field)
-
-        # handling of completely empty sub fields
-        if ((year == '' and month == '' and day == '') and
-            (field.get_value('date_only') or (hour == '' and minute == ''))): 
-            if field.get_value('required'):
-                self.raise_error('required_not_found', field)
-            else:
-                # field is not required, return None for no entry
-                return None
-        # handling of partially empty sub fields; invalid datetime
-        if ((year == '' or month == '' or day == '') or
-            (not field.get_value('date_only') and
-             (hour == '' or minute == ''))):
-            self.raise_error('not_datetime', field)
-
-        try:
-            result = parse('%s/%s/%s %s:%s' %(year, month, day, hour, minute))
-        # ugh, a host of string based exceptions
-        except ('DateTimeError', 'Invalid Date Components', 'TimeError'):
-            self.raise_error('not_datetime', field)
-
-        # check if things are within range
-        start_datetime = field.get_value('start_datetime')
-        if (start_datetime is not None and
-            result < start_datetime):
-            self.raise_error('datetime_out_of_range', field)
-        end_datetime = field.get_value('end_datetime')
-        if (end_datetime is not None and
-            result >= end_datetime):
-            self.raise_error('datetime_out_of_range', field)
-
-        return result
+"""
+
+$Id$
+"""
+
+from StringValidator import StringValidator
+from Zope.Misc.DateTimeParse import parse
+
+
+class DateTimeValidator(StringValidator):
+
+    propertyNames = StringValidator.propertyNames + \
+                    ['required', 'startDateTime', 'endDateTime']
+
+    requiredNotFound = 'Input is required but no input given.'
+    notDateTime = 'You did not enter a valid date and time.'
+    datetimeOutOfRange = 'The date and time you entered were out of range.'
+    
+    def validate(self, field, key, REQUEST):    
+        try:
+            year = field.validate_sub_field('year', REQUEST)
+            month = field.validate_sub_field('month', REQUEST)
+            day = field.validate_sub_field('day', REQUEST)
+            
+            if field.get_value('date_only'):
+                hour = 0
+                minute = 0
+            else:
+                hour = field.validate_sub_field('hour', REQUEST)
+                minute = field.validate_sub_field('minute', REQUEST)
+        except ValidationError:
+            self.raiseError('not_datetime', field)
+
+        # handling of completely empty sub fields
+        if ((year == '' and month == '' and day == '') and
+            (field.get_value('date_only') or (hour == '' and minute == ''))): 
+            if field.get_value('required'):
+                self.raise_error('required_not_found', field)
+            else:
+                # field is not required, return None for no entry
+                return None
+        # handling of partially empty sub fields; invalid datetime
+        if ((year == '' or month == '' or day == '') or
+            (not field.get_value('date_only') and
+             (hour == '' or minute == ''))):
+            self.raise_error('not_datetime', field)
+
+        try:
+            result = parse('%s/%s/%s %s:%s' %(year, month, day, hour, minute))
+        # ugh, a host of string based exceptions
+        except ('DateTimeError', 'Invalid Date Components', 'TimeError'):
+            self.raise_error('not_datetime', field)
+
+        # check if things are within range
+        start_datetime = field.get_value('start_datetime')
+        if (start_datetime is not None and
+            result < start_datetime):
+            self.raise_error('datetime_out_of_range', field)
+        end_datetime = field.get_value('end_datetime')
+        if (end_datetime is not None and
+            result >= end_datetime):
+            self.raise_error('datetime_out_of_range', field)
+
+        return result


=== Zope3/lib/python/Zope/App/Formulator/Validators/EmailValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-import re
-from StringValidator import StringValidator
-
-class EmailValidator(StringValidator):
-
-    __implements__ = StringValidator.__implements__
-
-    messageNames = StringValidator.messageNames + ['notEmail']
-
-    notEmail = 'You did not enter an email address.'
-
-    # contributed, I don't pretend to understand this..
-    pattern = re.compile("^([0-9a-z_&.+-]+!)*[0-9a-z_&.+-]+"
-                         "@(([0-9a-z]([0-9a-z-]*[0-9a-z])?\.)+"
-                         "[a-z]{2,3}|([0-9]{1,3}\.){3}[0-9]{1,3})$")
-    
-    def validate(self, field, value):
-        value = StringValidator.validate(self, field, value)
-
-        if value == "" and not field.getValue('isRequired'):
-            return value
-
-        if self.pattern.search(value.lower()) == None:
-            self.raiseError('notEmail', field)
-        return value
+"""
+
+$Id$
+"""
+
+import re
+from StringValidator import StringValidator
+
+class EmailValidator(StringValidator):
+
+    __implements__ = StringValidator.__implements__
+
+    messageNames = StringValidator.messageNames + ['notEmail']
+
+    notEmail = 'You did not enter an email address.'
+
+    # contributed, I don't pretend to understand this..
+    pattern = re.compile("^([0-9a-z_&.+-]+!)*[0-9a-z_&.+-]+"
+                         "@(([0-9a-z]([0-9a-z-]*[0-9a-z])?\.)+"
+                         "[a-z]{2,3}|([0-9]{1,3}\.){3}[0-9]{1,3})$")
+    
+    def validate(self, field, value):
+        value = StringValidator.validate(self, field, value)
+
+        if value == "" and not field.getValue('isRequired'):
+            return value
+
+        if self.pattern.search(value.lower()) == None:
+            self.raiseError('notEmail', field)
+        return value


=== Zope3/lib/python/Zope/App/Formulator/Validators/FileValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from Zope.App.Formulator.Validator import Validator
-
-
-class FileValidator(Validator):
-
-    __implements__ = Validator.__implements__
-
-    def validate(self, field, value):
-        return value
-
+"""
+
+$Id$
+"""
+
+from Zope.App.Formulator.Validator import Validator
+
+
+class FileValidator(Validator):
+
+    __implements__ = Validator.__implements__
+
+    def validate(self, field, value):
+        return value
+


=== Zope3/lib/python/Zope/App/Formulator/Validators/FloatValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from StringBaseValidator import StringBaseValidator
-
-
-class FloatValidator(StringBaseValidator):
-
-    __implements__ = StringBaseValidator.__implements__
-
-    messageNames = StringBaseValidator.messageNames + ['notFloat']
-    notFloat = "You did not enter a floating point number."
-
-
-    def validate(self, field, value):
-        value = StringBaseValidator.validate(self, field, value)
-        if value == "" and not field.getValue('isRequired'):
-            return value
-
-        try:
-            value = float(value)
-        except ValueError:
-            self.raiseError('notFloat', field)
-        return value
+"""
+
+$Id$
+"""
+
+from StringBaseValidator import StringBaseValidator
+
+
+class FloatValidator(StringBaseValidator):
+
+    __implements__ = StringBaseValidator.__implements__
+
+    messageNames = StringBaseValidator.messageNames + ['notFloat']
+    notFloat = "You did not enter a floating point number."
+
+
+    def validate(self, field, value):
+        value = StringBaseValidator.validate(self, field, value)
+        if value == "" and not field.getValue('isRequired'):
+            return value
+
+        try:
+            value = float(value)
+        except ValueError:
+            self.raiseError('notFloat', field)
+        return value


=== Zope3/lib/python/Zope/App/Formulator/Validators/IntegerValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from StringBaseValidator import StringBaseValidator
-
-class IntegerValidator(StringBaseValidator):
-    """ """
-
-    __implements__ = StringBaseValidator.__implements__
-
-    propertyNames = StringBaseValidator.propertyNames +\
-                    ['start', 'end']
-
-    start = ""
-    end = ""
-    messageNames = StringBaseValidator.messageNames +\
-                   ['notInteger', 'integerOutOfRange']
-
-    notInteger = 'You did not enter an integer.'
-    integerOutOfRange = 'The integer you entered was out of range.'
-
-    def validate(self, field, value):
-        value = StringBaseValidator.validate(self, field, value)
-        
-        # we need to add this check again
-        if value == "" and not field.getValue('isRequired'):
-            return value
-
-        try:
-            value = int(value)
-        except ValueError:
-            self.raiseError('notInteger', field)
-
-        if self.start != "" and value < self.start:
-            self.raiseError('integerOutOfRange', field)
-        if self.end != "" and value >= self.end:
-            self.raiseError('integerOutOfRange', field)
-        return value
+"""
+
+$Id$
+"""
+
+from StringBaseValidator import StringBaseValidator
+
+class IntegerValidator(StringBaseValidator):
+    """ """
+
+    __implements__ = StringBaseValidator.__implements__
+
+    propertyNames = StringBaseValidator.propertyNames +\
+                    ['start', 'end']
+
+    start = ""
+    end = ""
+    messageNames = StringBaseValidator.messageNames +\
+                   ['notInteger', 'integerOutOfRange']
+
+    notInteger = 'You did not enter an integer.'
+    integerOutOfRange = 'The integer you entered was out of range.'
+
+    def validate(self, field, value):
+        value = StringBaseValidator.validate(self, field, value)
+        
+        # we need to add this check again
+        if value == "" and not field.getValue('isRequired'):
+            return value
+
+        try:
+            value = int(value)
+        except ValueError:
+            self.raiseError('notInteger', field)
+
+        if self.start != "" and value < self.start:
+            self.raiseError('integerOutOfRange', field)
+        if self.end != "" and value >= self.end:
+            self.raiseError('integerOutOfRange', field)
+        return value


=== Zope3/lib/python/Zope/App/Formulator/Validators/ListLinesValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from LinesValidator import LinesValidator
-
-class ListLinesValidator(LinesValidator):
-    """A validator that can deal with lines that have a | separator
-    in them to split between text and value of list items.
-    """
-
-    __implements__ = LinesValidator.__implements__
-    
-    def validate(self, value):
-        
-        value = Validator.LinesValidator.validate(value)
-        result = []
-        for line in value:
-            elements = string.split(line, "|")
-            if len(elements) >= 2:
-                text, value = elements[:2]
-            else:
-                text = line
-                value = line
-            text = string.strip(text)
-            value = string.strip(value)
-            result.append((text, value))
-        return result
+"""
+
+$Id$
+"""
+
+from LinesValidator import LinesValidator
+
+class ListLinesValidator(LinesValidator):
+    """A validator that can deal with lines that have a | separator
+    in them to split between text and value of list items.
+    """
+
+    __implements__ = LinesValidator.__implements__
+    
+    def validate(self, value):
+        
+        value = Validator.LinesValidator.validate(value)
+        result = []
+        for line in value:
+            elements = string.split(line, "|")
+            if len(elements) >= 2:
+                text, value = elements[:2]
+            else:
+                text = line
+                value = line
+            text = string.strip(text)
+            value = string.strip(value)
+            result.append((text, value))
+        return result


=== Zope3/lib/python/Zope/App/Formulator/Validators/MultiSelectionValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from Zope.App.Formulator.Validator import Validator
-from types import ListType
-
-class MultiSelectionValidator(Validator):
-    """ """
-    
-    __implements__ = Validator.__implements__
-
-    propertyNames = Validator.propertyNames + ['required']
-
-    required = 1
-
-    messageNames = Validator.messageNames + ['requiredNotFound',
-                                             'unknownSelection']
-    
-    requiredNotFound = 'Input is required but no input given.'
-    unknownSelection = 'You selected an item that was not in the list.'
-
-    
-    def validate(self, field, value):
-        values = value
-        # NOTE: a hack to deal with single item selections
-        if not isinstance(values, ListType):
-            # put whatever we got in a list
-            values = [values]
-
-        # if we selected nothing and entry is required, give error, otherwise
-        # give entry list
-        if len(values) == 0:
-            if field.get_value('isRequired'):
-                self.raise_error('requiredNotFound', field)
-            else:
-                return values
-            
-        # create a dictionary of possible values
-        value_dict = {}
-        for item in field.get_value('items'):
-            try:
-                item_text, item_value = item
-            except ValueError:
-                item_text = item
-                item_value = item
-            value_dict[item_value] = 0
-        # check whether all values are in dictionary
-        result = []
-        for value in values:
-            # FIXME: hack to accept int values as well
-            try:
-                int_value = int(value)
-            except ValueError:
-                int_value = None
-            if int_value is not None and value_dict.has_key(int_value):
-                result.append(int_value)
-                continue
-            if value_dict.has_key(value):
-                result.append(value)
-                continue
-            self.raise_error('unknownSelection', field)
-        # everything checks out
-        return result
+"""
+
+$Id$
+"""
+
+from Zope.App.Formulator.Validator import Validator
+from types import ListType
+
+class MultiSelectionValidator(Validator):
+    """ """
+    
+    __implements__ = Validator.__implements__
+
+    propertyNames = Validator.propertyNames + ['required']
+
+    required = 1
+
+    messageNames = Validator.messageNames + ['requiredNotFound',
+                                             'unknownSelection']
+    
+    requiredNotFound = 'Input is required but no input given.'
+    unknownSelection = 'You selected an item that was not in the list.'
+
+    
+    def validate(self, field, value):
+        values = value
+        # NOTE: a hack to deal with single item selections
+        if not isinstance(values, ListType):
+            # put whatever we got in a list
+            values = [values]
+
+        # if we selected nothing and entry is required, give error, otherwise
+        # give entry list
+        if len(values) == 0:
+            if field.get_value('isRequired'):
+                self.raise_error('requiredNotFound', field)
+            else:
+                return values
+            
+        # create a dictionary of possible values
+        value_dict = {}
+        for item in field.get_value('items'):
+            try:
+                item_text, item_value = item
+            except ValueError:
+                item_text = item
+                item_value = item
+            value_dict[item_value] = 0
+        # check whether all values are in dictionary
+        result = []
+        for value in values:
+            # FIXME: hack to accept int values as well
+            try:
+                int_value = int(value)
+            except ValueError:
+                int_value = None
+            if int_value is not None and value_dict.has_key(int_value):
+                result.append(int_value)
+                continue
+            if value_dict.has_key(value):
+                result.append(value)
+                continue
+            self.raise_error('unknownSelection', field)
+        # everything checks out
+        return result


=== Zope3/lib/python/Zope/App/Formulator/Validators/PatternValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from StringValidator import StringValidator
-import PatternChecker
-
-class PatternValidator(StringValidator):
-
-    __implements__ = StringValidator.__implements__
-
-    # does the real work
-    checker = PatternChecker.PatternChecker()
-    
-    propertyNames = StringValidator.propertyNames +\
-                     ['pattern']
-
-    pattern = ""
-
-    messageNames = StringValidator.messageNames +\
-                    ['patternNotMatched']
-
-    patternNotMatched = "The entered value did not match the pattern."
-
-    def validate(self, field, value):
-        value = StringValidator.validate(self, field, value)
-        
-        if value == "" and not field.get_value('required'):
-            return value
-
-        value = self.checker.validate_value([field.get_value('pattern')],
-                                            value)
-        if value is None:
-            self.raise_error('patternNotMatched', field)
-        return value
+"""
+
+$Id$
+"""
+
+from StringValidator import StringValidator
+import PatternChecker
+
+class PatternValidator(StringValidator):
+
+    __implements__ = StringValidator.__implements__
+
+    # does the real work
+    checker = PatternChecker.PatternChecker()
+    
+    propertyNames = StringValidator.propertyNames +\
+                     ['pattern']
+
+    pattern = ""
+
+    messageNames = StringValidator.messageNames +\
+                    ['patternNotMatched']
+
+    patternNotMatched = "The entered value did not match the pattern."
+
+    def validate(self, field, value):
+        value = StringValidator.validate(self, field, value)
+        
+        if value == "" and not field.get_value('required'):
+            return value
+
+        value = self.checker.validate_value([field.get_value('pattern')],
+                                            value)
+        if value is None:
+            self.raise_error('patternNotMatched', field)
+        return value


=== Zope3/lib/python/Zope/App/Formulator/Validators/SelectionValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from StringBaseValidator import StringBaseValidator
-
-
-class SelectionValidator(StringBaseValidator):
-
-    __implements__ = StringBaseValidator.__implements__
-
-    messageNames = StringBaseValidator.messageNames +\
-                   ['unknownSelection']
-
-    unknownSelection = 'You selected an item that was not in the list.'
-    
-    def validate(self, field, value):
-        value = StringBaseValidator.validate(self, field, value)
-
-        if value == "" and not field.get_value('required'):
-            return value
-
-        # get the text and the value from the list of items
-        for item in field.get_value('items'):
-            try:
-                item_text, item_value = item
-            except ValueError:
-                item_text = item
-                item_value = item
-            
-            # check if the value is equal to the *string* version of
-            # item_value; if that's the case, we can return the *original*
-            # value in the list (not the submitted value). This way, integers
-            # will remain integers.
-            if str(item_value) == value:
-                return item_value
-            
-        # if we didn't find the value, return error
-        self.raise_error('unknownSelection', field)
+"""
+
+$Id$
+"""
+
+from StringBaseValidator import StringBaseValidator
+
+
+class SelectionValidator(StringBaseValidator):
+
+    __implements__ = StringBaseValidator.__implements__
+
+    messageNames = StringBaseValidator.messageNames +\
+                   ['unknownSelection']
+
+    unknownSelection = 'You selected an item that was not in the list.'
+    
+    def validate(self, field, value):
+        value = StringBaseValidator.validate(self, field, value)
+
+        if value == "" and not field.get_value('required'):
+            return value
+
+        # get the text and the value from the list of items
+        for item in field.get_value('items'):
+            try:
+                item_text, item_value = item
+            except ValueError:
+                item_text = item
+                item_value = item
+            
+            # check if the value is equal to the *string* version of
+            # item_value; if that's the case, we can return the *original*
+            # value in the list (not the submitted value). This way, integers
+            # will remain integers.
+            if str(item_value) == value:
+                return item_value
+            
+        # if we didn't find the value, return error
+        self.raise_error('unknownSelection', field)


=== Zope3/lib/python/Zope/App/Formulator/Validators/StringBaseValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from Zope.App.Formulator.Validator import Validator
-from types import StringType
-
-  
-class StringBaseValidator(Validator):
-    """Simple string validator.
-    """
-
-    __implements__ = Validator.__implements__
-    
-    propertyNames = Validator.propertyNames + ['required']
-    messageNames = Validator.messageNames + ['requiredNotFound']
-    
-    requiredNotFound = 'Input is required but no input given.'
-    illegalValue = 'The value is not a string.'
-
-        
-    def validate(self, field, value):
-        """ """
-        if not isinstance(value, StringType):
-            self.raiseError('illegalValue', field)
-        value = value.strip()
-        if field.getValue('isRequired') and value == "":
-            self.raiseError('requiredNotFound', field)
-
-        return value
+"""
+
+$Id$
+"""
+
+from Zope.App.Formulator.Validator import Validator
+from types import StringType
+
+  
+class StringBaseValidator(Validator):
+    """Simple string validator.
+    """
+
+    __implements__ = Validator.__implements__
+    
+    propertyNames = Validator.propertyNames + ['required']
+    messageNames = Validator.messageNames + ['requiredNotFound']
+    
+    requiredNotFound = 'Input is required but no input given.'
+    illegalValue = 'The value is not a string.'
+
+        
+    def validate(self, field, value):
+        """ """
+        if not isinstance(value, StringType):
+            self.raiseError('illegalValue', field)
+        value = value.strip()
+        if field.getValue('isRequired') and value == "":
+            self.raiseError('requiredNotFound', field)
+
+        return value


=== Zope3/lib/python/Zope/App/Formulator/Validators/StringValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from StringBaseValidator import StringBaseValidator
-
-
-class StringValidator(StringBaseValidator):
-    """ """
-
-    __implements__ = StringBaseValidator.__implements__
-    
-
-    propertyNames = StringBaseValidator.propertyNames + \
-                    ['maxLength', 'truncate']
-    maxLength = 0
-    truncate = 0
-    
-    messageNames = StringBaseValidator.messageNames + \
-                    ['tooLong']
-
-    tooLong = 'Too much input was given.'
-
-
-    def validate(self, field, value):
-        value = StringBaseValidator.validate(self, field, value)
-
-        maxLength = self.maxLength or 0
-        
-        if maxLength > 0 and len(value) > maxLength:
-            if self.truncate:
-                value = value[:maxLength]
-            else:
-                self.raiseError('tooLong', field)
-
-        return value
-
+"""
+
+$Id$
+"""
+
+from StringBaseValidator import StringBaseValidator
+
+
+class StringValidator(StringBaseValidator):
+    """ """
+
+    __implements__ = StringBaseValidator.__implements__
+    
+
+    propertyNames = StringBaseValidator.propertyNames + \
+                    ['maxLength', 'truncate']
+    maxLength = 0
+    truncate = 0
+    
+    messageNames = StringBaseValidator.messageNames + \
+                    ['tooLong']
+
+    tooLong = 'Too much input was given.'
+
+
+    def validate(self, field, value):
+        value = StringBaseValidator.validate(self, field, value)
+
+        maxLength = self.maxLength or 0
+        
+        if maxLength > 0 and len(value) > maxLength:
+            if self.truncate:
+                value = value[:maxLength]
+            else:
+                self.raiseError('tooLong', field)
+
+        return value
+


=== Zope3/lib/python/Zope/App/Formulator/Validators/TextValidator.py 1.1.4.1 => 1.1.4.2 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-from LinesValidator import LinesValidator
-
-class TextValidator(LinesValidator):
-    """ """
-    
-    def validate(self, field, value):
-        value = LinesValidator.validate(self, field, value)
-        # we need to add this check again
-        if value == [] and not field.get_value('isRequired'):
-            return ""
-
-        # join everything into string again with \n and return
-        return "\n".join(value)
-
+"""
+
+$Id$
+"""
+
+from LinesValidator import LinesValidator
+
+class TextValidator(LinesValidator):
+    """ """
+    
+    def validate(self, field, value):
+        value = LinesValidator.validate(self, field, value)
+        # we need to add this check again
+        if value == [] and not field.get_value('isRequired'):
+            return ""
+
+        # join everything into string again with \n and return
+        return "\n".join(value)
+