Mercurial > babel > mirror
changeset 567:c81a11cb1476 trunk
add a compat module to shield the code from changes in different versions of Python
author | fschwarz |
---|---|
date | Mon, 26 Sep 2011 09:42:43 +0000 |
parents | 593157da23f3 |
children | 39ff5164e8ea |
files | babel/compat.py babel/localedata.py scripts/import_cldr.py |
diffstat | 3 files changed, 33 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/babel/compat.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2007-2011 Edgewall Software +# All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://babel.edgewall.org/wiki/License. +# +# This software consists of voluntary contributions made by many +# individuals. For the exact contribution history, see the revision +# history and logs, available at http://babel.edgewall.org/log/. + +try: + from xml.etree import ElementTree +except ImportError: + from elementtree import ElementTree + +try: + any = any +except NameError: + def any(iterable): + return filter(None, list(iterable)) + +try: + import threading +except ImportError: + import dummy_threading as threading +
--- a/babel/localedata.py +++ b/babel/localedata.py @@ -19,12 +19,10 @@ import os import cPickle as pickle -try: - import threading -except ImportError: - import dummy_threading as threading from UserDict import DictMixin +from babel.compat import threading + __all__ = ['exists', 'locale_identifiers', 'load'] __docformat__ = 'restructuredtext en'
--- a/scripts/import_cldr.py +++ b/scripts/import_cldr.py @@ -17,27 +17,19 @@ import os import re import sys -try: - from xml.etree.ElementTree import parse -except ImportError: - from elementtree.ElementTree import parse # 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]), '..')) from babel import dates, numbers +from babel.compat import any, ElementTree from babel.plural import PluralRule from babel.localedata import Alias +parse = ElementTree.parse weekdays = {'mon': 0, 'tue': 1, 'wed': 2, 'thu': 3, 'fri': 4, 'sat': 5, 'sun': 6} -try: - any -except NameError: - def any(iterable): - return filter(None, list(iterable)) - def _text(elem): buf = [elem.text or '']