This fixes bz #570392
As a consequence of using doc=_('some message') the _()
method was returning a Gettext instance, thus when optparse
was handed the help text it received a Gettext instance instead
of a basestring. optparse tried to operate on the Gettext instance
as if it were a basestring and since it wasn't threw an exception.
The fix is to promote (e.g. cast) the option.doc to unicode.
If the option.doc was a str it becomes unicode, if it was unicode
nothing happens, if it was Gettext (or any other object implementing
the __unicode__() method) object is converted to unicode via the
objects rules.
The patch appears to be trivial but figuring the exact general fix and
why wasn't :-)
By the way, while debugging this I discovered strings which were not
localized, sometimes option.doc would be a str and sometimes a Gettext
object. In a subsequent patch I'll fix all those unlocalized doc
strings, but I don't want to bury this fix along with a load of
string fixes.
--
John Dennis <[email protected]>
Looking to carve out IT costs?
www.redhat.com/carveoutcosts/
>From 1d1913e5036c8d476ed6209d768762bea56d92d5 Mon Sep 17 00:00:00 2001
From: John Dennis <[email protected]>
Date: Thu, 4 Mar 2010 18:41:51 -0500
Subject: [PATCH 4/4] fix bug 570392, command help traceback
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
As a consequence of using doc=_('some message') the _()
method was returning a Gettext instance, thus when optparse
was handed the help text it received a Gettext instance instead
of a basestring. optparse tried to operate on the Gettext instance
as if it were a basestring and since it wasn't threw an exception.
The fix is to promote (e.g. cast) the option.doc to unicode.
If the option.doc was a str it becomes unicode, if it was unicode
nothing happens, if it was Gettext (or any other object implementing
the __unicode__() method) object is converted to unicode via the
objects rules.
By the way, while debugging this I discovered strings which were not
localized, sometimes option.doc would be a str and sometimes a Gettext
object. In a subsequent patch I'll fix all those unlocalized doc
strings, but I don't want to bury this fix along with a load of
string fixes.
---
ipalib/cli.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 715f2e1..a05722d 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -828,7 +828,7 @@ class cli(backend.Executioner):
for option in cmd.options():
kw = dict(
dest=option.name,
- help=option.doc,
+ help=unicode(option.doc),
)
if option.password and self.env.interactive:
kw['action'] = 'store_true'
--
1.6.6.1
_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel