Opened 18 years ago
Closed 18 years ago
#4742 closed defect (fixed)
trac-admin: output stream in trouble
Reported by: | Emmanuel Blot | Owned by: | Emmanuel Blot |
---|---|---|---|
Priority: | low | Milestone: | 0.11 |
Component: | admin/console | Version: | devel |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
When trac-admin project permission list
is invoked, the command fails with the following error:
Trac [/Users/eblot/Trac/Db/trunk]> permission list Command failed: encode() argument 1 must be string, not None
The same error also occurs if the permissions are listed for a specific user.
The trouble comes from the print_table()
method.
When it attempts to retrieve the defaut encoding for the output stream, the defaut encoding may be defined to 'None' rather than being undefined. In such a case, the getattr()
built-in function return 'None' instead of the fallback parameter ('utf-8').
This leads to evaluate None
as the charset rather than 'utf-8'. Maybe this is Mac OS X -only issue, I did not test it on other platforms.
The following patch solves the issue - as I'm not sure it does the exact same thing that was originally expected, I did not commit it to the trunk. Let me know if you want me to commit it.
-
trac/util/text.py
110 110 def print_table(data, headers=None, sep=' ', out=None): 111 111 if out is None: 112 112 out = sys.stdout 113 charset = getattr(out, 'encoding', 'utf-8')113 charset = getattr(out, 'encoding', None) or 'utf-8' 114 114 data = list(data) 115 115 if headers: 116 116 data.insert(0, headers)
Attachments (0)
Change History (3)
comment:1 by , 18 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Summary: | trac-admin: 'permission list' failure → trac-admin: output stream in trouble |
comment:2 by , 18 years ago
Reproduced on Windows as well, where your fix works as well. Please apply.
I just bumped into this issue once more, this time with Linux Debian.
The same issue occurs when the trac-admin standard output is piped to the stdin of any other process.
If nobody objects, I'll apply this patch today.