Author: ianb
Date: 2006-10-18 16:08:13 -0600 (Wed, 18 Oct 2006)
New Revision: 2025

Modified:
   FormEncode/trunk/formencode/htmlfill.py
Log:
Improve the error message when you mix unicode and an encoded form

Modified: FormEncode/trunk/formencode/htmlfill.py
===================================================================
--- FormEncode/trunk/formencode/htmlfill.py     2006-10-16 14:43:35 UTC (rev 
2024)
+++ FormEncode/trunk/formencode/htmlfill.py     2006-10-18 22:08:13 UTC (rev 
2025)
@@ -195,6 +195,7 @@
         self.text_as_default = text_as_default
 
     def feed(self, data):
+        self.data_is_str = isinstance(data, str)
         self.source = data
         self.lines = data.split('\n')
         self.source_pos = 1, 0
@@ -230,8 +231,22 @@
                 assert False, (
                     "These errors were not used in the form: %s" % 
                     ', '.join(error_text))
-        self._text = ''.join([
-            t for t in self._content if not isinstance(t, tuple)])
+        try:
+            self._text = ''.join([
+                t for t in self._content if not isinstance(t, tuple)])
+        except UnicodeDecodeError, e:
+            if self.data_is_str:
+                raise UnicodeDecodeError(
+                    "The form was passed in as an encoded string, but "
+                    "some data or error messages were unicode strings; "
+                    "the form should be passed in as a unicode string "
+                    "(error: %s)" % e)
+            else:
+                raise UnicodeDecodeError(
+                    "The form was passed in as an unicode string, but "
+                    "some data or error message was an encoded string; "
+                    "the data and error messages should be passed in as "
+                    "unicode strings (error: %s)" % e)
 
     def add_key(self, key):
         self.used_keys[key] = 1


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs

Reply via email to