Problems with DateValidator (strftime raises TypeError as it gets unicode, not string)
Marcin Kasperski <[email protected]>
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Take a look at the following example:
from datetime import date
import formencode
since = formencode.All(
formencode.validators.DateValidator(
earliest_date = date(1995, 1, 1),
latest_date = date.today(),
),
formencode.validators.DateConverter(
month_style = 'dd/mm/yyyy', not_empty=True, strip=True),
)
since.to_python('10/12/2001')
# Above works correctly, returns datetime.date(2001,12,10)
since.to_python('strangetext')
# Also works correctly, raises formencode.api.Invalid
since.to_python('10/12/1991')
# buuuuuuum!!!!!
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/FormEncode-0.7.1-py2.4.egg/formencode/api.py", line 368, in to_python
value = tp(value, state)
File "/usr/lib/python2.4/site-packages/FormEncode-0.7.1-py2.4.egg/formencode/compound.py", line 57, in _to_python
to_python)
File "/usr/lib/python2.4/site-packages/FormEncode-0.7.1-py2.4.egg/formencode/compound.py", line 118, in attempt_convert
value = validate(validator, value, state)
File "/usr/lib/python2.4/site-packages/FormEncode-0.7.1-py2.4.egg/formencode/compound.py", line 15, in to_python
return validator.to_python(value, state)
File "/usr/lib/python2.4/site-packages/FormEncode-0.7.1-py2.4.egg/formencode/api.py", line 371, in to_python
vp(value, state)
File "/usr/lib/python2.4/site-packages/FormEncode-0.7.1-py2.4.egg/formencode/validators.py", line 827, in validate_python
date_formatted = earliest_date.strftime(
TypeError: strftime() argument 1 must be str, not unicode
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/