VMM: Decode localized numbers to the current encoding.
That avoids UnicodeDecodeErrors since locale.format(%d) may return localized
numbers, which contain NO-BREAK SPACE as the thousands separator.
--- a/VirtualMailManager/cli/subcommands.py Tue Aug 28 22:37:43 2012 +0000
+++ b/VirtualMailManager/cli/subcommands.py Sat Sep 01 23:02:01 2012 +0000
@@ -295,13 +295,15 @@
q_limit = u'Storage: %(bytes)s; Messages: %(messages)s'
if not details:
info['bytes'] = human_size(info['bytes'])
- info['messages'] = locale.format('%d', info['messages'], True)
+ info['messages'] = locale.format('%d', info['messages'],
+ True).decode(ENCODING, 'replace')
info['quota limit/user'] = q_limit % info
_print_info(ctx, info, _(u'Domain'))
else:
info[0]['bytes'] = human_size(info[0]['bytes'])
info[0]['messages'] = locale.format('%d', info[0]['messages'],
- True)
+ True).decode(ENCODING,
+ 'replace')
info[0]['quota limit/user'] = q_limit % info[0]
_print_info(ctx, info[0], _(u'Domain'))
if details == u'accounts':
@@ -917,8 +919,10 @@
}
else:
q_usage = {
- 'used': locale.format('%d', used, True),
- 'limit': locale.format('%d', limit, True),
+ 'used': locale.format('%d', used, True).decode(ENCODING,
+ 'replace'),
+ 'limit': locale.format('%d', limit, True).decode(ENCODING,
+ 'replace'),
}
if limit:
q_usage['percent'] = locale.format('%6.2f', 100. / limit * used, True)
--- a/VirtualMailManager/common.py Tue Aug 28 22:37:43 2012 +0000
+++ b/VirtualMailManager/common.py Sat Sep 01 23:02:01 2012 +0000
@@ -86,7 +86,7 @@
# TP: e.g.: '%(size)s %(prefix)s' -> '118.30 MiB'
return _(u'%(size)s %(prefix)s') % {
'size': locale.format('%.2f', float(size) / multiply,
- True),
+ True).decode(ENCODING, 'replace'),
'prefix': prefix}