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
ef94ca08
Commit
ef94ca08
authored
Sep 29, 2012
by
William Tisäter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MEMORY_CACHE and MMAP_CACHE in Python 3 - issue #21
parent
a4d3785f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
pygeoip/__init__.py
+8
-4
pygeoip/util.py
+2
-2
No files found.
pygeoip/__init__.py
View file @
ef94ca08
...
...
@@ -42,7 +42,7 @@ from threading import Lock
try
:
from
StringIO
import
StringIO
except
ImportError
:
from
io
import
StringIO
from
io
import
StringIO
,
BytesIO
import
pygeoip.const
from
pygeoip
import
util
...
...
@@ -110,7 +110,8 @@ class GeoIP(GeoIPBase):
elif
self
.
_flags
&
const
.
MEMORY_CACHE
:
f
=
open
(
filename
,
'rb'
)
self
.
_memoryBuffer
=
f
.
read
()
self
.
_filehandle
=
StringIO
(
self
.
_memoryBuffer
)
iohandle
=
BytesIO
if
PY3
else
StringIO
self
.
_filehandle
=
iohandle
(
self
.
_memoryBuffer
)
f
.
close
()
else
:
...
...
@@ -150,7 +151,8 @@ class GeoIP(GeoIPBase):
flag
=
'unicode_escape'
delim
=
self
.
_filehandle
.
read
(
3
)
if
(
delim
==
chars
)
if
PY3
else
(
delim
==
unicode
(
chars
,
flag
)):
self
.
_databaseType
=
ord
(
self
.
_filehandle
.
read
(
1
))
byte
=
self
.
_filehandle
.
read
(
1
)
self
.
_databaseType
=
ord
(
byte
)
# Compatibility with databases from April 2003 and earlier
if
(
self
.
_databaseType
>=
106
):
...
...
@@ -212,7 +214,9 @@ class GeoIP(GeoIPBase):
x
=
[
0
,
0
]
for
i
in
range
(
2
):
for
j
in
range
(
self
.
_recordLength
):
x
[
i
]
+=
ord
(
buf
[
self
.
_recordLength
*
i
+
j
])
<<
(
j
*
8
)
byte
=
buf
[
self
.
_recordLength
*
i
+
j
]
magic
=
byte
if
type
(
byte
)
is
int
else
ord
(
byte
)
x
[
i
]
+=
magic
<<
(
j
*
8
)
if
ipnum
&
(
1
<<
depth
):
if
x
[
1
]
>=
self
.
_databaseSegments
:
return
x
[
1
]
...
...
pygeoip/util.py
View file @
ef94ca08
...
...
@@ -53,10 +53,10 @@ def ip2long_v4(ip):
if
PY3
:
# int and long are unified in py3
return
int
(
ip_array
[
0
])
*
16777216
+
int
(
ip_array
[
1
])
*
65536
+
\
int
(
ip_array
[
2
])
*
256
+
int
(
ip_array
[
3
])
int
(
ip_array
[
2
])
*
256
+
int
(
ip_array
[
3
])
else
:
return
long
(
ip_array
[
0
])
*
16777216
+
long
(
ip_array
[
1
])
*
65536
+
\
long
(
ip_array
[
2
])
*
256
+
long
(
ip_array
[
3
])
long
(
ip_array
[
2
])
*
256
+
long
(
ip_array
[
3
])
def
ip2long_v6
(
ip
):
...
...
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