[MERGE] forward port branch 9.0 up to 1dae7ea1d6

This commit is contained in:
Christophe Simonis
2018-05-14 11:29:57 +02:00
+6 -2
View File
@@ -47,10 +47,14 @@ class GeoIPResolver(object):
r = self._db.city(ip)
except (ValueError, geoip2.errors.AddressNotFoundError):
return {}
# Compatibility with Legacy database.
# Some ips cannot be located to a specific country. Legacy DB used to locate them in
# continent instead of country. Do the same to not change behavior of existing code.
country = r.country if r.country.geoname_id else r.continent
return {
'city': r.city.name,
'country_code': r.country.iso_code,
'country_name': r.country.name,
'country_code': country.iso_code,
'country_name': country.name,
'region': r.subdivisions[0].iso_code if r.subdivisions else None,
'time_zone': r.location.time_zone,
}