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

Fixed issues importing encodingKludge module.

This commit is contained in:
echel0n 2014-11-24 14:31:50 -08:00
parent 6a140aa907
commit a9b44a156d
9 changed files with 33 additions and 31 deletions

View File

@ -11,7 +11,7 @@
# SickRage is distributed in the hope that it will be useful, # SickRage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 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 # You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>. # along with SickRage. If not, see <http://www.gnu.org/licenses/>.
@ -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):
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)

View File

@ -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.

View File

@ -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"""

View File

@ -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"

View File

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

View File

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

View File

@ -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 = {}

View File

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

View File

@ -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 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 # uncomment next line so leave the db intact between test and at the end
#return False # 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))
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(): def setUp_test_episode_file():
if not os.path.exists(FILEDIR): if not os.path.exists(FILEDIR):