Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ matrix:
- python: 2.7
dist: trusty
env: RUN_SNYK=1
- python: 3.3
dist: trusty
- python: 3.4
dist: trusty
- python: 3.5
dist: trusty
- python: 3.6
Expand Down
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
History
-------

1.4.2
1.5.0
++++++++++++++++++

* Python 3.3 and 3.4 are no longer supported.
* The extension source directory was moved to prevent an ``ImportWarning``
when importing the module on Python 2 with ``-Wdefault`` set. Reported by
David Szotten and Craig de Stigter. GitHub #31.
Expand Down
5 changes: 3 additions & 2 deletions maxminddb/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def __init__(self, database, mode=MODE_AUTO):
"""
if (mode == MODE_AUTO and mmap) or mode == MODE_MMAP:
with open(database, 'rb') as db_file:
self._buffer = mmap.mmap(
db_file.fileno(), 0, access=mmap.ACCESS_READ)
self._buffer = mmap.mmap(db_file.fileno(),
0,
access=mmap.ACCESS_READ)
self._buffer_size = self._buffer.size()
filename = database
elif mode in (MODE_AUTO, MODE_FILE):
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def run_setup(with_cext):
packages=find_packages('.'),
package_data={'': ['LICENSE']},
package_dir={'maxminddb': 'maxminddb'},
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
include_package_data=True,
install_requires=requirements,
tests_require=['nose'],
Expand All @@ -143,8 +144,6 @@ def run_setup(with_cext):
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down
51 changes: 24 additions & 27 deletions tests/reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class BaseTestReader(object):
def test_reader(self):
for record_size in [24, 28, 32]:
for ip_version in [4, 6]:
file_name = (
'tests/data/test-data/MaxMind-DB-test-ipv' +
str(ip_version) + '-' + str(record_size) + '.mmdb')
file_name = ('tests/data/test-data/MaxMind-DB-test-ipv' +
str(ip_version) + '-' + str(record_size) +
'.mmdb')
reader = open_database(file_name, self.mode)

self._check_metadata(reader, ip_version, record_size)
Expand All @@ -75,12 +75,13 @@ def test_decoder(self):
self.assertEqual(record['double'], 42.123456)
self.assertAlmostEqual(record['float'], 1.1)
self.assertEqual(record['int32'], -268435456)
self.assertEqual({
'mapX': {
'arrayX': [7, 8, 9],
'utf8_stringX': 'hello'
},
}, record['map'])
self.assertEqual(
{
'mapX': {
'arrayX': [7, 8, 9],
'utf8_stringX': 'hello'
},
}, record['map'])

self.assertEqual(record['uint16'], 100)
self.assertEqual(record['uint32'], 268435456)
Expand Down Expand Up @@ -166,12 +167,11 @@ def test_too_many_constructor_args(self):

def test_bad_constructor_mode(self):
cls = self.readerClass[0]
self.assertRaisesRegex(
ValueError,
r'Unsupported open mode \(100\)',
cls,
'README.md',
mode=100)
self.assertRaisesRegex(ValueError,
r'Unsupported open mode \(100\)',
cls,
'README.md',
mode=100)

def test_no_constructor_args(self):
cls = self.readerClass[0]
Expand Down Expand Up @@ -341,10 +341,9 @@ def _check_metadata(self, reader, ip_version, record_size):
def _check_ip_v4(self, reader, file_name):
for i in range(6):
address = '1.1.1.' + str(pow(2, i))
self.assertEqual({
'ip': address
}, reader.get(address), 'found expected data record for ' + address
+ ' in ' + file_name)
self.assertEqual({'ip': address}, reader.get(address),
'found expected data record for ' + address +
' in ' + file_name)

pairs = {
'1.1.1.3': '1.1.1.2',
Expand Down Expand Up @@ -372,10 +371,9 @@ def _check_ip_v6(self, reader, file_name):
]

for address in subnets:
self.assertEqual({
'ip': address
}, reader.get(address), 'found expected data record for ' + address
+ ' in ' + file_name)
self.assertEqual({'ip': address}, reader.get(address),
'found expected data record for ' + address +
' in ' + file_name)

pairs = {
'::2:0:1': '::2:0:0',
Expand All @@ -389,10 +387,9 @@ def _check_ip_v6(self, reader, file_name):
}

for key_address, value_address in pairs.items():
self.assertEqual({
'ip': value_address
}, reader.get(key_address), 'found expected data record for ' +
key_address + ' in ' + file_name)
self.assertEqual({'ip': value_address}, reader.get(key_address),
'found expected data record for ' + key_address +
' in ' + file_name)

for ip in ['1.1.1.33', '255.254.253.123', '89fa::']:
self.assertIsNone(reader.get(ip))
Expand Down