Skip to content

Commit 07547f3

Browse files
committed
Fail more usefully for MODE_MMAP_EXT without the extension
1 parent 2099787 commit 07547f3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

maxminddb/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ def open_database(database, mode=MODE_AUTO):
2727
* MODE_AUTO - tries MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that
2828
order. Default mode.
2929
"""
30-
if (mode == MODE_AUTO and maxminddb.extension and
31-
hasattr(maxminddb.extension, 'Reader')) or mode == MODE_MMAP_EXT:
30+
has_extension = maxminddb.extension and hasattr(maxminddb.extension, 'Reader')
31+
if (mode == MODE_AUTO and has_extension) or mode == MODE_MMAP_EXT:
32+
if not has_extension:
33+
raise ImportError(
34+
"MODE_MMAP_EXT requires the maxminddb.extension module to be available")
3235
return maxminddb.extension.Reader(database)
3336
elif mode in (MODE_AUTO, MODE_MMAP, MODE_FILE, MODE_MEMORY):
3437
return maxminddb.reader.Reader(database, mode)

0 commit comments

Comments
 (0)