New version
- Make sure we pass a locale-agnostic string to Decimal() (vpodzime)
This commit is contained in:
parent
acef3dd342
commit
7deccfd1fc
@ -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 <vpodzime@redhat.com> - 0.3-3
|
||||
- Make sure we pass a locale-agnostic string to Decimal() (vpodzime)
|
||||
|
||||
* Mon Mar 7 2016 Vratislav Podzimek <vpodzime@redhat.com> - 0.3-2
|
||||
- Make Size instances hashable (vpodzime)
|
||||
|
||||
|
||||
49
locale_agnostic_dec.patch
Normal file
49
locale_agnostic_dec.patch
Normal file
@ -0,0 +1,49 @@
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user