1import pycountry
2
3
4class Countries(object):
5    AFGHANISTAN = 'af'
6    ALAND_ISLANDS = 'ax'
7    ALBANIA = 'al'
8    ALGERIA = 'dz'
9    AMERICAN_SAMOA = 'as'
10    ANDORRA = 'ad'
11    ANGOLA = 'ao'
12    ANGUILLA = 'ai'
13    ANTARCTICA = 'aq'
14    ANTIGUA_AND_BARBUDA = 'ag'
15    ARGENTINA = 'ar'
16    ARMENIA = 'am'
17    ARUBA = 'aw'
18    AUSTRALIA = 'au'
19    AUSTRIA = 'at'
20    AZERBAIJAN = 'az'
21    BAHAMAS = 'bs'
22    BAHRAIN = 'bh'
23    BANGLADESH = 'bd'
24    BARBADOS = 'bb'
25    BELARUS = 'by'
26    BELGIUM = 'be'
27    BELIZE = 'bz'
28    BENIN = 'bj'
29    BERMUDA = 'bm'
30    BHUTAN = 'bt'
31    BOLIVIA = 'bo'
32    BONAIRE = 'bq'
33    BOSNIA_AND_HERZEGOVINA = 'bq'
34    BOTSWANA = 'bw'
35    BOUVET_ISLAND = 'bv'
36    BRAZIL = 'br'
37    BRITISH_INDIAN_OCEAN_TERRITORY = 'io'
38    BRITISH_VIRGIN_ISLANDS = 'vg'
39    BRUNEI_DARUSSALAM = 'bn'
40    BULGARIA = 'bg'
41    BURKINA_FASO = 'bf'
42    BURUNDI = 'bi'
43    CAMBODIA = 'kh'
44    CAMEROON = 'cm'
45    CANADA = 'ca'
46    CAPE_VERDE = 'cv'
47    CAYMAN_ISLANDS = 'ky'
48    CENTRAL_AFRICAN_REPUBLIC = 'cf'
49    CHAD = 'td'
50    CHILE = 'cl'
51    CHINA = 'cn'
52    CHRISTMAS_ISLAND = 'cx'
53    COCOS_KEELING_ISLANDS = 'cc'
54    COLOMBIA = 'co'
55    COMOROS = 'km'
56    COOK_ISLANDS = 'ck'
57    COSTA_RICA = 'cr'
58    COTE_DIVOIRE = 'ci'
59    CROATIA = 'hr'
60    CUBA = 'cu'
61    CURACAO = 'cw'
62    CYPRUS = 'cy'
63    CZECH_REPUBLIC = 'cz'
64    DENMARK = 'dk'
65    DEMOCRATIC_REPUBLIC_OF_THE_CONGO = 'cd'
66    DJIBOUTI = 'dj'
67    DOMINICA = 'dm'
68    DOMINICAN_REPUBLIC = 'do'
69    ECUADOR = 'ec'
70    EGYPT = 'eg'
71    EL_SALVADOR = 'sv'
72    EQUATORIAL_GUINEA = 'gq'
73    ERITREA = 'er'
74    ESTONIA = 'ee'
75    ETHIOPIA = 'et'
76    FALKLAND_ISLANDS_MALVINAS = 'fk'
77    FAROE_ISLANDS = 'fo'
78    FEDERATED_STATES_OF_MICRONESIA = 'fm'
79    FIJI = 'fj'
80    FINLAND = 'fi'
81    FRANCE = 'fr'
82    FRENCH_GUIANA = 'gf'
83    FRENCH_POLYNESIA = 'pf'
84    FRENCH_SOUTHERN_TERRITORIES = 'tf'
85    GABON = 'ga'
86    GAMBIA = 'gm'
87    GEORGIA = 'ge'
88    GERMANY = 'de'
89    GHANA = 'gh'
90    GIBRALTAR = 'gi'
91    GREECE = 'gr'
92    GREENLAND = 'gl'
93    GRENADA = 'gd'
94    GUADELOUPE = 'gp'
95    GUAM = 'gu'
96    GUATEMALA = 'gt'
97    GUERNSEY = 'gg'
98    GUINEA = 'gn'
99    GUINEA_BISSAU = 'gw'
100    GUYANA = 'gy'
101    HAITI = 'ht'
102    HEARD_ISLAND_AND_MCDONALD_ISLANDS = 'hm'
103    HONDURAS = 'hn'
104    HONG_KONG = 'hk'
105    HUNGARY = 'hu'
106    ICELAND = 'is'
107    INDIA = 'in'
108    INDONESIA = 'id'
109    IRAN = 'ir'
110    IRAQ = 'iq'
111    IRELAND = 'ie'
112    ISLE_OF_MAN = 'im'
113    ISRAEL = 'il'
114    ITALY = 'it'
115    JAMAICA = 'jm'
116    JAPAN = 'jp'
117    JERSEY = 'je'
118    JORDAN = 'jo'
119    KAZAKHSTAN = 'kz'
120    KENYA = 'ke'
121    KIRIBATI = 'ki'
122    KUWAIT = 'kw'
123    KYRGYZSTAN = 'kg'
124    LAOS = 'la'
125    LATVIA = 'lv'
126    LEBANON = 'lb'
127    LESOTHO = 'ls'
128    LIBERIA = 'lr'
129    LIBYA = 'ly'
130    LIECHTENSTEIN = 'li'
131    LITHUANIA = 'lt'
132    LUXEMBOURG = 'lu'
133    MACAO = 'mo'
134    MACEDONIA = 'mk'
135    MADAGASCAR = 'mg'
136    MALAWI = 'mw'
137    MALAYSIA = 'my'
138    MALDIVES = 'mv'
139    MALI = 'ml'
140    MALTA = 'mt'
141    MARSHALL_ISLANDS = 'mh'
142    MARTINIQUE = 'mq'
143    MAURITANIA = 'mr'
144    MAURITIUS = 'mu'
145    MAYOTTE = 'yt'
146    MEXICO = 'mx'
147    MOLDOVA = 'md'
148    MONACO = 'mc'
149    MONGOLIA = 'mn'
150    MONTENEGRO = 'me'
151    MONTSERRAT = 'ms'
152    MOROCCO = 'ma'
153    MOZAMBIQUE = 'mz'
154    MYANMAR = 'mm'
155    NAMIBIA = 'na'
156    NAURU = 'nr'
157    NEPAL = 'np'
158    NETHERLANDS = 'nl'
159    NEW_CALEDONIA = 'nc'
160    NEW_ZEALAND = 'nz'
161    NICARAGUA = 'ni'
162    NIGER = 'ne'
163    NIGERIA = 'ng'
164    NIUE = 'nu'
165    NORFOLK_ISLAND = 'nf'
166    NORTH_KOREA = 'kp'
167    NORTHERN_MARIANA_ISLANDS = 'mp'
168    NORWAY = 'no'
169    OMAN = 'om'
170    PAKISTAN = 'pk'
171    PALAU = 'pw'
172    PALESTINE = 'ps'
173    PANAMA = 'pa'
174    PAPUA_NEW_GUINEA = 'pg'
175    PARAGUAY = 'py'
176    PERU = 'pe'
177    PHILIPPINES = 'ph'
178    PITCAIRN_ISLANDS = 'pn'
179    POLAND = 'pl'
180    PORTUGAL = 'pt'
181    PUERTO_RICO = 'pr'
182    QATAR = 'qa'
183    REPUBLIC_OF_CONGO = 'cg'
184    REUNION = 're'
185    ROMANIA = 'ro'
186    RUSSIA = 'ru'
187    RWANDA = 'rw'
188    SAINT_BARTHELEMY = 'bl'
189    SAINT_HELENA_ASCENSION_AND_TRISTAN_DA_CUNHA = 'sh'
190    SAINT_KITTS_AND_NEVIS = 'kn'
191    SAINT_LUCIA = 'lc'
192    SAINT_MARTIN = 'mf'
193    SAINT_PIERRE_AND_MIQUELON = 'pm'
194    SAINT_VINCENT_AND_THE_GRENADINES = 'vc'
195    SAMOA = 'ws'
196    SAN_MARINO = 'sm'
197    SAO_TOME_AND_PRINCIPE = 'st'
198    SAUDI_ARABIA = 'sa'
199    SENEGAL = 'sn'
200    SERBIA = 'rs'
201    SEYCHELLES = 'sc'
202    SIERRA_LEONE = 'sl'
203    SINGAPORE = 'sg'
204    SINT_MAARTEN = 'sx'
205    SLOVAKIA = 'sk'
206    SLOVENIA = 'si'
207    SOLOMON_ISLANDS = 'sb'
208    SOMALIA = 'so'
209    SOUTH_AFRICA = 'za'
210    SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS = 'gs'
211    SOUTH_KOREA = 'kr'
212    SOUTH_SUDAN = 'ss'
213    SPAIN = 'es'
214    SRI_LANKA = 'lk'
215    SUDAN = 'sd'
216    SURINAME = 'sr'
217    SVALBARD_AND_JAN_MAYEN = 'sj'
218    SWAZILAND = 'sz'
219    SWEDEN = 'se'
220    SWITZERLAND = 'ch'
221    SYRIA = 'sy'
222    TAIWAN = 'tw'
223    TAJIKISTAN = 'tj'
224    TANZANIA = 'tz'
225    THAILAND = 'th'
226    TIMOR_LESTE = 'tl'
227    TOGO = 'tg'
228    TOKELAU = 'tk'
229    TONGA = 'to'
230    TRINIDAD_AND_TOBAGO = 'tt'
231    TUNISIA = 'tn'
232    TURKEY = 'tr'
233    TURKMENISTAN = 'tm'
234    TURKS_AND_CAICOS_ISLANDS = 'tc'
235    TUVALU = 'tv'
236    UGANDA = 'ug'
237    UKRAINE = 'ua'
238    UNITED_ARAB_EMIRATES = 'ae'
239    UNITED_KINGDOM = 'gb'
240    UNITED_STATES = 'us'
241    UNITED_STATES_MINOR_OUTLYING_ISLANDS = 'um'
242    URUGUAY = 'uy'
243    US_VIRGIN_ISLANDS = 'vi'
244    UZBEKISTAN = 'uz'
245    VANUATU = 'vu'
246    VATICAN = 'va'
247    VENEZUELA = 've'
248    VIETNAM = 'vn'
249    WALLIS_AND_FUTUNA = 'wf'
250    WESTERN_SAHARA = 'eh'
251    YEMEN = 'ye'
252    ZAMBIA = 'zm'
253    ZIMBABWE = 'zw'
254
255    FORMER_SOVIET_UNION_COUNTRIES = set([RUSSIA, UKRAINE, BELARUS, KAZAKHSTAN, AZERBAIJAN, KYRGYZSTAN, GEORGIA, UZBEKISTAN, ARMENIA, TAJIKISTAN, MOLDOVA, TURKMENISTAN, LATVIA, LITHUANIA, ESTONIA])
256    CJK_COUNTRIES = set([CHINA, JAPAN, SOUTH_KOREA, TAIWAN, HONG_KONG, MACAO])
257
258    all_country_iso_codes = set([c.alpha2.lower() for c in pycountry.countries])
259
260    @classmethod
261    def is_valid_country_code(cls, alpha2_code):
262        return alpha2_code and alpha2_code.lower() in cls.all_country_iso_codes
263