1. Rune Halvorsen
  2. pblight

Commits

Rune Halvorsen  committed 8210a13

Made the string type checker more liberal

  • Participants
  • Parent commits adb99e0
  • Branches default

Comments (0)

Files changed (1)

File pblight.py

View file
         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):