From 7deccfd1fcddf597a16797212911b661b2424c59 Mon Sep 17 00:00:00 2001 From: Vratislav Podzimek Date: Wed, 9 Mar 2016 13:51:24 +0100 Subject: [PATCH] New version - Make sure we pass a locale-agnostic string to Decimal() (vpodzime) --- libbytesize.spec | 7 +++++- locale_agnostic_dec.patch | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 locale_agnostic_dec.patch diff --git a/libbytesize.spec b/libbytesize.spec index c96c7c5..bd3c786 100644 --- a/libbytesize.spec +++ b/libbytesize.spec @@ -1,12 +1,13 @@ Name: libbytesize Version: 0.3 -Release: 2%{?dist} +Release: 3%{?dist} Summary: A library for working with sizes in bytes License: LGPLv2+ URL: https://github.com/rhinstaller/libbytesize Source0: https://github.com/rhinstaller/libbytesize/archive/%{name}-%{version}.tar.gz Patch0: size_instances_hashable.patch +Patch1: locale_agnostic_dec.patch %define realname bytesize @@ -55,6 +56,7 @@ the library from Python 3 easier and more convenient. %prep %setup -q -n %{name}-%{version} %patch0 -p1 +%patch1 -p1 %build %configure @@ -89,6 +91,9 @@ find %{buildroot} -type f -name "*.la" | xargs %{__rm} %{python3_sitearch}/bytesize/__pycache__/bytesize.* %changelog +* Wed Mar 9 2016 Vratislav Podzimek - 0.3-3 +- Make sure we pass a locale-agnostic string to Decimal() (vpodzime) + * Mon Mar 7 2016 Vratislav Podzimek - 0.3-2 - Make Size instances hashable (vpodzime) diff --git a/locale_agnostic_dec.patch b/locale_agnostic_dec.patch new file mode 100644 index 0000000..774a6c0 --- /dev/null +++ b/locale_agnostic_dec.patch @@ -0,0 +1,49 @@ +From d2642df497ad0d0e66c3d46347df7b7b659b3c7d Mon Sep 17 00:00:00 2001 +From: Vratislav Podzimek +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 +--- + 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 +