From 0ee2b8c326d47387bacb713a3ab369fa9a7a22ee Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Thu, 30 Nov 2023 10:33:00 +0000 Subject: [PATCH] Changed django.contrib.gis.geoip2 package to a module. --- .../contrib/gis/{geoip2/base.py => geoip2.py} | 26 +++++++++++++++++-- django/contrib/gis/geoip2/__init__.py | 24 ----------------- 2 files changed, 24 insertions(+), 26 deletions(-) rename django/contrib/gis/{geoip2/base.py => geoip2.py} (92%) delete mode 100644 django/contrib/gis/geoip2/__init__.py diff --git a/django/contrib/gis/geoip2/base.py b/django/contrib/gis/geoip2.py similarity index 92% rename from django/contrib/gis/geoip2/base.py rename to django/contrib/gis/geoip2.py index 0781dd524e0f..898f5d596da8 100644 --- a/django/contrib/gis/geoip2/base.py +++ b/django/contrib/gis/geoip2.py @@ -1,14 +1,36 @@ +""" +This module houses the GeoIP2 object, a wrapper for the MaxMind GeoIP2(R) +Python API (https://geoip2.readthedocs.io/). This is an alternative to the +Python GeoIP2 interface provided by MaxMind. + +GeoIP(R) is a registered trademark of MaxMind, Inc. + +For IP-based geolocation, this module requires the GeoLite2 Country and City +datasets, in binary format (CSV will not work!). The datasets may be +downloaded from MaxMind at https://dev.maxmind.com/geoip/geoip2/geolite2/. +Grab GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz, and unzip them in the +directory corresponding to settings.GEOIP_PATH. +""" + import socket import warnings -import geoip2.database - from django.conf import settings from django.core.exceptions import ValidationError from django.core.validators import validate_ipv46_address from django.utils._os import to_path from django.utils.deprecation import RemovedInDjango60Warning +__all__ = ["HAS_GEOIP2"] + +try: + import geoip2.database +except ImportError: + HAS_GEOIP2 = False +else: + HAS_GEOIP2 = True + __all__ += ["GeoIP2", "GeoIP2Exception"] + # Creating the settings dictionary with any settings, if needed. GEOIP_SETTINGS = { "GEOIP_PATH": getattr(settings, "GEOIP_PATH", None), diff --git a/django/contrib/gis/geoip2/__init__.py b/django/contrib/gis/geoip2/__init__.py deleted file mode 100644 index 71b71f68dbaf..000000000000 --- a/django/contrib/gis/geoip2/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -""" -This module houses the GeoIP2 object, a wrapper for the MaxMind GeoIP2(R) -Python API (https://geoip2.readthedocs.io/). This is an alternative to the -Python GeoIP2 interface provided by MaxMind. - -GeoIP(R) is a registered trademark of MaxMind, Inc. - -For IP-based geolocation, this module requires the GeoLite2 Country and City -datasets, in binary format (CSV will not work!). The datasets may be -downloaded from MaxMind at https://dev.maxmind.com/geoip/geoip2/geolite2/. -Grab GeoLite2-Country.mmdb.gz and GeoLite2-City.mmdb.gz, and unzip them in the -directory corresponding to settings.GEOIP_PATH. -""" -__all__ = ["HAS_GEOIP2"] - -try: - import geoip2 # NOQA -except ImportError: - HAS_GEOIP2 = False -else: - from .base import GeoIP2, GeoIP2Exception - - HAS_GEOIP2 = True - __all__ += ["GeoIP2", "GeoIP2Exception"]