Opened 14 years ago
Closed 14 years ago
#10016 closed defect (fixed)
`print_table()` doesn't support unicode characters
Reported by: | Jun Omae | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 0.12.3 |
Component: | general | Version: | 0.12.2rc1 |
Severity: | normal | Keywords: | unicode |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Attachments (2)
Change History (8)
by , 14 years ago
Attachment: | wrong-print-table.png added |
---|
comment:1 by , 14 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
by , 14 years ago
Attachment: | t10016-print-table.diff added |
---|
comment:2 by , 14 years ago
In attachment:t10016-print-table.diff, print_table()
supports east-asian-ambiguous and detects the ambiguous width with the locale.
On Unix, detects with LANG
environment.
On Windows, detects with code page using ctypes.windll.kernel32.GetConsoleOutputCP()
. If ctypes
is unavailable (e.g. Python 2.4), detects with stderr.encoding
and sysout.encoding
.
follow-up: 4 comment:3 by , 14 years ago
Tested the patch, works as expected!
However there are a few more simplifications that could be done before or after the commit:
max()
can take a generator expression even in Python 2.4- those 3 lines:
if cell is None: cell = '' cell = to_unicode(cell)
could be just:cell = to_unicode(cell or '')
- as you do
to_unicode()
andline
derives from au"..."
format, theif isinstance(line, unicode)
check is unnecessary - not strictly related to your change, but as you touched that line (near the end of the patch):
out.write(''.join(['-' for x in xrange(0, <n>)]))
it could be simplified to:out.write('-' * <n>)
follow-up: 5 comment:4 by , 14 years ago
Replying to cboos:
- those 3 lines:
if cell is None: cell = '' cell = to_unicode(cell)could be just:cell = to_unicode(cell or '')
If None is passed as a cell value, print_table()
shows blank cell. Otherwise, it shows text which is converted with to_unicode
. When False
value is passed, it shows False
text. However it shows wrong formatted table.
I understood the other points which my patch is verbose code. I modified the points and the above problem in https://github.com/jun66j5/trac/compare/edgewall:0.12-stable...jun66j5:t10016-print-table.
comment:5 by , 14 years ago
Replying to jomae:
Replying to cboos:
… could be just:
cell = to_unicode(cell or '')… When
False
value is passed, it showsFalse
text. However it shows wrong formatted table.
You're right, I only considered string vs. None, but data
can eventually contain arbitrary values.
https://github.com/jun66j5/trac/compare/edgewall:0.12-stable...jun66j5:t10016-print-table.
Good for me!
comment:6 by , 14 years ago
Milestone: | next-minor-0.12.x → 0.12.3 |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Thanks for your reviews, Christian! Committed in [10655/branches/0.12-stable] and [10656/trunk].
Support east-asian-ambiguous for
print_table()