python-iso3166-0.8.git20170319/0000755000175500017550000000000013111536052015152 5ustar debacledebaclepython-iso3166-0.8.git20170319/CHANGES0000644000175500017550000000356513063426442016165 0ustar debacledebacle======= Changes ======= 0.8 - February 5, 2017 ----------------------- * Updated entries - Czechia (changed 2016-09) - United Kingdom of Great Britain and Northern Ireland (changed 2014-12) 0.7 - February 13, 2015 ----------------------- * Added new attribute ``apolitical_name`` to Country. This field reflects the ISO short name but has unnecessarily inflammatory modifiers removed. Specifically: "Taiwan, Province of China" maps to "Taiwan" and "Palestine, State of" maps to "Palestine." * Updated entries - Holy See (changed in 2014-12) * CountryLookup now raises KeyError when passed an unknown integer rather than AttributeError. (thanks unsignedint!) 0.6 - September 28, 2014 ------------------------ * Updated entries - Cabo Verde (changed in 2013-11) * Documented the dictionaries used for looking up countries by alpha2, etc. (thanks brunetton!) 0.5 - February 13, 2014 ----------------------- * Added ``__contains__`` to CountryLookup (thanks tomako!) * Current through ISO newsletter VI-16 - No changes needed 0.4 - February 14, 2013 ----------------------- * Current through ISO newsletter VI-14 * Updated entries - Palestine 0.3 - September 4, 2012 ----------------------- * Current through ISO newsletter VI-13 * Fix changes from 0.2 (thanks vincentfretin!): - Venezuela - Saint Helena - Bolivia 0.2 - March 26, 2012 -------------------- * Current through ISO newsletter VI-12 * Added missing entry for Afghanistan * Updated entries - Bolivia (ISO Newsletter VI-6) - Libya (VI-11) - Saint Helena (VI-7) - Sudan (VI-10) - Venezuela (VI-5) * New entries: - Bonaire, Sint Eustatius and Saba (VI-8) - Curaçao (VI-8) - Sint Maarten (Dutch part) (VI-8) - South Sudan (VI-10) * Deleted entries: - Netherlands Antilles (VI-8) 0.1 - December 14, 2010 ----------------------- - Initial release python-iso3166-0.8.git20170319/ez_setup.py0000644000175500017550000002405513063426442017377 0ustar debacledebacle#!python """Bootstrap setuptools installation If you want to use setuptools in your package's setup.py, just include this file in the same directory with it, and add this to the top of your setup.py:: from ez_setup import use_setuptools use_setuptools() If you want to require a specific version of setuptools, set a download mirror, or use an alternate download directory, you can do so by supplying the appropriate options to ``use_setuptools()``. This file can also be run as a script to install or upgrade setuptools. """ import sys DEFAULT_VERSION = "0.6c11" DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] md5_data = { 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', 'setuptools-0.6c10-py2.3.egg': 'ce1e2ab5d3a0256456d9fc13800a7090', 'setuptools-0.6c10-py2.4.egg': '57d6d9d6e9b80772c59a53a8433a5dd4', 'setuptools-0.6c10-py2.5.egg': 'de46ac8b1c97c895572e5e8596aeb8c7', 'setuptools-0.6c10-py2.6.egg': '58ea40aef06da02ce641495523a0b7f5', 'setuptools-0.6c11-py2.3.egg': '2baeac6e13d414a9d28e7ba5b5a596de', 'setuptools-0.6c11-py2.4.egg': 'bd639f9b0eac4c42497034dec2ec0c2b', 'setuptools-0.6c11-py2.5.egg': '64c94f3bf7a72a13ec83e0b24f2749b2', 'setuptools-0.6c11-py2.6.egg': 'bfa92100bd772d5a213eedd356d64086', 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', 'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20', 'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab', 'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53', 'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2', 'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e', 'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372', 'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902', 'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de', 'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b', 'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03', 'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a', 'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6', 'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a', } import sys, os try: from hashlib import md5 except ImportError: from md5 import md5 def _validate_md5(egg_name, data): if egg_name in md5_data: digest = md5(data).hexdigest() if digest != md5_data[egg_name]: print >>sys.stderr, ( "md5 validation of %s failed! (Possible download problem?)" % egg_name ) sys.exit(2) return data def use_setuptools( version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15 ): """Automatically find/download setuptools and make it available on sys.path `version` should be a valid setuptools version number that is available as an egg for download under the `download_base` URL (which should end with a '/'). `to_dir` is the directory where setuptools will be downloaded, if it is not already available. If `download_delay` is specified, it should be the number of seconds that will be paused before initiating a download, should one be required. If an older version of setuptools is installed, this routine will print a message to ``sys.stderr`` and raise SystemExit in an attempt to abort the calling script. """ was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules def do_download(): egg = download_setuptools(version, download_base, to_dir, download_delay) sys.path.insert(0, egg) import setuptools; setuptools.bootstrap_install_from = egg try: import pkg_resources except ImportError: return do_download() try: pkg_resources.require("setuptools>="+version); return except pkg_resources.VersionConflict, e: if was_imported: print >>sys.stderr, ( "The required version of setuptools (>=%s) is not available, and\n" "can't be installed while this script is running. Please install\n" " a more recent version first, using 'easy_install -U setuptools'." "\n\n(Currently using %r)" ) % (version, e.args[0]) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return do_download() except pkg_resources.DistributionNotFound: return do_download() def download_setuptools( version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay = 15 ): """Download setuptools from a specified location and return its filename `version` should be a valid setuptools version number that is available as an egg for download under the `download_base` URL (which should end with a '/'). `to_dir` is the directory where the egg will be downloaded. `delay` is the number of seconds to pause before an actual download attempt. """ import urllib2, shutil egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) url = download_base + egg_name saveto = os.path.join(to_dir, egg_name) src = dst = None if not os.path.exists(saveto): # Avoid repeated downloads try: from distutils import log if delay: log.warn(""" --------------------------------------------------------------------------- This script requires setuptools version %s to run (even to display help). I will attempt to download it for you (from %s), but you may need to enable firewall access for this script first. I will start the download in %d seconds. (Note: if this machine does not have network access, please obtain the file %s and place it in this directory before rerunning this script.) ---------------------------------------------------------------------------""", version, download_base, delay, url ); from time import sleep; sleep(delay) log.warn("Downloading %s", url) src = urllib2.urlopen(url) # Read/write all in one block, so we don't create a corrupt file # if the download is interrupted. data = _validate_md5(egg_name, src.read()) dst = open(saveto,"wb"); dst.write(data) finally: if src: src.close() if dst: dst.close() return os.path.realpath(saveto) def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" try: import setuptools except ImportError: egg = None try: egg = download_setuptools(version, delay=0) sys.path.insert(0,egg) from setuptools.command.easy_install import main return main(list(argv)+[egg]) # we're done here finally: if egg and os.path.exists(egg): os.unlink(egg) else: if setuptools.__version__ == '0.0.1': print >>sys.stderr, ( "You have an obsolete version of setuptools installed. Please\n" "remove it from your system entirely before rerunning this script." ) sys.exit(2) req = "setuptools>="+version import pkg_resources try: pkg_resources.require(req) except pkg_resources.VersionConflict: try: from setuptools.command.easy_install import main except ImportError: from easy_install import main main(list(argv)+[download_setuptools(delay=0)]) sys.exit(0) # try to force an exit else: if argv: from setuptools.command.easy_install import main main(argv) else: print "Setuptools version",version,"or greater has been installed." print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' def update_md5(filenames): """Update our built-in md5 registry""" import re for name in filenames: base = os.path.basename(name) f = open(name,'rb') md5_data[base] = md5(f.read()).hexdigest() f.close() data = [" %r: %r,\n" % it for it in md5_data.items()] data.sort() repl = "".join(data) import inspect srcfile = inspect.getsourcefile(sys.modules[__name__]) f = open(srcfile, 'rb'); src = f.read(); f.close() match = re.search("\nmd5_data = {\n([^}]+)}", src) if not match: print >>sys.stderr, "Internal error!" sys.exit(2) src = src[:match.start(1)] + repl + src[match.end(1):] f = open(srcfile,'w') f.write(src) f.close() if __name__=='__main__': if len(sys.argv)>2 and sys.argv[1]=='--md5update': update_md5(sys.argv[2:]) else: main(sys.argv[1:]) python-iso3166-0.8.git20170319/MANIFEST.in0000644000175500017550000000006613063426442016721 0ustar debacledebacleinclude LICENSE.txt include README.rst include CHANGESpython-iso3166-0.8.git20170319/tox.ini0000644000175500017550000000011413063426442016470 0ustar debacledebacle[tox] envlist = py27,py34 [testenv] deps=pytest commands=py.test {posargs} python-iso3166-0.8.git20170319/.gitignore0000644000175500017550000000014513063426442017151 0ustar debacledebacle.DS_Store .*.swp *~ *.pyc /dist/ /build/ *.egg-info .coverage /cover docs/_build/ .tox/ pyvenv.cfg python-iso3166-0.8.git20170319/README.rst0000644000175500017550000000466113063426442016657 0ustar debacledebacle============================================================ python-iso3166 - Standalone ISO 3166-1 country definitions ============================================================ :Authors: Mike Spindel :Version: 0.8 ISO 3166-1 defines two-letter, three-letter, and three-digit country codes. `python-iso3166` is a self-contained module that converts between these codes and the corresponding country name. Installation ============ :: $ pip install iso3166 Usage ===== Country details --------------- :: >>> from iso3166 import countries >>> >>> countries.get('us') Country(name=u'United States', alpha2='US', alpha3='USA', numeric='840') >>> countries.get('ala') Country(name=u'\xc5land Islands', alpha2='AX', alpha3='ALA', numeric='248') >>> countries.get(8) Country(name=u'Albania', alpha2='AL', alpha3='ALB', numeric='008') Country lists and indexes ------------------------- :: >>> from iso3166 import countries >>> for c in countries: print c >>> Country(name=u'Afghanistan', alpha2='AF', alpha3='AFG', numeric='004') Country(name=u'\xc5land Islands', alpha2='AX', alpha3='ALA', numeric='248') Country(name=u'Albania', alpha2='AL', alpha3='ALB', numeric='008') Country(name=u'Algeria', alpha2='DZ', alpha3='DZA', numeric='012') :: >>> import iso3166 >>> iso3166.countries_by_name >>> {u'AFGHANISTAN': Country(name=u'Afghanistan', alpha2='AF', alpha3='AFG', numeric='004'), u'ALBANIA': Country(name=u'Albania', alpha2='AL', alpha3='ALB', numeric='008'), u'ALGERIA': Country(name=u'Algeria', alpha2='DZ', alpha3='DZA', numeric='012'), ... >>> iso3166.countries_by_numeric >>> {'004': Country(name=u'Afghanistan', alpha2='AF', alpha3='AFG', numeric='004'), '008': Country(name=u'Albania', alpha2='AL', alpha3='ALB', numeric='008'), '010': Country(name=u'Antarctica', alpha2='AQ', alpha3='ATA', numeric='010'), ... >>> iso3166.countries_by_alpha2 >>> {'AD': Country(name=u'Andorra', alpha2='AD', alpha3='AND', numeric='020'), 'AE': Country(name=u'United Arab Emirates', alpha2='AE', alpha3='ARE', numeric='784'), 'AF': Country(name=u'Afghanistan', alpha2='AF', alpha3='AFG', numeric='004'), ... >>> iso3166.countries_by_alpha3 >>> {'ABW': Country(name=u'Aruba', alpha2='AW', alpha3='ABW', numeric='533'), 'AFG': Country(name=u'Afghanistan', alpha2='AF', alpha3='AFG', numeric='004'), 'AGO': Country(name=u'Angola', alpha2='AO', alpha3='AGO', numeric='024'), ... python-iso3166-0.8.git20170319/setup.cfg0000644000175500017550000000010313063426442016774 0ustar debacledebacle[bdist_wheel] universal = 1 [metadata] license_file = LICENSE.txt python-iso3166-0.8.git20170319/setup.py0000644000175500017550000000222713063426442016676 0ustar debacledebacleimport os.path try: from setuptools import setup, find_packages except ImportError: from ez_setup import use_setuptools use_setuptools() from setuptools import setup, find_packages def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup(name='iso3166', version="0.8", author="Mike Spindel", author_email="mike@spindel.is", license="MIT", keywords="iso 3166-1 country codes", url="http://github.com/deactivated/python-iso3166", description='Self-contained ISO 3166-1 country definitions.', packages=find_packages(exclude=['ez_setup']), long_description=read('README.rst'), zip_safe=False, classifiers=[ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Intended Audience :: Developers", "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", ]) python-iso3166-0.8.git20170319/LICENSE.txt0000644000175500017550000000207013063426442017003 0ustar debacledebacleCopyright (c) 2010, 2011, 2012, 2013, 2014 Mike Spindel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. python-iso3166-0.8.git20170319/tests/0000755000175500017550000000000013063426442016323 5ustar debacledebaclepython-iso3166-0.8.git20170319/tests/test_listings.py0000644000175500017550000000210713063426442021570 0ustar debacledebacle# -*- coding: utf-8 -*- import pytest import iso3166 def test_country_list(): country_list = iso3166.countries assert len(country_list) > 100 assert all(isinstance(c, iso3166.Country) for c in country_list) def test_by_name(): table = iso3166.countries_by_name assert len(table) >= len(iso3166.countries) assert table["AFGHANISTAN"].name == "Afghanistan" def test_by_alt_name(): table = iso3166.countries_by_apolitical_name assert len(table) >= len(iso3166.countries) assert table["AFGHANISTAN"].name == "Afghanistan" assert table["TAIWAN"].apolitical_name == "Taiwan" def test_by_number(): table = iso3166.countries_by_numeric assert len(table) >= len(iso3166.countries) assert table["008"].name == "Albania" def test_by_alpha2(): table = iso3166.countries_by_alpha2 assert len(table) >= len(iso3166.countries) assert table['AE'].name == "United Arab Emirates" def test_by_alpha3(): table = iso3166.countries_by_alpha3 assert len(table) >= len(iso3166.countries) assert table['AFG'].name == 'Afghanistan' python-iso3166-0.8.git20170319/tests/test_lookup.py0000644000175500017550000000315413063426442021250 0ustar debacledebacle# -*- coding: utf-8 -*- import pytest import iso3166 from iso3166 import countries def check_lookup(alpha2, matching_keys, missing_keys): for k in matching_keys: assert countries[k].alpha2 == alpha2 assert countries.get(k).alpha2 == alpha2 assert k in countries for k in missing_keys: with pytest.raises(KeyError): countries.get(k) with pytest.raises(KeyError): countries[k] assert countries.get(k, None) is None def test_length(): assert len(countries) == len(iso3166._records) def test_empty_string(): check_lookup("US", ["us", "US"], [""]) def test_none(): check_lookup("US", ["us", "US"], [None]) def test_alpha2(): check_lookup("US", ["us", "US"], ["zz"]) def test_alpha3(): check_lookup("US", ["usa", "USA"], ["zzz"]) def test_name(): check_lookup("US", ["united states", "United STates"], ["zzzzz"]) def test_numeric(): check_lookup("US", [840, "840"], [111, "111"]) def test_alt_name(): check_lookup("TW", ["taiwan", "Taiwan, province of china"], ["zzzzz"]) check_lookup("PS", ["palestine", "palestine, state of"], ["zzzz"]) def test_data(): assert len(list(countries)) > 0 for country in countries: assert len(country.alpha2) == 2 assert country.alpha2.upper() == country.alpha2 assert len(country.alpha3) == 3 assert country.alpha3.upper() == country.alpha3 assert len(country.numeric) == 3 assert country.numeric == ("%03d" % int(country.numeric)) assert len(country.name) > 3 assert len(country.apolitical_name) > 3 python-iso3166-0.8.git20170319/iso3166/0000755000175500017550000000000013063426442016273 5ustar debacledebaclepython-iso3166-0.8.git20170319/iso3166/__init__.py0000644000175500017550000004461513063426442020416 0ustar debacledebacle# -*- coding: utf-8 -*- import re from numbers import Integral from collections import namedtuple __all__ = ["countries"] try: basestring except NameError: basestring = str Country = namedtuple('Country', 'name alpha2 alpha3 numeric apolitical_name') _records = [ Country(u"Afghanistan", "AF", "AFG", "004", u"Afghanistan"), Country(u"Åland Islands", "AX", "ALA", "248", u"Åland Islands"), Country(u"Albania", "AL", "ALB", "008", u"Albania"), Country(u"Algeria", "DZ", "DZA", "012", u"Algeria"), Country(u"American Samoa", "AS", "ASM", "016", u"American Samoa"), Country(u"Andorra", "AD", "AND", "020", u"Andorra"), Country(u"Angola", "AO", "AGO", "024", u"Angola"), Country(u"Anguilla", "AI", "AIA", "660", u"Anguilla"), Country(u"Antarctica", "AQ", "ATA", "010", u"Antarctica"), Country(u"Antigua and Barbuda", "AG", "ATG", "028", u"Antigua and Barbuda"), Country(u"Argentina", "AR", "ARG", "032", u"Argentina"), Country(u"Armenia", "AM", "ARM", "051", u"Armenia"), Country(u"Aruba", "AW", "ABW", "533", u"Aruba"), Country(u"Australia", "AU", "AUS", "036", u"Australia"), Country(u"Austria", "AT", "AUT", "040", u"Austria"), Country(u"Azerbaijan", "AZ", "AZE", "031", u"Azerbaijan"), Country(u"Bahamas", "BS", "BHS", "044", u"Bahamas"), Country(u"Bahrain", "BH", "BHR", "048", u"Bahrain"), Country(u"Bangladesh", "BD", "BGD", "050", u"Bangladesh"), Country(u"Barbados", "BB", "BRB", "052", u"Barbados"), Country(u"Belarus", "BY", "BLR", "112", u"Belarus"), Country(u"Belgium", "BE", "BEL", "056", u"Belgium"), Country(u"Belize", "BZ", "BLZ", "084", u"Belize"), Country(u"Benin", "BJ", "BEN", "204", u"Benin"), Country(u"Bermuda", "BM", "BMU", "060", u"Bermuda"), Country(u"Bhutan", "BT", "BTN", "064", u"Bhutan"), Country(u"Bolivia, Plurinational State of", "BO", "BOL", "068", u"Bolivia, Plurinational State of"), Country(u"Bonaire, Sint Eustatius and Saba", "BQ", "BES", "535", u"Bonaire, Sint Eustatius and Saba"), Country(u"Bosnia and Herzegovina", "BA", "BIH", "070", u"Bosnia and Herzegovina"), Country(u"Botswana", "BW", "BWA", "072", u"Botswana"), Country(u"Bouvet Island", "BV", "BVT", "074", u"Bouvet Island"), Country(u"Brazil", "BR", "BRA", "076", u"Brazil"), Country(u"British Indian Ocean Territory", "IO", "IOT", "086", u"British Indian Ocean Territory"), Country(u"Brunei Darussalam", "BN", "BRN", "096", u"Brunei Darussalam"), Country(u"Bulgaria", "BG", "BGR", "100", u"Bulgaria"), Country(u"Burkina Faso", "BF", "BFA", "854", u"Burkina Faso"), Country(u"Burundi", "BI", "BDI", "108", u"Burundi"), Country(u"Cambodia", "KH", "KHM", "116", u"Cambodia"), Country(u"Cameroon", "CM", "CMR", "120", u"Cameroon"), Country(u"Canada", "CA", "CAN", "124", u"Canada"), Country(u"Cabo Verde", "CV", "CPV", "132", u"Cabo Verde"), Country(u"Cayman Islands", "KY", "CYM", "136", u"Cayman Islands"), Country(u"Central African Republic", "CF", "CAF", "140", u"Central African Republic"), Country(u"Chad", "TD", "TCD", "148", u"Chad"), Country(u"Chile", "CL", "CHL", "152", u"Chile"), Country(u"China", "CN", "CHN", "156", u"China"), Country(u"Christmas Island", "CX", "CXR", "162", u"Christmas Island"), Country(u"Cocos (Keeling) Islands", "CC", "CCK", "166", u"Cocos (Keeling) Islands"), Country(u"Colombia", "CO", "COL", "170", u"Colombia"), Country(u"Comoros", "KM", "COM", "174", u"Comoros"), Country(u"Congo", "CG", "COG", "178", u"Congo"), Country(u"Congo, Democratic Republic of the", "CD", "COD", "180", u"Congo, Democratic Republic of the"), Country(u"Cook Islands", "CK", "COK", "184", u"Cook Islands"), Country(u"Costa Rica", "CR", "CRI", "188", u"Costa Rica"), Country(u"Côte d'Ivoire", "CI", "CIV", "384", u"Côte d'Ivoire"), Country(u"Croatia", "HR", "HRV", "191", u"Croatia"), Country(u"Cuba", "CU", "CUB", "192", u"Cuba"), Country(u"Curaçao", "CW", "CUW", "531", u"Curaçao"), Country(u"Cyprus", "CY", "CYP", "196", u"Cyprus"), Country(u"Czechia", "CZ", "CZE", "203", u"Czechia"), Country(u"Denmark", "DK", "DNK", "208", u"Denmark"), Country(u"Djibouti", "DJ", "DJI", "262", u"Djibouti"), Country(u"Dominica", "DM", "DMA", "212", u"Dominica"), Country(u"Dominican Republic", "DO", "DOM", "214", u"Dominican Republic"), Country(u"Ecuador", "EC", "ECU", "218", u"Ecuador"), Country(u"Egypt", "EG", "EGY", "818", u"Egypt"), Country(u"El Salvador", "SV", "SLV", "222", u"El Salvador"), Country(u"Equatorial Guinea", "GQ", "GNQ", "226", u"Equatorial Guinea"), Country(u"Eritrea", "ER", "ERI", "232", u"Eritrea"), Country(u"Estonia", "EE", "EST", "233", u"Estonia"), Country(u"Ethiopia", "ET", "ETH", "231", u"Ethiopia"), Country(u"Falkland Islands (Malvinas)", "FK", "FLK", "238", u"Falkland Islands (Malvinas)"), Country(u"Faroe Islands", "FO", "FRO", "234", u"Faroe Islands"), Country(u"Fiji", "FJ", "FJI", "242", u"Fiji"), Country(u"Finland", "FI", "FIN", "246", u"Finland"), Country(u"France", "FR", "FRA", "250", u"France"), Country(u"French Guiana", "GF", "GUF", "254", u"French Guiana"), Country(u"French Polynesia", "PF", "PYF", "258", u"French Polynesia"), Country(u"French Southern Territories", "TF", "ATF", "260", u"French Southern Territories"), Country(u"Gabon", "GA", "GAB", "266", u"Gabon"), Country(u"Gambia", "GM", "GMB", "270", u"Gambia"), Country(u"Georgia", "GE", "GEO", "268", u"Georgia"), Country(u"Germany", "DE", "DEU", "276", u"Germany"), Country(u"Ghana", "GH", "GHA", "288", u"Ghana"), Country(u"Gibraltar", "GI", "GIB", "292", u"Gibraltar"), Country(u"Greece", "GR", "GRC", "300", u"Greece"), Country(u"Greenland", "GL", "GRL", "304", u"Greenland"), Country(u"Grenada", "GD", "GRD", "308", u"Grenada"), Country(u"Guadeloupe", "GP", "GLP", "312", u"Guadeloupe"), Country(u"Guam", "GU", "GUM", "316", u"Guam"), Country(u"Guatemala", "GT", "GTM", "320", u"Guatemala"), Country(u"Guernsey", "GG", "GGY", "831", u"Guernsey"), Country(u"Guinea", "GN", "GIN", "324", u"Guinea"), Country(u"Guinea-Bissau", "GW", "GNB", "624", u"Guinea-Bissau"), Country(u"Guyana", "GY", "GUY", "328", u"Guyana"), Country(u"Haiti", "HT", "HTI", "332", u"Haiti"), Country(u"Heard Island and McDonald Islands", "HM", "HMD", "334", u"Heard Island and McDonald Islands"), Country(u"Holy See", "VA", "VAT", "336", u"Holy See"), Country(u"Honduras", "HN", "HND", "340", u"Honduras"), Country(u"Hong Kong", "HK", "HKG", "344", u"Hong Kong"), Country(u"Hungary", "HU", "HUN", "348", u"Hungary"), Country(u"Iceland", "IS", "ISL", "352", u"Iceland"), Country(u"India", "IN", "IND", "356", u"India"), Country(u"Indonesia", "ID", "IDN", "360", u"Indonesia"), Country(u"Iran, Islamic Republic of", "IR", "IRN", "364", u"Iran, Islamic Republic of"), Country(u"Iraq", "IQ", "IRQ", "368", u"Iraq"), Country(u"Ireland", "IE", "IRL", "372", u"Ireland"), Country(u"Isle of Man", "IM", "IMN", "833", u"Isle of Man"), Country(u"Israel", "IL", "ISR", "376", u"Israel"), Country(u"Italy", "IT", "ITA", "380", u"Italy"), Country(u"Jamaica", "JM", "JAM", "388", u"Jamaica"), Country(u"Japan", "JP", "JPN", "392", u"Japan"), Country(u"Jersey", "JE", "JEY", "832", u"Jersey"), Country(u"Jordan", "JO", "JOR", "400", u"Jordan"), Country(u"Kazakhstan", "KZ", "KAZ", "398", u"Kazakhstan"), Country(u"Kenya", "KE", "KEN", "404", u"Kenya"), Country(u"Kiribati", "KI", "KIR", "296", u"Kiribati"), Country(u"Korea, Democratic People's Republic of", "KP", "PRK", "408", u"Korea, Democratic People's Republic of"), Country(u"Korea, Republic of", "KR", "KOR", "410", u"Korea, Republic of"), Country(u"Kuwait", "KW", "KWT", "414", u"Kuwait"), Country(u"Kyrgyzstan", "KG", "KGZ", "417", u"Kyrgyzstan"), Country(u"Lao People's Democratic Republic", "LA", "LAO", "418", u"Lao People's Democratic Republic"), Country(u"Latvia", "LV", "LVA", "428", u"Latvia"), Country(u"Lebanon", "LB", "LBN", "422", u"Lebanon"), Country(u"Lesotho", "LS", "LSO", "426", u"Lesotho"), Country(u"Liberia", "LR", "LBR", "430", u"Liberia"), Country(u"Libya", "LY", "LBY", "434", u"Libya"), Country(u"Liechtenstein", "LI", "LIE", "438", u"Liechtenstein"), Country(u"Lithuania", "LT", "LTU", "440", u"Lithuania"), Country(u"Luxembourg", "LU", "LUX", "442", u"Luxembourg"), Country(u"Macao", "MO", "MAC", "446", u"Macao"), Country(u"Macedonia, the former Yugoslav Republic of", "MK", "MKD", "807", u"Macedonia, the former Yugoslav Republic of"), Country(u"Madagascar", "MG", "MDG", "450", u"Madagascar"), Country(u"Malawi", "MW", "MWI", "454", u"Malawi"), Country(u"Malaysia", "MY", "MYS", "458", u"Malaysia"), Country(u"Maldives", "MV", "MDV", "462", u"Maldives"), Country(u"Mali", "ML", "MLI", "466", u"Mali"), Country(u"Malta", "MT", "MLT", "470", u"Malta"), Country(u"Marshall Islands", "MH", "MHL", "584", u"Marshall Islands"), Country(u"Martinique", "MQ", "MTQ", "474", u"Martinique"), Country(u"Mauritania", "MR", "MRT", "478", u"Mauritania"), Country(u"Mauritius", "MU", "MUS", "480", u"Mauritius"), Country(u"Mayotte", "YT", "MYT", "175", u"Mayotte"), Country(u"Mexico", "MX", "MEX", "484", u"Mexico"), Country(u"Micronesia, Federated States of", "FM", "FSM", "583", u"Micronesia, Federated States of"), Country(u"Moldova, Republic of", "MD", "MDA", "498", u"Moldova, Republic of"), Country(u"Monaco", "MC", "MCO", "492", u"Monaco"), Country(u"Mongolia", "MN", "MNG", "496", u"Mongolia"), Country(u"Montenegro", "ME", "MNE", "499", u"Montenegro"), Country(u"Montserrat", "MS", "MSR", "500", u"Montserrat"), Country(u"Morocco", "MA", "MAR", "504", u"Morocco"), Country(u"Mozambique", "MZ", "MOZ", "508", u"Mozambique"), Country(u"Myanmar", "MM", "MMR", "104", u"Myanmar"), Country(u"Namibia", "NA", "NAM", "516", u"Namibia"), Country(u"Nauru", "NR", "NRU", "520", u"Nauru"), Country(u"Nepal", "NP", "NPL", "524", u"Nepal"), Country(u"Netherlands", "NL", "NLD", "528", u"Netherlands"), Country(u"New Caledonia", "NC", "NCL", "540", u"New Caledonia"), Country(u"New Zealand", "NZ", "NZL", "554", u"New Zealand"), Country(u"Nicaragua", "NI", "NIC", "558", u"Nicaragua"), Country(u"Niger", "NE", "NER", "562", u"Niger"), Country(u"Nigeria", "NG", "NGA", "566", u"Nigeria"), Country(u"Niue", "NU", "NIU", "570", u"Niue"), Country(u"Norfolk Island", "NF", "NFK", "574", u"Norfolk Island"), Country(u"Northern Mariana Islands", "MP", "MNP", "580", u"Northern Mariana Islands"), Country(u"Norway", "NO", "NOR", "578", u"Norway"), Country(u"Oman", "OM", "OMN", "512", u"Oman"), Country(u"Pakistan", "PK", "PAK", "586", u"Pakistan"), Country(u"Palau", "PW", "PLW", "585", u"Palau"), Country(u"Palestine, State of", "PS", "PSE", "275", u"Palestine"), Country(u"Panama", "PA", "PAN", "591", u"Panama"), Country(u"Papua New Guinea", "PG", "PNG", "598", u"Papua New Guinea"), Country(u"Paraguay", "PY", "PRY", "600", u"Paraguay"), Country(u"Peru", "PE", "PER", "604", u"Peru"), Country(u"Philippines", "PH", "PHL", "608", u"Philippines"), Country(u"Pitcairn", "PN", "PCN", "612", u"Pitcairn"), Country(u"Poland", "PL", "POL", "616", u"Poland"), Country(u"Portugal", "PT", "PRT", "620", u"Portugal"), Country(u"Puerto Rico", "PR", "PRI", "630", u"Puerto Rico"), Country(u"Qatar", "QA", "QAT", "634", u"Qatar"), Country(u"Réunion", "RE", "REU", "638", u"Réunion"), Country(u"Romania", "RO", "ROU", "642", u"Romania"), Country(u"Russian Federation", "RU", "RUS", "643", u"Russian Federation"), Country(u"Rwanda", "RW", "RWA", "646", u"Rwanda"), Country(u"Saint Barthélemy", "BL", "BLM", "652", u"Saint Barthélemy"), Country(u"Saint Helena, Ascension and Tristan da Cunha", "SH", "SHN", "654", u"Saint Helena, Ascension and Tristan da Cunha"), Country(u"Saint Kitts and Nevis", "KN", "KNA", "659", u"Saint Kitts and Nevis"), Country(u"Saint Lucia", "LC", "LCA", "662", u"Saint Lucia"), Country(u"Saint Martin (French part)", "MF", "MAF", "663", u"Saint Martin (French part)"), Country(u"Saint Pierre and Miquelon", "PM", "SPM", "666", u"Saint Pierre and Miquelon"), Country(u"Saint Vincent and the Grenadines", "VC", "VCT", "670", u"Saint Vincent and the Grenadines"), Country(u"Samoa", "WS", "WSM", "882", u"Samoa"), Country(u"San Marino", "SM", "SMR", "674", u"San Marino"), Country(u"Sao Tome and Principe", "ST", "STP", "678", u"Sao Tome and Principe"), Country(u"Saudi Arabia", "SA", "SAU", "682", u"Saudi Arabia"), Country(u"Senegal", "SN", "SEN", "686", u"Senegal"), Country(u"Serbia", "RS", "SRB", "688", u"Serbia"), Country(u"Seychelles", "SC", "SYC", "690", u"Seychelles"), Country(u"Sierra Leone", "SL", "SLE", "694", u"Sierra Leone"), Country(u"Singapore", "SG", "SGP", "702", u"Singapore"), Country(u"Sint Maarten (Dutch part)", "SX", "SXM", "534", u"Sint Maarten (Dutch part)"), Country(u"Slovakia", "SK", "SVK", "703", u"Slovakia"), Country(u"Slovenia", "SI", "SVN", "705", u"Slovenia"), Country(u"Solomon Islands", "SB", "SLB", "090", u"Solomon Islands"), Country(u"Somalia", "SO", "SOM", "706", u"Somalia"), Country(u"South Africa", "ZA", "ZAF", "710", u"South Africa"), Country(u"South Georgia and the South Sandwich Islands", "GS", "SGS", "239", u"South Georgia and the South Sandwich Islands",), Country(u"South Sudan", "SS", "SSD", "728", u"South Sudan"), Country(u"Spain", "ES", "ESP", "724", u"Spain"), Country(u"Sri Lanka", "LK", "LKA", "144", u"Sri Lanka"), Country(u"Sudan", "SD", "SDN", "729", u"Sudan"), Country(u"Suriname", "SR", "SUR", "740", u"Suriname"), Country(u"Svalbard and Jan Mayen", "SJ", "SJM", "744", u"Svalbard and Jan Mayen"), Country(u"Swaziland", "SZ", "SWZ", "748", u"Swaziland"), Country(u"Sweden", "SE", "SWE", "752", u"Sweden"), Country(u"Switzerland", "CH", "CHE", "756", u"Switzerland"), Country(u"Syrian Arab Republic", "SY", "SYR", "760", u"Syrian Arab Republic"), Country(u"Taiwan, Province of China", "TW", "TWN", "158", u"Taiwan"), Country(u"Tajikistan", "TJ", "TJK", "762", u"Tajikistan"), Country(u"Tanzania, United Republic of", "TZ", "TZA", "834", u"Tanzania, United Republic of"), Country(u"Thailand", "TH", "THA", "764", u"Thailand"), Country(u"Timor-Leste", "TL", "TLS", "626", u"Timor-Leste"), Country(u"Togo", "TG", "TGO", "768", u"Togo"), Country(u"Tokelau", "TK", "TKL", "772", u"Tokelau"), Country(u"Tonga", "TO", "TON", "776", u"Tonga"), Country(u"Trinidad and Tobago", "TT", "TTO", "780", u"Trinidad and Tobago"), Country(u"Tunisia", "TN", "TUN", "788", u"Tunisia"), Country(u"Turkey", "TR", "TUR", "792", u"Turkey"), Country(u"Turkmenistan", "TM", "TKM", "795", u"Turkmenistan"), Country(u"Turks and Caicos Islands", "TC", "TCA", "796", u"Turks and Caicos Islands"), Country(u"Tuvalu", "TV", "TUV", "798", u"Tuvalu"), Country(u"Uganda", "UG", "UGA", "800", u"Uganda"), Country(u"Ukraine", "UA", "UKR", "804", u"Ukraine"), Country(u"United Arab Emirates", "AE", "ARE", "784", u"United Arab Emirates"), Country(u"United Kingdom of Great Britain and Northern Ireland", "GB", "GBR", "826", u"United Kingdom of Great Britain and Northern Ireland"), Country(u"United States of America", "US", "USA", "840", u"United States of America"), Country(u"United States Minor Outlying Islands", "UM", "UMI", "581", u"United States Minor Outlying Islands"), Country(u"Uruguay", "UY", "URY", "858", u"Uruguay"), Country(u"Uzbekistan", "UZ", "UZB", "860", u"Uzbekistan"), Country(u"Vanuatu", "VU", "VUT", "548", u"Vanuatu"), Country(u"Venezuela, Bolivarian Republic of", "VE", "VEN", "862", u"Venezuela, Bolivarian Republic of"), Country(u"Viet Nam", "VN", "VNM", "704", u"Viet Nam"), Country(u"Virgin Islands, British", "VG", "VGB", "092", u"Virgin Islands, British"), Country(u"Virgin Islands, U.S.", "VI", "VIR", "850", u"Virgin Islands, U.S."), Country(u"Wallis and Futuna", "WF", "WLF", "876", u"Wallis and Futuna"), Country(u"Western Sahara", "EH", "ESH", "732", u"Western Sahara"), Country(u"Yemen", "YE", "YEM", "887", u"Yemen"), Country(u"Zambia", "ZM", "ZMB", "894", u"Zambia"), Country(u"Zimbabwe", "ZW", "ZWE", "716", u"Zimbabwe")] def _build_index(idx): return dict((r[idx].upper(), r) for r in _records) # Internal country indexes _by_alpha2 = _build_index(1) _by_alpha3 = _build_index(2) _by_numeric = _build_index(3) _by_name = _build_index(0) _by_apolitical_name = _build_index(4) # Documented accessors for the country indexes countries_by_alpha2 = _by_alpha2 countries_by_alpha3 = _by_alpha3 countries_by_numeric = _by_numeric countries_by_name = _by_name countries_by_apolitical_name = _by_apolitical_name NOT_FOUND = object() class _CountryLookup(object): def get(self, key, default=NOT_FOUND): if isinstance(key, Integral): r = _by_numeric.get("%03d" % key, default) elif isinstance(key, basestring): k = key.upper() if len(k) == 2: r = _by_alpha2.get(k, default) elif len(k) == 3 and re.match(r"[0-9]{3}", k): r = _by_numeric.get(k, default) elif len(k) == 3: r = _by_alpha3.get(k, default) elif k in _by_name: r = _by_name.get(k, default) else: r = _by_apolitical_name.get(k, default) else: r = default if r == NOT_FOUND: raise KeyError(key) return r __getitem__ = get def __len__(self): return len(_records) def __iter__(self): return iter(_records) def __contains__(self, item): try: self.get(item) return True except KeyError: return False countries = _CountryLookup()