diff --git a/django/contrib/gis/geoip/base.py b/django/contrib/gis/geoip/base.py index 39a651f727..a1d476c0a5 100644 --- a/django/contrib/gis/geoip/base.py +++ b/django/contrib/gis/geoip/base.py @@ -1,5 +1,6 @@ import os import re +import warnings from ctypes import c_char_p from django.contrib.gis.geoip.libgeoip import GEOIP_SETTINGS @@ -11,6 +12,7 @@ from django.contrib.gis.geoip.prototypes import ( ) from django.core.validators import ipv4_re from django.utils import six +from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_bytes # Regular expressions for recognizing the GeoIP free database editions. @@ -81,6 +83,13 @@ class GeoIP(object): * city: The name of the GeoIP city data file. Defaults to 'GeoLiteCity.dat'; overrides the GEOIP_CITY settings attribute. """ + + warnings.warn( + "django.contrib.gis.geoip is deprecated in favor of " + "django.contrib.gis.geoip2 and the MaxMind GeoLite2 database " + "format.", RemovedInDjango20Warning, 2 + ) + # Checking the given cache option. if cache in self.cache_options: self._cache = cache diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 4a14acd734..cc1495efee 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -45,6 +45,8 @@ details on these changes. * The ``GeoManager`` and ``GeoQuerySet`` classes will be removed. +* The ``django.contrib.gis.geoip`` module will be removed. + * The ``supports_recursion`` check for template loaders will be removed from: * ``django.template.engine.Engine.find_template()`` diff --git a/docs/ref/contrib/gis/geoip.txt b/docs/ref/contrib/gis/geoip.txt index 0fb7fde99c..efe33ebef3 100644 --- a/docs/ref/contrib/gis/geoip.txt +++ b/docs/ref/contrib/gis/geoip.txt @@ -5,6 +5,12 @@ Geolocation with GeoIP .. module:: django.contrib.gis.geoip :synopsis: High-level Python interface for MaxMind's GeoIP C library. +.. deprecated:: 1.9 + + This module is deprecated in favor of :doc:`django.contrib.gis.geoip2 + `, which supports IPv6 and the GeoLite2 database + format. + The :class:`GeoIP` object is a ctypes wrapper for the `MaxMind GeoIP C API`__. [#]_ diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index 6d482038af..82ff5a08bc 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -1049,6 +1049,13 @@ As of Django 1.8, ``current_app`` is set on the ``request`` object. For consistency, these views will require the caller to set ``current_app`` on the ``request`` instead of passing it in a separate argument. +``django.contrib.gis.geoip`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The :mod:`django.contrib.gis.geoip2` module supersedes +``django.contrib.gis.geoip``. The new module provides a similar API except that +it doesn't provide the legacy GeoIP-Python API compatibility methods. + Miscellaneous ~~~~~~~~~~~~~ diff --git a/tests/gis_tests/test_geoip.py b/tests/gis_tests/test_geoip.py index c77c7cc529..6afd441216 100644 --- a/tests/gis_tests/test_geoip.py +++ b/tests/gis_tests/test_geoip.py @@ -3,12 +3,15 @@ from __future__ import unicode_literals import os import unittest +import warnings from unittest import skipUnless from django.conf import settings from django.contrib.gis.geoip import HAS_GEOIP from django.contrib.gis.geos import HAS_GEOS, GEOSGeometry +from django.test import ignore_warnings from django.utils import six +from django.utils.deprecation import RemovedInDjango20Warning if HAS_GEOIP: from django.contrib.gis.geoip import GeoIP, GeoIPException @@ -22,6 +25,7 @@ if HAS_GEOIP: @skipUnless(HAS_GEOIP and getattr(settings, "GEOIP_PATH", None), "GeoIP is required along with the GEOIP_PATH setting.") +@ignore_warnings(category=RemovedInDjango20Warning) class GeoIPTest(unittest.TestCase): addr = '128.249.1.1' fqdn = 'tmc.edu' @@ -115,3 +119,12 @@ class GeoIPTest(unittest.TestCase): d = g.country('200.26.205.1') # Some databases have only unaccented countries self.assertIn(d['country_name'], ('CuraƧao', 'Curacao')) + + def test_deprecation_warning(self): + with warnings.catch_warnings(record=True) as warns: + warnings.simplefilter('always') + GeoIP() + + self.assertEqual(len(warns), 1) + msg = str(warns[0].message) + self.assertIn('django.contrib.gis.geoip is deprecated', msg)