diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2023-11-30 10:33:00 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-12-05 14:01:59 +0100 |
| commit | 0ee2b8c326d47387bacb713a3ab369fa9a7a22ee (patch) | |
| tree | e007f273cf8eac3be7efa1acf4bdac086b1dc9ed | |
| parent | 60c7cb90f88c0819276da6407134ac311503fcad (diff) | |
Changed django.contrib.gis.geoip2 package to a module.
| -rw-r--r-- | django/contrib/gis/geoip2.py (renamed from django/contrib/gis/geoip2/base.py) | 26 | ||||
| -rw-r--r-- | django/contrib/gis/geoip2/__init__.py | 24 |
2 files changed, 24 insertions, 26 deletions
diff --git a/django/contrib/gis/geoip2/base.py b/django/contrib/gis/geoip2.py index 0781dd524e..898f5d596d 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 71b71f68db..0000000000 --- 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"] |
