mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
Merge pull request #1412 from clinton-hall/libs/babelfish
Update babelfish to 0.5.5
This commit is contained in:
commit
8c8f58eae8
5 changed files with 19 additions and 49 deletions
|
@ -5,10 +5,10 @@
|
||||||
# that can be found in the LICENSE file.
|
# that can be found in the LICENSE file.
|
||||||
#
|
#
|
||||||
__title__ = 'babelfish'
|
__title__ = 'babelfish'
|
||||||
__version__ = '0.5.4-dev'
|
__version__ = '0.5.5-dev'
|
||||||
__author__ = 'Antoine Bertin'
|
__author__ = 'Antoine Bertin'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__copyright__ = 'Copyright 2013 the BabelFish authors'
|
__copyright__ = 'Copyright 2015 the BabelFish authors'
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,14 @@ class ConverterManager(object):
|
||||||
return self.converters[ep.name]
|
return self.converters[ep.name]
|
||||||
for ep in (EntryPoint.parse(c) for c in self.registered_converters + self.internal_converters):
|
for ep in (EntryPoint.parse(c) for c in self.registered_converters + self.internal_converters):
|
||||||
if ep.name == name:
|
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]
|
return self.converters[ep.name]
|
||||||
raise KeyError(name)
|
raise KeyError(name)
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,10 @@ class Country(CountryMeta(str('CountryBase'), (object,), {})):
|
||||||
self.alpha2 = state
|
self.alpha2 = state
|
||||||
|
|
||||||
def __getattr__(self, name):
|
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):
|
def __hash__(self):
|
||||||
return hash(self.alpha2)
|
return hash(self.alpha2)
|
||||||
|
|
|
@ -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!')
|
|
|
@ -283,6 +283,11 @@ class TestLanguage(TestCase, _Py26FixTestCase):
|
||||||
self.assertTrue(hasattr(Language('fra'), 'alpha2'))
|
self.assertTrue(hasattr(Language('fra'), 'alpha2'))
|
||||||
self.assertFalse(hasattr(Language('bej'), '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):
|
def test_country(self):
|
||||||
self.assertEqual(Language('por', 'BR').country, Country('BR'))
|
self.assertEqual(Language('por', 'BR').country, Country('BR'))
|
||||||
self.assertEqual(Language('eng', Country('US')).country, Country('US'))
|
self.assertEqual(Language('eng', Country('US')).country, Country('US'))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue