Commit 75fcee23 authored by Jérome Perrin's avatar Jérome Perrin

backport c1852 from upstream


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34923 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 414cadba
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import string, re import re
import PatternChecker import PatternChecker
from DummyField import fields from DummyField import fields
from DateTime import DateTime from DateTime import DateTime
...@@ -102,10 +102,10 @@ class StringBaseValidator(Validator): ...@@ -102,10 +102,10 @@ class StringBaseValidator(Validator):
if isinstance(value, str): if isinstance(value, str):
if field.has_value('whitespace_preserve'): if field.has_value('whitespace_preserve'):
if not field.get_value('whitespace_preserve'): if not field.get_value('whitespace_preserve'):
value = string.strip(value) value = value.strip()
else: else:
# XXX Compatibility: use to prevent KeyError exception from get_value # XXX Compatibility: use to prevent KeyError exception from get_value
value = string.strip(value) value = value.strip()
if field.get_value('required') and value == "": if field.get_value('required') and value == "":
self.raise_error('required_not_found', field) self.raise_error('required_not_found', field)
...@@ -181,7 +181,7 @@ class EmailValidator(StringValidator): ...@@ -181,7 +181,7 @@ class EmailValidator(StringValidator):
if value == "" and not field.get_value('required'): if value == "" and not field.get_value('required'):
return value return value
if self.pattern.search(string.lower(value)) == None: if self.pattern.search(value.lower()) == None:
self.raise_error('not_email', field) self.raise_error('not_email', field)
return value return value
...@@ -376,7 +376,7 @@ class LinesValidator(StringBaseValidator): ...@@ -376,7 +376,7 @@ class LinesValidator(StringBaseValidator):
value = StringBaseValidator.validate(self, field, key, REQUEST) value = StringBaseValidator.validate(self, field, key, REQUEST)
# Added as a patch for hidden values # Added as a patch for hidden values
if isinstance(value, (list, tuple)): if isinstance(value, (list, tuple)):
value = string.join(value, "\n") value = value.join('\n')
# we need to add this check again # we need to add this check again
if value == "" and not field.get_value('required'): if value == "" and not field.get_value('required'):
return [] return []
...@@ -387,7 +387,7 @@ class LinesValidator(StringBaseValidator): ...@@ -387,7 +387,7 @@ class LinesValidator(StringBaseValidator):
if max_length and len(value) > max_length: if max_length and len(value) > max_length:
self.raise_error('too_long', field) self.raise_error('too_long', field)
# split input into separate lines # split input into separate lines
lines = string.split(value, "\n") lines = value.split("\n")
# check whether we have too many lines # check whether we have too many lines
max_lines = field.get_value('max_lines') or 0 max_lines = field.get_value('max_lines') or 0
...@@ -401,7 +401,7 @@ class LinesValidator(StringBaseValidator): ...@@ -401,7 +401,7 @@ class LinesValidator(StringBaseValidator):
whitespace_preserve = field.get_value('whitespace_preserve') whitespace_preserve = field.get_value('whitespace_preserve')
for line in lines: for line in lines:
if not whitespace_preserve: if not whitespace_preserve:
line = string.strip(line) line = line.strip()
if max_linelength and len(line) > max_linelength: if max_linelength and len(line) > max_linelength:
self.raise_error('line_too_long', field) self.raise_error('line_too_long', field)
result.append(line) result.append(line)
...@@ -418,7 +418,7 @@ class TextValidator(LinesValidator): ...@@ -418,7 +418,7 @@ class TextValidator(LinesValidator):
return "" return ""
# join everything into string again with \n and return # join everything into string again with \n and return
return string.join(value, "\n") return "\n".join(value)
TextValidatorInstance = TextValidator() TextValidatorInstance = TextValidator()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment