String encoding
#1
this is more a not to other people running into the same kind of bugs as i have. they can be quite hard to find.

xbmc's python is very sensitive to string encodings. here's a recent experience when i built a cache into ooba.

i had these lines:
Quote:localfile=cachefolder+'f'+digest+'.'+ext
fcache=file(localfile,'wb')


and it chrashed (refused to open the file) whenever ext was not an empty string (e.g. localfile="faa6abcb928ad22070e69cf30591a5432.gif"). note this only happened on the xbox, not in the emu. i managed to get it to work by doing this:


Quote:localfile=cachefolder+'f'+digest+'.'+ext.encode('iso-8859-1')

note, ext comes from a regexp that has been applied to a url:

Quote:extre=re.compile('\w?(jpg|jpeg|gif|png)\w?',re.ignorecase) #be very flexible with extension.
def getimageextension(url):
result=extre.findall(url)
if len(result)>0:
result=result[-1].lower()       #prioritize the last match
if result=='jpeg': result='jpg'
return result
else:
return ''

and the url was read from xml with minidom. i suppose it is when it is read from xml that something happens to the encoding.



i've also had similar problems with controllists when i was trying to add items that were encoded wrongly (utf-8).
Reply

Logout Mark Read Team Forum Stats Members Help
String encoding0