Skip to content

Commit

Permalink
Deal with unicode strings
Browse files Browse the repository at this point in the history
The ironic client was trying to convert unicode strings received from the
API to ascii causing it to fail, this patch will correct it.

Change-Id: I8765abb188f758f982807a38f5d291fbc2be0da9
Closes-Bug: #1247156
  • Loading branch information
umago committed Nov 12, 2013
1 parent d821056 commit 11f7da9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ironicclient/common/utils.py
Expand Up @@ -108,9 +108,9 @@ def print_dict(d, dict_property="Property", wrap=0, outfile=None):
for k, v in sorted(six.iteritems(d), key=lambda x: x[0]):
# convert dict to str to check length
if isinstance(v, dict):
v = str(v)
v = six.text_type(v)
if wrap > 0:
v = textwrap.fill(str(v), wrap)
v = textwrap.fill(six.text_type(v), wrap)
# if value has a newline, add in multiple rows
# e.g. fault with stacktrace
if v and isinstance(v, six.string_types) and r'\n' in v:
Expand Down
6 changes: 6 additions & 0 deletions ironicclient/tests/test_utils.py
Expand Up @@ -78,3 +78,9 @@ def test_args_array_to_patch_remove(self):
my_args['attributes'])
self.assertEqual(patch, [{'op': 'remove', 'path': '/foo'},
{'op': 'remove', 'path': '/extra/bar'}])

def test_print_dict_unicode(self):
unicode_str = u'\u2026'
output_file = six.StringIO()
utils.print_dict({'K': 'k', 'Key': unicode_str}, outfile=output_file)
self.assertIn(unicode_str, output_file.getvalue())

0 comments on commit 11f7da9

Please sign in to comment.