Repository navigation
isinstance(filename, "utf-8") #304
Description
Activity
Not sure what you are asking for but you are welcome to send a pull request
Easy - according to content of the error, the second argument of isinstance can't be string (i.e. 'utf-8'). 'isinstance' is not the way how you check file encoding. I'm not sure what is a propper way (that's why I asked it on SO) but the current implementation is clearly wrong.
How about isinstance(filename, unicode) ? (HT: @mjpieters)
isinstance(filename, str)should work. It isnot isinstance()and the code is trying to convert it tostrbecause that is the right type for both Python 2 and 3 here.https://enjoydoingitwrong.wordpress.com/2009/06/22/unicode-is-not-utf/
so I'm not sure if you want to check encoding (in that case isinstance(filename, unicode) is not the answer) or just check if the content is instance of basestring or unicode.@mjpieters - if you know it for sure, can you change it?
@mnowotka You can change it by sending a pull request 😃
That (original) code looks like a double encoding bug waiting to happen.
@wiredfool: No, it's fine; Python 2
not strmeansunicode, so it needs to be encoded, in Python 3,not strmeansbytes, so it needs to be decoded.- added a commit that references this issue
on Jul 25, 2013 @mjpieters fair enough.
This line: https://github.com/python-imaging/Pillow/blob/master/PIL/ImageFont.py#L264 causes error as described here:
http://stackoverflow.com/questions/17863735/python-pillow-better-pil-encoding-check-bug
Please, fix it.