Skip to content

Commit

Permalink
Support for unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed Jun 6, 2012
1 parent 6a0651c commit fc6f87d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)" % (
Expand Down
2 changes: 1 addition & 1 deletion codegen_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 12 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement

import os
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fc6f87d

Please sign in to comment.