From: Felix Schwarz Date: Mon, 26 Sep 2011 09:42:43 +0000 (+0000) Subject: add a compat module to shield the code from changes in different versions of Python X-Git-Tag: 1.0~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e99515b298fa3b2f6e0003c0cb3631207720005;p=thirdparty%2Fbabel.git add a compat module to shield the code from changes in different versions of Python --- diff --git a/babel/compat.py b/babel/compat.py new file mode 100644 index 00000000..c5479d23 --- /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 + diff --git a/babel/localedata.py b/babel/localedata.py index e0517324..d128ec8d 100644 --- 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' diff --git a/scripts/import_cldr.py b/scripts/import_cldr.py index ed724e46..65654ceb 100755 --- a/scripts/import_cldr.py +++ b/scripts/import_cldr.py @@ -17,27 +17,19 @@ from optparse import OptionParser 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 '']