From 6ed00a7b11f2f69161348411d9433dcd93e44cd7 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 10 Sep 2017 15:12:53 +0200 Subject: [PATCH] Reduce number of imports --- resources/lib/loghandler.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/resources/lib/loghandler.py b/resources/lib/loghandler.py index 9aebb3e9..f81c962d 100644 --- a/resources/lib/loghandler.py +++ b/resources/lib/loghandler.py @@ -2,8 +2,6 @@ ############################################################################### import logging import xbmc - -from utils import tryEncode ############################################################################### LEVELS = { logging.ERROR: xbmc.LOGERROR, @@ -14,6 +12,22 @@ LEVELS = { ############################################################################### +def tryEncode(uniString, encoding='utf-8'): + """ + Will try to encode uniString (in unicode) to encoding. This possibly + fails with e.g. Android TV's Python, which does not accept arguments for + string.encode() + """ + if isinstance(uniString, str): + # already encoded + return uniString + try: + uniString = uniString.encode(encoding, "ignore") + except TypeError: + uniString = uniString.encode() + return uniString + + def config(): logger = logging.getLogger('PLEX') logger.addHandler(LogHandler())