Edgewall Software
Modify

Opened 13 years ago

Closed 13 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:

Description

print_table() doesn't support unicode characters. The trac-admin commands show the wrong format of a table.

See #4717 and #10006.

Attachments (2)

wrong-print-table.png (10.3 KB ) - added by Jun Omae 13 years ago.
t10016-print-table.diff (6.8 KB ) - added by Jun Omae 13 years ago.
Support east-asian-ambiguous for print_table()

Download all attachments as: .zip

Change History (8)

by Jun Omae, 13 years ago

Attachment: wrong-print-table.png added

comment:1 by Jun Omae, 13 years ago

Owner: set to Jun Omae
Status: newassigned

by Jun Omae, 13 years ago

Attachment: t10016-print-table.diff added

Support east-asian-ambiguous for print_table()

comment:2 by Jun Omae, 13 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.

comment:3 by Christian Boos, 13 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() and line derives from a u"..." format, the if 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>)
    

in reply to:  3 ; comment:4 by Jun Omae, 13 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.

in reply to:  4 comment:5 by Christian Boos, 13 years ago

Replying to jomae:

Replying to cboos:

… could be just:

cell = to_unicode(cell or '')

… When False value is passed, it shows False 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 Jun Omae, 13 years ago

Milestone: next-minor-0.12.x0.12.3
Resolution: fixed
Status: assignedclosed

Thanks for your reviews, Christian! Committed in [10655/branches/0.12-stable] and [10656/trunk].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.