SSO Python module shouldn't use gettext.install
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
Ubuntu Single Sign On Client | Status tracked in Trunk | |||||
Stable-3-0 |
Fix Committed
|
Undecided
|
Unassigned | |||
Stable-4-0 |
Fix Released
|
Undecided
|
Unassigned | |||
Trunk |
Fix Released
|
Undecided
|
Michael Terry | |||
ubuntu-sso-client (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | |||
Precise |
Fix Released
|
Undecided
|
Unassigned | |||
Quantal |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[Impact]
A consumer of the ubuntu_sso python module will have their translations rendered inoperable after importing ubuntu_sso.utils.ui (which happens accidentally easily, like say importing ubuntuone.
One noticeable side effect of this is that all Deja Dup users that back up to Ubuntu One and have a utf8 filename in the backup, will see an error instead of being able to back up. (bug 989496)
[Test Case]
python
> import ubuntu_sso.utils.ui
> _
If the fault exists, you'll see:
<bound method NullTranslation
If everything is fine (and the module didn't define _ in the global context), you'll see:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
[Regression Potential]
Unexpected regressions might include lack of translations for ubuntu_sso if the patch messes up grabbing those translations.
[Original Report]
In utils/ui.py, the following lines are used:
INSTALL_KWARGS = {}
if sys.version_info < (3,):
INSTALL_
gettext.
But that causes problems for Python apps that use the module. For example, duplicity ran into a problem where it uses gettext.install, only to be later overridden by ubuntu_sso's gettext.install. It's not suitable for a Python module to attempt to own Python builtins like _().
This can be reproduced like so:
> import gettext
> gettext.
> print(_)
<bound method NullTranslation
> import ubuntu_
> print(_)
<bound method NullTranslation
You see how it's changed to ugettext instead of gettext? And it's switched default domains.
A more suitable thing for ubuntu_sso to do is something like:
t = gettext.
_ = t.ugettext
This is what the gettext documentation recommends for modules (http://
Related branches
- Roberto Alsina (community): Approve
- dobey (community): Approve
-
Diff: 43 lines (+17/-4)2 files modifiedubuntu_sso/utils/tests/test_ui.py (+13/-1)
ubuntu_sso/utils/ui.py (+4/-3)
Changed in ubuntu-sso-client (Ubuntu Quantal): | |
milestone: | none → ubuntu-12.10-beta-2 |
description: | updated |
description: | updated |
See bug 989496 for an example of the kind of issue it can cause (in this case, duplicity merely imports ubuntuone. platform. credentials, which ends up importing ubuntu_sso's ui module).