More string bytes fixes

This commit is contained in:
croneter 2020-12-19 08:19:24 +01:00
parent d7525274e9
commit d306f36869
3 changed files with 8 additions and 23 deletions

View file

@ -59,14 +59,14 @@ class ContextMenu(xbmcgui.WindowXMLDialog):
if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK):
if self.getFocusId() == LIST:
option = self.list_.getSelectedItem()
self.selected_option = option.getLabel().decode('utf-8')
self.selected_option = option.getLabel()
LOG.info('option selected: %s', self.selected_option)
self.close()
def _add_editcontrol(self, x, y, height, width, password=None):
media = path_ops.path.join(
v.ADDON_PATH, 'resources', 'skins', 'default', 'media')
filename = utils.try_encode(path_ops.path.join(media, 'white.png'))
filename = path_ops.path.join(media, 'white.png')
control = xbmcgui.ControlImage(0, 0, 0, 0,
filename=filename,
aspectRatio=0,

View file

@ -155,6 +155,7 @@ class plexgdm(object):
while self._registration_is_running:
try:
data, addr = update_sock.recvfrom(1024)
data = data.decode()
log.debug("Recieved UDP packet from [%s] containing [%s]"
% (addr, data.strip()))
except socket.error:

View file

@ -320,31 +320,15 @@ def cast(func, value):
def extend_url(url, params):
"""
Pass in an url [unicode] and params [dict]. Returns the extended url
Pass in an url [string] and params [dict]. Returns the extended url
'<url><? or &><urllib.urlencode(params)>'
in unicode
in string
"""
params = encode_dict(params) if params else {}
params = urllib.parse.urlencode(params).decode('utf-8')
params = urllib.parse.urlencode(params)
if '?' in url:
return '%s&%s' % (url, params)
return f'{url}&{params}'
else:
return '%s?%s' % (url, params)
def encode_dict(dictionary):
"""
Pass in a dict. Will return the same dict with all keys and values encoded
in utf-8 - as long as they are unicode. Ignores all non-unicode entries
Useful for urllib.urlencode or urllib.(un)quote
"""
for key, value in dictionary.items():
if isinstance(key, str):
dictionary[key.encode('utf-8')] = dictionary.pop(key)
if isinstance(value, str):
dictionary[key] = value.encode('utf-8')
return dictionary
return f'{url}?{params}'
def parse_qs(qs, keep_blank_values=0, strict_parsing=0):