# HG changeset patch # User fschwarz # Date 1317030163 0 # Node ID c81a11cb1476f25c356cb2d33bdfc7fe39708e1a # Parent 593157da23f3af1263a79495e6a69954c80fea18 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 --- /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 --- 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 --- 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 '']