From cf943057438987efb6ae83b08ae0350fa00b5ab4 Mon Sep 17 00:00:00 2001 From: marcelveldt Date: Thu, 21 Jan 2016 11:15:31 +0100 Subject: [PATCH] prevent possible unicode error in window method --- resources/lib/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 7878a08e..11a059b3 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -43,10 +43,16 @@ def window(property, value=None, clear=False, windowid=10000): # Get or set window property WINDOW = xbmcgui.Window(windowid) + #setproperty accepts both string and unicode but utf-8 strings are adviced by kodi devs because some unicode can give issues + if isinstance(property, unicode): + property = property.encode("utf-8") + if isinstance(value, unicode): + value = value.encode("utf-8") + if clear: WINDOW.clearProperty(property) - elif value is not None: #setproperty accepts both string and unicode but utf-8 string seems best practice to pass - WINDOW.setProperty(property.encode("utf-8"), value.encode("utf-8")) + elif value is not None: + WINDOW.setProperty(property, value) else: #getproperty returns string so convert to unicode return WINDOW.getProperty(property).decode("utf-8")