Felix Schwarz [Tue, 5 May 2020 08:05:56 +0000 (08:05 +0000)]
fix tests when using Python 3.9a6
In Python 3.9a6 integer values for future flags were changed to prevent
collision with compiler flags. We need to retrieve these at runtime so
the test suite works with Python <= 3.8 as well as Python 3.9.
Felix Schwarz [Tue, 5 May 2020 07:58:01 +0000 (09:58 +0200)]
stop using deprecated ElementTree methods "getchildren()" and "getiterator()"
Both methods were removed in Python 3.9 as mentioned in the release notes:
> Methods getchildren() and getiterator() of classes ElementTree and Element in
> the ElementTree module have been removed. They were deprecated in Python 3.2.
> Use iter(x) or list(x) instead of x.getchildren() and x.iter() or
> list(x.iter()) instead of x.getiterator().
CyanNani123 [Mon, 13 Jan 2020 22:13:01 +0000 (23:13 +0100)]
catalog.rst: Add __iter__ to Catalog documentation
The declaration of __iter__ under the special-members
directive makes it visible in the documentation.
The docstring describing __iter__ already exists.
Niklas Hambüchen [Mon, 27 Jan 2020 23:37:22 +0000 (00:37 +0100)]
Fix unicode printing error on Python 2 without TTY.
Until now, on Python 2.7, `python setup.py test | cat` crashed in the test
runner with
======================================================================
ERROR: test_abort_invalid_po_file (tests.messages.test_pofile.ReadPoTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "src/babel/tests/messages/test_pofile.py", line 458, in test_abort_invalid_po_file
output = pofile.read_po(buf, locale='fr', abort_invalid=False)
File "src/babel/babel/messages/pofile.py", line 377, in read_po
parser.parse(fileobj)
File "src/babel/babel/messages/pofile.py", line 310, in parse
self._process_message_line(lineno, line)
File "src/babel/babel/messages/pofile.py", line 210, in _process_message_line
self._process_keyword_line(lineno, line, obsolete)
File "src/babel/babel/messages/pofile.py", line 222, in _process_keyword_line
self._invalid_pofile(line, lineno, "Start of line didn't match any expected keyword.")
File "src/babel/babel/messages/pofile.py", line 325, in _invalid_pofile
print(u"WARNING: Problem on line {0}: {1}".format(lineno + 1, line))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 84: ordinal not in range(128)
The test suite would show this when printing the `à` in the test pofile contents
Pour toute question, veuillez communiquer avec Fulano à nadie@blah.com
But this bug is not confined to the test suite only. Any call to `read_po()`
with invalid .po file could trigger it in non-test code when
`sys.stdout.encoding` is `None`, which is the default for Python 2 when
`sys.stdout.isatty()` is false (as induced e.g. by `| cat`).
The fix is to `repr()` the line when printing the WARNING.
Niklas Hambüchen [Tue, 28 Jan 2020 01:46:25 +0000 (02:46 +0100)]
Introduce invariant that _invalid_pofile() takes unicode line.
This makes debugging and reasoning about the code easier;
otherwise it is surprising that sometimes `line` is a unicode
and sometimes not.
So far, when it was not, it could either be only `""` or
`'Algo esta mal'`; thus this commit makes those two u"" strings.
In all other cases, it was guaranteed that it's unicode,
because all code paths leading to `_invalid_pofile()` went through
if not isinstance(line, text_type):
line = line.decode(self.catalog.charset)
Miro Hrončok [Sun, 5 Jan 2020 23:37:39 +0000 (00:37 +0100)]
Replace usage of parser.suite with ast.parse
Replaced usage of the long-superseded "parser.suite" module in the
mako.util package for parsing the python magic encoding comment with the
"ast.parse" function introduced many years ago in Python 2.5, as
"parser.suite" is emitting deprecation warnings in Python 3.9.
sebleblanc [Tue, 3 Dec 2019 04:45:42 +0000 (04:45 +0000)]
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.
Miro Hrončok [Thu, 14 Mar 2019 18:54:42 +0000 (19:54 +0100)]
Fix conftest.py compatibility with pytest 4.3
While pytest in tox.ini is explicitly set to be 3.3.2, in Fedora 31
we are about to update to a newer version of pytest.
In order to be able to test babel, we need pytest 4.3 support.
This adds support for pytest 4.3 without breaking support for 3.3.2.
Jon Dufresne [Thu, 11 Oct 2018 03:34:09 +0000 (20:34 -0700)]
Remove unnecessary compat shim 'binary_type'
The bytes type is available on all supported Pythons. On Python 2, it is
an alias of str, same as binary_type. By removing the shim, makes the
code more forward compatible.
mondeja [Sat, 13 Oct 2018 12:49:30 +0000 (14:49 +0200)]
Avoid KeyError trying to get data on WindowsXP
I've found this issue trying to compile documentation with Sphinx on WindowsXP with `make html` command. Some data dictionaries are void on my machine, so using lazy 'get' on those can prevent next `KeyError`:
```
C:\Path\to\my\project\doc>make html
{'MapID': '8,9', 'Index': 165, 'Std': 'Hora estándar árabe', 'Display': '(GMT+04
:00) Abu Dhabi, Muscat', 'TZI': b'\x10\xff\xff\xff\x00\x00\x00\x00\xc4\xff\xff\x
ff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano árab
e'}
{'MapID': '-1,71', 'Index': 158, 'Std': 'Hora estándar árabe D', 'Display': '(GM
T+03:00) Baghdad', 'TZI': b'L\xff\xff\xff\x00\x00\x00\x00\xc4\xff\xff\xff\x00\x0
0\n\x00\x00\x00\x01\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\
x01\x00\x03\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano árabe'}
{'MapID': '12,13', 'Index': 195, 'Std': 'Hora estándar de Asia C.', 'Display': '
(GMT+06:00) Astana, Dhaka', 'TZI': b'\x98\xfe\xff\xff\x00\x00\x00\x00\xc4\xff\xf
f\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'Dlt': 'Hora de verano d
e Asia C.'}
{}
Traceback (most recent call last):
File "c:\python34\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "c:\python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python34\Scripts\sphinx-build.exe\__main__.py", line 5, in <module>
File "c:\python34\lib\site-packages\sphinx\cmd\build.py", line 25, in <module>
from sphinx.application import Sphinx
File "c:\python34\lib\site-packages\sphinx\application.py", line 29, in <modul
e>
from sphinx.config import Config, check_unicode
File "c:\python34\lib\site-packages\sphinx\config.py", line 28, in <module>
from sphinx.util.i18n import format_date
File "c:\python34\lib\site-packages\sphinx\util\i18n.py", line 20, in <module>
import babel.dates
File "c:\python34\lib\site-packages\babel\dates.py", line 29, in <module>
from babel.util import UTC, LOCALTZ
File "c:\python34\lib\site-packages\babel\util.py", line 19, in <module>
from babel import localtime
File "c:\python34\lib\site-packages\babel\localtime\__init__.py", line 74, in
<module>
LOCALTZ = get_localzone()
File "c:\python34\lib\site-packages\babel\localtime\__init__.py", line 70, in
get_localzone
return _get_localzone()
File "c:\python34\lib\site-packages\babel\localtime\_win32.py", line 97, in _g
et_localzone
return pytz.timezone(get_localzone_name())
File "c:\python34\lib\site-packages\babel\localtime\_win32.py", line 70, in ge
t_localzone_name
if data['Std'] == tzwin:
KeyError: 'Std'
```
Luke Plant [Thu, 7 Jun 2018 12:21:19 +0000 (15:21 +0300)]
Simplify format_currency code by pulling out/using helpers.
In detail:
1. Use the already existing get_currency_name function which does
the plural form logic already.
2. Create a similar `get_currency_unit_pattern` function.
This function could be useful if someone wanted to write
something very similar to the _format_currency_long_name
functionality but with some different customizations,
so it is now publicly documented.
3. Simplify the _format_currency_long_name function - it
is now much flatter.
4. Add more tests to ensure certain cases are really covered.
(e.g. different unit patterns depending on the count)
An upshot of the changes is that we have reduced (and made more consistent)
the number of places where we need to peek into `Locale._data` -
get_currency_name and get_currency_unit_pattern are the only places that
babel.numbers does this.