Commits

Rune Halvorsen committed 8210a13

Made the string type checker more liberal

Comments (0)

Files changed (1)

         return data.decode("utf-8")
 
     def check_type(self, data):
-        if not isinstance(data, unicode):
-            raise TypeError()
+        if isinstance(data, str):
+            try:
+                data.encode("utf-8")
+                return
+            except UnicodeDecodeError:
+                pass
+        elif isinstance(data, unicode):
+            return
+        raise TypeError()
 
 
 class BytesField(LengthDelimitedField):