summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2024-01-07 07:15:40 +0000
committerGitHub <noreply@github.com>2024-01-07 08:15:40 +0100
commitcc56c22a24ef717cc3111e92ca146136fa518d55 (patch)
treeaca8f9142cbb55c63895c420e7a6bf387811e47f /django
parent53fc6ac64976a7693d2272050a03b71e56b16578 (diff)
Fixed #35091 -- Allowed GeoIP2 querying using IPv4Address/IPv6Address.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/gis/geoip2.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/contrib/gis/geoip2.py b/django/contrib/gis/geoip2.py
index 5f49954209..d0f3bb9fb3 100644
--- a/django/contrib/gis/geoip2.py
+++ b/django/contrib/gis/geoip2.py
@@ -12,6 +12,7 @@ Grab GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz, and unzip them in the
directory corresponding to settings.GEOIP_PATH.
"""
+import ipaddress
import socket
import warnings
@@ -172,10 +173,10 @@ class GeoIP2:
def _check_query(self, query, city=False, city_or_country=False):
"Check the query and database availability."
- # Making sure a string was passed in for the query.
- if not isinstance(query, str):
+ if not isinstance(query, (str, ipaddress.IPv4Address, ipaddress.IPv6Address)):
raise TypeError(
- "GeoIP query must be a string, not type %s" % type(query).__name__
+ "GeoIP query must be a string or instance of IPv4Address or "
+ "IPv6Address, not type %s" % type(query).__name__,
)
# Extra checks for the existence of country and city databases.