From 1656f23ef9cb4d08aa8acc0eb0399f3c47eee9e4 Mon Sep 17 00:00:00 2001 From: Nic Wolfe Date: Tue, 17 Jul 2012 21:00:04 -0600 Subject: [PATCH] Revert the encoding changes for now while fixing the bug that was affecting the database migration. --- sickbeard/encodingKludge.py | 23 +++++++------- tests/encodingTests.py | 62 ------------------------------------- 2 files changed, 12 insertions(+), 73 deletions(-) delete mode 100644 tests/encodingTests.py diff --git a/sickbeard/encodingKludge.py b/sickbeard/encodingKludge.py index 12a635e5eb..ce5b6a7a9a 100644 --- a/sickbeard/encodingKludge.py +++ b/sickbeard/encodingKludge.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with Sick Beard. If not, see . -import os, traceback +import os from sickbeard import logger import sickbeard @@ -48,15 +48,16 @@ def fixListEncodings(x): def ek(func, *args): + result = None - def changeByteStringToUnicode(obj): - if type(obj) == str: - logger.log(u"A bytestring was used as an argument for function "+func.__name__+": "+repr(obj), logger.WARNING) - logger.log(''.join(traceback.format_stack()), logger.DEBUG) - return obj.decode(sickbeard.SYS_ENCODING) - else: - return obj - - args = map(changeByteStringToUnicode, args) + if os.name == 'nt': + result = func(*args) + else: + result = func(*[x.encode(sickbeard.SYS_ENCODING) if type(x) in (str, unicode) else x for x in args]) - return func(*args) + if type(result) == in (list, tuple): + return fixListEncodings(result) + elif type(result) == str: + return fixStupidEncodings(result) + else: + return result diff --git a/tests/encodingTests.py b/tests/encodingTests.py deleted file mode 100644 index 40402f189b..0000000000 --- a/tests/encodingTests.py +++ /dev/null @@ -1,62 +0,0 @@ -# coding=UTF-8 - -import unittest -import sys, os, locale - -sys.path.append(os.path.abspath('..')) -sys.path.append(os.path.abspath('../lib')) - -import sickbeard, sickbeard.encodingKludge as ek - -try: - locale.setlocale(locale.LC_ALL, "") - sickbeard.SYS_ENCODING = locale.getpreferredencoding() -except (locale.Error, IOError): - pass - -# for OSes that are poorly configured I'll just force UTF-8 -if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'): - sickbeard.SYS_ENCODING = 'UTF-8' - -class EncodingTests(unittest.TestCase): - - test_filename = u'test.\xee\xe2\xe9\xe8.txt' - test_path_unicode = u'test_data' + os.sep + u'encoding_tests' - test_path_bytestring = str(test_path_unicode) - - def setUp(self): - print "setting up" - f = open(self.test_path_unicode + os.sep + self.test_filename, 'w') - f.write('test data') - f.close() - - def tearDown(self): - os.remove(self.test_path_unicode + os.sep + self.test_filename) - - def test_unicode(self): - ufiles = os.listdir(self.test_path_unicode) - files = os.listdir(self.test_path_bytestring) - - print - print 'Testing that the encoding', sickbeard.SYS_ENCODING, 'behaves as we expect it would' - - self.assertEqual(ufiles[0], files[0].decode(sickbeard.SYS_ENCODING)) - - def test_ek(self): - str_file = ek.ek(os.listdir, self.test_path_bytestring)[0] - unicode_file = ek.ek(os.listdir, self.test_path_unicode)[0] - - # no matter if we give unicode or not we should get unicode back - self.assertEqual(u'test.\xee\xe2\xe9\xe8.txt', unicode_file) - self.assertEqual(u'test.\xee\xe2\xe9\xe8.txt', str_file) - - # we should be able to append it onto a string without an exception - self.assertEqual(unicode, type("str" + unicode_file)) - self.assertEqual(unicode, type(u"unicode" + unicode_file)) - - # we should be able to encode it arbitrarily without an exception - self.assertEqual('test.\xc3\xae\xc3\xa2\xc3\xa9\xc3\xa8.txt', unicode_file.encode('utf-8')) - -if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(EncodingTests) - unittest.TextTestRunner(verbosity=2).run(suite)