mirror of
https://github.com/django/django.git
synced 2025-03-12 18:30:48 +00:00
Simplified GeoIP2._query() when passing IPv4Address()/IPv6Address() instances.
There is no need to call validate_ipv46_address() for ipaddress.IPv4Address()/ipaddress.IPv6Address() instances since this relies on trying to create these kind objects from strings, so they will always be valid.
This commit is contained in:
parent
b3c5830769
commit
0cabed9efa
@ -153,11 +153,12 @@ class GeoIP2:
|
|||||||
if require_city and not self.is_city:
|
if require_city and not self.is_city:
|
||||||
raise GeoIP2Exception(f"Invalid GeoIP city data file: {self._path}")
|
raise GeoIP2Exception(f"Invalid GeoIP city data file: {self._path}")
|
||||||
|
|
||||||
try:
|
if isinstance(query, str):
|
||||||
validate_ipv46_address(query)
|
try:
|
||||||
except ValidationError:
|
validate_ipv46_address(query)
|
||||||
# GeoIP2 only takes IP addresses, so try to resolve a hostname.
|
except ValidationError:
|
||||||
query = socket.gethostbyname(query)
|
# GeoIP2 only takes IP addresses, so try to resolve a hostname.
|
||||||
|
query = socket.gethostbyname(query)
|
||||||
|
|
||||||
function = self._reader.city if self.is_city else self._reader.country
|
function = self._reader.city if self.is_city else self._reader.country
|
||||||
return function(query)
|
return function(query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user