From 1f009cc5a3c45598757dbc0a9c0f9feff2c301af Mon Sep 17 00:00:00 2001 From: Phillip Berndt Date: Sat, 17 Jan 2015 17:45:23 +0100 Subject: [PATCH] Unicode compatibility for Python 2 setattr(object, unicode that can't be encoded to ascii, value) did not work there. So instead, force encoding as utf8 which hopefully everyone out there uses. --- bitfield/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bitfield/forms.py b/bitfield/forms.py index 0eccedef..f0f0cb2d 100644 --- a/bitfield/forms.py +++ b/bitfield/forms.py @@ -40,7 +40,10 @@ def clean(self, value): result = BitHandler(0, [k for k, v in self.choices]) for k in value: try: - setattr(result, str(k), True) + try: + setattr(result, unicode(k).encode("utf8"), True) + except NameError: + setattr(result, str(k), True) except AttributeError: raise ValidationError('Unknown choice: %r' % (k,)) return int(result)