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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

args = parser.parse_args()

random.seed(0)
reader = maxminddb.open_database(args.file, args.mode)


Expand Down
14 changes: 6 additions & 8 deletions maxminddb/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down