diff --git a/sickbeard/encodingKludge.py b/sickbeard/encodingKludge.py index dc6d4bad..6df8736a 100644 --- a/sickbeard/encodingKludge.py +++ b/sickbeard/encodingKludge.py @@ -11,7 +11,7 @@ # SickRage is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with SickRage. If not, see . @@ -29,17 +29,18 @@ import ftfy.bad_codecs # which return something should always return unicode. def fixStupidEncodings(x, silent=False): - if type(x) in [str, unicode]: + if type(x) == str: try: - return ftfy.fix_text(u'' + x).decode(sickbeard.SYS_ENCODING) + return str(ftfy.fix_text(u'' + x)).decode(sickbeard.SYS_ENCODING) except UnicodeDecodeError: logger.log(u"Unable to decode value: " + repr(x), logger.ERROR) - return None + elif type(x) == unicode: + return x else: logger.log( u"Unknown value passed in, ignoring it: " + str(type(x)) + " (" + repr(x) + ":" + repr(type(x)) + ")", logger.DEBUG if silent else logger.ERROR) - return None + def fixListEncodings(x): if type(x) != list and type(x) != tuple: @@ -47,21 +48,13 @@ def fixListEncodings(x): else: return filter(lambda x: x != None, map(fixStupidEncodings, x)) - -def callPeopleStupid(x): - try: - return ftfy.fix_text(x).encode(sickbeard.SYS_ENCODING) - except (UnicodeEncodeError, UnicodeDecodeError): - 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( - x) + ", " + sickbeard.SYS_ENCODING, logger.ERROR) - return ftfy.fix_text(x).encode(sickbeard.SYS_ENCODING, 'ignore') - def ek(func, *args, **kwargs): if os.name == 'nt': result = func(*args, **kwargs) else: - result = func(*[callPeopleStupid(x) if type(x) in (str, unicode) else x for x in args], **kwargs) + result = func( + *[ftfy.fix_text(u'' + x).encode(sickbeard.SYS_ENCODING) if type(x) in (str, unicode) else x for x in args], + **kwargs) if type(result) in (list, tuple): return fixListEncodings(result) diff --git a/sickbeard/exceptions.py b/sickbeard/exceptions.py index e7a14a93..3a81bfa7 100644 --- a/sickbeard/exceptions.py +++ b/sickbeard/exceptions.py @@ -18,7 +18,6 @@ from sickbeard.encodingKludge import fixStupidEncodings - def ex(e): """ Returns a unicode string from the exception text if it exists. diff --git a/sickbeard/failed_history.py b/sickbeard/failed_history.py index b80ced5a..32c3a8cd 100644 --- a/sickbeard/failed_history.py +++ b/sickbeard/failed_history.py @@ -26,8 +26,7 @@ from sickbeard.exceptions import ex, EpisodeNotFoundException from sickbeard.history import dateFormat from sickbeard.common import Quality from sickbeard.common import WANTED, FAILED -from encodingKludge import fixStupidEncodings - +from sickbeard.encodingKludge import fixStupidEncodings def prepareFailedName(release): """Standardizes release name for failed DB""" diff --git a/sickbeard/history.py b/sickbeard/history.py index b1a9f870..45f15f96 100644 --- a/sickbeard/history.py +++ b/sickbeard/history.py @@ -20,7 +20,7 @@ import db import datetime from sickbeard.common import SNATCHED, SUBTITLED, FAILED, Quality -from encodingKludge import fixStupidEncodings +from sickbeard.encodingKludge import fixStupidEncodings dateFormat = "%Y%m%d%H%M%S" diff --git a/sickbeard/notifiers/emailnotify.py b/sickbeard/notifiers/emailnotify.py index 02e6d396..ff412f2c 100644 --- a/sickbeard/notifiers/emailnotify.py +++ b/sickbeard/notifiers/emailnotify.py @@ -29,7 +29,7 @@ import sickbeard from sickbeard import logger, common from sickbeard import db -from encodingKludge import fixStupidEncodings +from sickbeard.encodingKludge import fixStupidEncodings from sickbeard.exceptions import ex diff --git a/sickbeard/nzbSplitter.py b/sickbeard/nzbSplitter.py index ca71c289..6b60c20c 100644 --- a/sickbeard/nzbSplitter.py +++ b/sickbeard/nzbSplitter.py @@ -29,7 +29,7 @@ from sickbeard import encodingKludge as ek from sickbeard.exceptions import ex from name_parser.parser import NameParser, InvalidNameException, InvalidShowException -from encodingKludge import fixStupidEncodings +from sickbeard.encodingKludge import fixStupidEncodings def getSeasonNZBs(name, urlData, season): diff --git a/sickbeard/scene_exceptions.py b/sickbeard/scene_exceptions.py index 931e8e38..7ca5f977 100644 --- a/sickbeard/scene_exceptions.py +++ b/sickbeard/scene_exceptions.py @@ -27,7 +27,7 @@ from sickbeard import helpers from sickbeard import name_cache from sickbeard import logger from sickbeard import db -from encodingKludge import fixStupidEncodings +from sickbeard.encodingKludge import fixStupidEncodings exception_dict = {} anidb_exception_dict = {} diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index d8322b34..01d3453e 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -33,7 +33,7 @@ from sickbeard.exceptions import AuthException from sickbeard.rssfeeds import RSSFeeds from sickbeard import clients from name_parser.parser import NameParser, InvalidNameException, InvalidShowException -from encodingKludge import fixStupidEncodings +from sickbeard.encodingKludge import fixStupidEncodings class CacheDBConnection(db.DBConnection): def __init__(self, providerName): diff --git a/tests/test_lib.py b/tests/test_lib.py index 14b2ae0d..7f956b67 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -191,14 +191,25 @@ def tearDown_test_db(): although this seams not to work on my system it leaves me with an zero kb file """ # uncomment next line so leave the db intact between test and at the end - #return False - if os.path.exists(os.path.join(TESTDIR, TESTDBNAME)): - os.remove(os.path.join(TESTDIR, TESTDBNAME)) - if os.path.exists(os.path.join(TESTDIR, TESTCACHEDBNAME)): - os.remove(os.path.join(TESTDIR, TESTCACHEDBNAME)) - if os.path.exists(os.path.join(TESTDIR, TESTFAILEDDBNAME)): - os.remove(os.path.join(TESTDIR, TESTFAILEDDBNAME)) + # return False + try: + if os.path.exists(os.path.join(TESTDIR, TESTDBNAME)): + os.remove(os.path.join(TESTDIR, TESTDBNAME)) + except: + pass + + try: + if os.path.exists(os.path.join(TESTDIR, TESTCACHEDBNAME)): + os.remove(os.path.join(TESTDIR, TESTCACHEDBNAME)) + except: + pass + + try: + if os.path.exists(os.path.join(TESTDIR, TESTFAILEDDBNAME)): + os.remove(os.path.join(TESTDIR, TESTFAILEDDBNAME)) + except: + pass def setUp_test_episode_file(): if not os.path.exists(FILEDIR):