Blob Blame History Raw
From d2642df497ad0d0e66c3d46347df7b7b659b3c7d Mon Sep 17 00:00:00 2001
From: Vratislav Podzimek <vpodzime@redhat.com>
Date: Tue, 8 Mar 2016 16:56:43 +0100
Subject: [PATCH] Make sure we pass a locale-agnostic string to Decimal()

Decimal() doesn't take into account the current locale, but we get a localized
result from bs_convert_to().

Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
---
 src/python/bytesize.py            | 12 ++++++++++--
 tests/lbs_py_override_unittest.py | 26 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/python/bytesize.py b/src/python/bytesize.py
index 179719c..3a32b65 100644
--- a/src/python/bytesize.py
+++ b/src/python/bytesize.py
@@ -4,6 +4,8 @@ from ctypes import POINTER, byref
 import six
 from decimal import Decimal
 
+import locale
+
 import gettext
 _ = lambda x: gettext.translation("libbytesize", fallback=True).gettext(x) if x != "" else ""
 
@@ -356,9 +358,15 @@ class Size(object):
             real_unit = unit_strs.get(unit)
             if real_unit is None:
                 raise ValueError("Invalid unit specification: '%s'" % unit)
-            return Decimal(self._c_size.convert_to(real_unit))
+            ret = self._c_size.convert_to(real_unit)
         else:
-            return Decimal(self._c_size.convert_to(unit))
+            ret = self._c_size.convert_to(unit)
+
+        radix = locale.nl_langinfo(locale.RADIXCHAR)
+        if radix != '.':
+            ret = ret.replace(radix, '.')
+
+        return Decimal(ret)
 
     def human_readable(self, min_unit=B, max_places=2, xlate=True):
         if isinstance(min_unit, six.string_types):

-- 
2.5.0