|
25 | 25 |
|
26 | 26 | """ |
27 | 27 |
|
28 | | -import sys |
29 | | - |
30 | 28 | import requests |
31 | 29 |
|
| 30 | +from requests.utils import default_user_agent |
| 31 | + |
32 | 32 | import geoip2 |
33 | 33 | import geoip2.models |
34 | 34 |
|
35 | | -from requests.utils import default_user_agent |
| 35 | +from .compat import compat_ip_address |
36 | 36 |
|
37 | 37 | from .errors import (AddressNotFoundError, AuthenticationError, GeoIP2Error, |
38 | 38 | HTTPError, InvalidRequestError, OutOfQueriesError, |
39 | 39 | PermissionRequiredError) |
40 | 40 |
|
41 | | -if sys.version_info[0] == 2 or (sys.version_info[0] == 3 and |
42 | | - sys.version_info[1] < 3): |
43 | | - import ipaddr as ipaddress # pylint:disable=F0401 |
44 | | - |
45 | | - ipaddress.ip_address = ipaddress.IPAddress |
46 | | -else: |
47 | | - import ipaddress # pylint:disable=F0401 |
48 | | - |
49 | 41 |
|
50 | 42 | class Client(object): |
51 | 43 | """Creates a new client object. |
@@ -96,6 +88,7 @@ def __init__(self, |
96 | 88 | host='geoip.maxmind.com', |
97 | 89 | locales=None, |
98 | 90 | timeout=None): |
| 91 | + """Construct a Client.""" |
99 | 92 | # pylint: disable=too-many-arguments |
100 | 93 | if locales is None: |
101 | 94 | locales = ['en'] |
@@ -144,7 +137,7 @@ def insights(self, ip_address='me'): |
144 | 137 |
|
145 | 138 | def _response_for(self, path, model_class, ip_address): |
146 | 139 | if ip_address != 'me': |
147 | | - ip_address = str(ipaddress.ip_address(ip_address)) |
| 140 | + ip_address = str(compat_ip_address(ip_address)) |
148 | 141 | uri = '/'.join([self._base_uri, path, ip_address]) |
149 | 142 | response = requests.get(uri, |
150 | 143 | auth=(self._user_id, self._license_key), |
|
0 commit comments