Private GIT

Skip to content
Snippets Groups Projects
Commit a9b44a15 authored by echel0n's avatar echel0n
Browse files

Fixed issues importing encodingKludge module.

parent 6a140aa9
No related branches found
No related tags found
No related merge requests found
...@@ -29,17 +29,18 @@ import ftfy.bad_codecs ...@@ -29,17 +29,18 @@ import ftfy.bad_codecs
# which return something should always return unicode. # which return something should always return unicode.
def fixStupidEncodings(x, silent=False): def fixStupidEncodings(x, silent=False):
if type(x) in [str, unicode]: if type(x) == str:
try: try:
return ftfy.fix_text(u'' + x).decode(sickbeard.SYS_ENCODING) return str(ftfy.fix_text(u'' + x)).decode(sickbeard.SYS_ENCODING)
except UnicodeDecodeError: except UnicodeDecodeError:
logger.log(u"Unable to decode value: " + repr(x), logger.ERROR) logger.log(u"Unable to decode value: " + repr(x), logger.ERROR)
return None elif type(x) == unicode:
return x
else: else:
logger.log( logger.log(
u"Unknown value passed in, ignoring it: " + str(type(x)) + " (" + repr(x) + ":" + repr(type(x)) + ")", u"Unknown value passed in, ignoring it: " + str(type(x)) + " (" + repr(x) + ":" + repr(type(x)) + ")",
logger.DEBUG if silent else logger.ERROR) logger.DEBUG if silent else logger.ERROR)
return None
def fixListEncodings(x): def fixListEncodings(x):
if type(x) != list and type(x) != tuple: if type(x) != list and type(x) != tuple:
...@@ -47,21 +48,13 @@ def fixListEncodings(x): ...@@ -47,21 +48,13 @@ def fixListEncodings(x):
else: else:
return filter(lambda x: x != None, map(fixStupidEncodings, x)) 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): def ek(func, *args, **kwargs):
if os.name == 'nt': if os.name == 'nt':
result = func(*args, **kwargs) result = func(*args, **kwargs)
else: 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): if type(result) in (list, tuple):
return fixListEncodings(result) return fixListEncodings(result)
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
from sickbeard.encodingKludge import fixStupidEncodings from sickbeard.encodingKludge import fixStupidEncodings
def ex(e): def ex(e):
""" """
Returns a unicode string from the exception text if it exists. Returns a unicode string from the exception text if it exists.
......
...@@ -26,8 +26,7 @@ from sickbeard.exceptions import ex, EpisodeNotFoundException ...@@ -26,8 +26,7 @@ from sickbeard.exceptions import ex, EpisodeNotFoundException
from sickbeard.history import dateFormat from sickbeard.history import dateFormat
from sickbeard.common import Quality from sickbeard.common import Quality
from sickbeard.common import WANTED, FAILED from sickbeard.common import WANTED, FAILED
from encodingKludge import fixStupidEncodings from sickbeard.encodingKludge import fixStupidEncodings
def prepareFailedName(release): def prepareFailedName(release):
"""Standardizes release name for failed DB""" """Standardizes release name for failed DB"""
......
...@@ -20,7 +20,7 @@ import db ...@@ -20,7 +20,7 @@ import db
import datetime import datetime
from sickbeard.common import SNATCHED, SUBTITLED, FAILED, Quality from sickbeard.common import SNATCHED, SUBTITLED, FAILED, Quality
from encodingKludge import fixStupidEncodings from sickbeard.encodingKludge import fixStupidEncodings
dateFormat = "%Y%m%d%H%M%S" dateFormat = "%Y%m%d%H%M%S"
......
...@@ -29,7 +29,7 @@ import sickbeard ...@@ -29,7 +29,7 @@ import sickbeard
from sickbeard import logger, common from sickbeard import logger, common
from sickbeard import db from sickbeard import db
from encodingKludge import fixStupidEncodings from sickbeard.encodingKludge import fixStupidEncodings
from sickbeard.exceptions import ex from sickbeard.exceptions import ex
......
...@@ -29,7 +29,7 @@ from sickbeard import encodingKludge as ek ...@@ -29,7 +29,7 @@ from sickbeard import encodingKludge as ek
from sickbeard.exceptions import ex from sickbeard.exceptions import ex
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
from encodingKludge import fixStupidEncodings from sickbeard.encodingKludge import fixStupidEncodings
def getSeasonNZBs(name, urlData, season): def getSeasonNZBs(name, urlData, season):
......
...@@ -27,7 +27,7 @@ from sickbeard import helpers ...@@ -27,7 +27,7 @@ from sickbeard import helpers
from sickbeard import name_cache from sickbeard import name_cache
from sickbeard import logger from sickbeard import logger
from sickbeard import db from sickbeard import db
from encodingKludge import fixStupidEncodings from sickbeard.encodingKludge import fixStupidEncodings
exception_dict = {} exception_dict = {}
anidb_exception_dict = {} anidb_exception_dict = {}
......
...@@ -33,7 +33,7 @@ from sickbeard.exceptions import AuthException ...@@ -33,7 +33,7 @@ from sickbeard.exceptions import AuthException
from sickbeard.rssfeeds import RSSFeeds from sickbeard.rssfeeds import RSSFeeds
from sickbeard import clients from sickbeard import clients
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
from encodingKludge import fixStupidEncodings from sickbeard.encodingKludge import fixStupidEncodings
class CacheDBConnection(db.DBConnection): class CacheDBConnection(db.DBConnection):
def __init__(self, providerName): def __init__(self, providerName):
......
...@@ -192,13 +192,24 @@ def tearDown_test_db(): ...@@ -192,13 +192,24 @@ def tearDown_test_db():
""" """
# uncomment next line so leave the db intact between test and at the end # uncomment next line so leave the db intact between test and at the end
# return False # return False
try:
if os.path.exists(os.path.join(TESTDIR, TESTDBNAME)): if os.path.exists(os.path.join(TESTDIR, TESTDBNAME)):
os.remove(os.path.join(TESTDIR, TESTDBNAME)) os.remove(os.path.join(TESTDIR, TESTDBNAME))
except:
pass
try:
if os.path.exists(os.path.join(TESTDIR, TESTCACHEDBNAME)): if os.path.exists(os.path.join(TESTDIR, TESTCACHEDBNAME)):
os.remove(os.path.join(TESTDIR, TESTCACHEDBNAME)) os.remove(os.path.join(TESTDIR, TESTCACHEDBNAME))
except:
pass
try:
if os.path.exists(os.path.join(TESTDIR, TESTFAILEDDBNAME)): if os.path.exists(os.path.join(TESTDIR, TESTFAILEDDBNAME)):
os.remove(os.path.join(TESTDIR, TESTFAILEDDBNAME)) os.remove(os.path.join(TESTDIR, TESTFAILEDDBNAME))
except:
pass
def setUp_test_episode_file(): def setUp_test_episode_file():
if not os.path.exists(FILEDIR): if not os.path.exists(FILEDIR):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment