Refs #25184 -- Started deprecation for contrib.gis.geoip.
This commit is contained in:
parent
7f0953ce1f
commit
1e2362ca0f
|
@ -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
|
||||
|
|
|
@ -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()``
|
||||
|
|
|
@ -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
|
||||
</ref/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`__. [#]_
|
||||
|
||||
|
|
|
@ -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
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue