Final encoding fix. It now work on IRC and unit tests pass, both with Python 2 & 3.

This commit is contained in:
Valentin Lorentz 2013-01-22 21:02:04 +01:00
parent a4a595b39a
commit 30c5519acb
2 changed files with 7 additions and 4 deletions

View File

@ -294,9 +294,14 @@ class Tokenizer(object):
token = token[1:-1]
# FIXME: No need to tell you this is a hack.
# It has to handle both IRC commands and serialized configuration.
#
# Whoever you are, if you make a single modification to this
# code, TEST the code with Python 2 & 3, both with the unit
# tests and on IRC with this: @echo "好"
if sys.version_info[0] < 3:
try:
token = token.encode('utf8').decode('string_escape')
token = token.decode('utf8')
except:
token = token.decode('string_escape')
else:

View File

@ -73,10 +73,8 @@ class TokenizerTestCase(SupyTestCase):
['foo', 'bar baz', 'quux'])
def testUnicode(self):
print repr((tokenize(u''), ['']))
print repr((tokenize(u'""'), ['']))
self.assertEqual(tokenize(u''), [''])
self.assertEqual(tokenize(u'""'), [''])
self.assertEqual(tokenize(u''), [u''])
self.assertEqual(tokenize(u'""'), [u''])
def testNesting(self):
self.assertEqual(tokenize('[]'), [[]])