How to use the maxminddb.const.MODE_FD function in maxminddb

To help you get started, we’ve selected a few maxminddb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github m-lab / mlab-ns / server / mlabns / third_party / geoip2 / maxminddb / reader.py View on Github external
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_size = self._buffer.size()
            filename = database
        elif mode in (MODE_AUTO, MODE_FILE):
            self._buffer = FileBuffer(database)
            self._buffer_size = self._buffer.size()
            filename = database
        elif mode == MODE_MEMORY:
            with open(database, 'rb') as db_file:
                self._buffer = db_file.read()
                self._buffer_size = len(self._buffer)
            filename = database
        elif mode == MODE_FD:
            self._buffer = database.read()
            self._buffer_size = len(self._buffer)
            filename = database.name
        else:
            raise ValueError(
                'Unsupported open mode ({0}). Only MODE_AUTO, MODE_FILE, '
                'MODE_MEMORY and MODE_FD are supported by the pure Python '
                'Reader'.format(mode))

        metadata_start = self._buffer.rfind(
            self._METADATA_START_MARKER, max(0,
                                             self._buffer_size - 128 * 1024))

        if metadata_start == -1:
            self.close()
            raise InvalidDatabaseError('Error opening database file ({0}). '
github maxmind / MaxMind-DB-Reader-python / maxminddb / reader.py View on Github external
with open(database, 'rb') as db_file:
                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):
            self._buffer = FileBuffer(database)
            self._buffer_size = self._buffer.size()
            filename = database
        elif mode == MODE_MEMORY:
            with open(database, 'rb') as db_file:
                self._buffer = db_file.read()
                self._buffer_size = len(self._buffer)
            filename = database
        elif mode == MODE_FD:
            self._buffer = database.read()
            self._buffer_size = len(self._buffer)
            filename = database.name
        else:
            raise ValueError(
                'Unsupported open mode ({0}). Only MODE_AUTO, MODE_FILE, '
                'MODE_MEMORY and MODE_FD are supported by the pure Python '
                'Reader'.format(mode))

        metadata_start = self._buffer.rfind(
            self._METADATA_START_MARKER, max(0,
                                             self._buffer_size - 128 * 1024))

        if metadata_start == -1:
            self.close()
            raise InvalidDatabaseError('Error opening database file ({0}). '