diff --git a/.travis.yml b/.travis.yml index 08a2cda..17af7fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,8 @@ matrix: dist: trusty - python: 3.7 dist: xenial + - python: 3.8 + dist: xenial env: RUN_LINTER=1 - python: nightly dist: xenial diff --git a/examples/benchmark.py b/examples/benchmark.py index 80ebe8f..a74bd27 100644 --- a/examples/benchmark.py +++ b/examples/benchmark.py @@ -22,6 +22,7 @@ args = parser.parse_args() +random.seed(0) reader = maxminddb.open_database(args.file, args.mode) diff --git a/maxminddb/reader.py b/maxminddb/reader.py index 6d5b916..5654889 100644 --- a/maxminddb/reader.py +++ b/maxminddb/reader.py @@ -15,7 +15,7 @@ import struct -from maxminddb.compat import byte_from_int, compat_ip_address, string_type +from maxminddb.compat import compat_ip_address, string_type from maxminddb.const import MODE_AUTO, MODE_MMAP, MODE_FILE, MODE_MEMORY, MODE_FD from maxminddb.decoder import Decoder from maxminddb.errors import InvalidDatabaseError @@ -179,15 +179,13 @@ def _read_node(self, node_number, index): offset = base_offset + index * 3 node_bytes = b'\x00' + self._buffer[offset:offset + 3] elif record_size == 28: - (middle, ) = struct.unpack( - b'!B', self._buffer[base_offset + 3:base_offset + 4]) + offset = base_offset + 3 * index + node_bytes = bytearray(self._buffer[offset:offset + 4]) if index: - middle &= 0x0F + node_bytes[0] = 0x0F & node_bytes[0] else: - middle = (0xF0 & middle) >> 4 - offset = base_offset + index * 4 - node_bytes = byte_from_int(middle) + self._buffer[offset:offset + - 3] + middle = (0xF0 & node_bytes.pop()) >> 4 + node_bytes.insert(0, middle) elif record_size == 32: offset = base_offset + index * 4 node_bytes = self._buffer[offset:offset + 4]