diff --git a/libs/babelfish/__init__.py b/libs/babelfish/__init__.py index 205254a5..559705a2 100644 --- a/libs/babelfish/__init__.py +++ b/libs/babelfish/__init__.py @@ -5,10 +5,10 @@ # that can be found in the LICENSE file. # __title__ = 'babelfish' -__version__ = '0.5.4-dev' +__version__ = '0.5.5-dev' __author__ = 'Antoine Bertin' __license__ = 'BSD' -__copyright__ = 'Copyright 2013 the BabelFish authors' +__copyright__ = 'Copyright 2015 the BabelFish authors' import sys diff --git a/libs/babelfish/converters/__init__.py b/libs/babelfish/converters/__init__.py index 9a0a1bd9..feb687b0 100644 --- a/libs/babelfish/converters/__init__.py +++ b/libs/babelfish/converters/__init__.py @@ -241,7 +241,14 @@ class ConverterManager(object): return self.converters[ep.name] for ep in (EntryPoint.parse(c) for c in self.registered_converters + self.internal_converters): if ep.name == name: - self.converters[ep.name] = ep.load(require=False)() + # `require` argument of ep.load() is deprecated in newer versions of setuptools + if hasattr(ep, 'resolve'): + plugin = ep.resolve() + elif hasattr(ep, '_load'): + plugin = ep._load() + else: + plugin = ep.load(require=False) + self.converters[ep.name] = plugin() return self.converters[ep.name] raise KeyError(name) diff --git a/libs/babelfish/country.py b/libs/babelfish/country.py index ce32d9b5..4c24b52b 100644 --- a/libs/babelfish/country.py +++ b/libs/babelfish/country.py @@ -82,7 +82,10 @@ class Country(CountryMeta(str('CountryBase'), (object,), {})): self.alpha2 = state def __getattr__(self, name): - return country_converters[name].convert(self.alpha2) + try: + return country_converters[name].convert(self.alpha2) + except KeyError: + raise AttributeError(name) def __hash__(self): return hash(self.alpha2) diff --git a/libs/babelfish/data/get_files.py b/libs/babelfish/data/get_files.py deleted file mode 100644 index aaa090cc..00000000 --- a/libs/babelfish/data/get_files.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (c) 2013 the BabelFish authors. All rights reserved. -# Use of this source code is governed by the 3-clause BSD license -# that can be found in the LICENSE file. -# -from __future__ import unicode_literals -import os.path -import tempfile -import zipfile -import requests - - -DATA_DIR = os.path.dirname(__file__) - -# iso-3166-1.txt -print('Downloading ISO-3166-1 standard (ISO country codes)...') -with open(os.path.join(DATA_DIR, 'iso-3166-1.txt'), 'w') as f: - r = requests.get('http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt.htm') - f.write(r.content.strip()) - -# iso-639-3.tab -print('Downloading ISO-639-3 standard (ISO language codes)...') -with tempfile.TemporaryFile() as f: - r = requests.get('http://www-01.sil.org/iso639-3/iso-639-3_Code_Tables_20130531.zip') - f.write(r.content) - with zipfile.ZipFile(f) as z: - z.extract('iso-639-3.tab', DATA_DIR) - -# iso-15924 -print('Downloading ISO-15924 standard (ISO script codes)...') -with tempfile.TemporaryFile() as f: - r = requests.get('http://www.unicode.org/iso15924/iso15924.txt.zip') - f.write(r.content) - with zipfile.ZipFile(f) as z: - z.extract('iso15924-utf8-20131012.txt', DATA_DIR) - -# opensubtitles supported languages -print('Downloading OpenSubtitles supported languages...') -with open(os.path.join(DATA_DIR, 'opensubtitles_languages.txt'), 'w') as f: - r = requests.get('http://www.opensubtitles.org/addons/export_languages.php') - f.write(r.content) - -print('Done!') diff --git a/libs/babelfish/tests.py b/libs/babelfish/tests.py index cf688af9..beed5469 100644 --- a/libs/babelfish/tests.py +++ b/libs/babelfish/tests.py @@ -283,6 +283,11 @@ class TestLanguage(TestCase, _Py26FixTestCase): self.assertTrue(hasattr(Language('fra'), 'alpha2')) self.assertFalse(hasattr(Language('bej'), 'alpha2')) + def test_country_hasattr(self): + self.assertTrue(hasattr(Country('US'), 'name')) + self.assertTrue(hasattr(Country('FR'), 'alpha2')) + self.assertFalse(hasattr(Country('BE'), 'none')) + def test_country(self): self.assertEqual(Language('por', 'BR').country, Country('BR')) self.assertEqual(Language('eng', Country('US')).country, Country('US'))