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 action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK):
if self.getFocusId() == LIST: if self.getFocusId() == LIST:
option = self.list_.getSelectedItem() 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) LOG.info('option selected: %s', self.selected_option)
self.close() self.close()
def _add_editcontrol(self, x, y, height, width, password=None): def _add_editcontrol(self, x, y, height, width, password=None):
media = path_ops.path.join( media = path_ops.path.join(
v.ADDON_PATH, 'resources', 'skins', 'default', 'media') 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, control = xbmcgui.ControlImage(0, 0, 0, 0,
filename=filename, filename=filename,
aspectRatio=0, aspectRatio=0,

View file

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

View file

@ -320,31 +320,15 @@ def cast(func, value):
def extend_url(url, params): 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)>' '<url><? or &><urllib.urlencode(params)>'
in unicode in string
""" """
params = encode_dict(params) if params else {} params = urllib.parse.urlencode(params)
params = urllib.parse.urlencode(params).decode('utf-8')
if '?' in url: if '?' in url:
return '%s&%s' % (url, params) return f'{url}&{params}'
else: else:
return '%s?%s' % (url, params) return f'{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
def parse_qs(qs, keep_blank_values=0, strict_parsing=0): def parse_qs(qs, keep_blank_values=0, strict_parsing=0):