Merge pull request #282 from oddstr13/pr-unicode-windows-path-1

Make sure file paths are text, not binary
This commit is contained in:
mcarlton00 2020-04-20 19:51:55 -04:00 committed by GitHub
commit 275c4a0bd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -4,9 +4,12 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################## ##################################################################################################
import os import os
import sys
import logging import logging
import traceback import traceback
from six import ensure_text
from kodi_six import xbmc, xbmcaddon from kodi_six import xbmc, xbmcaddon
import database import database
@ -86,6 +89,9 @@ class MyFormatter(logging.Formatter):
logging.Formatter.__init__(self, fmt) logging.Formatter.__init__(self, fmt)
def format(self, record): def format(self, record):
if record.pathname:
record.pathname = ensure_text(record.pathname, sys.getfilesystemencoding())
self._gen_rel_path(record) self._gen_rel_path(record)
# Call the original formatter class to do the grunt work # Call the original formatter class to do the grunt work
@ -98,6 +104,8 @@ class MyFormatter(logging.Formatter):
res = [] res = []
for o in traceback.format_exception(*exc_info): for o in traceback.format_exception(*exc_info):
o = ensure_text(o, sys.getfilesystemencoding())
if o.startswith(' File "'): if o.startswith(' File "'):
# If this split can't handle your file names, you should seriously consider renaming your files. # 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] fn = o.split(' File "', 2)[1].split('", line ', 1)[0]

View File

@ -5,8 +5,9 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import json import json
import os import os
import sys
from six import iteritems from six import iteritems, ensure_text
from helper import LazyLogger from helper import LazyLogger
@ -33,7 +34,9 @@ class Objects(object):
''' Load objects mapping. ''' 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) self.objects = json.load(infile)
def map(self, item, mapping_name): def map(self, item, mapping_name):