From 5bd08635f2886bd631d2cb6ab6ca6f2e719fd6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Mon, 20 Apr 2020 20:20:17 +0200 Subject: [PATCH] Make sure file paths is text, not binary Work around https://bugs.python.org/issue6543 for Python 2 --- jellyfin_kodi/helper/loghandler.py | 8 ++++++++ jellyfin_kodi/objects/obj.py | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jellyfin_kodi/helper/loghandler.py b/jellyfin_kodi/helper/loghandler.py index 0e8fabc7..d6b5b4c9 100644 --- a/jellyfin_kodi/helper/loghandler.py +++ b/jellyfin_kodi/helper/loghandler.py @@ -4,9 +4,12 @@ from __future__ import division, absolute_import, print_function, unicode_litera ################################################################################################## import os +import sys import logging import traceback +from six import ensure_text + from kodi_six import xbmc, xbmcaddon import database @@ -86,6 +89,9 @@ class MyFormatter(logging.Formatter): logging.Formatter.__init__(self, fmt) def format(self, record): + if record.pathname: + record.pathname = ensure_text(record.pathname, sys.getfilesystemencoding()) + self._gen_rel_path(record) # Call the original formatter class to do the grunt work @@ -98,6 +104,8 @@ class MyFormatter(logging.Formatter): res = [] for o in traceback.format_exception(*exc_info): + o = ensure_text(o, sys.getfilesystemencoding()) + if o.startswith(' File "'): # If this split can't handle your file names, you should seriously consider renaming your files. fn = o.split(' File "', 2)[1].split('", line ', 1)[0] diff --git a/jellyfin_kodi/objects/obj.py b/jellyfin_kodi/objects/obj.py index 81b2b666..d04aa982 100644 --- a/jellyfin_kodi/objects/obj.py +++ b/jellyfin_kodi/objects/obj.py @@ -5,8 +5,9 @@ from __future__ import division, absolute_import, print_function, unicode_litera import json import os +import sys -from six import iteritems +from six import iteritems, ensure_text from helper import LazyLogger @@ -33,7 +34,9 @@ class Objects(object): ''' Load objects mapping. ''' - with open(os.path.join(os.path.dirname(__file__), 'obj_map.json')) as infile: + file_dir = os.path.dirname(ensure_text(__file__, sys.getfilesystemencoding())) + + with open(os.path.join(file_dir, 'obj_map.json')) as infile: self.objects = json.load(infile) def map(self, item, mapping_name):