Commit 3f72b3ea by Jiri Techet

Open database with correct encoding in mmap and mem cache mode

This is already done when database is open without caching or mmap. The current implementation
leads to different behaviour when different flags are used.
parent 4269ec8a
...@@ -101,13 +101,13 @@ class GeoIP(object): ...@@ -101,13 +101,13 @@ class GeoIP(object):
self._flags &= ~const.MMAP_CACHE self._flags &= ~const.MMAP_CACHE
if self._flags & const.MMAP_CACHE: if self._flags & const.MMAP_CACHE:
f = open(filename, 'rb') f = codecs.open(filename, 'rb', ENCODING)
access = mmap.ACCESS_READ access = mmap.ACCESS_READ
self._filehandle = mmap.mmap(f.fileno(), 0, access=access) self._filehandle = mmap.mmap(f.fileno(), 0, access=access)
f.close() f.close()
elif self._flags & const.MEMORY_CACHE: elif self._flags & const.MEMORY_CACHE:
f = open(filename, 'rb') f = codecs.open(filename, 'rb', ENCODING)
self._memoryBuffer = f.read() self._memoryBuffer = f.read()
iohandle = BytesIO if PY3 else StringIO iohandle = BytesIO if PY3 else StringIO
self._filehandle = iohandle(self._memoryBuffer) self._filehandle = iohandle(self._memoryBuffer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment