1
0
mirror of https://github.com/moparisthebest/SickRage synced 2025-01-07 03:48:02 -05:00

Fix for issue #939 - utf8 decoding issues

This commit is contained in:
echel0n 2014-11-24 12:17:32 -08:00
parent 1003e342ca
commit f73aee78cc
2 changed files with 8 additions and 13 deletions

View File

@ -25,6 +25,7 @@ import signal
import sys import sys
import shutil import shutil
import subprocess import subprocess
import traceback
if sys.version_info < (2, 6): if sys.version_info < (2, 6):
print "Sorry, requires Python 2.6 or 2.7." print "Sorry, requires Python 2.6 or 2.7."
@ -68,6 +69,7 @@ throwaway = datetime.datetime.strptime('20110101', '%Y%m%d')
signal.signal(signal.SIGINT, sickbeard.sig_handler) signal.signal(signal.SIGINT, sickbeard.sig_handler)
signal.signal(signal.SIGTERM, sickbeard.sig_handler) signal.signal(signal.SIGTERM, sickbeard.sig_handler)
class SickRage(object): class SickRage(object):
def __init__(self): def __init__(self):
# system event callback for shutdown/restart # system event callback for shutdown/restart
@ -127,9 +129,6 @@ class SickRage(object):
try: try:
locale.setlocale(locale.LC_ALL, "") locale.setlocale(locale.LC_ALL, "")
except (locale.Error, IOError):
pass
try:
sickbeard.SYS_ENCODING = locale.getpreferredencoding() sickbeard.SYS_ENCODING = locale.getpreferredencoding()
except (locale.Error, IOError): except (locale.Error, IOError):
pass pass
@ -146,9 +145,8 @@ class SickRage(object):
# On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError # On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError
sys.setdefaultencoding(sickbeard.SYS_ENCODING) sys.setdefaultencoding(sickbeard.SYS_ENCODING)
except: except:
print 'Sorry, you MUST add the SickRage folder to the PYTHONPATH environment variable' sys.exit("Sorry, you MUST add the SickRage folder to the PYTHONPATH environment variable\n" +
print 'or find another way to force Python to use ' + sickbeard.SYS_ENCODING + ' for string encoding.' "or find another way to force Python to use " + sickbeard.SYS_ENCODING + " for string encoding.")
sys.exit(1)
# Need console logging for SickBeard.py and SickBeard-console.exe # Need console logging for SickBeard.py and SickBeard-console.exe
self.consoleLogging = (not hasattr(sys, "frozen")) or (sickbeard.MY_NAME.lower().find('-console') > 0) self.consoleLogging = (not hasattr(sys, "frozen")) or (sickbeard.MY_NAME.lower().find('-console') > 0)
@ -456,9 +454,9 @@ class SickRage(object):
sickbeard.showList.append(curShow) sickbeard.showList.append(curShow)
except Exception, e: except Exception, e:
logger.log( logger.log(
u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8', u"There was an error creating the show in " + sqlShow["location"] + ": " + str(e).decode('utf-8'),
'replace'),
logger.ERROR) logger.ERROR)
logger.log(traceback.format_exc(), logger.DEBUG)
def restore(self, srcDir, dstDir): def restore(self, srcDir, dstDir):
try: try:
@ -508,7 +506,7 @@ class SickRage(object):
popen_list = [os.path.join(sickbeard.PROG_DIR, 'updater.exe'), str(sickbeard.PID), popen_list = [os.path.join(sickbeard.PROG_DIR, 'updater.exe'), str(sickbeard.PID),
sys.executable] sys.executable]
else: else:
logger.log(u"Unknown SB launch method, please file a bug report about this", logger.ERROR) logger.log(u"Unknown SR launch method, please file a bug report about this", logger.ERROR)
popen_list = [sys.executable, os.path.join(sickbeard.PROG_DIR, 'updater.py'), popen_list = [sys.executable, os.path.join(sickbeard.PROG_DIR, 'updater.py'),
str(sickbeard.PID), str(sickbeard.PID),
sys.executable, sys.executable,

View File

@ -40,8 +40,6 @@ def fixStupidEncodings(x, silent=False):
logger.DEBUG if silent else logger.ERROR) logger.DEBUG if silent else logger.ERROR)
return None return None
def fixListEncodings(x): def fixListEncodings(x):
if type(x) != list and type(x) != tuple: if type(x) != list and type(x) != tuple:
return x return x
@ -52,13 +50,12 @@ def fixListEncodings(x):
def callPeopleStupid(x): def callPeopleStupid(x):
try: try:
return x.encode(sickbeard.SYS_ENCODING) return x.encode(sickbeard.SYS_ENCODING)
except UnicodeEncodeError: except (UnicodeEncodeError, UnicodeDecodeError):
logger.log( logger.log(
u"YOUR COMPUTER SUCKS! Your data is being corrupted by a bad locale/encoding setting. Report this error on the forums or IRC please: " + repr( u"YOUR COMPUTER SUCKS! Your data is being corrupted by a bad locale/encoding setting. Report this error on the forums or IRC please: " + repr(
x) + ", " + sickbeard.SYS_ENCODING, logger.ERROR) x) + ", " + sickbeard.SYS_ENCODING, logger.ERROR)
return x.encode(sickbeard.SYS_ENCODING, 'ignore') return x.encode(sickbeard.SYS_ENCODING, 'ignore')
def ek(func, *args, **kwargs): def ek(func, *args, **kwargs):
if os.name == 'nt': if os.name == 'nt':
result = func(*args, **kwargs) result = func(*args, **kwargs)