Author: ianb
Date: 2008-11-14 16:19:09 -0700 (Fri, 14 Nov 2008)
New Revision: 3654
Modified:
FormEncode/trunk/docs/news.txt
FormEncode/trunk/formencode/validators.py
Log:
Make FieldsMatch raise a normal Invalid error when passed a non-dictionary (SF
2261391)
Modified: FormEncode/trunk/docs/news.txt
===================================================================
--- FormEncode/trunk/docs/news.txt 2008-11-14 23:11:35 UTC (rev 3653)
+++ FormEncode/trunk/docs/news.txt 2008-11-14 23:19:09 UTC (rev 3654)
@@ -14,6 +14,9 @@
* In :class:`formencode.validators.Email` allow single-character
domain names (like x.com).
+* Make :class:`formencode.validators.FieldsMatch` give a normal
+ ``Invalid`` exception if you pass it a non-dictionary.
+
1.1
---
Modified: FormEncode/trunk/formencode/validators.py
===================================================================
--- FormEncode/trunk/formencode/validators.py 2008-11-14 23:11:35 UTC (rev
3653)
+++ FormEncode/trunk/formencode/validators.py 2008-11-14 23:19:09 UTC (rev
3654)
@@ -2628,8 +2628,14 @@
messages = {
'invalid': _("Fields do not match (should be %(match)s)"),
'invalidNoMatch': _("Fields do not match"),
+ 'notDict': _("Fields should be a dictionary"),
}
+ def __init__(self, *args, **kw):
+ super(FormValidator, self).__init__(*args, **kw)
+ if len(self.field_names) < 2:
+ raise TypeError("FieldsMatch() requires at least two field names")
+
def validate_partial(self, field_dict, state):
for name in self.field_names:
if not field_dict.has_key(name):
@@ -2637,7 +2643,11 @@
self.validate_python(field_dict, state)
def validate_python(self, field_dict, state):
- ref = field_dict[self.field_names[0]]
+ try:
+ ref = field_dict[self.field_names[0]]
+ except TypeError:
+ # Generally because field_dict isn't a dict
+ raise Invalid(self.message('notDict', state), field_dict, state)
errors = {}
for name in self.field_names[1:]:
if field_dict.get(name, '') != ref:
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs