From 8f9b12079df19ba58e1d03fcc9d0a8ccd17031b6 Mon Sep 17 00:00:00 2001 From: He Chen Date: Mon, 19 Aug 2019 16:06:41 -0400 Subject: [PATCH 1/2] fix small decimal with disabled decimal_quantization --- babel/numbers.py | 2 +- tests/test_numbers.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/babel/numbers.py b/babel/numbers.py index 6888c9cb4..cf819fc9a 100644 --- a/babel/numbers.py +++ b/babel/numbers.py @@ -1063,7 +1063,7 @@ def _format_int(self, value, min, max, locale): def _quantize_value(self, value, locale, frac_prec): quantum = get_decimal_quantum(frac_prec[1]) rounded = value.quantize(quantum) - a, sep, b = str(rounded).partition(".") + a, sep, b = "{:f}".format(rounded).partition(".") number = (self._format_int(a, self.int_prec[0], self.int_prec[1], locale) + self._format_frac(b or '0', locale, frac_prec)) diff --git a/tests/test_numbers.py b/tests/test_numbers.py index 6e26fe900..a980a66ad 100644 --- a/tests/test_numbers.py +++ b/tests/test_numbers.py @@ -690,3 +690,7 @@ def test_parse_decimal_nbsp_heuristics(): n = decimal.Decimal("12345.123") assert numbers.parse_decimal("12 345.123", locale="fi") == n assert numbers.parse_decimal(numbers.format_decimal(n, locale="fi"), locale="fi") == n + + +def test_very_small_decimal_no_quantization(): + assert numbers.format_decimal(decimal.Decimal('1E-7'), locale='en', decimal_quantization=False) == '0.0000001' From ffd8452b3bf3e0f71d99b47461060958114878cf Mon Sep 17 00:00:00 2001 From: sebleblanc Date: Tue, 3 Dec 2019 04:45:42 +0000 Subject: [PATCH 2/2] Hardcode "ignore" method The "ignore" method used to force the opening of the file. Some editors (emacs) create symbolic links to use as synchronization locks. Those links have an extension that matches the opened file, but the links themselves do not point to an existing file, thus causing Babel to attempt to open a file that does not exist. This fix skips opening of a file altogether when using the method "ignore" in the mapping file. --- babel/messages/extract.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/babel/messages/extract.py b/babel/messages/extract.py index db429b2ea..e7d7ad70f 100644 --- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -236,9 +236,12 @@ def extract_from_file(method, filename, keywords=DEFAULT_KEYWORDS, :returns: list of tuples of the form ``(lineno, message, comments, context)`` :rtype: list[tuple[int, str|tuple[str], list[str], str|None] """ + if method == 'ignore': + return [] + with open(filename, 'rb') as fileobj: - return list(extract(method, fileobj, keywords, comment_tags, options, - strip_comment_tags)) + return list(extract(method, fileobj, keywords, comment_tags, + options, strip_comment_tags)) def extract(method, fileobj, keywords=DEFAULT_KEYWORDS, comment_tags=(),