Author: ianb
Date: 2008-12-18 14:11:15 -0700 (Thu, 18 Dec 2008)
New Revision: 3738

Modified:
   FormEncode/trunk/docs/news.txt
   FormEncode/trunk/formencode/api.py
Log:
Make the __unicode__ method safer

Modified: FormEncode/trunk/docs/news.txt
===================================================================
--- FormEncode/trunk/docs/news.txt      2008-12-17 23:30:53 UTC (rev 3737)
+++ FormEncode/trunk/docs/news.txt      2008-12-18 21:11:15 UTC (rev 3738)
@@ -3,6 +3,12 @@
 
 .. contents::
 
+svn trunk
+---------
+
+* Be more careful about ``unicode(Invalid(...))``, to make sure it
+  always returns unicode.
+
 1.2
 ---
 

Modified: FormEncode/trunk/formencode/api.py
===================================================================
--- FormEncode/trunk/formencode/api.py  2008-12-17 23:30:53 UTC (rev 3737)
+++ FormEncode/trunk/formencode/api.py  2008-12-18 21:11:15 UTC (rev 3738)
@@ -119,7 +119,12 @@
         return val    
 
     def __unicode__(self):
-        return self.msg
+        if isinstance(self.msg, unicode):
+            return self.msg
+        elif isinstance(self.msg, str):
+            return self.msg.decode('utf8')
+        else:
+            return unicode(self.msg)
 
     def unpack_errors(self, encode_variables=False, dict_char='.',
                       list_char='-'):


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs

Reply via email to