Reduce number of imports

This commit is contained in:
tomkat83 2017-09-10 15:12:53 +02:00
parent 907c542950
commit 6ed00a7b11

View file

@ -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())