diff options
author | Erick Wilder <erickwilder@gmail.com> | 2015-09-09 18:58:47 -0300 |
---|---|---|
committer | Erick Wilder <erickwilder@gmail.com> | 2015-09-09 18:58:47 -0300 |
commit | 17d77d0fa8d6e4dd799bbbb1b8bba744788cc647 (patch) | |
tree | a465e0de2a981ce5575f8775cc7357c88dae17e7 | |
parent | aa5b28d3c59c2fa811e929cf8158b4f942faf86e (diff) | |
parent | 2265065a8ded307a7a5e87e948f36b6240e47f0c (diff) | |
download | babel-17d77d0fa8d6e4dd799bbbb1b8bba744788cc647.tar.gz |
Merge pull request #193 from erickwilder/issue174/2.x-backport
Backporting #174 bugfix to 2.x version
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | babel/__init__.py | 2 | ||||
-rw-r--r-- | babel/numbers.py | 4 | ||||
-rwxr-xr-x | scripts/import_cldr.py | 6 | ||||
-rwxr-xr-x | setup.py | 2 | ||||
-rw-r--r-- | tests/test_core.py | 26 |
6 files changed, 39 insertions, 6 deletions
@@ -1,6 +1,11 @@ Babel Changelog =============== +Version 2.1 +----------- +(bugfix release, to be defined) +- Fix Locale.parse using ``global.dat`` incompatible types (https://github.com/mitsuhiko/babel/issues/174) + Version 2.0 ----------- diff --git a/babel/__init__.py b/babel/__init__.py index 6854931..d889503 100644 --- a/babel/__init__.py +++ b/babel/__init__.py @@ -21,4 +21,4 @@ from babel.core import UnknownLocaleError, Locale, default_locale, \ negotiate_locale, parse_locale, get_locale_identifier -__version__ = '2.0' +__version__ = '2.1' diff --git a/babel/numbers.py b/babel/numbers.py index 587d640..d7a20d1 100644 --- a/babel/numbers.py +++ b/babel/numbers.py @@ -134,6 +134,10 @@ def get_territory_currencies(territory, start_date=None, end_date=None, result = [] for currency_code, start, end, is_tender in curs: + if start: + start = date_(*start) + if end: + end = date_(*end) if ((is_tender and tender) or \ (not is_tender and non_tender)) and _is_active(start, end): if include_details: diff --git a/scripts/import_cldr.py b/scripts/import_cldr.py index 3a2f121..a9350ae 100755 --- a/scripts/import_cldr.py +++ b/scripts/import_cldr.py @@ -21,8 +21,6 @@ try: except ImportError: from xml.etree import ElementTree -from datetime import date - # Make sure we're using Babel source, and not some previously installed version sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '..')) @@ -103,12 +101,12 @@ def _parse_currency_date(s): if not s: return None parts = s.split('-', 2) - return date(*map(int, parts + [1] * (3 - len(parts)))) + return tuple(map(int, parts + [1] * (3 - len(parts)))) def _currency_sort_key(tup): code, start, end, tender = tup - return int(not tender), start or date(1, 1, 1) + return int(not tender), start or (1, 1, 1) def main(): @@ -32,7 +32,7 @@ class import_cldr(Command): setup( name='Babel', - version='2.0', + version='2.1', description='Internationalization utilities', long_description=\ """A collection of tools for internationalizing Python applications.""", diff --git a/tests/test_core.py b/tests/test_core.py index ac2611d..58118aa 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -269,3 +269,29 @@ def test_parse_locale(): assert core.parse_locale('en_US.UTF-8') == ('en', 'US', None, None) assert (core.parse_locale('de_DE.iso885915@euro') == ('de', 'DE', None, None)) + +def test_compatible_classes_in_global_and_localedata(): + # Use pickle module rather than cPickle since cPickle.Unpickler is a method + # on Python 2 + import pickle + + class Unpickler(pickle.Unpickler): + def find_class(self, module, name): + # *.dat files must have compatible classes between Python 2 and 3 + if module.split('.')[0] == 'babel': + return pickle.Unpickler.find_class(self, module, name) + raise pickle.UnpicklingError("global '%s.%s' is forbidden" % + (module, name)) + + def load(filename): + with open(filename, 'rb') as f: + return Unpickler(f).load() + + load('babel/global.dat') + load('babel/localedata/root.dat') + load('babel/localedata/en.dat') + load('babel/localedata/en_US.dat') + load('babel/localedata/en_US_POSIX.dat') + load('babel/localedata/zh_Hans_CN.dat') + load('babel/localedata/zh_Hant_TW.dat') + load('babel/localedata/es_419.dat') |