Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert the encoding changes for now while fixing the bug that was aff…

…ecting the database migration.
  • Loading branch information...
commit 1656f23ef9cb4d08aa8acc0eb0399f3c47eee9e4 1 parent f913c47
@midgetspy authored
Showing with 12 additions and 73 deletions.
  1. +12 −11 sickbeard/encodingKludge.py
  2. +0 −62 tests/encodingTests.py
View
23 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 <http://www.gnu.org/licenses/>.
-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
View
62 tests/encodingTests.py
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.