From 30c5519acb0478e32b084b3ebd8ea21fd6b114fb Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 22 Jan 2013 21:02:04 +0100 Subject: [PATCH] Final encoding fix. It now work on IRC and unit tests pass, both with Python 2 & 3. --- src/callbacks.py | 5 +++++ test/test_callbacks.py | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index c647a8ac6..48a42cae6 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -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: diff --git a/test/test_callbacks.py b/test/test_callbacks.py index 21626edda..76aa97424 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -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('[]'), [[]])