[Sugar-devel] [PATCH] Workaround to Python 2.7 regression in locale.format(): it disallows trailing text after the format specifier.
Walter Bender
walter.bender at gmail.com
Fri Nov 26 09:43:25 EST 2010
From: Walter Bender <walter at sugarlabs.org>
This patch addresses a regression in the updater on F14 systems.
The CP updater searches for and properly identifies bundles to update,
but then it fails to display the dialog that enables you to proceed with
the update. The problem is with the call to locale.format in view.py in the
updater:
The problem is with line 391 in _format_size()
return locale.format(_('%.1f MB'), size / 1024.0 / 1024)
locale.format doesn't seem to like '%f x' as seen in the code snippet below:
import locale
locale.format('%f MB', 123)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/locale.py", line 189, in format
"format specifier, %s not valid") % repr(percent))
ValueError: format() must be given exactly one %char format specifier,
'%f MB' not valid.
This is a documented regression in locale.format in Python 2.7:
https://bugs.launchpad.net/update-manager/+bug/673297
The proposed fix is to pull the trailing characters out of the locale.format
expression, e.g.,
return '%s MB' % (locale.format(''%.1f MB'), size / 1024.0 / 1024)
The approach has been discussed on IRC and in SL ticket #2491.
It has been tested on sugar-jhbuild on F14.
|TestCase|
On a system with Python 2.7:
1. open the updater in the control panel
2. check for updates
3. see if the dialog completes
---
extensions/cpsection/updater/view.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/extensions/cpsection/updater/view.py
b/extensions/cpsection/updater/view.py
index de50d8d..c75ad01 100644
--- a/extensions/cpsection/updater/view.py
+++ b/extensions/cpsection/updater/view.py
@@ -385,7 +385,7 @@ def _format_size(size):
return _('1 KB')
elif size < 1024 * 1024:
# TRANS: download size of small updates, e.g. '250 KB'
- return locale.format(_('%.0f KB'), size / 1024.0)
+ return _('%s KB') % (locale.format('%.0f', size / 1024.0))
else:
# TRANS: download size of updates, e.g. '2.3 MB'
- return locale.format(_('%.1f MB'), size / 1024.0 / 1024)
+ return _('%s MB') % locale.format('%.1f', size / 1024.0 / 1024)
--
1.7.3.2
--
Walter Bender
Sugar Labs
http://www.sugarlabs.org
More information about the Sugar-devel
mailing list