From fc6f87d29a3f860dbe15e11ecc99f1c0f07a9b40 Mon Sep 17 00:00:00 2001 From: Marek Majkowski Date: Wed, 6 Jun 2012 17:44:22 +0100 Subject: [PATCH] Support for unicode --- codegen.py | 7 +++++-- codegen_helpers.py | 2 +- tests/test_basic.py | 13 ++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/codegen.py b/codegen.py index 487c5ec..53cd369 100644 --- a/codegen.py +++ b/codegen.py @@ -136,8 +136,11 @@ def _method_params_list(m): def print_encode_method(m): print "# %s" % (' '.join(_default_params(m)),) print "def %s(%s):" % (m.encode, ', '.join(_method_params_list(m)),) - for f in [f for f in m.arguments if not f.banned and f.t in ['table']]: - print " %s_raw = table.encode(%s)" % (f.n, f.n) + for f in [f for f in m.arguments if not f.banned]: + if f.t == 'table': + print " %s_raw = table.encode(%s)" % (f.n, f.n) + elif f.t == 'shortstr': + print " %s = %s.encode('utf-8')" % (f.n, f.n) if m.hasContent: print " props, headers = split_headers(user_headers, %s_PROPS_SET)" % ( diff --git a/codegen_helpers.py b/codegen_helpers.py index 034eeb0..702b778 100644 --- a/codegen_helpers.py +++ b/codegen_helpers.py @@ -32,7 +32,7 @@ def do_print(self, prefix, decor): class FieldStr(Field): def _do_print(self, prefix, dname): - print prefix+"%s = data[offset : offset+str_len]" % dname + print prefix+"%s = data[offset : offset+str_len].decode('utf-8')" % dname print prefix+"offset += str_len" class FieldTable(Field): diff --git a/tests/test_basic.py b/tests/test_basic.py index d3fad6d..ea87072 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from __future__ import with_statement import os @@ -317,7 +318,7 @@ def test_properties(self): recv_headers = r['headers'] del recv_headers['x-puka-delivery-tag'] - self.assertEqual(repr(headers), repr(recv_headers)) + self.assertEqual(headers, recv_headers) promise = client.queue_delete(queue=self.name) client.wait(promise) @@ -475,6 +476,16 @@ def test_basic_qos(self, client): client.wait(promise) + @base.connect + def test_unicode(self, client): + self.name += u'ęśćł' + promise = client.queue_declare(queue=self.name) + result = client.wait(promise) + self.assertEqual(result['queue'], self.name) + + promise = client.queue_delete(queue=self.name) + client.wait(promise) + if __name__ == '__main__': import tests