Commit eeaaa314 by Jennifer Ennis

merged pull request to fix #7

parent 536fbc2b
...@@ -34,6 +34,7 @@ import socket ...@@ -34,6 +34,7 @@ import socket
import mmap import mmap
import gzip import gzip
import codecs import codecs
from StringIO import StringIO
from . import const from . import const
from .util import ip2long from .util import ip2long
...@@ -97,9 +98,14 @@ class GeoIP(GeoIPBase): ...@@ -97,9 +98,14 @@ class GeoIP(GeoIPBase):
self._filehandle = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) self._filehandle = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
elif self._flags & const.MEMORY_CACHE: elif self._flags & const.MEMORY_CACHE:
self._filehandle = gzip.open(filename, 'rb') if filename.endswith('.gz'):
self._memoryBuffer = self._filehandle.read() opener = gzip.open
else:
opener = open
with opener(filename, 'rb') as f:
self._memoryBuffer = f.read()
self._filehandle = StringIO(self._memoryBuffer)
else: else:
self._filehandle = codecs.open(filename, 'rb','latin_1') self._filehandle = codecs.open(filename, 'rb','latin_1')
......
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