Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* MODE_MMAP_EXT - use the C extension with memory map.
* MODE_MMAP - read from memory map. Pure Python.
* MODE_FILE - read database as standard file. Pure Python.
* MODE_MEMORY - load database into memory. Pure Python.
* MODE_FD - the param passed via database is a file descriptor, not
a path. This mode implies MODE_MEMORY.
* MODE_AUTO - tries MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that
order. Default mode.
"""
has_extension = maxminddb.extension and hasattr(maxminddb.extension, "Reader")
if (mode == MODE_AUTO and has_extension) or mode == MODE_MMAP_EXT:
if not has_extension:
raise ValueError(
"MODE_MMAP_EXT requires the maxminddb.extension module to be available"
)
return maxminddb.extension.Reader(database)
if mode in (MODE_AUTO, MODE_MMAP, MODE_FILE, MODE_MEMORY, MODE_FD):
return PyReader(database, mode)
raise ValueError("Unsupported open mode: {0}".format(mode))
* MODE_MMAP - read from memory map. Pure Python.
* MODE_FILE - read database as standard file. Pure Python.
* MODE_MEMORY - load database into memory. Pure Python.
* MODE_FD - the param passed via database is a file descriptor, not
a path. This mode implies MODE_MEMORY.
* MODE_AUTO - tries MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that
order. Default mode.
"""
has_extension = maxminddb.extension and hasattr(maxminddb.extension,
'Reader')
if (mode == MODE_AUTO and has_extension) or mode == MODE_MMAP_EXT:
if not has_extension:
raise ValueError(
"MODE_MMAP_EXT requires the maxminddb.extension module to be available"
)
return maxminddb.extension.Reader(database)
elif mode in (MODE_AUTO, MODE_MMAP, MODE_FILE, MODE_MEMORY, MODE_FD):
return maxminddb.reader.Reader(database, mode)
raise ValueError('Unsupported open mode: {0}'.format(mode))