From: <sub...@co...> - 2009-03-05 23:03:20
|
Author: chrisz Date: 2009-03-05 16:03:14 -0700 (Thu, 05 Mar 2009) New Revision: 3801 Modified: FormEncode/trunk/formencode/validators.py Log: Fix for bug #2666139: On a German Win XP system, DateValidator breaks in March when the German locale is activated, because the month name contains a non-ascii character and DateValidator tries to decode it, wrongly assuming the system is using utf-8, while Windows is using cp1252. Modified: FormEncode/trunk/formencode/validators.py =================================================================== --- FormEncode/trunk/formencode/validators.py 2009-03-05 17:53:16 UTC (rev 3800) +++ FormEncode/trunk/formencode/validators.py 2009-03-05 23:03:14 UTC (rev 3801) @@ -23,6 +23,7 @@ Validator/Converters for use with FormEncode. """ +import locale import warnings import re DateTime = None @@ -829,8 +830,8 @@ def validate_python(self, value, state): date_format = self.message('date_format', state) if isinstance(date_format, unicode): - # strftime doesn't like unicode - encoding = 'utf8' + # strftime uses the locale encoding, not Unicode + encoding = locale.getlocale(locale.LC_TIME)[1] or 'utf-8' date_format = date_format.encode(encoding) else: encoding = None |