[Python-modules-commits] [python-geoip2] 01/05: Import python-geoip2_2.5.0+dfsg1.orig.tar.gz
Ondřej Nový
onovy at moszumanska.debian.org
Fri May 12 14:12:51 UTC 2017
This is an automated email from the git hooks/post-receive script.
onovy pushed a commit to branch master
in repository python-geoip2.
commit cba45d4629a691e35e69c98cb250547808ea6efb
Author: Ondřej Nový <onovy at debian.org>
Date: Fri May 12 16:01:03 2017 +0200
Import python-geoip2_2.5.0+dfsg1.orig.tar.gz
---
HISTORY.rst | 7 ++
PKG-INFO | 28 ++++-
README.rst | 26 +++-
geoip2.egg-info/PKG-INFO | 28 ++++-
geoip2.egg-info/SOURCES.txt | 7 +-
geoip2/__init__.py | 4 +-
geoip2/compat.py | 2 +
geoip2/database.py | 15 ++-
geoip2/models.py | 42 ++++++-
geoip2/records.py | 34 +++---
geoip2/webservice.py | 17 +--
setup.cfg | 1 -
tests/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb | Bin 3919 -> 4024 bytes
.../GeoIP2-City-Test-Broken-Double-Format.mmdb | Bin 20377 -> 19041 bytes
.../GeoIP2-City-Test-Invalid-Node-Count.mmdb | Bin 20759 -> 19423 bytes
tests/data/test-data/GeoIP2-City-Test.mmdb | Bin 20739 -> 19403 bytes
.../test-data/GeoIP2-Connection-Type-Test.mmdb | Bin 3779 -> 2463 bytes
tests/data/test-data/GeoIP2-Country-Test.mmdb | Bin 17561 -> 16189 bytes
.../data/test-data/GeoIP2-DensityIncome-Test.mmdb | Bin 0 -> 1650 bytes
tests/data/test-data/GeoIP2-Domain-Test.mmdb | Bin 6326 -> 4947 bytes
tests/data/test-data/GeoIP2-Enterprise-Test.mmdb | Bin 3828 -> 6545 bytes
tests/data/test-data/GeoIP2-ISP-Test.mmdb | Bin 76196 -> 75113 bytes
.../data/test-data/GeoIP2-Precision-City-Test.mmdb | Bin 21360 -> 0 bytes
.../GeoIP2-Precision-Enterprise-Test.mmdb | Bin 0 -> 8625 bytes
.../data/test-data/GeoIP2-Precision-ISP-Test.mmdb | Bin 76443 -> 0 bytes
tests/data/test-data/GeoLite2-ASN-Test.mmdb | Bin 0 -> 1753 bytes
.../test-data/MaxMind-DB-no-ipv4-search-tree.mmdb | Bin 2251 -> 1614 bytes
.../test-data/MaxMind-DB-string-value-entries.mmdb | Bin 1341 -> 579 bytes
.../MaxMind-DB-test-broken-pointers-24.mmdb | Bin 1289 -> 527 bytes
.../MaxMind-DB-test-broken-search-tree-24.mmdb | Bin 1313 -> 551 bytes
tests/data/test-data/MaxMind-DB-test-decoder.mmdb | Bin 3944 -> 2732 bytes
tests/data/test-data/MaxMind-DB-test-ipv4-24.mmdb | Bin 1298 -> 536 bytes
tests/data/test-data/MaxMind-DB-test-ipv4-28.mmdb | Bin 1462 -> 573 bytes
tests/data/test-data/MaxMind-DB-test-ipv4-32.mmdb | Bin 1626 -> 610 bytes
tests/data/test-data/MaxMind-DB-test-ipv6-24.mmdb | Bin 2806 -> 1545 bytes
tests/data/test-data/MaxMind-DB-test-ipv6-28.mmdb | Bin 3222 -> 1751 bytes
tests/data/test-data/MaxMind-DB-test-ipv6-32.mmdb | Bin 3638 -> 1957 bytes
.../MaxMind-DB-test-metadata-pointers.mmdb | Bin 2258 -> 2198 bytes
tests/data/test-data/MaxMind-DB-test-mixed-24.mmdb | Bin 3066 -> 1847 bytes
tests/data/test-data/MaxMind-DB-test-mixed-28.mmdb | Bin 3511 -> 2089 bytes
tests/data/test-data/MaxMind-DB-test-mixed-32.mmdb | Bin 3956 -> 2331 bytes
tests/data/test-data/MaxMind-DB-test-nested.mmdb | Bin 3802 -> 2590 bytes
tests/database_test.py | 28 ++++-
tests/models_test.py | 59 +++++++---
tests/webservice_test.py | 131 ++++++++++++---------
45 files changed, 304 insertions(+), 125 deletions(-)
diff --git a/HISTORY.rst b/HISTORY.rst
index 120054b..c45ea6d 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,13 @@
History
-------
+2.5.0 (2017-05-08)
+++++++++++++++++++
+
+* Added support for GeoLite2 ASN database.
+* Corrected documentation of errors raised when using the database reader.
+ Reported by Radek Holý. GitHub #42.
+
2.4.2 (2016-12-08)
++++++++++++++++++
diff --git a/PKG-INFO b/PKG-INFO
index 87cf1ef..af452b3 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: geoip2
-Version: 2.4.2
+Version: 2.5.0
Summary: MaxMind GeoIP2 API
Home-page: http://www.maxmind.com/
Author: Gregory Oschwald
@@ -193,6 +193,22 @@ Description: =========================
'128.101.101.101'
>>> reader.close()
+ ASN Database
+ ^^^^^^^^^^^^
+
+ .. code-block:: pycon
+
+ >>> import geoip2.database
+ >>>
+ >>> # This creates a Reader object. You should use the same object
+ >>> # across multiple requests as creation of it is expensive.
+ >>> with geoip2.database.Reader('/path/to/GeoLite2-ASN.mmdb') as reader:
+ >>> response = reader.asn('1.128.0.0')
+ >>> response.autonomous_system_number
+ 1221
+ >>> response.autonomous_system_organization
+ 'Telstra Pty Ltd'
+
Connection-Type Database
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -305,11 +321,13 @@ Description: =========================
Database Reader Exceptions
--------------------------
- If the database file does not exist or is not readable, a ``ValueError`` will
- be thrown. If the file is invalid or there is a bug in the reader, a
- ``maxminddb.InvalidDatabaseError`` will be thrown with a description of the
+ If the database file does not exist or is not readable, the constructor will
+ raise a ``FileNotFoundError`` on Python 3 or an ``IOError`` on Python 2.
+ If the IP address passed to a method is invalid, a ``ValueError`` will be
+ raised. If the file is invalid or there is a bug in the reader, a
+ ``maxminddb.InvalidDatabaseError`` will be raised with a description of the
problem. If an IP address is not in the database, a ``AddressNotFoundError``
- exception will be thrown.
+ will be raised.
Values to use for Database or Dictionary Keys
---------------------------------------------
diff --git a/README.rst b/README.rst
index 7dce8ce..5542bb2 100644
--- a/README.rst
+++ b/README.rst
@@ -185,6 +185,22 @@ Anonymous IP Database
'128.101.101.101'
>>> reader.close()
+ASN Database
+^^^^^^^^^^^^
+
+.. code-block:: pycon
+
+ >>> import geoip2.database
+ >>>
+ >>> # This creates a Reader object. You should use the same object
+ >>> # across multiple requests as creation of it is expensive.
+ >>> with geoip2.database.Reader('/path/to/GeoLite2-ASN.mmdb') as reader:
+ >>> response = reader.asn('1.128.0.0')
+ >>> response.autonomous_system_number
+ 1221
+ >>> response.autonomous_system_organization
+ 'Telstra Pty Ltd'
+
Connection-Type Database
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -297,11 +313,13 @@ ISP Database
Database Reader Exceptions
--------------------------
-If the database file does not exist or is not readable, a ``ValueError`` will
-be thrown. If the file is invalid or there is a bug in the reader, a
-``maxminddb.InvalidDatabaseError`` will be thrown with a description of the
+If the database file does not exist or is not readable, the constructor will
+raise a ``FileNotFoundError`` on Python 3 or an ``IOError`` on Python 2.
+If the IP address passed to a method is invalid, a ``ValueError`` will be
+raised. If the file is invalid or there is a bug in the reader, a
+``maxminddb.InvalidDatabaseError`` will be raised with a description of the
problem. If an IP address is not in the database, a ``AddressNotFoundError``
-exception will be thrown.
+will be raised.
Values to use for Database or Dictionary Keys
---------------------------------------------
diff --git a/geoip2.egg-info/PKG-INFO b/geoip2.egg-info/PKG-INFO
index 87cf1ef..af452b3 100644
--- a/geoip2.egg-info/PKG-INFO
+++ b/geoip2.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: geoip2
-Version: 2.4.2
+Version: 2.5.0
Summary: MaxMind GeoIP2 API
Home-page: http://www.maxmind.com/
Author: Gregory Oschwald
@@ -193,6 +193,22 @@ Description: =========================
'128.101.101.101'
>>> reader.close()
+ ASN Database
+ ^^^^^^^^^^^^
+
+ .. code-block:: pycon
+
+ >>> import geoip2.database
+ >>>
+ >>> # This creates a Reader object. You should use the same object
+ >>> # across multiple requests as creation of it is expensive.
+ >>> with geoip2.database.Reader('/path/to/GeoLite2-ASN.mmdb') as reader:
+ >>> response = reader.asn('1.128.0.0')
+ >>> response.autonomous_system_number
+ 1221
+ >>> response.autonomous_system_organization
+ 'Telstra Pty Ltd'
+
Connection-Type Database
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -305,11 +321,13 @@ Description: =========================
Database Reader Exceptions
--------------------------
- If the database file does not exist or is not readable, a ``ValueError`` will
- be thrown. If the file is invalid or there is a bug in the reader, a
- ``maxminddb.InvalidDatabaseError`` will be thrown with a description of the
+ If the database file does not exist or is not readable, the constructor will
+ raise a ``FileNotFoundError`` on Python 3 or an ``IOError`` on Python 2.
+ If the IP address passed to a method is invalid, a ``ValueError`` will be
+ raised. If the file is invalid or there is a bug in the reader, a
+ ``maxminddb.InvalidDatabaseError`` will be raised with a description of the
problem. If an IP address is not in the database, a ``AddressNotFoundError``
- exception will be thrown.
+ will be raised.
Values to use for Database or Dictionary Keys
---------------------------------------------
diff --git a/geoip2.egg-info/SOURCES.txt b/geoip2.egg-info/SOURCES.txt
index 746d421..c3ecf06 100644
--- a/geoip2.egg-info/SOURCES.txt
+++ b/geoip2.egg-info/SOURCES.txt
@@ -12,6 +12,7 @@ docs/html/objects.inv
docs/html/py-modindex.html
docs/html/search.html
docs/html/searchindex.js
+docs/html/_sources/index.rst.txt
docs/html/_sources/index.txt
docs/html/_static/ajax-loader.gif
docs/html/_static/basic.css
@@ -24,6 +25,7 @@ docs/html/_static/down-pressed.png
docs/html/_static/down.png
docs/html/_static/file.png
docs/html/_static/jquery-1.11.1.js
+docs/html/_static/jquery-3.1.0.js
docs/html/_static/jquery.js
docs/html/_static/minus.png
docs/html/_static/navigation.png
@@ -59,11 +61,12 @@ tests/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb
tests/data/test-data/GeoIP2-City-Test.mmdb
tests/data/test-data/GeoIP2-Connection-Type-Test.mmdb
tests/data/test-data/GeoIP2-Country-Test.mmdb
+tests/data/test-data/GeoIP2-DensityIncome-Test.mmdb
tests/data/test-data/GeoIP2-Domain-Test.mmdb
tests/data/test-data/GeoIP2-Enterprise-Test.mmdb
tests/data/test-data/GeoIP2-ISP-Test.mmdb
-tests/data/test-data/GeoIP2-Precision-City-Test.mmdb
-tests/data/test-data/GeoIP2-Precision-ISP-Test.mmdb
+tests/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb
+tests/data/test-data/GeoLite2-ASN-Test.mmdb
tests/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb
tests/data/test-data/MaxMind-DB-string-value-entries.mmdb
tests/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb
diff --git a/geoip2/__init__.py b/geoip2/__init__.py
index d5ac954..3609acd 100644
--- a/geoip2/__init__.py
+++ b/geoip2/__init__.py
@@ -1,7 +1,7 @@
# pylint:disable=C0111
__title__ = 'geoip2'
-__version__ = '2.4.2'
+__version__ = '2.5.0'
__author__ = 'Gregory Oschwald'
__license__ = 'Apache License, Version 2.0'
-__copyright__ = 'Copyright (c) 2013-2016 Maxmind, Inc.'
+__copyright__ = 'Copyright (c) 2013-2017 Maxmind, Inc.'
diff --git a/geoip2/compat.py b/geoip2/compat.py
index 67c5fa6..228198c 100644
--- a/geoip2/compat.py
+++ b/geoip2/compat.py
@@ -6,12 +6,14 @@ import ipaddress
# pylint: skip-file
if sys.version_info[0] == 2:
+
def compat_ip_address(address):
"""Intended for internal use only."""
if isinstance(address, bytes):
address = address.decode()
return ipaddress.ip_address(address)
else:
+
def compat_ip_address(address):
"""Intended for internal use only."""
return ipaddress.ip_address(address)
diff --git a/geoip2/database.py b/geoip2/database.py
index ed21d6d..3e0a427 100644
--- a/geoip2/database.py
+++ b/geoip2/database.py
@@ -120,6 +120,17 @@ class Reader(object):
return self._flat_model_for(geoip2.models.AnonymousIP,
'GeoIP2-Anonymous-IP', ip_address)
+ def asn(self, ip_address):
+ """Get the ASN object for the IP address.
+
+ :param ip_address: IPv4 or IPv6 address as a string.
+
+ :returns: :py:class:`geoip2.models.ASN` object
+
+ """
+ return self._flat_model_for(geoip2.models.ASN, 'GeoLite2-ASN',
+ ip_address)
+
def connection_type(self, ip_address):
"""Get the ConnectionType object for the IP address.
@@ -168,8 +179,8 @@ class Reader(object):
if database_type not in self.metadata().database_type:
caller = inspect.stack()[2][3]
raise TypeError("The %s method cannot be used with the "
- "%s database" %
- (caller, self.metadata().database_type))
+ "%s database" % (caller,
+ self.metadata().database_type))
record = self._db_reader.get(ip_address)
if record is None:
raise geoip2.errors.AddressNotFoundError(
diff --git a/geoip2/models.py b/geoip2/models.py
index 15e951b..d50fb91 100644
--- a/geoip2/models.py
+++ b/geoip2/models.py
@@ -368,6 +368,40 @@ class AnonymousIP(SimpleModel):
self.raw = raw
+class ASN(SimpleModel):
+ """Model class for the GeoLite2 ASN.
+
+ This class provides the following attribute:
+
+ .. attribute:: autonomous_system_number
+
+ The autonomous system number associated with the IP address.
+
+ :type: int
+
+ .. attribute:: autonomous_system_organization
+
+ The organization associated with the registered autonomous system number
+ for the IP address.
+
+ :type: unicode
+
+ .. attribute:: ip_address
+
+ The IP address used in the lookup.
+
+ :type: unicode
+ """
+
+ # pylint:disable=too-many-arguments
+ def __init__(self, raw):
+ self.autonomous_system_number = raw.get('autonomous_system_number')
+ self.autonomous_system_organization = raw.get(
+ 'autonomous_system_organization')
+ self.ip_address = raw.get('ip_address')
+ self.raw = raw
+
+
class ConnectionType(SimpleModel):
"""Model class for the GeoIP2 Connection-Type.
@@ -424,7 +458,7 @@ class Domain(SimpleModel):
self.raw = raw
-class ISP(SimpleModel):
+class ISP(ASN):
"""Model class for the GeoIP2 ISP.
This class provides the following attribute:
@@ -463,10 +497,6 @@ class ISP(SimpleModel):
# pylint:disable=too-many-arguments
def __init__(self, raw):
- self.autonomous_system_number = raw.get('autonomous_system_number')
- self.autonomous_system_organization = raw.get(
- 'autonomous_system_organization')
+ super(ISP, self).__init__(raw)
self.isp = raw.get('isp')
self.organization = raw.get('organization')
- self.ip_address = raw.get('ip_address')
- self.raw = raw
diff --git a/geoip2/records.py b/geoip2/records.py
index 6037894..09a03f3 100644
--- a/geoip2/records.py
+++ b/geoip2/records.py
@@ -50,9 +50,8 @@ class PlaceRecord(Record):
def name(self):
"""Dict with locale codes as keys and localized name as value."""
# pylint:disable=E1101
- return next(
- (self.names.get(x) for x in self._locales
- if x in self.names), None)
+ return next((self.names.get(x) for x in self._locales
+ if x in self.names), None)
class City(PlaceRecord):
@@ -243,8 +242,8 @@ class RepresentedCountry(Country):
"""
- _valid_attributes = set(['confidence', 'geoname_id', 'iso_code', 'names',
- 'type'])
+ _valid_attributes = set(
+ ['confidence', 'geoname_id', 'iso_code', 'names', 'type'])
class Location(Record):
@@ -314,9 +313,11 @@ class Location(Record):
"""
- _valid_attributes = set(['average_income', 'accuracy_radius', 'latitude',
- 'longitude', 'metro_code', 'population_density',
- 'postal_code', 'postal_confidence', 'time_zone'])
+ _valid_attributes = set([
+ 'average_income', 'accuracy_radius', 'latitude', 'longitude',
+ 'metro_code', 'population_density', 'postal_code', 'postal_confidence',
+ 'time_zone'
+ ])
class MaxMind(Record):
@@ -594,14 +595,17 @@ class Traits(Record):
"""
- _valid_attributes = set(
- ['autonomous_system_number', 'autonomous_system_organization',
- 'connection_type', 'domain', 'is_anonymous_proxy',
- 'is_legitimate_proxy', 'is_satellite_provider', 'isp', 'ip_address',
- 'organization', 'user_type'])
+ _valid_attributes = set([
+ 'autonomous_system_number', 'autonomous_system_organization',
+ 'connection_type', 'domain', 'is_anonymous_proxy',
+ 'is_legitimate_proxy', 'is_satellite_provider', 'isp', 'ip_address',
+ 'organization', 'user_type'
+ ])
def __init__(self, **kwargs):
- for k in ['is_anonymous_proxy', 'is_legitimate_proxy',
- 'is_satellite_provider']:
+ for k in [
+ 'is_anonymous_proxy', 'is_legitimate_proxy',
+ 'is_satellite_provider'
+ ]:
kwargs[k] = bool(kwargs.get(k, False))
super(Traits, self).__init__(**kwargs)
diff --git a/geoip2/webservice.py b/geoip2/webservice.py
index 18e593d..fa6981f 100644
--- a/geoip2/webservice.py
+++ b/geoip2/webservice.py
@@ -95,7 +95,7 @@ class Client(object):
self._locales = locales
# requests 2.12.2 requires that the username passed to auth be bytes
# or a string, with the former being preferred.
- self._user_id = str(user_id)
+ self._user_id = user_id if isinstance(user_id, bytes) else str(user_id)
self._license_key = license_key
self._base_uri = 'https://%s/geoip/v2.1' % host
self._timeout = timeout
@@ -141,13 +141,14 @@ class Client(object):
if ip_address != 'me':
ip_address = str(compat_ip_address(ip_address))
uri = '/'.join([self._base_uri, path, ip_address])
- response = requests.get(uri,
- auth=(self._user_id, self._license_key),
- headers={
- 'Accept': 'application/json',
- 'User-Agent': self._user_agent()
- },
- timeout=self._timeout)
+ response = requests.get(
+ uri,
+ auth=(self._user_id, self._license_key),
+ headers={
+ 'Accept': 'application/json',
+ 'User-Agent': self._user_agent()
+ },
+ timeout=self._timeout)
if response.status_code == 200:
body = self._handle_success(response, uri)
return model_class(body, locales=self._locales)
diff --git a/setup.cfg b/setup.cfg
index 0d92335..7f2f5e5 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -9,5 +9,4 @@ universal = 1
[egg_info]
tag_build =
tag_date = 0
-tag_svn_revision = 0
diff --git a/tests/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb b/tests/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb
index 0962c5f..3bfd806 100644
Binary files a/tests/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb and b/tests/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb b/tests/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb
index 5c11193..eb18c5b 100644
Binary files a/tests/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb and b/tests/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb b/tests/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb
index cb88a95..78eeaad 100644
Binary files a/tests/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb and b/tests/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-City-Test.mmdb b/tests/data/test-data/GeoIP2-City-Test.mmdb
index c488dc4..ab8b82d 100644
Binary files a/tests/data/test-data/GeoIP2-City-Test.mmdb and b/tests/data/test-data/GeoIP2-City-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-Connection-Type-Test.mmdb b/tests/data/test-data/GeoIP2-Connection-Type-Test.mmdb
index d566083..ab73a05 100644
Binary files a/tests/data/test-data/GeoIP2-Connection-Type-Test.mmdb and b/tests/data/test-data/GeoIP2-Connection-Type-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-Country-Test.mmdb b/tests/data/test-data/GeoIP2-Country-Test.mmdb
index a49174a..9faf299 100644
Binary files a/tests/data/test-data/GeoIP2-Country-Test.mmdb and b/tests/data/test-data/GeoIP2-Country-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-DensityIncome-Test.mmdb b/tests/data/test-data/GeoIP2-DensityIncome-Test.mmdb
new file mode 100644
index 0000000..be978fd
Binary files /dev/null and b/tests/data/test-data/GeoIP2-DensityIncome-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-Domain-Test.mmdb b/tests/data/test-data/GeoIP2-Domain-Test.mmdb
index 70ecd6b..4c37c34 100644
Binary files a/tests/data/test-data/GeoIP2-Domain-Test.mmdb and b/tests/data/test-data/GeoIP2-Domain-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-Enterprise-Test.mmdb b/tests/data/test-data/GeoIP2-Enterprise-Test.mmdb
index c3af0be..7e853d0 100644
Binary files a/tests/data/test-data/GeoIP2-Enterprise-Test.mmdb and b/tests/data/test-data/GeoIP2-Enterprise-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-ISP-Test.mmdb b/tests/data/test-data/GeoIP2-ISP-Test.mmdb
index 0c2ba23..24e9e1e 100644
Binary files a/tests/data/test-data/GeoIP2-ISP-Test.mmdb and b/tests/data/test-data/GeoIP2-ISP-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-Precision-City-Test.mmdb b/tests/data/test-data/GeoIP2-Precision-City-Test.mmdb
deleted file mode 100644
index 9f358c1..0000000
Binary files a/tests/data/test-data/GeoIP2-Precision-City-Test.mmdb and /dev/null differ
diff --git a/tests/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb b/tests/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb
new file mode 100644
index 0000000..13178a3
Binary files /dev/null and b/tests/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb differ
diff --git a/tests/data/test-data/GeoIP2-Precision-ISP-Test.mmdb b/tests/data/test-data/GeoIP2-Precision-ISP-Test.mmdb
deleted file mode 100644
index c8e72f9..0000000
Binary files a/tests/data/test-data/GeoIP2-Precision-ISP-Test.mmdb and /dev/null differ
diff --git a/tests/data/test-data/GeoLite2-ASN-Test.mmdb b/tests/data/test-data/GeoLite2-ASN-Test.mmdb
new file mode 100644
index 0000000..6a02e60
Binary files /dev/null and b/tests/data/test-data/GeoLite2-ASN-Test.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb b/tests/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb
index ae5c3b2..5ee0e6d 100644
Binary files a/tests/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb and b/tests/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-string-value-entries.mmdb b/tests/data/test-data/MaxMind-DB-string-value-entries.mmdb
index a06c861..c645cb1 100644
Binary files a/tests/data/test-data/MaxMind-DB-string-value-entries.mmdb and b/tests/data/test-data/MaxMind-DB-string-value-entries.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb b/tests/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb
index 58cfde5..c354274 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb and b/tests/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb b/tests/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb
index 5819e5f..c62f5c8 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb and b/tests/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-decoder.mmdb b/tests/data/test-data/MaxMind-DB-test-decoder.mmdb
index bf15c2e..50caae1 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-decoder.mmdb and b/tests/data/test-data/MaxMind-DB-test-decoder.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-ipv4-24.mmdb b/tests/data/test-data/MaxMind-DB-test-ipv4-24.mmdb
index 1b45bd9..1530ca5 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-ipv4-24.mmdb and b/tests/data/test-data/MaxMind-DB-test-ipv4-24.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-ipv4-28.mmdb b/tests/data/test-data/MaxMind-DB-test-ipv4-28.mmdb
index a414269..24908b8 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-ipv4-28.mmdb and b/tests/data/test-data/MaxMind-DB-test-ipv4-28.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-ipv4-32.mmdb b/tests/data/test-data/MaxMind-DB-test-ipv4-32.mmdb
index b9d5e64..c38eaf1 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-ipv4-32.mmdb and b/tests/data/test-data/MaxMind-DB-test-ipv4-32.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-ipv6-24.mmdb b/tests/data/test-data/MaxMind-DB-test-ipv6-24.mmdb
index ae4e2f4..8ba7bab 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-ipv6-24.mmdb and b/tests/data/test-data/MaxMind-DB-test-ipv6-24.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-ipv6-28.mmdb b/tests/data/test-data/MaxMind-DB-test-ipv6-28.mmdb
index 6bd076c..1082f85 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-ipv6-28.mmdb and b/tests/data/test-data/MaxMind-DB-test-ipv6-28.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-ipv6-32.mmdb b/tests/data/test-data/MaxMind-DB-test-ipv6-32.mmdb
index 0ea2b49..f28f359 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-ipv6-32.mmdb and b/tests/data/test-data/MaxMind-DB-test-ipv6-32.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb b/tests/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb
index 1b95c33..533439d 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb and b/tests/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-mixed-24.mmdb b/tests/data/test-data/MaxMind-DB-test-mixed-24.mmdb
index 8221234..a16a00e 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-mixed-24.mmdb and b/tests/data/test-data/MaxMind-DB-test-mixed-24.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-mixed-28.mmdb b/tests/data/test-data/MaxMind-DB-test-mixed-28.mmdb
index b5d9686..e6bdfd3 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-mixed-28.mmdb and b/tests/data/test-data/MaxMind-DB-test-mixed-28.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-mixed-32.mmdb b/tests/data/test-data/MaxMind-DB-test-mixed-32.mmdb
index e639be7..8bb88e8 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-mixed-32.mmdb and b/tests/data/test-data/MaxMind-DB-test-mixed-32.mmdb differ
diff --git a/tests/data/test-data/MaxMind-DB-test-nested.mmdb b/tests/data/test-data/MaxMind-DB-test-nested.mmdb
index 26a8e9d..891d065 100644
Binary files a/tests/data/test-data/MaxMind-DB-test-nested.mmdb and b/tests/data/test-data/MaxMind-DB-test-nested.mmdb differ
diff --git a/tests/database_test.py b/tests/database_test.py
index 9b37a2d..21c622d 100644
--- a/tests/database_test.py
+++ b/tests/database_test.py
@@ -25,7 +25,6 @@ if sys.version_info[0] == 2:
class BaseTestReader(object):
-
def test_language_list(self):
reader = geoip2.database.Reader(
'tests/data/test-data/GeoIP2-Country-Test.mmdb',
@@ -76,6 +75,26 @@ class BaseTestReader(object):
self.assertEqual(record.ip_address, ip_address)
reader.close()
+ def test_asn(self):
+ reader = geoip2.database.Reader(
+ 'tests/data/test-data/GeoLite2-ASN-Test.mmdb')
+
+ ip_address = '1.128.0.0'
+ record = reader.asn(ip_address)
+ self.assertEqual(record.autonomous_system_number, 1221)
+ self.assertEqual(record.autonomous_system_organization,
+ 'Telstra Pty Ltd')
+ self.assertEqual(record.ip_address, ip_address)
+
+ self.assertRegex(
+ str(record),
+ r'geoip2.models.ASN\(.*1\.128\.0\.0.*\)',
+ 'str representation is correct')
+
+ self.assertEqual(record, eval(repr(record)), "ASN repr can be eval'd")
+
+ reader.close()
+
def test_city(self):
reader = geoip2.database.Reader(
'tests/data/test-data/GeoIP2-City-Test.mmdb')
@@ -101,7 +120,8 @@ class BaseTestReader(object):
str(record), r'ConnectionType\(\{.*Cable/DSL.*\}\)',
'ConnectionType str representation is reasonable')
- self.assertEqual(record, eval(repr(record)),
+ self.assertEqual(record,
+ eval(repr(record)),
"ConnectionType repr can be eval'd")
reader.close()
@@ -127,8 +147,8 @@ class BaseTestReader(object):
str(record), r'Domain\(\{.*maxmind.com.*\}\)',
'Domain str representation is reasonable')
- self.assertEqual(record, eval(repr(record)),
- "Domain repr can be eval'd")
+ self.assertEqual(record,
+ eval(repr(record)), "Domain repr can be eval'd")
reader.close()
diff --git a/tests/models_test.py b/tests/models_test.py
index e6286b5..63843e6 100644
--- a/tests/models_test.py
+++ b/tests/models_test.py
@@ -24,18 +24,24 @@ class TestModels(unittest.TestCase):
'city': {
'confidence': 76,
'geoname_id': 9876,
- 'names': {'en': 'Minneapolis'},
+ 'names': {
+ 'en': 'Minneapolis'
+ },
},
'continent': {
'code': 'NA',
'geoname_id': 42,
- 'names': {'en': 'North America'},
+ 'names': {
+ 'en': 'North America'
+ },
},
'country': {
'confidence': 99,
'geoname_id': 1,
'iso_code': 'US',
- 'names': {'en': 'United States of America'},
+ 'names': {
+ 'en': 'United States of America'
+ },
},
'location': {
'average_income': 24626,
@@ -54,21 +60,29 @@ class TestModels(unittest.TestCase):
'confidence': 88,
'geoname_id': 574635,
'iso_code': 'MN',
- 'names': {'en': 'Minnesota'},
+ 'names': {
+ 'en': 'Minnesota'
+ },
}, {
'geoname_id': 123,
'iso_code': 'HP',
- 'names': {'en': 'Hennepin'},
+ 'names': {
+ 'en': 'Hennepin'
+ },
}],
'registered_country': {
'geoname_id': 2,
'iso_code': 'CA',
- 'names': {'en': 'Canada'},
+ 'names': {
+ 'en': 'Canada'
+ },
},
'represented_country': {
'geoname_id': 3,
'iso_code': 'GB',
- 'names': {'en': 'United Kingdom'},
+ 'names': {
+ 'en': 'United Kingdom'
+ },
'type': 'military',
},
'traits': {
@@ -144,14 +158,15 @@ class TestModels(unittest.TestCase):
r'^geoip2.models.Insights\(\{.*geoname_id.*\}, \[.*en.*\]\)',
'Insights str representation looks reasonable')
- self.assertEqual(model, eval(repr(model)),
- "Insights repr can be eval'd")
+ self.assertEqual(model,
+ eval(repr(model)), "Insights repr can be eval'd")
self.assertRegex(
str(model.location), r'^geoip2.records.Location\(.*longitude=.*\)',
'Location str representation is reasonable')
- self.assertEqual(model.location, eval(repr(model.location)),
+ self.assertEqual(model.location,
+ eval(repr(model.location)),
"Location repr can be eval'd")
def test_insights_min(self):
@@ -189,17 +204,23 @@ class TestModels(unittest.TestCase):
'continent': {
'code': 'NA',
'geoname_id': 42,
- 'names': {'en': 'North America'},
+ 'names': {
+ 'en': 'North America'
+ },
},
'country': {
'geoname_id': 1,
'iso_code': 'US',
- 'names': {'en': 'United States of America'},
+ 'names': {
+ 'en': 'United States of America'
+ },
},
'registered_country': {
'geoname_id': 2,
'iso_code': 'CA',
- 'names': {'en': 'Canada'},
+ 'names': {
+ 'en': 'Canada'
+ },
},
'traits': {
'ip_address': '1.2.3.4',
@@ -266,9 +287,15 @@ class TestModels(unittest.TestCase):
'__eq__ does not blow up on weird input')
def test_unknown_keys(self):
- model = geoip2.models.City({'traits': {'ip_address': '1.2.3.4',
- 'invalid': 'blah'},
- 'unk_base': {'blah': 1}})
+ model = geoip2.models.City({
+ 'traits': {
+ 'ip_address': '1.2.3.4',
+ 'invalid': 'blah'
+ },
+ 'unk_base': {
+ 'blah': 1
+ }
+ })
with self.assertRaises(AttributeError):
model.unk_base
with self.assertRaises(AttributeError):
diff --git a/tests/webservice_test.py b/tests/webservice_test.py
index 584eb9e..95e9851 100644
--- a/tests/webservice_test.py
+++ b/tests/webservice_test.py
@@ -7,8 +7,8 @@ sys.path.append('..')
import geoip2
import requests_mock
from geoip2.errors import (AddressNotFoundError, AuthenticationError,
- GeoIP2Error, HTTPError, InvalidRequestError, OutOfQueriesError,
- PermissionRequiredError)
+ GeoIP2Error, HTTPError, InvalidRequestError,
+ OutOfQueriesError, PermissionRequiredError)
from geoip2.webservice import Client
if sys.version_info[:2] == (2, 6):
@@ -22,22 +22,31 @@ if sys.version_info[0] == 2:
class TestClient(unittest.TestCase):
-
def setUp(self):
self.client = Client(42, 'abcdef123456')
base_uri = 'https://geoip.maxmind.com/geoip/v2.1/'
country = {
- 'continent': {'code': 'NA',
- 'geoname_id': 42,
- 'names': {'en': 'North America'}},
+ 'continent': {
+ 'code': 'NA',
+ 'geoname_id': 42,
+ 'names': {
+ 'en': 'North America'
+ }
+ },
'country': {
'geoname_id': 1,
'iso_code': 'US',
- 'names': {'en': 'United States of America'}
+ 'names': {
+ 'en': 'United States of America'
+ }
+ },
+ 'maxmind': {
+ 'queries_remaining': 11
+ },
+ 'traits': {
+ 'ip_address': '1.2.3.4'
},
- 'maxmind': {'queries_remaining': 11},
- 'traits': {'ip_address': '1.2.3.4'},
}
def _content_type(self, endpoint):
@@ -46,10 +55,11 @@ class TestClient(unittest.TestCase):
@requests_mock.mock()
def test_country_ok(self, mock):
- mock.get(self.base_uri + 'country/1.2.3.4',
- json=self.country,
- status_code=200,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/1.2.3.4',
+ json=self.country,
+ status_code=200,
+ headers={'Content-Type': self._content_type('country')})
country = self.client.country('1.2.3.4')
self.assertEqual(
type(country), geoip2.models.Country,
@@ -73,10 +83,11 @@ class TestClient(unittest.TestCase):
@requests_mock.mock()
def test_me(self, mock):
- mock.get(self.base_uri + 'country/me',
- json=self.country,
- status_code=200,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/me',
+ json=self.country,
+ status_code=200,
+ headers={'Content-Type': self._content_type('country')})
implicit_me = self.client.country()
self.assertEqual(
type(implicit_me), geoip2.models.Country,
@@ -88,9 +99,10 @@ class TestClient(unittest.TestCase):
@requests_mock.mock()
def test_200_error(self, mock):
- mock.get(self.base_uri + 'country/1.1.1.1',
- status_code=200,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/1.1.1.1',
+ status_code=200,
+ headers={'Content-Type': self._content_type('country')})
with self.assertRaisesRegex(GeoIP2Error,
'could not decode the response as JSON'):
self.client.country('1.1.1.1')
@@ -103,20 +115,22 @@ class TestClient(unittest.TestCase):
@requests_mock.mock()
def test_no_body_error(self, mock):
- mock.get(self.base_uri + 'country/' + '1.2.3.7',
- text='',
- status_code=400,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/' + '1.2.3.7',
+ text='',
+ status_code=400,
+ headers={'Content-Type': self._content_type('country')})
with self.assertRaisesRegex(
HTTPError, 'Received a 400 error for .* with no body'):
self.client.country('1.2.3.7')
@requests_mock.mock()
def test_weird_body_error(self, mock):
- mock.get(self.base_uri + 'country/' + '1.2.3.8',
- text='{"wierd": 42}',
- status_code=400,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/' + '1.2.3.8',
+ text='{"wierd": 42}',
+ status_code=400,
+ headers={'Content-Type': self._content_type('country')})
with self.assertRaisesRegex(HTTPError,
'Response contains JSON but it does not '
'specify code or error keys'):
@@ -124,10 +138,11 @@ class TestClient(unittest.TestCase):
@requests_mock.mock()
def test_bad_body_error(self, mock):
- mock.get(self.base_uri + 'country/' + '1.2.3.9',
- text='bad body',
- status_code=400,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/' + '1.2.3.9',
+ text='bad body',
+ status_code=400,
+ headers={'Content-Type': self._content_type('country')})
with self.assertRaisesRegex(
HTTPError, 'it did not include the expected JSON body'):
self.client.country('1.2.3.9')
@@ -141,9 +156,10 @@ class TestClient(unittest.TestCase):
@requests_mock.mock()
def test_300_error(self, mock):
- mock.get(self.base_uri + 'country/' + '1.2.3.11',
- status_code=300,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/' + '1.2.3.11',
+ status_code=300,
+ headers={'Content-Type': self._content_type('country')})
with self.assertRaisesRegex(HTTPError,
'Received a very surprising HTTP status '
'\(300\) for'):
@@ -194,10 +210,11 @@ class TestClient(unittest.TestCase):
def _test_error(self, mock, status, error_code, error_class):
msg = 'Some error message'
body = {'error': msg, 'code': error_code}
- mock.get(self.base_uri + 'country/1.2.3.18',
- json=body,
- status_code=status,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/1.2.3.18',
+ json=body,
+ status_code=status,
+ headers={'Content-Type': self._content_type('country')})
with self.assertRaisesRegex(error_class, msg):
self.client.country('1.2.3.18')
@@ -206,19 +223,21 @@ class TestClient(unittest.TestCase):
msg = 'Unknown error type'
ip = '1.2.3.19'
body = {'error': msg, 'code': 'UNKNOWN_TYPE'}
- mock.get(self.base_uri + 'country/' + ip,
- json=body,
- status_code=400,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/' + ip,
+ json=body,
+ status_code=400,
+ headers={'Content-Type': self._content_type('country')})
with self.assertRaisesRegex(InvalidRequestError, msg):
self.client.country(ip)
@requests_mock.mock()
def test_request(self, mock):
- mock.get(self.base_uri + 'country/' + '1.2.3.4',
- json=self.country,
- status_code=200,
- headers={'Content-Type': self._content_type('country')})
+ mock.get(
+ self.base_uri + 'country/' + '1.2.3.4',
+ json=self.country,
+ status_code=200,
+ headers={'Content-Type': self._content_type('country')})
self.client.country('1.2.3.4')
request = mock.request_history[-1]
@@ -233,20 +252,22 @@ class TestClient(unittest.TestCase):
@requests_mock.mock()
def test_city_ok(self, mock):
- mock.get(self.base_uri + 'city/' + '1.2.3.4',
- json=self.country,
... 25 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-geoip2.git
More information about the Python-modules-commits
mailing list