|
From: <sub...@co...> - 2005-11-19 23:03:11
|
Author: ianb
Date: 2005-11-19 23:03:06 +0000 (Sat, 19 Nov 2005)
New Revision: 1296
Modified:
FormEncode/trunk/formencode/validators.py
Log:
Added some tests; fix String wrt the new handling of empty (turn all empty things to empty strings, not None)
Modified: FormEncode/trunk/formencode/validators.py
===================================================================
--- FormEncode/trunk/formencode/validators.py 2005-11-19 22:57:27 UTC (rev 1295)
+++ FormEncode/trunk/formencode/validators.py 2005-11-19 23:03:06 UTC (rev 1296)
@@ -895,6 +895,18 @@
"""
Convert a value to a float or integer. Tries to convert it to
an integer if no information is lost.
+
+ ::
+
+ >>> Number.to_python('10')
+ 10
+ >>> Number.to_python('10.5')
+ 10.5
+ >>> Number.to_python('ten')
+ Traceback (most recent call last):
+ ...
+ Invalid: Please enter a number
+
"""
messages = {
@@ -918,6 +930,21 @@
Also takes a `max` and `min` argument, and the string length must
fall in that range.
+
+ ::
+
+ >>> String(min=2).to_python('a')
+ Traceback (most recent call last):
+ ...
+ Invalid: Enter a value 2 characters long or more
+ >>> String(max=10).to_python('xxxxxxxxxxx')
+ Traceback (most recent call last):
+ ...
+ Invalid: Enter a value less than 10 characters long
+ >>> String().from_python(None)
+ ''
+ >>> String().from_python([])
+ ''
"""
min = None
@@ -947,6 +974,9 @@
return str(value)
return ""
+ def empty_value(self, value):
+ return ''
+
class Set(FancyValidator):
"""
|