Skip to content

Commit

Permalink
fix table output for multibyte characters
Browse files Browse the repository at this point in the history
Encoding unicode text with `str` does not work
for multibyte characters.
  • Loading branch information
quiver committed Mar 26, 2014
1 parent cfc91b5 commit 50fbaf0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion awscli/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import struct

import colorama
import six


def determine_terminal_width(default_width=80):
Expand Down Expand Up @@ -397,7 +398,7 @@ def add_row(self, row):
self._update_max_widths(row)

def _format_row(self, row):
return [str(r) for r in row]
return [six.text_type(r) for r in row]

def _update_max_widths(self, row):
if not self._max_widths:
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def test_title_accounts_for_outer_padding(self):
self.assertEqual(
self.section.total_width(padding=2, outer_padding=3), 17)

def test_unicode_text_row(self):
self.section.add_row([1])
self.section.add_row(['check'])
self.section.add_row([u'\u2713'])
self.assertEqual(
self.section.rows,
[[u'1'], [u'check'], [u'\u2713']])


class TestMultiTable(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 50fbaf0

Please sign in to comment.