Comment 10 for bug 530333

Revision history for this message
Iakov Davydov (iakov-davydov) wrote :

Hello,
Sorry I cannot test it right now (my exaile instalation is on the different pc).
But here is simple test for unicode and optparse:

davidov@theatre:~/tmp/optparse$ python test1.py --help
Traceback (most recent call last):
  File "test1.py", line 7, in <module>
    (options, args) = parser.parse_args()
  File "/usr/lib/python2.6/optparse.py", line 1394, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/usr/lib/python2.6/optparse.py", line 1434, in _process_args
    self._process_long_opt(rargs, values)
  File "/usr/lib/python2.6/optparse.py", line 1509, in _process_long_opt
    option.process(opt, value, values, self)
  File "/usr/lib/python2.6/optparse.py", line 788, in process
    self.action, self.dest, opt, value, values, parser)
  File "/usr/lib/python2.6/optparse.py", line 810, in take_action
    parser.print_help()
  File "/usr/lib/python2.6/optparse.py", line 1664, in print_help
    file.write(self.format_help().encode(encoding, "replace"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 116: ordinal not in range(128)
davidov@theatre:~/tmp/optparse$ python test2.py --help
Usage: test2.py [options]

Options:
  -h, --help show this help message and exit
  -f FILE, --file=FILE файл

davidov@theatre:~/tmp/optparse$ diff -u test1.py test2.py
--- test1.py 2010-03-02 12:44:32.639580195 +0300
+++ test2.py 2010-03-02 12:45:06.829555252 +0300
@@ -2,6 +2,6 @@
 from optparse import OptionParser
 parser = OptionParser()
 parser.add_option("-f", "--file", dest="filename",
- help="файл", metavar="FILE")
+ help=u"файл", metavar="FILE")

 (options, args) = parser.parse_args()

So you have just to use unicode strings for uncode help messages; that seems not to be optparse bug.