Skip to content

Commit 769d753

Browse files
committed
refactored isEU logic
1 parent 1710996 commit 769d753

File tree

6 files changed

+37
-261
lines changed

6 files changed

+37
-261
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Request behavior can be modified by setting the `request_options` keyword argume
232232

233233
### Internationalization
234234

235-
When looking up an IP address, the response object includes a `details.country_name` and `details.isEU` attributes which includes the country name and true if the country is a member of EU, based on American English. It is possible to return the country name in other languages by setting the `countries_file` keyword argument when creating the `IPinfo` object.
235+
When looking up an IP address, the response object includes a `details.country_name` and `details.isEU` attributes which includes the country based on American English. It is possible to return the country name in other languages by setting the `countries_file` and remove or add EU countries by setting `eu_countries_file` keyword argument when creating the `IPinfo` object.
236236

237237
The file must be a `.json` file with the following structure:
238238

ipinfo/countries.json

Lines changed: 1 addition & 252 deletions
Original file line numberDiff line numberDiff line change
@@ -1,252 +1 @@
1-
{
2-
"BD": {"name":"Bangladesh", "isEU":false},
3-
"BE": {"name":"Belgium", "isEU":true},
4-
"BF": {"name":"Burkina Faso", "isEU":false},
5-
"BG": {"name":"Bulgaria", "isEU":true},
6-
"BA": {"name":"Bosnia and Herzegovina", "isEU":false},
7-
"BB": {"name":"Barbados", "isEU":false},
8-
"WF": {"name":"Wallis and Futuna", "isEU":false},
9-
"BL": {"name":"Saint Barthelemy", "isEU":false},
10-
"BM": {"name":"Bermuda", "isEU":false},
11-
"BN": {"name":"Brunei", "isEU":false},
12-
"BO": {"name":"Bolivia", "isEU":false},
13-
"BH": {"name":"Bahrain", "isEU":false},
14-
"BI": {"name":"Burundi", "isEU":false},
15-
"BJ": {"name":"Benin", "isEU":false},
16-
"BT": {"name":"Bhutan", "isEU":false},
17-
"JM": {"name":"Jamaica", "isEU":false},
18-
"BV": {"name":"Bouvet Island", "isEU":false},
19-
"BW": {"name":"Botswana", "isEU":false},
20-
"WS": {"name":"Samoa", "isEU":false},
21-
"BQ": {"name":"Bonaire, Saint Eustatius and Saba ", "isEU":false},
22-
"BR": {"name":"Brazil", "isEU":false},
23-
"BS": {"name":"Bahamas", "isEU":false},
24-
"JE": {"name":"Jersey", "isEU":false},
25-
"BY": {"name":"Belarus", "isEU":false},
26-
"BZ": {"name":"Belize", "isEU":false},
27-
"RU": {"name":"Russia", "isEU":false},
28-
"RW": {"name":"Rwanda", "isEU":false},
29-
"RS": {"name":"Serbia", "isEU":false},
30-
"TL": {"name":"East Timor", "isEU":false},
31-
"RE": {"name":"Reunion", "isEU":false},
32-
"TM": {"name":"Turkmenistan", "isEU":false},
33-
"TJ": {"name":"Tajikistan", "isEU":false},
34-
"RO": {"name":"Romania", "isEU":true},
35-
"TK": {"name":"Tokelau", "isEU":false},
36-
"GW": {"name":"Guinea-Bissau", "isEU":false},
37-
"GU": {"name":"Guam", "isEU":false},
38-
"GT": {"name":"Guatemala", "isEU":false},
39-
"GS": {"name":"South Georgia and the South Sandwich Islands", "isEU":false},
40-
"GR": {"name":"Greece", "isEU":true},
41-
"GQ": {"name":"Equatorial Guinea", "isEU":false},
42-
"GP": {"name":"Guadeloupe", "isEU":false},
43-
"JP": {"name":"Japan", "isEU":false},
44-
"GY": {"name":"Guyana", "isEU":false},
45-
"GG": {"name":"Guernsey", "isEU":false},
46-
"GF": {"name":"French Guiana", "isEU":false},
47-
"GE": {"name":"Georgia", "isEU":false},
48-
"GD": {"name":"Grenada", "isEU":false},
49-
"GB": {"name":"United Kingdom", "isEU":false},
50-
"GA": {"name":"Gabon", "isEU":false},
51-
"SV": {"name":"El Salvador", "isEU":false},
52-
"GN": {"name":"Guinea", "isEU":false},
53-
"GM": {"name":"Gambia", "isEU":false},
54-
"GL": {"name":"Greenland", "isEU":false},
55-
"GI": {"name":"Gibraltar", "isEU":false},
56-
"GH": {"name":"Ghana", "isEU":false},
57-
"OM": {"name":"Oman", "isEU":false},
58-
"TN": {"name":"Tunisia", "isEU":false},
59-
"JO": {"name":"Jordan", "isEU":false},
60-
"HR": {"name":"Croatia", "isEU":true},
61-
"HT": {"name":"Haiti", "isEU":false},
62-
"HU": {"name":"Hungary", "isEU":true},
63-
"HK": {"name":"Hong Kong", "isEU":false},
64-
"HN": {"name":"Honduras", "isEU":false},
65-
"HM": {"name":"Heard Island and McDonald Islands", "isEU":false},
66-
"VE": {"name":"Venezuela", "isEU":false},
67-
"PR": {"name":"Puerto Rico", "isEU":false},
68-
"PS": {"name":"Palestinian Territory", "isEU":false},
69-
"PW": {"name":"Palau", "isEU":false},
70-
"PT": {"name":"Portugal", "isEU":true},
71-
"SJ": {"name":"Svalbard and Jan Mayen", "isEU":false},
72-
"PY": {"name":"Paraguay", "isEU":false},
73-
"IQ": {"name":"Iraq", "isEU":false},
74-
"PA": {"name":"Panama", "isEU":false},
75-
"PF": {"name":"French Polynesia", "isEU":false},
76-
"PG": {"name":"Papua New Guinea", "isEU":false},
77-
"PE": {"name":"Peru", "isEU":false},
78-
"PK": {"name":"Pakistan", "isEU":false},
79-
"PH": {"name":"Philippines", "isEU":false},
80-
"PN": {"name":"Pitcairn", "isEU":false},
81-
"PL": {"name":"Poland", "isEU":true},
82-
"PM": {"name":"Saint Pierre and Miquelon", "isEU":false},
83-
"ZM": {"name":"Zambia", "isEU":false},
84-
"EH": {"name":"Western Sahara", "isEU":false},
85-
"EE": {"name":"Estonia", "isEU":true},
86-
"EG": {"name":"Egypt", "isEU":false},
87-
"ZA": {"name":"South Africa", "isEU":false},
88-
"EC": {"name":"Ecuador", "isEU":false},
89-
"IT": {"name":"Italy", "isEU":true},
90-
"VN": {"name":"Vietnam", "isEU":false},
91-
"SB": {"name":"Solomon Islands", "isEU":false},
92-
"ET": {"name":"Ethiopia", "isEU":false},
93-
"SO": {"name":"Somalia", "isEU":false},
94-
"ZW": {"name":"Zimbabwe", "isEU":false},
95-
"SA": {"name":"Saudi Arabia", "isEU":false},
96-
"ES": {"name":"Spain", "isEU":true},
97-
"ER": {"name":"Eritrea", "isEU":false},
98-
"ME": {"name":"Montenegro", "isEU":false},
99-
"MD": {"name":"Moldova", "isEU":false},
100-
"MG": {"name":"Madagascar", "isEU":false},
101-
"MF": {"name":"Saint Martin", "isEU":false},
102-
"MA": {"name":"Morocco", "isEU":false},
103-
"MC": {"name":"Monaco", "isEU":false},
104-
"UZ": {"name":"Uzbekistan", "isEU":false},
105-
"MM": {"name":"Myanmar", "isEU":false},
106-
"ML": {"name":"Mali", "isEU":false},
107-
"MO": {"name":"Macao", "isEU":false},
108-
"MN": {"name":"Mongolia", "isEU":false},
109-
"MH": {"name":"Marshall Islands", "isEU":false},
110-
"MK": {"name":"Macedonia", "isEU":false},
111-
"MU": {"name":"Mauritius", "isEU":false},
112-
"MT": {"name":"Malta", "isEU":true},
113-
"MW": {"name":"Malawi", "isEU":false},
114-
"MV": {"name":"Maldives", "isEU":false},
115-
"MQ": {"name":"Martinique", "isEU":false},
116-
"MP": {"name":"Northern Mariana Islands", "isEU":false},
117-
"MS": {"name":"Montserrat", "isEU":false},
118-
"MR": {"name":"Mauritania", "isEU":false},
119-
"IM": {"name":"Isle of Man", "isEU":false},
120-
"UG": {"name":"Uganda", "isEU":false},
121-
"TZ": {"name":"Tanzania", "isEU":false},
122-
"MY": {"name":"Malaysia", "isEU":false},
123-
"MX": {"name":"Mexico", "isEU":false},
124-
"IL": {"name":"Israel", "isEU":false},
125-
"FR": {"name":"France", "isEU":true},
126-
"IO": {"name":"British Indian Ocean Territory", "isEU":false},
127-
"SH": {"name":"Saint Helena", "isEU":false},
128-
"FI": {"name":"Finland", "isEU":true},
129-
"FJ": {"name":"Fiji", "isEU":false},
130-
"FK": {"name":"Falkland Islands", "isEU":false},
131-
"FM": {"name":"Micronesia", "isEU":false},
132-
"FO": {"name":"Faroe Islands", "isEU":false},
133-
"NI": {"name":"Nicaragua", "isEU":false},
134-
"NL": {"name":"Netherlands", "isEU":true},
135-
"NO": {"name":"Norway", "isEU":false},
136-
"NA": {"name":"Namibia", "isEU":false},
137-
"VU": {"name":"Vanuatu", "isEU":false},
138-
"NC": {"name":"New Caledonia", "isEU":false},
139-
"NE": {"name":"Niger", "isEU":false},
140-
"NF": {"name":"Norfolk Island", "isEU":false},
141-
"NG": {"name":"Nigeria", "isEU":false},
142-
"NZ": {"name":"New Zealand", "isEU":false},
143-
"NP": {"name":"Nepal", "isEU":false},
144-
"NR": {"name":"Nauru", "isEU":false},
145-
"NU": {"name":"Niue", "isEU":false},
146-
"CK": {"name":"Cook Islands", "isEU":false},
147-
"XK": {"name":"Kosovo", "isEU":false},
148-
"CI": {"name":"Ivory Coast", "isEU":false},
149-
"CH": {"name":"Switzerland", "isEU":false},
150-
"CO": {"name":"Colombia", "isEU":false},
151-
"CN": {"name":"China", "isEU":false},
152-
"CM": {"name":"Cameroon", "isEU":false},
153-
"CL": {"name":"Chile", "isEU":false},
154-
"CC": {"name":"Cocos Islands", "isEU":false},
155-
"CA": {"name":"Canada", "isEU":false},
156-
"CG": {"name":"Republic of the Congo", "isEU":false},
157-
"CF": {"name":"Central African Republic", "isEU":false},
158-
"CD": {"name":"Democratic Republic of the Congo", "isEU":false},
159-
"CZ": {"name":"Czech Republic", "isEU":true},
160-
"CY": {"name":"Cyprus", "isEU":true},
161-
"CX": {"name":"Christmas Island", "isEU":false},
162-
"CR": {"name":"Costa Rica", "isEU":false},
163-
"CW": {"name":"Curacao", "isEU":false},
164-
"CV": {"name":"Cape Verde", "isEU":false},
165-
"CU": {"name":"Cuba", "isEU":false},
166-
"SZ": {"name":"Swaziland", "isEU":false},
167-
"SY": {"name":"Syria", "isEU":false},
168-
"SX": {"name":"Sint Maarten", "isEU":false},
169-
"KG": {"name":"Kyrgyzstan", "isEU":false},
170-
"KE": {"name":"Kenya", "isEU":false},
171-
"SS": {"name":"South Sudan", "isEU":false},
172-
"SR": {"name":"Suriname", "isEU":false},
173-
"KI": {"name":"Kiribati", "isEU":false},
174-
"KH": {"name":"Cambodia", "isEU":false},
175-
"KN": {"name":"Saint Kitts and Nevis", "isEU":false},
176-
"KM": {"name":"Comoros", "isEU":false},
177-
"ST": {"name":"Sao Tome and Principe", "isEU":false},
178-
"SK": {"name":"Slovakia", "isEU":true},
179-
"KR": {"name":"South Korea", "isEU":false},
180-
"SI": {"name":"Slovenia", "isEU":true},
181-
"KP": {"name":"North Korea", "isEU":false},
182-
"KW": {"name":"Kuwait", "isEU":false},
183-
"SN": {"name":"Senegal", "isEU":false},
184-
"SM": {"name":"San Marino", "isEU":false},
185-
"SL": {"name":"Sierra Leone", "isEU":false},
186-
"SC": {"name":"Seychelles", "isEU":false},
187-
"KZ": {"name":"Kazakhstan", "isEU":false},
188-
"KY": {"name":"Cayman Islands", "isEU":false},
189-
"SG": {"name":"Singapore", "isEU":false},
190-
"SE": {"name":"Sweden", "isEU":true},
191-
"SD": {"name":"Sudan", "isEU":false},
192-
"DO": {"name":"Dominican Republic", "isEU":false},
193-
"DM": {"name":"Dominica", "isEU":false},
194-
"DJ": {"name":"Djibouti", "isEU":false},
195-
"DK": {"name":"Denmark", "isEU":true},
196-
"VG": {"name":"British Virgin Islands", "isEU":false},
197-
"DE": {"name":"Germany", "isEU":true},
198-
"YE": {"name":"Yemen", "isEU":false},
199-
"DZ": {"name":"Algeria", "isEU":false},
200-
"US": {"name":"United States", "isEU":false},
201-
"UY": {"name":"Uruguay", "isEU":false},
202-
"YT": {"name":"Mayotte", "isEU":false},
203-
"UM": {"name":"United States Minor Outlying Islands", "isEU":false},
204-
"LB": {"name":"Lebanon", "isEU":false},
205-
"LC": {"name":"Saint Lucia", "isEU":false},
206-
"LA": {"name":"Laos", "isEU":false},
207-
"TV": {"name":"Tuvalu", "isEU":false},
208-
"TW": {"name":"Taiwan", "isEU":false},
209-
"TT": {"name":"Trinidad and Tobago", "isEU":false},
210-
"TR": {"name":"Turkey", "isEU":false},
211-
"LK": {"name":"Sri Lanka", "isEU":false},
212-
"LI": {"name":"Liechtenstein", "isEU":false},
213-
"LV": {"name":"Latvia", "isEU":true},
214-
"TO": {"name":"Tonga", "isEU":false},
215-
"LT": {"name":"Lithuania", "isEU":true},
216-
"LU": {"name":"Luxembourg", "isEU":true},
217-
"LR": {"name":"Liberia", "isEU":false},
218-
"LS": {"name":"Lesotho", "isEU":false},
219-
"TH": {"name":"Thailand", "isEU":false},
220-
"TF": {"name":"French Southern Territories", "isEU":false},
221-
"TG": {"name":"Togo", "isEU":false},
222-
"TD": {"name":"Chad", "isEU":false},
223-
"TC": {"name":"Turks and Caicos Islands", "isEU":false},
224-
"LY": {"name":"Libya", "isEU":false},
225-
"VA": {"name":"Vatican", "isEU":false},
226-
"VC": {"name":"Saint Vincent and the Grenadines", "isEU":false},
227-
"AE": {"name":"United Arab Emirates", "isEU":false},
228-
"AD": {"name":"Andorra", "isEU":false},
229-
"AG": {"name":"Antigua and Barbuda", "isEU":false},
230-
"AF": {"name":"Afghanistan", "isEU":false},
231-
"AI": {"name":"Anguilla", "isEU":false},
232-
"VI": {"name":"U.S. Virgin Islands", "isEU":false},
233-
"IS": {"name":"Iceland", "isEU":false},
234-
"IR": {"name":"Iran", "isEU":false},
235-
"AM": {"name":"Armenia", "isEU":false},
236-
"AL": {"name":"Albania", "isEU":false},
237-
"AO": {"name":"Angola", "isEU":false},
238-
"AQ": {"name":"Antarctica", "isEU":false},
239-
"AS": {"name":"American Samoa", "isEU":false},
240-
"AR": {"name":"Argentina", "isEU":false},
241-
"AU": {"name":"Australia", "isEU":false},
242-
"AT": {"name":"Austria", "isEU":true},
243-
"AW": {"name":"Aruba", "isEU":false},
244-
"IN": {"name":"India", "isEU":false},
245-
"AX": {"name":"Aland Islands", "isEU":false},
246-
"AZ": {"name":"Azerbaijan", "isEU":false},
247-
"IE": {"name":"Ireland", "isEU":true},
248-
"ID": {"name":"Indonesia", "isEU":false},
249-
"UA": {"name":"Ukraine", "isEU":false},
250-
"QA": {"name":"Qatar", "isEU":false},
251-
"MZ": {"name":"Mozambique","isEU":false}
252-
}
1+
{"BD": "Bangladesh", "BE": "Belgium", "BF": "Burkina Faso", "BG": "Bulgaria", "BA": "Bosnia and Herzegovina", "BB": "Barbados", "WF": "Wallis and Futuna", "BL": "Saint Barthelemy", "BM": "Bermuda", "BN": "Brunei", "BO": "Bolivia", "BH": "Bahrain", "BI": "Burundi", "BJ": "Benin", "BT": "Bhutan", "JM": "Jamaica", "BV": "Bouvet Island", "BW": "Botswana", "WS": "Samoa", "BQ": "Bonaire, Saint Eustatius and Saba ", "BR": "Brazil", "BS": "Bahamas", "JE": "Jersey", "BY": "Belarus", "BZ": "Belize", "RU": "Russia", "RW": "Rwanda", "RS": "Serbia", "TL": "East Timor", "RE": "Reunion", "TM": "Turkmenistan", "TJ": "Tajikistan", "RO": "Romania", "TK": "Tokelau", "GW": "Guinea-Bissau", "GU": "Guam", "GT": "Guatemala", "GS": "South Georgia and the South Sandwich Islands", "GR": "Greece", "GQ": "Equatorial Guinea", "GP": "Guadeloupe", "JP": "Japan", "GY": "Guyana", "GG": "Guernsey", "GF": "French Guiana", "GE": "Georgia", "GD": "Grenada", "GB": "United Kingdom", "GA": "Gabon", "SV": "El Salvador", "GN": "Guinea", "GM": "Gambia", "GL": "Greenland", "GI": "Gibraltar", "GH": "Ghana", "OM": "Oman", "TN": "Tunisia", "JO": "Jordan", "HR": "Croatia", "HT": "Haiti", "HU": "Hungary", "HK": "Hong Kong", "HN": "Honduras", "HM": "Heard Island and McDonald Islands", "VE": "Venezuela", "PR": "Puerto Rico", "PS": "Palestinian Territory", "PW": "Palau", "PT": "Portugal", "SJ": "Svalbard and Jan Mayen", "PY": "Paraguay", "IQ": "Iraq", "PA": "Panama", "PF": "French Polynesia", "PG": "Papua New Guinea", "PE": "Peru", "PK": "Pakistan", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PM": "Saint Pierre and Miquelon", "ZM": "Zambia", "EH": "Western Sahara", "EE": "Estonia", "EG": "Egypt", "ZA": "South Africa", "EC": "Ecuador", "IT": "Italy", "VN": "Vietnam", "SB": "Solomon Islands", "ET": "Ethiopia", "SO": "Somalia", "ZW": "Zimbabwe", "SA": "Saudi Arabia", "ES": "Spain", "ER": "Eritrea", "ME": "Montenegro", "MD": "Moldova", "MG": "Madagascar", "MF": "Saint Martin", "MA": "Morocco", "MC": "Monaco", "UZ": "Uzbekistan", "MM": "Myanmar", "ML": "Mali", "MO": "Macao", "MN": "Mongolia", "MH": "Marshall Islands", "MK": "Macedonia", "MU": "Mauritius", "MT": "Malta", "MW": "Malawi", "MV": "Maldives", "MQ": "Martinique", "MP": "Northern Mariana Islands", "MS": "Montserrat", "MR": "Mauritania", "IM": "Isle of Man", "UG": "Uganda", "TZ": "Tanzania", "MY": "Malaysia", "MX": "Mexico", "IL": "Israel", "FR": "France", "IO": "British Indian Ocean Territory", "SH": "Saint Helena", "FI": "Finland", "FJ": "Fiji", "FK": "Falkland Islands", "FM": "Micronesia", "FO": "Faroe Islands", "NI": "Nicaragua", "NL": "Netherlands", "NO": "Norway", "NA": "Namibia", "VU": "Vanuatu", "NC": "New Caledonia", "NE": "Niger", "NF": "Norfolk Island", "NG": "Nigeria", "NZ": "New Zealand", "NP": "Nepal", "NR": "Nauru", "NU": "Niue", "CK": "Cook Islands", "XK": "Kosovo", "CI": "Ivory Coast", "CH": "Switzerland", "CO": "Colombia", "CN": "China", "CM": "Cameroon", "CL": "Chile", "CC": "Cocos Islands", "CA": "Canada", "CG": "Republic of the Congo", "CF": "Central African Republic", "CD": "Democratic Republic of the Congo", "CZ": "Czech Republic", "CY": "Cyprus", "CX": "Christmas Island", "CR": "Costa Rica", "CW": "Curacao", "CV": "Cape Verde", "CU": "Cuba", "SZ": "Swaziland", "SY": "Syria", "SX": "Sint Maarten", "KG": "Kyrgyzstan", "KE": "Kenya", "SS": "South Sudan", "SR": "Suriname", "KI": "Kiribati", "KH": "Cambodia", "KN": "Saint Kitts and Nevis", "KM": "Comoros", "ST": "Sao Tome and Principe", "SK": "Slovakia", "KR": "South Korea", "SI": "Slovenia", "KP": "North Korea", "KW": "Kuwait", "SN": "Senegal", "SM": "San Marino", "SL": "Sierra Leone", "SC": "Seychelles", "KZ": "Kazakhstan", "KY": "Cayman Islands", "SG": "Singapore", "SE": "Sweden", "SD": "Sudan", "DO": "Dominican Republic", "DM": "Dominica", "DJ": "Djibouti", "DK": "Denmark", "VG": "British Virgin Islands", "DE": "Germany", "YE": "Yemen", "DZ": "Algeria", "US": "United States", "UY": "Uruguay", "YT": "Mayotte", "UM": "United States Minor Outlying Islands", "LB": "Lebanon", "LC": "Saint Lucia", "LA": "Laos", "TV": "Tuvalu", "TW": "Taiwan", "TT": "Trinidad and Tobago", "TR": "Turkey", "LK": "Sri Lanka", "LI": "Liechtenstein", "LV": "Latvia", "TO": "Tonga", "LT": "Lithuania", "LU": "Luxembourg", "LR": "Liberia", "LS": "Lesotho", "TH": "Thailand", "TF": "French Southern Territories", "TG": "Togo", "TD": "Chad", "TC": "Turks and Caicos Islands", "LY": "Libya", "VA": "Vatican", "VC": "Saint Vincent and the Grenadines", "AE": "United Arab Emirates", "AD": "Andorra", "AG": "Antigua and Barbuda", "AF": "Afghanistan", "AI": "Anguilla", "VI": "U.S. Virgin Islands", "IS": "Iceland", "IR": "Iran", "AM": "Armenia", "AL": "Albania", "AO": "Angola", "AQ": "Antarctica", "AS": "American Samoa", "AR": "Argentina", "AU": "Australia", "AT": "Austria", "AW": "Aruba", "IN": "India", "AX": "Aland Islands", "AZ": "Azerbaijan", "IE": "Ireland", "ID": "Indonesia", "UA": "Ukraine", "QA": "Qatar", "MZ": "Mozambique"}

ipinfo/eu.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["IE","AT","LT","LU","LV","DE","DK","SE","SI","SK","CZ","CY","NL","FI","FR","MT","ES","IT","EE","PL","PT","HU","HR","GR","RO","BG","BE"]

ipinfo/handler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .handler_utils import (
1717
API_URL,
1818
COUNTRY_FILE_DEFAULT,
19+
COUNTRY_EU_FILE_DEFAULT,
1920
BATCH_MAX_SIZE,
2021
CACHE_MAXSIZE,
2122
CACHE_TTL,
@@ -44,6 +45,11 @@ def __init__(self, access_token=None, **kwargs):
4445
kwargs.get("countries_file")
4546
)
4647

48+
# load eu countries file
49+
self.eu_countries = handler_utils.read_eu_country_names(
50+
kwargs.get("eu_countries_file")
51+
)
52+
4753
# setup req opts
4854
self.request_options = kwargs.get("request_options", {})
4955
if "timeout" not in self.request_options:
@@ -99,7 +105,7 @@ def getDetails(self, ip_address=None, timeout=None):
99105
details = response.json()
100106

101107
# format & cache
102-
handler_utils.format_details(details, self.countries)
108+
handler_utils.format_details(details, self.countries,self.eu_countries)
103109
self.cache[cache_key(ip_address)] = details
104110

105111
return Details(details)
@@ -215,7 +221,7 @@ def getBatchDetails(
215221
# format all
216222
for detail in result.values():
217223
if isinstance(detail, dict):
218-
handler_utils.format_details(detail, self.countries)
224+
handler_utils.format_details(detail, self.countries,self.eu_countries)
219225

220226
return result
221227

ipinfo/handler_async.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def __init__(self, access_token=None, **kwargs):
4545
kwargs.get("countries_file")
4646
)
4747

48+
# load eu countries file
49+
self.eu_countries = handler_utils.read_eu_country_names(
50+
kwargs.get("eu_countries_file")
51+
)
52+
4853
# setup req opts
4954
self.request_options = kwargs.get("request_options", {})
5055
if "timeout" not in self.request_options:
@@ -122,7 +127,7 @@ async def getDetails(self, ip_address=None, timeout=None):
122127
details = await resp.json()
123128

124129
# format & cache
125-
handler_utils.format_details(details, self.countries)
130+
handler_utils.format_details(details, self.countries,self.eu_countries)
126131
self.cache[cache_key(ip_address)] = details
127132

128133
return Details(details)
@@ -272,7 +277,7 @@ async def _do_batch_req(
272277
# format & fill up cache
273278
for ip_address, details in json_resp.items():
274279
if isinstance(details, dict):
275-
handler_utils.format_details(details, self.countries)
280+
handler_utils.format_details(details, self.countries,self.eu_countries)
276281
self.cache[cache_key(ip_address)] = details
277282

278283
# merge cached results with new lookup

0 commit comments

Comments
 (0)