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
d0f84176
Commit
d0f84176
authored
Oct 08, 2014
by
Gregory Oschwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for NetSpeedCell databases
parent
c1259b45
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
pygeoip/__init__.py
+13
-2
tests/test_netspeed_cell.py
+15
-0
No files found.
pygeoip/__init__.py
View file @
d0f84176
...
...
@@ -168,6 +168,8 @@ class GeoIP(object):
const
.
CITY_EDITION_REV1_V6
,
const
.
ORG_EDITION
,
const
.
ISP_EDITION
,
const
.
NETSPEED_EDITION_REV1
,
const
.
NETSPEED_EDITION_REV1_V6
,
const
.
ASNUM_EDITION
,
const
.
ASNUM_EDITION_V6
):
self
.
_databaseSegments
=
0
...
...
@@ -453,7 +455,15 @@ class GeoIP(object):
:arg addr: IP address (e.g. 203.0.113.30)
"""
return
const
.
NETSPEED_NAMES
[
self
.
id_by_addr
(
addr
)]
if
self
.
_databaseType
==
const
.
NETSPEED_EDITION
:
return
const
.
NETSPEED_NAMES
[
self
.
id_by_addr
(
addr
)]
elif
self
.
_databaseType
in
(
const
.
NETSPEED_EDITION_REV1
,
const
.
NETSPEED_EDITION_REV1_V6
):
ipnum
=
util
.
ip2long
(
addr
)
return
self
.
_get_org
(
ipnum
)
raise
GeoIPError
(
'Invalid database type, expected NetSpeed or NetSpeedCell'
)
def
netspeed_by_name
(
self
,
hostname
):
"""
...
...
@@ -496,7 +506,8 @@ class GeoIP(object):
:arg addr: IP address (e.g. 203.0.113.30)
"""
valid
=
(
const
.
ORG_EDITION
,
const
.
ISP_EDITION
,
const
.
ASNUM_EDITION
,
const
.
ASNUM_EDITION_V6
)
valid
=
(
const
.
ORG_EDITION
,
const
.
ISP_EDITION
,
const
.
ASNUM_EDITION
,
const
.
ASNUM_EDITION_V6
)
if
self
.
_databaseType
not
in
valid
:
message
=
'Invalid database type, expected Org, ISP or ASNum'
raise
GeoIPError
(
message
)
...
...
tests/test_netspeed_cell.py
0 → 100644
View file @
d0f84176
# -*- coding: utf-8 -*-
import
unittest
import
pygeoip
from
tests.config
import
NETSPEEDCELL_DB_PATH
class
TestGeoIPNetspeedCellFunctions
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
gi
=
pygeoip
.
GeoIP
(
NETSPEEDCELL_DB_PATH
)
def
testNetSpeedByAddrWrapper
(
self
):
netspeed
=
self
.
gi
.
netspeed_by_addr
(
'2.125.160.1'
)
self
.
assertEqual
(
netspeed
,
'Dialup'
)
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