Skip to content

Commit bf50f5c

Browse files
committed
Drop Python 2 support
1 parent ba92347 commit bf50f5c

File tree

9 files changed

+22
-56
lines changed

9 files changed

+22
-56
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
language: python
33
matrix:
44
include:
5-
- python: 2.7
6-
- python: 3.5
75
- python: 3.6
86
- python: 3.7
97
- python: 3.8
108
env:
119
- RUN_SNYK=1
1210
- RUN_LINTER=1
1311
- python: nightly
14-
- python: pypy
1512
allow_failures:
1613
- python: nightly
1714

HISTORY.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
History
44
-------
55

6+
4.0.0
7+
++++++++++++++++++
8+
9+
* IMPORTANT: Python 2.7 and 3.5 support has been dropped. Python 3.6 or greater
10+
is required.
11+
612
3.0.0 (2019-12-20)
713
++++++++++++++++++
814

README.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,11 @@ Database Reader Exceptions
331331
--------------------------
332332

333333
If the database file does not exist or is not readable, the constructor will
334-
raise a ``FileNotFoundError`` on Python 3 or an ``IOError`` on Python 2.
335-
If the IP address passed to a method is invalid, a ``ValueError`` will be
336-
raised. If the file is invalid or there is a bug in the reader, a
337-
``maxminddb.InvalidDatabaseError`` will be raised with a description of the
338-
problem. If an IP address is not in the database, a ``AddressNotFoundError``
339-
will be raised.
334+
raise a ``FileNotFoundError``. If the IP address passed to a method is
335+
invalid, a ``ValueError`` will be raised. If the file is invalid or there is a
336+
bug in the reader, a ``maxminddb.InvalidDatabaseError`` will be raised with a
337+
description of the problem. If an IP address is not in the database, a
338+
``AddressNotFoundError`` will be raised.
340339

341340
Values to use for Database or Dictionary Keys
342341
---------------------------------------------
@@ -402,8 +401,7 @@ correction, please `contact MaxMind support
402401
Requirements
403402
------------
404403

405-
This code requires Python 2.7+ or 3.5+. Older versions are not supported.
406-
This library has been tested with CPython and PyPy.
404+
Python 3.6 or greater is required. Older versions are not supported.
407405

408406
The Requests HTTP library is also required. See
409407
<http://python-requests.org> for details.

geoip2/compat.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

geoip2/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def _get(self, database_type, ip_address):
197197
raise geoip2.errors.AddressNotFoundError(
198198
"The address %s is not in the database." % ip_address
199199
)
200-
return (record, prefix_len)
200+
return record, prefix_len
201201

202202
def _model_for(self, model_class, types, ip_address):
203203
(record, prefix_len) = self._get(types, ip_address)

geoip2/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from abc import ABCMeta
1616

1717
import geoip2.records
18-
from geoip2.compat import compat_ip_network
1918
from geoip2.mixins import SimpleEquality
2019

2120

@@ -331,7 +330,7 @@ def network(self):
331330
prefix_len = self._prefix_len
332331
if ip_address is None or prefix_len is None:
333332
return None
334-
network = compat_ip_network("{}/{}".format(ip_address, prefix_len), False)
333+
network = ipaddress.ip_network("{}/{}".format(ip_address, prefix_len), False)
335334
self._network = network
336335
return network
337336

geoip2/records.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# pylint:disable=R0903
1212
from abc import ABCMeta
1313

14-
from geoip2.compat import compat_ip_network
1514
from geoip2.mixins import SimpleEquality
1615

1716

@@ -799,6 +798,6 @@ def network(self):
799798
if ip_address is None or prefix_len is None:
800799
return None
801800
network = "{}/{}".format(ip_address, prefix_len)
802-
network = compat_ip_network(network, False)
801+
network = ipaddress.ip_network(network, False)
803802
self._network = network
804803
return network

geoip2/webservice.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
2626
"""
2727

28+
import ipaddress
2829
import requests
29-
3030
from requests.utils import default_user_agent
3131

3232
import geoip2
3333
import geoip2.models
3434

35-
from .compat import compat_ip_address
36-
3735
from .errors import (
3836
AddressNotFoundError,
3937
AuthenticationError,
@@ -159,7 +157,7 @@ def insights(self, ip_address="me"):
159157

160158
def _response_for(self, path, model_class, ip_address):
161159
if ip_address != "me":
162-
ip_address = str(compat_ip_address(ip_address))
160+
ip_address = str(ipaddress.ip_address(ip_address))
163161
uri = "/".join([self._base_uri, path, ip_address])
164162
response = requests.get(
165163
uri,

tests/webservice_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4+
import copy
5+
import ipaddress
46
import sys
57

68
sys.path.append("..")
79

8-
import copy
910
import geoip2
1011
import requests_mock
1112
from geoip2.errors import (
@@ -18,7 +19,6 @@
1819
PermissionRequiredError,
1920
)
2021
from geoip2.webservice import Client
21-
from geoip2.compat import compat_ip_network
2222

2323
if sys.version_info[:2] == (2, 6):
2424
import unittest2 as unittest
@@ -106,7 +106,7 @@ def test_country_ok(self, mock):
106106
"registered_country is_in_european_union is True",
107107
)
108108
self.assertEqual(
109-
country.traits.network, compat_ip_network("1.2.3.0/24"), "network"
109+
country.traits.network, ipaddress.ip_network("1.2.3.0/24"), "network"
110110
)
111111
self.assertEqual(country.raw, self.country, "raw response is correct")
112112

@@ -315,7 +315,7 @@ def test_city_ok(self, mock):
315315
city = self.client.city("1.2.3.4")
316316
self.assertEqual(type(city), geoip2.models.City, "return value of client.city")
317317
self.assertEqual(
318-
city.traits.network, compat_ip_network("1.2.3.0/24"), "network"
318+
city.traits.network, ipaddress.ip_network("1.2.3.0/24"), "network"
319319
)
320320

321321
@requests_mock.mock()
@@ -331,7 +331,7 @@ def test_insights_ok(self, mock):
331331
type(insights), geoip2.models.Insights, "return value of client.insights"
332332
)
333333
self.assertEqual(
334-
insights.traits.network, compat_ip_network("1.2.3.0/24"), "network"
334+
insights.traits.network, ipaddress.ip_network("1.2.3.0/24"), "network"
335335
)
336336
self.assertEqual(insights.traits.static_ip_score, 1.3, "static_ip_score is 1.3")
337337
self.assertEqual(insights.traits.user_count, 2, "user_count is 2")

0 commit comments

Comments
 (0)