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
71190eea
Commit
71190eea
authored
Sep 29, 2012
by
William Tisäter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary __future__ imports
parent
05322189
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
20 deletions
+18
-20
.gitignore
+2
-3
pygeoip/__init__.py
+15
-16
pygeoip/const.py
+1
-1
No files found.
.gitignore
View file @
71190eea
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
*env
*env
*.pyc
*.pyc
*.egg-info
*.egg-info
*.dat
tests/data/*
.tox
.tox
build
build
dist
dist
\ No newline at end of file
pygeoip/__init__.py
View file @
71190eea
...
@@ -32,7 +32,6 @@ You should have received a copy of the GNU Lesser General Public License
...
@@ -32,7 +32,6 @@ You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
"""
"""
from
__future__
import
with_statement
,
division
import
os
import
os
import
math
import
math
import
socket
import
socket
...
@@ -70,7 +69,6 @@ class GeoIPMetaclass(type):
...
@@ -70,7 +69,6 @@ class GeoIPMetaclass(type):
flag (default) and then try later to initialize with MEMORY_CACHE, it
flag (default) and then try later to initialize with MEMORY_CACHE, it
will still return the STANDARD one.
will still return the STANDARD one.
"""
"""
if
not
hasattr
(
cls
,
'_instances'
):
if
not
hasattr
(
cls
,
'_instances'
):
cls
.
_instances
=
{}
cls
.
_instances
=
{}
...
@@ -106,21 +104,19 @@ class GeoIP(GeoIPBase):
...
@@ -106,21 +104,19 @@ class GeoIP(GeoIPBase):
self
.
_flags
=
flags
self
.
_flags
=
flags
if
self
.
_flags
&
const
.
MMAP_CACHE
:
if
self
.
_flags
&
const
.
MMAP_CACHE
:
with
open
(
filename
,
'rb'
)
as
f
:
f
=
open
(
filename
,
'rb'
)
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
()
elif
self
.
_flags
&
const
.
MEMORY_CACHE
:
elif
self
.
_flags
&
const
.
MEMORY_CACHE
:
if
filename
.
endswith
(
'.gz'
):
f
=
open
(
filename
,
'rb'
)
opener
=
gzip
.
open
self
.
_memoryBuffer
=
f
.
read
()
else
:
self
.
_filehandle
=
StringIO
(
self
.
_memoryBuffer
)
opener
=
open
f
.
close
()
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'
,
'
iso-8859-
1'
)
self
.
_lock
=
Lock
()
self
.
_lock
=
Lock
()
self
.
_setup_segments
()
self
.
_setup_segments
()
...
@@ -158,15 +154,16 @@ class GeoIP(GeoIPBase):
...
@@ -158,15 +154,16 @@ class GeoIP(GeoIPBase):
if
(
delim
==
chars
)
if
PY3
else
(
delim
==
unicode
(
chars
,
flag
)):
if
(
delim
==
chars
)
if
PY3
else
(
delim
==
unicode
(
chars
,
flag
)):
self
.
_databaseType
=
ord
(
self
.
_filehandle
.
read
(
1
))
self
.
_databaseType
=
ord
(
self
.
_filehandle
.
read
(
1
))
# Backwards compatibility with databases from
# Compatibility with databases from April 2003 and earlier
# April 2003 and earlier
if
(
self
.
_databaseType
>=
106
):
if
(
self
.
_databaseType
>=
106
):
self
.
_databaseType
-=
105
self
.
_databaseType
-=
105
if
self
.
_databaseType
==
const
.
REGION_EDITION_REV0
:
if
self
.
_databaseType
==
const
.
REGION_EDITION_REV0
:
self
.
_databaseSegments
=
const
.
STATE_BEGIN_REV0
self
.
_databaseSegments
=
const
.
STATE_BEGIN_REV0
elif
self
.
_databaseType
==
const
.
REGION_EDITION_REV1
:
elif
self
.
_databaseType
==
const
.
REGION_EDITION_REV1
:
self
.
_databaseSegments
=
const
.
STATE_BEGIN_REV1
self
.
_databaseSegments
=
const
.
STATE_BEGIN_REV1
elif
self
.
_databaseType
in
(
const
.
CITY_EDITION_REV0
,
elif
self
.
_databaseType
in
(
const
.
CITY_EDITION_REV0
,
const
.
CITY_EDITION_REV1
,
const
.
CITY_EDITION_REV1
,
const
.
ORG_EDITION
,
const
.
ORG_EDITION
,
...
@@ -174,6 +171,7 @@ class GeoIP(GeoIPBase):
...
@@ -174,6 +171,7 @@ class GeoIP(GeoIPBase):
const
.
ASNUM_EDITION
):
const
.
ASNUM_EDITION
):
self
.
_databaseSegments
=
0
self
.
_databaseSegments
=
0
buf
=
self
.
_filehandle
.
read
(
const
.
SEGMENT_RECORD_LENGTH
)
buf
=
self
.
_filehandle
.
read
(
const
.
SEGMENT_RECORD_LENGTH
)
for
j
in
range
(
const
.
SEGMENT_RECORD_LENGTH
):
for
j
in
range
(
const
.
SEGMENT_RECORD_LENGTH
):
self
.
_databaseSegments
+=
(
ord
(
buf
[
j
])
<<
(
j
*
8
))
self
.
_databaseSegments
+=
(
ord
(
buf
[
j
])
<<
(
j
*
8
))
...
@@ -183,6 +181,7 @@ class GeoIP(GeoIPBase):
...
@@ -183,6 +181,7 @@ class GeoIP(GeoIPBase):
break
break
else
:
else
:
self
.
_filehandle
.
seek
(
-
4
,
os
.
SEEK_CUR
)
self
.
_filehandle
.
seek
(
-
4
,
os
.
SEEK_CUR
)
self
.
_filehandle
.
seek
(
filepos
,
os
.
SEEK_SET
)
self
.
_filehandle
.
seek
(
filepos
,
os
.
SEEK_SET
)
self
.
_lock
.
release
()
self
.
_lock
.
release
()
...
@@ -225,7 +224,7 @@ class GeoIP(GeoIPBase):
...
@@ -225,7 +224,7 @@ class GeoIP(GeoIPBase):
return
x
[
0
]
return
x
[
0
]
offset
=
x
[
0
]
offset
=
x
[
0
]
raise
Exception
(
'Error traversing database - perhaps it is corrupt?
'
)
raise
GeoIPError
(
'Corrupt database
'
)
def
_get_org
(
self
,
ipnum
):
def
_get_org
(
self
,
ipnum
):
"""
"""
...
...
pygeoip/const.py
View file @
71190eea
...
@@ -373,6 +373,7 @@ DATABASE_INFO_MAX_SIZE = 100
...
@@ -373,6 +373,7 @@ DATABASE_INFO_MAX_SIZE = 100
# Database editions
# Database editions
COUNTRY_EDITION
=
1
COUNTRY_EDITION
=
1
COUNTRY_EDITION_V6
=
12
REGION_EDITION_REV0
=
7
REGION_EDITION_REV0
=
7
REGION_EDITION_REV1
=
3
REGION_EDITION_REV1
=
3
CITY_EDITION_REV0
=
6
CITY_EDITION_REV0
=
6
...
@@ -383,7 +384,6 @@ ASNUM_EDITION = 9
...
@@ -383,7 +384,6 @@ ASNUM_EDITION = 9
# Not yet supported databases
# Not yet supported databases
PROXY_EDITION
=
8
PROXY_EDITION
=
8
NETSPEED_EDITION
=
11
NETSPEED_EDITION
=
11
COUNTRY_EDITION_V6
=
12
# Collection of databases
# Collection of databases
IPV6_EDITIONS
=
(
COUNTRY_EDITION_V6
,)
IPV6_EDITIONS
=
(
COUNTRY_EDITION_V6
,)
...
...
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