IS_MATCH fix, thanks Anthony

This commit is contained in:
Massimo Di Pierro
2011-12-25 12:24:40 -06:00
parent bd1e27e434
commit b2849070c9
2 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -1 +1 @@
Version 1.99.4 (2011-12-24 10:52:51) stable
Version 1.99.4 (2011-12-25 12:24:19) stable
+4 -3
View File
@@ -145,7 +145,7 @@ class IS_MATCH(Validator):
"""
def __init__(self, expression, error_message='invalid expression',
strict=False, search=False):
strict=False, search=False, extract=False):
if strict or not search:
if not expression.startswith('^'):
expression = '^(%s)' % expression
@@ -154,11 +154,12 @@ class IS_MATCH(Validator):
expression = '(%s)$' % expression
self.regex = re.compile(expression)
self.error_message = error_message
self.extract = extract
def __call__(self, value):
match = self.regex.search(value)
if match:
return (match.group(), None)
if match is not None:
return (self.extract and match.group() or value, None)
return (value, translate(self.error_message))