Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pygeoip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pygeoip
Commits
78a635b8
Commit
78a635b8
authored
Mar 28, 2012
by
Christian Hudon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for gzipped .dat files when in MEMORY_CACHE mode.
parent
f9e69e66
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
pygeoip/__init__.py
+10
-6
No files found.
pygeoip/__init__.py
View file @
78a635b8
...
...
@@ -32,6 +32,7 @@ import os
import
math
import
socket
import
mmap
import
gzip
from
.
import
const
from
.util
import
ip2long
...
...
@@ -78,11 +79,13 @@ class GeoIP(GeoIPBase):
"""
Initialize the class.
@param filename: path to a geoip database
@param filename: path to a geoip database. If MEMORY_CACHE is used,
the file can be gzipped.
@type filename: str
@param flags: flags that affect how the database is processed.
Currently the only supported flags are STANDARD, MEMORY_CACHE, and
MMAP_CACHE.
Currently the only supported flags are STANDARD (the default),
MEMORY_CACHE (preload the whole file into memory), and
MMAP_CACHE (access the file via mmap).
@type flags: int
"""
self
.
_filename
=
filename
...
...
@@ -92,12 +95,13 @@ class GeoIP(GeoIPBase):
with
open
(
filename
,
'rb'
)
as
f
:
self
.
_filehandle
=
mmap
.
mmap
(
f
.
fileno
(),
0
,
access
=
mmap
.
ACCESS_READ
)
elif
self
.
_flags
&
const
.
MEMORY_CACHE
:
self
.
_filehandle
=
gzip
.
open
(
filename
,
'rb'
)
self
.
_memoryBuffer
=
self
.
_filehandle
.
read
()
else
:
self
.
_filehandle
=
open
(
filename
,
'rb'
)
if
self
.
_flags
&
const
.
MEMORY_CACHE
:
self
.
_memoryBuffer
=
self
.
_filehandle
.
read
()
self
.
_setup_segments
()
def
_setup_segments
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment