Commit 85d0c92f by William Tisäter

Merge branch 'master' into continents

Conflicts:
	pygeoip/__init__.py
	pygeoip/const.py
parents 5e9d4771 28e45703
...@@ -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
Bootstrap manual for developers of pygeoip
Dependencies: tox, nose, epydoc
For testing we are using tox virtualenv-based Python version testing
and nose as test framwork.
Tox will create virtualenvs for all Python version pygeoip supports
and installs the current working tree using the setup.py install script.
Running the tests requires a couple of sample databases found on the
link below.
Maxmind sample databases for testing can be downloaded here:
http://www.defunct.cc/maxmind-geoip-samples.tar.gz (58 MB)
Extract the tarball in the tests directory and run tox from the root directory.
Please make sure your code passes all tests before opening pull requests.
All the best,
William Tisäter
Just run: Just run:
python setup.py install python setup.py install
\ No newline at end of file
recursive-include apidocs *
recursive-include tests *
include README.md
include COPYING
include DEVELOPER
include INSTALL
include epydoc.ini
include tox.ini
# Pure Python GeoIP API # # Pure Python GeoIP API #
The API is based on [MaxMind's C-based Python API](http://www.maxmind.com/app/python), The API is based on [MaxMind's C-based Python API](http://www.maxmind.com/app/python),
but the code itself is ported from the [Pure PHP GeoIP API](http://pear.php.net/package/Net_GeoIP) by Jim Winstead and Hans Lellelid. but the code itself is ported from the [Pure PHP GeoIP API](http://pear.php.net/package/Net_GeoIP) by Jim Winstead and Hans Lellelid.
It is mostly a drop-in replacement, except the `new` and `open` methods are gone. It is mostly a drop-in replacement, except the `new` and `open` methods are gone.
Tested using tox with Python version 2.5, 2.6, 2.7, 3.0 and 3.1. Tested using tox with Python version 2.5, 2.6, 2.7, 3.1, 3.2 and 3.3.
## Issues and contribution ## ## Issues and contribution ##
Bug reports are done by [creating an issue on Github](https://github.com/appliedsec/pygeoip/issues). If you want to contribute you can always [create a pull request](https://github.com/appliedsec/pygeoip/pulls) for discussion and code submission. Bug reports are done by [creating an issue on Github](https://github.com/appliedsec/pygeoip/issues). If you want to contribute you can always [create a pull request](https://github.com/appliedsec/pygeoip/pulls) for discussion and code submission.
## Installation ## ## Installation ##
You can easily install pygeoip with setuptools: You can easily install pygeoip with setuptools:
easy_install pygeoip easy_install pygeoip
## Supported Databases ## ## Supported Databases ##
* Country * Country
* Region * Region
* City * City
* Organization * Organization
* ISP * ISP
* ASN
## Quick Documentation ##
## Quick Documentation ##
Create your GeoIP instance with appropriate access flag. `STANDARD` reads data from disk when needed, `MEMORY_CACHE` loads database into memory on instantiation and `MMAP_CACHE` loads database into memory using mmap.
Create your GeoIP instance with appropriate access flag. `STANDARD` reads data from disk when needed, `MEMORY_CACHE` loads database into memory on instantiation and `MMAP_CACHE` loads database into memory using mmap.
import pygeoip
gi = pygeoip.GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE) import pygeoip
gi = pygeoip.GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE)
### Country lookup ###
### Country lookup ###
>>> gi.country_code_by_name('google.com')
'US' >>> gi.country_code_by_name('google.com')
>>> gi.country_code_by_addr('64.233.161.99') 'US'
'US' >>> gi.country_code_by_addr('64.233.161.99')
>>> gi.country_name_by_addr('64.233.161.99') 'US'
'United States' >>> gi.country_name_by_addr('64.233.161.99')
'United States'
### City lookup ###
### Region lookup ###
>>> gic = pygeoip.GeoIP('/path/to/GeoIPCity.dat')
>>> gic.record_by_addr('64.233.161.99') >>> gi = pygeoip.GeoIP('/path/to/GeoIPRegion.dat')
{ >>> gi.region_by_name('apple.com')
'city': 'Mountain View', {'region_name': 'CA', 'country_code': 'US'}
'region_name': 'CA',
'area_code': 650, ### City lookup ###
'longitude': -122.0574,
'country_code3': 'USA', >>> gi = pygeoip.GeoIP('/path/to/GeoIPCity.dat')
'latitude': 37.419199999999989, >>> gi.record_by_addr('64.233.161.99')
'postal_code': '94043', {
'dma_code': 807, 'city': 'Mountain View',
'country_code': 'US', 'region_name': 'CA',
'country_name': 'United States' 'area_code': 650,
} 'longitude': -122.0574,
'country_code3': 'USA',
### Timezone lookup ### 'latitude': 37.419199999999989,
'postal_code': '94043',
>>> gic = pygeoip.GeoIP('/path/to/GeoIPCity.dat') 'dma_code': 807,
>>> gic.time_zone_by_addr('64.233.161.99') 'country_code': 'US',
'America/Los_Angeles' 'country_name': 'United States'
}
For more information, [check out the full API documentation](http://packages.python.org/pygeoip). >>> gi.time_zone_by_addr('64.233.161.99')
\ No newline at end of file 'America/Los_Angeles'
### Organization lookup ###
>>> gi = pygeoip.GeoIP('/path/to/GeoIPOrg.dat')
>>> gi.org_by_name('dell.com')
'Dell Computer Corporation'
### ISP lookup ###
>>> gi = pygeoip.GeoIP('/path/to/GeoIPISP.dat')
>>> gi.org_by_name('cnn.com')
'Turner Broadcasting System'
### ASN lookup ###
>>> gi = pygeoip.GeoIP('/path/to/GeoIPASNum.dat')
>>> gi.org_by_name('cnn.com')
'AS5662 Turner Broadcasting'
For more information, [check out the full API documentation](http://packages.python.org/pygeoip).
pygeoip pygeoip-module.html pygeoip pygeoip-module.html
pygeoip.MMAP_CACHE pygeoip-module.html#MMAP_CACHE pygeoip.ENCODING pygeoip-module.html#ENCODING
pygeoip.STANDARD pygeoip-module.html#STANDARD
pygeoip.time_zone_by_country_and_region pygeoip.timezone-module.html#time_zone_by_country_and_region pygeoip.time_zone_by_country_and_region pygeoip.timezone-module.html#time_zone_by_country_and_region
pygeoip.MEMORY_CACHE pygeoip-module.html#MEMORY_CACHE
pygeoip.ip2long pygeoip.util-module.html#ip2long
pygeoip.__package__ pygeoip-module.html#__package__ pygeoip.__package__ pygeoip-module.html#__package__
pygeoip.STANDARD pygeoip-module.html#STANDARD
pygeoip.MMAP_CACHE pygeoip-module.html#MMAP_CACHE
pygeoip.MEMORY_CACHE pygeoip-module.html#MEMORY_CACHE
pygeoip.const pygeoip.const-module.html pygeoip.const pygeoip.const-module.html
pygeoip.const.GEOIP_STANDARD pygeoip.const-module.html#GEOIP_STANDARD pygeoip.const.GEOIP_STANDARD pygeoip.const-module.html#GEOIP_STANDARD
pygeoip.const.ENCODING pygeoip.const-module.html#ENCODING
pygeoip.const.COUNTRY_CODES3 pygeoip.const-module.html#COUNTRY_CODES3 pygeoip.const.COUNTRY_CODES3 pygeoip.const-module.html#COUNTRY_CODES3
pygeoip.const.PY3 pygeoip.const-module.html#PY3
pygeoip.const.IPV6_EDITIONS pygeoip.const-module.html#IPV6_EDITIONS
pygeoip.const.ORG_EDITION pygeoip.const-module.html#ORG_EDITION pygeoip.const.ORG_EDITION pygeoip.const-module.html#ORG_EDITION
pygeoip.const.ASNUM_EDITION pygeoip.const-module.html#ASNUM_EDITION pygeoip.const.ASNUM_EDITION pygeoip.const-module.html#ASNUM_EDITION
pygeoip.const.STRUCTURE_INFO_MAX_SIZE pygeoip.const-module.html#STRUCTURE_INFO_MAX_SIZE pygeoip.const.STRUCTURE_INFO_MAX_SIZE pygeoip.const-module.html#STRUCTURE_INFO_MAX_SIZE
...@@ -16,6 +19,7 @@ pygeoip.const.REGION_EDITION_REV0 pygeoip.const-module.html#REGION_EDITION_REV0 ...@@ -16,6 +19,7 @@ pygeoip.const.REGION_EDITION_REV0 pygeoip.const-module.html#REGION_EDITION_REV0
pygeoip.const.REGION_EDITION_REV1 pygeoip.const-module.html#REGION_EDITION_REV1 pygeoip.const.REGION_EDITION_REV1 pygeoip.const-module.html#REGION_EDITION_REV1
pygeoip.const.CANADA_OFFSET pygeoip.const-module.html#CANADA_OFFSET pygeoip.const.CANADA_OFFSET pygeoip.const-module.html#CANADA_OFFSET
pygeoip.const.MAX_ORG_RECORD_LENGTH pygeoip.const-module.html#MAX_ORG_RECORD_LENGTH pygeoip.const.MAX_ORG_RECORD_LENGTH pygeoip.const-module.html#MAX_ORG_RECORD_LENGTH
pygeoip.const.CITY_EDITIONS pygeoip.const-module.html#CITY_EDITIONS
pygeoip.const.__package__ pygeoip.const-module.html#__package__ pygeoip.const.__package__ pygeoip.const-module.html#__package__
pygeoip.const.CITY_EDITION_REV0 pygeoip.const-module.html#CITY_EDITION_REV0 pygeoip.const.CITY_EDITION_REV0 pygeoip.const-module.html#CITY_EDITION_REV0
pygeoip.const.STATE_BEGIN_REV1 pygeoip.const-module.html#STATE_BEGIN_REV1 pygeoip.const.STATE_BEGIN_REV1 pygeoip.const-module.html#STATE_BEGIN_REV1
...@@ -24,6 +28,7 @@ pygeoip.const.FULL_RECORD_LENGTH pygeoip.const-module.html#FULL_RECORD_LENGTH ...@@ -24,6 +28,7 @@ pygeoip.const.FULL_RECORD_LENGTH pygeoip.const-module.html#FULL_RECORD_LENGTH
pygeoip.const.COUNTRY_EDITION_V6 pygeoip.const-module.html#COUNTRY_EDITION_V6 pygeoip.const.COUNTRY_EDITION_V6 pygeoip.const-module.html#COUNTRY_EDITION_V6
pygeoip.const.ISP_EDITION pygeoip.const-module.html#ISP_EDITION pygeoip.const.ISP_EDITION pygeoip.const-module.html#ISP_EDITION
pygeoip.const.NETSPEED_EDITION pygeoip.const-module.html#NETSPEED_EDITION pygeoip.const.NETSPEED_EDITION pygeoip.const-module.html#NETSPEED_EDITION
pygeoip.const.PY2 pygeoip.const-module.html#PY2
pygeoip.const.WORLD_OFFSET pygeoip.const-module.html#WORLD_OFFSET pygeoip.const.WORLD_OFFSET pygeoip.const-module.html#WORLD_OFFSET
pygeoip.const.CITY_EDITION_REV1 pygeoip.const-module.html#CITY_EDITION_REV1 pygeoip.const.CITY_EDITION_REV1 pygeoip.const-module.html#CITY_EDITION_REV1
pygeoip.const.DATABASE_INFO_MAX_SIZE pygeoip.const-module.html#DATABASE_INFO_MAX_SIZE pygeoip.const.DATABASE_INFO_MAX_SIZE pygeoip.const-module.html#DATABASE_INFO_MAX_SIZE
...@@ -31,6 +36,7 @@ pygeoip.const.ORG_RECORD_LENGTH pygeoip.const-module.html#ORG_RECORD_LENGTH ...@@ -31,6 +36,7 @@ pygeoip.const.ORG_RECORD_LENGTH pygeoip.const-module.html#ORG_RECORD_LENGTH
pygeoip.const.COUNTRY_BEGIN pygeoip.const-module.html#COUNTRY_BEGIN pygeoip.const.COUNTRY_BEGIN pygeoip.const-module.html#COUNTRY_BEGIN
pygeoip.const.PROXY_EDITION pygeoip.const-module.html#PROXY_EDITION pygeoip.const.PROXY_EDITION pygeoip.const-module.html#PROXY_EDITION
pygeoip.const.STANDARD pygeoip.const-module.html#STANDARD pygeoip.const.STANDARD pygeoip.const-module.html#STANDARD
pygeoip.const.REGION_EDITIONS pygeoip.const-module.html#REGION_EDITIONS
pygeoip.const.FIPS_RANGE pygeoip.const-module.html#FIPS_RANGE pygeoip.const.FIPS_RANGE pygeoip.const-module.html#FIPS_RANGE
pygeoip.const.SEGMENT_RECORD_LENGTH pygeoip.const-module.html#SEGMENT_RECORD_LENGTH pygeoip.const.SEGMENT_RECORD_LENGTH pygeoip.const-module.html#SEGMENT_RECORD_LENGTH
pygeoip.const.COUNTRY_EDITION pygeoip.const-module.html#COUNTRY_EDITION pygeoip.const.COUNTRY_EDITION pygeoip.const-module.html#COUNTRY_EDITION
...@@ -40,6 +46,7 @@ pygeoip.const.MMAP_CACHE pygeoip.const-module.html#MMAP_CACHE ...@@ -40,6 +46,7 @@ pygeoip.const.MMAP_CACHE pygeoip.const-module.html#MMAP_CACHE
pygeoip.const.DMA_MAP pygeoip.const-module.html#DMA_MAP pygeoip.const.DMA_MAP pygeoip.const-module.html#DMA_MAP
pygeoip.const.COUNTRY_CODES pygeoip.const-module.html#COUNTRY_CODES pygeoip.const.COUNTRY_CODES pygeoip.const-module.html#COUNTRY_CODES
pygeoip.const.GEOIP_MEMORY_CACHE pygeoip.const-module.html#GEOIP_MEMORY_CACHE pygeoip.const.GEOIP_MEMORY_CACHE pygeoip.const-module.html#GEOIP_MEMORY_CACHE
pygeoip.const.REGION_CITY_EDITIONS pygeoip.const-module.html#REGION_CITY_EDITIONS
pygeoip.const.MEMORY_CACHE pygeoip.const-module.html#MEMORY_CACHE pygeoip.const.MEMORY_CACHE pygeoip.const-module.html#MEMORY_CACHE
pygeoip.const.MAX_RECORD_LENGTH pygeoip.const-module.html#MAX_RECORD_LENGTH pygeoip.const.MAX_RECORD_LENGTH pygeoip.const-module.html#MAX_RECORD_LENGTH
pygeoip.timezone pygeoip.timezone-module.html pygeoip.timezone pygeoip.timezone-module.html
...@@ -47,8 +54,10 @@ pygeoip.timezone._country pygeoip.timezone-module.html#_country ...@@ -47,8 +54,10 @@ pygeoip.timezone._country pygeoip.timezone-module.html#_country
pygeoip.timezone.time_zone_by_country_and_region pygeoip.timezone-module.html#time_zone_by_country_and_region pygeoip.timezone.time_zone_by_country_and_region pygeoip.timezone-module.html#time_zone_by_country_and_region
pygeoip.timezone.__package__ pygeoip.timezone-module.html#__package__ pygeoip.timezone.__package__ pygeoip.timezone-module.html#__package__
pygeoip.util pygeoip.util-module.html pygeoip.util pygeoip.util-module.html
pygeoip.util.ip2long pygeoip.util-module.html#ip2long
pygeoip.util.__package__ pygeoip.util-module.html#__package__ pygeoip.util.__package__ pygeoip.util-module.html#__package__
pygeoip.util.ip2long_v4 pygeoip.util-module.html#ip2long_v4
pygeoip.util.ip2long_v6 pygeoip.util-module.html#ip2long_v6
pygeoip.util.ip2long pygeoip.util-module.html#ip2long
pygeoip.GeoIP pygeoip.GeoIP-class.html pygeoip.GeoIP pygeoip.GeoIP-class.html
pygeoip.GeoIP.country_code_by_addr pygeoip.GeoIP-class.html#country_code_by_addr pygeoip.GeoIP.country_code_by_addr pygeoip.GeoIP-class.html#country_code_by_addr
pygeoip.GeoIP.region_by_name pygeoip.GeoIP-class.html#region_by_name pygeoip.GeoIP.region_by_name pygeoip.GeoIP-class.html#region_by_name
...@@ -56,15 +65,16 @@ pygeoip.GeoIP.record_by_name pygeoip.GeoIP-class.html#record_by_name ...@@ -56,15 +65,16 @@ pygeoip.GeoIP.record_by_name pygeoip.GeoIP-class.html#record_by_name
pygeoip.GeoIP._setup_segments pygeoip.GeoIP-class.html#_setup_segments pygeoip.GeoIP._setup_segments pygeoip.GeoIP-class.html#_setup_segments
pygeoip.GeoIP._seek_country pygeoip.GeoIP-class.html#_seek_country pygeoip.GeoIP._seek_country pygeoip.GeoIP-class.html#_seek_country
pygeoip.GeoIP.__init__ pygeoip.GeoIP-class.html#__init__ pygeoip.GeoIP.__init__ pygeoip.GeoIP-class.html#__init__
pygeoip.GeoIP.time_zone_by_name pygeoip.GeoIP-class.html#time_zone_by_name
pygeoip.GeoIP._get_region pygeoip.GeoIP-class.html#_get_region pygeoip.GeoIP._get_region pygeoip.GeoIP-class.html#_get_region
pygeoip.GeoIP.country_code_by_name pygeoip.GeoIP-class.html#country_code_by_name pygeoip.GeoIP.country_code_by_name pygeoip.GeoIP-class.html#country_code_by_name
pygeoip.GeoIP._get_org pygeoip.GeoIP-class.html#_get_org pygeoip.GeoIP._get_org pygeoip.GeoIP-class.html#_get_org
pygeoip.GeoIP._lookup_country_id pygeoip.GeoIP-class.html#_lookup_country_id
pygeoip.GeoIP.time_zone_by_addr pygeoip.GeoIP-class.html#time_zone_by_addr pygeoip.GeoIP.time_zone_by_addr pygeoip.GeoIP-class.html#time_zone_by_addr
pygeoip.GeoIP.id_by_addr pygeoip.GeoIP-class.html#id_by_addr
pygeoip.GeoIP.time_zone_by_name pygeoip.GeoIP-class.html#time_zone_by_name
pygeoip.GeoIP._get_record pygeoip.GeoIP-class.html#_get_record pygeoip.GeoIP._get_record pygeoip.GeoIP-class.html#_get_record
pygeoip.GeoIP.org_by_addr pygeoip.GeoIP-class.html#org_by_addr pygeoip.GeoIP.org_by_addr pygeoip.GeoIP-class.html#org_by_addr
pygeoip.GeoIP.region_by_addr pygeoip.GeoIP-class.html#region_by_addr pygeoip.GeoIP.region_by_addr pygeoip.GeoIP-class.html#region_by_addr
pygeoip.GeoIP._gethostbyname pygeoip.GeoIP-class.html#_gethostbyname
pygeoip.GeoIP.record_by_addr pygeoip.GeoIP-class.html#record_by_addr pygeoip.GeoIP.record_by_addr pygeoip.GeoIP-class.html#record_by_addr
pygeoip.GeoIP.country_name_by_addr pygeoip.GeoIP-class.html#country_name_by_addr pygeoip.GeoIP.country_name_by_addr pygeoip.GeoIP-class.html#country_name_by_addr
pygeoip.GeoIP.org_by_name pygeoip.GeoIP-class.html#org_by_name pygeoip.GeoIP.org_by_name pygeoip.GeoIP-class.html#org_by_name
......
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
...@@ -256,7 +256,7 @@ page was last updated. </p> ...@@ -256,7 +256,7 @@ page was last updated. </p>
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
...@@ -60,11 +60,11 @@ ...@@ -60,11 +60,11 @@
</b></center><br /> </b></center><br />
<h1 class="epydoc">Module Hierarchy</h1> <h1 class="epydoc">Module Hierarchy</h1>
<ul class="nomargin-top"> <ul class="nomargin-top">
<li> <strong class="uidlink"><a href="pygeoip-module.html">pygeoip</a></strong>: <em class="summary">Pure Python GeoIP API.</em> <li> <strong class="uidlink"><a href="pygeoip-module.html">pygeoip</a></strong>: <em class="summary">Pure Python GeoIP API</em>
<ul> <ul>
<li> <strong class="uidlink"><a href="pygeoip.const-module.html">pygeoip.const</a></strong>: <em class="summary">Constants needed for parsing binary GeoIP databases.</em> </li> <li> <strong class="uidlink"><a href="pygeoip.const-module.html">pygeoip.const</a></strong>: <em class="summary">Constants needed for the binary parser.</em> </li>
<li> <strong class="uidlink"><a href="pygeoip.timezone-module.html">pygeoip.timezone</a></strong> </li> <li> <strong class="uidlink"><a href="pygeoip.timezone-module.html">pygeoip.timezone</a></strong>: <em class="summary">Time zone functions.</em> </li>
<li> <strong class="uidlink"><a href="pygeoip.util-module.html">pygeoip.util</a></strong>: <em class="summary">Misc.</em> </li> <li> <strong class="uidlink"><a href="pygeoip.util-module.html">pygeoip.util</a></strong>: <em class="summary">Utility functions.</em> </li>
</ul> </ul>
</li> </li>
</ul> </ul>
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
...@@ -60,21 +60,14 @@ ...@@ -60,21 +60,14 @@
</table> </table>
<!-- ==================== PACKAGE DESCRIPTION ==================== --> <!-- ==================== PACKAGE DESCRIPTION ==================== -->
<h1 class="epydoc">Package pygeoip</h1><p class="nomargin-top"><span class="codelink"><a href="pygeoip-pysrc.html">source&nbsp;code</a></span></p> <h1 class="epydoc">Package pygeoip</h1><p class="nomargin-top"><span class="codelink"><a href="pygeoip-pysrc.html">source&nbsp;code</a></span></p>
<p>Pure Python GeoIP API. The API is based off of <a <p>Pure Python GeoIP API</p>
href="http://www.maxmind.com/app/python" target="_top">MaxMind's C-based <p>The API is based on MaxMind's C-based Python API, but the code itself
Python API</a>, but the code itself is based on the <a is ported from the Pure PHP GeoIP API by Jim Winstead and Hans
href="http://pear.php.net/package/Net_GeoIP/" target="_top">pure PHP5 Lellelid.</p>
API</a> by Jim Winstead and Hans Lellelid.</p>
<p>It is mostly a drop-in replacement, except the <code>new</code> and
<code>open</code> methods are gone. You should instantiate the <a
href="pygeoip.GeoIP-class.html" class="link">GeoIP</a> class
yourself:</p>
<p><code>gi = GeoIP('/path/to/GeoIP.dat',
pygeoip.MEMORY_CACHE)</code></p>
<hr /> <hr />
<div class="fields"> <p><strong>Author:</strong> <div class="fields"> <p><strong>Author:</strong>
Jennifer Ennis &lt;zaylea at gmail dot com&gt; Jennifer Ennis &lt;zaylea@gmail.com&gt;
</p> </p>
<p><strong>License:</strong> <p><strong>License:</strong>
Copyright(C) 2004 MaxMind LLC Copyright(C) 2004 MaxMind LLC
...@@ -109,9 +102,9 @@ ...@@ -109,9 +102,9 @@
</tr> </tr>
<tr><td class="summary"> <tr><td class="summary">
<ul class="nomargin"> <ul class="nomargin">
<li> <strong class="uidlink"><a href="pygeoip.const-module.html">pygeoip.const</a></strong>: <em class="summary">Constants needed for parsing binary GeoIP databases.</em> </li> <li> <strong class="uidlink"><a href="pygeoip.const-module.html">pygeoip.const</a></strong>: <em class="summary">Constants needed for the binary parser.</em> </li>
<li> <strong class="uidlink"><a href="pygeoip.timezone-module.html">pygeoip.timezone</a></strong> </li> <li> <strong class="uidlink"><a href="pygeoip.timezone-module.html">pygeoip.timezone</a></strong>: <em class="summary">Time zone functions.</em> </li>
<li> <strong class="uidlink"><a href="pygeoip.util-module.html">pygeoip.util</a></strong>: <em class="summary">Misc.</em> </li> <li> <strong class="uidlink"><a href="pygeoip.util-module.html">pygeoip.util</a></strong>: <em class="summary">Utility functions.</em> </li>
</ul></td></tr> </ul></td></tr>
</table> </table>
...@@ -183,6 +176,13 @@ ...@@ -183,6 +176,13 @@
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<a name="STANDARD"></a><span class="summary-name">STANDARD</span> = <code title="0">0</code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="MMAP_CACHE"></a><span class="summary-name">MMAP_CACHE</span> = <code title="8">8</code> <a name="MMAP_CACHE"></a><span class="summary-name">MMAP_CACHE</span> = <code title="8">8</code>
</td> </td>
</tr> </tr>
...@@ -197,7 +197,7 @@ ...@@ -197,7 +197,7 @@
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<a name="STANDARD"></a><span class="summary-name">STANDARD</span> = <code title="0">0</code> <a name="ENCODING"></a><span class="summary-name">ENCODING</span> = <code title="'iso-8859-1'"><code class="variable-quote">'</code><code class="variable-string">iso-8859-1</code><code class="variable-quote">'</code></code>
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -167,7 +167,7 @@ object --+ ...@@ -167,7 +167,7 @@ object --+
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
...@@ -177,7 +177,7 @@ exceptions.BaseException --+ ...@@ -177,7 +177,7 @@ exceptions.BaseException --+
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
...@@ -337,7 +337,7 @@ object --+ ...@@ -337,7 +337,7 @@ object --+
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
...@@ -61,12 +61,12 @@ ...@@ -61,12 +61,12 @@
</table> </table>
<!-- ==================== MODULE DESCRIPTION ==================== --> <!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module const</h1><p class="nomargin-top"><span class="codelink"><a href="pygeoip.const-pysrc.html">source&nbsp;code</a></span></p> <h1 class="epydoc">Module const</h1><p class="nomargin-top"><span class="codelink"><a href="pygeoip.const-pysrc.html">source&nbsp;code</a></span></p>
<p>Constants needed for parsing binary GeoIP databases. It is part of the <p>Constants needed for the binary parser. Part of the pygeoip
pygeoip package.</p> package.</p>
<hr /> <hr />
<div class="fields"> <p><strong>Author:</strong> <div class="fields"> <p><strong>Author:</strong>
Jennifer Ennis &lt;zaylea at gmail dot com&gt; Jennifer Ennis &lt;zaylea@gmail.com&gt;
</p> </p>
<p><strong>License:</strong> <p><strong>License:</strong>
Copyright(C) 2004 MaxMind LLC Copyright(C) 2004 MaxMind LLC
...@@ -103,6 +103,20 @@ ...@@ -103,6 +103,20 @@
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<a name="PY2"></a><span class="summary-name">PY2</span> = <code title="True">True</code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="PY3"></a><span class="summary-name">PY3</span> = <code title="False">False</code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="GEOIP_STANDARD"></a><span class="summary-name">GEOIP_STANDARD</span> = <code title="0">0</code> <a name="GEOIP_STANDARD"></a><span class="summary-name">GEOIP_STANDARD</span> = <code title="0">0</code>
</td> </td>
</tr> </tr>
...@@ -240,6 +254,13 @@ ...@@ -240,6 +254,13 @@
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<a name="COUNTRY_EDITION_V6"></a><span class="summary-name">COUNTRY_EDITION_V6</span> = <code title="12">12</code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="REGION_EDITION_REV0"></a><span class="summary-name">REGION_EDITION_REV0</span> = <code title="7">7</code> <a name="REGION_EDITION_REV0"></a><span class="summary-name">REGION_EDITION_REV0</span> = <code title="7">7</code>
</td> </td>
</tr> </tr>
...@@ -282,14 +303,14 @@ ...@@ -282,14 +303,14 @@
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<a name="PROXY_EDITION"></a><span class="summary-name">PROXY_EDITION</span> = <code title="8">8</code> <a name="ASNUM_EDITION"></a><span class="summary-name">ASNUM_EDITION</span> = <code title="9">9</code>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<a name="ASNUM_EDITION"></a><span class="summary-name">ASNUM_EDITION</span> = <code title="9">9</code> <a name="PROXY_EDITION"></a><span class="summary-name">PROXY_EDITION</span> = <code title="8">8</code>
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -303,7 +324,28 @@ ...@@ -303,7 +324,28 @@
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<a name="COUNTRY_EDITION_V6"></a><span class="summary-name">COUNTRY_EDITION_V6</span> = <code title="12">12</code> <a name="IPV6_EDITIONS"></a><span class="summary-name">IPV6_EDITIONS</span> = <code title="(12)"><code class="variable-group">(</code>12<code class="variable-group">)</code></code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="CITY_EDITIONS"></a><span class="summary-name">CITY_EDITIONS</span> = <code title="(6, 2)"><code class="variable-group">(</code>6<code class="variable-op">, </code>2<code class="variable-group">)</code></code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="REGION_EDITIONS"></a><span class="summary-name">REGION_EDITIONS</span> = <code title="(7, 3)"><code class="variable-group">(</code>7<code class="variable-op">, </code>3<code class="variable-group">)</code></code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="REGION_CITY_EDITIONS"></a><span class="summary-name">REGION_CITY_EDITIONS</span> = <code title="(7, 3, 6, 2)"><code class="variable-group">(</code>7<code class="variable-op">, </code>3<code class="variable-op">, </code>6<code class="variable-op">, </code>2<code class="variable-group">)</code></code>
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -380,7 +422,14 @@ ...@@ -380,7 +422,14 @@
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<a name="__package__"></a><span class="summary-name">__package__</span> = <code title="None">None</code> <a name="ENCODING"></a><span class="summary-name">ENCODING</span> = <code title="'iso-8859-1'"><code class="variable-quote">'</code><code class="variable-string">iso-8859-1</code><code class="variable-quote">'</code></code>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<a name="__package__"></a><span class="summary-name">__package__</span> = <code title="'pygeoip'"><code class="variable-quote">'</code><code class="variable-string">pygeoip</code><code class="variable-quote">'</code></code>
</td> </td>
</tr> </tr>
</table> </table>
...@@ -538,7 +587,7 @@ ...@@ -538,7 +587,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -61,7 +61,27 @@ ...@@ -61,7 +61,27 @@
</table> </table>
<!-- ==================== MODULE DESCRIPTION ==================== --> <!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module timezone</h1><p class="nomargin-top"><span class="codelink"><a href="pygeoip.timezone-pysrc.html">source&nbsp;code</a></span></p> <h1 class="epydoc">Module timezone</h1><p class="nomargin-top"><span class="codelink"><a href="pygeoip.timezone-pysrc.html">source&nbsp;code</a></span></p>
<!-- ==================== FUNCTIONS ==================== --> <p>Time zone functions. Part of the pygeoip package.</p>
<hr />
<div class="fields"> <p><strong>Author:</strong>
Jennifer Ennis &lt;zaylea@gmail.com&gt;
</p>
<p><strong>License:</strong>
Copyright(C) 2004 MaxMind LLC
<p>This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.</p>
<p>This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.</p>
<p>You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
&lt;http://www.gnu.org/licenses/lgpl.txt&gt;.</p>
</p>
</div><!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a> <a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3" <table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white"> cellspacing="0" width="100%" bgcolor="white">
...@@ -212,7 +232,7 @@ ...@@ -212,7 +232,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -61,11 +61,11 @@ ...@@ -61,11 +61,11 @@
</table> </table>
<!-- ==================== MODULE DESCRIPTION ==================== --> <!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module util</h1><p class="nomargin-top"><span class="codelink"><a href="pygeoip.util-pysrc.html">source&nbsp;code</a></span></p> <h1 class="epydoc">Module util</h1><p class="nomargin-top"><span class="codelink"><a href="pygeoip.util-pysrc.html">source&nbsp;code</a></span></p>
<p>Misc. utility functions. It is part of the pygeoip package.</p> <p>Utility functions. Part of the pygeoip package.</p>
<hr /> <hr />
<div class="fields"> <p><strong>Author:</strong> <div class="fields"> <p><strong>Author:</strong>
Jennifer Ennis &lt;zaylea at gmail dot com&gt; Jennifer Ennis &lt;zaylea@gmail.com&gt;
</p> </p>
<p><strong>License:</strong> <p><strong>License:</strong>
Copyright(C) 2004 MaxMind LLC Copyright(C) 2004 MaxMind LLC
...@@ -100,12 +100,12 @@ ...@@ -100,12 +100,12 @@
</tr> </tr>
<tr> <tr>
<td width="15%" align="right" valign="top" class="summary"> <td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">int</span> <span class="summary-type">&nbsp;</span>
</td><td class="summary"> </td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0"> <table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> <tr>
<td><span class="summary-sig"><a href="pygeoip.util-module.html#ip2long" class="summary-sig-name">ip2long</a>(<span class="summary-sig-arg">ip</span>)</span><br /> <td><span class="summary-sig"><a href="pygeoip.util-module.html#ip2long" class="summary-sig-name">ip2long</a>(<span class="summary-sig-arg">ip</span>)</span><br />
Convert a IPv4 address into a 32-bit integer.</td> Wrapper function for IPv4 and IPv6 converters</td>
<td align="right" valign="top"> <td align="right" valign="top">
<span class="codelink"><a href="pygeoip.util-pysrc.html#ip2long">source&nbsp;code</a></span> <span class="codelink"><a href="pygeoip.util-pysrc.html#ip2long">source&nbsp;code</a></span>
...@@ -115,6 +115,40 @@ ...@@ -115,6 +115,40 @@
</td> </td>
</tr> </tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">int</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="pygeoip.util-module.html#ip2long_v4" class="summary-sig-name">ip2long_v4</a>(<span class="summary-sig-arg">ip</span>)</span><br />
Convert a IPv4 address into a 32-bit integer.</td>
<td align="right" valign="top">
<span class="codelink"><a href="pygeoip.util-pysrc.html#ip2long_v4">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">long</span>
</td><td class="summary">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><span class="summary-sig"><a href="pygeoip.util-module.html#ip2long_v6" class="summary-sig-name">ip2long_v6</a>(<span class="summary-sig-arg">ip</span>)</span><br />
Convert a IPv6 address into long.</td>
<td align="right" valign="top">
<span class="codelink"><a href="pygeoip.util-pysrc.html#ip2long_v6">source&nbsp;code</a></span>
</td>
</tr>
</table>
</td>
</tr>
</table> </table>
<!-- ==================== VARIABLES ==================== --> <!-- ==================== VARIABLES ==================== -->
<a name="section-Variables"></a> <a name="section-Variables"></a>
...@@ -173,6 +207,29 @@ ...@@ -173,6 +207,29 @@
</td> </td>
</tr></table> </tr></table>
<p>Wrapper function for IPv4 and IPv6 converters</p>
<dl class="fields">
<dt>Parameters:</dt>
<dd><ul class="nomargin-top">
<li><strong class="pname"><code>ip</code></strong> (str) - IPv4 or IPv6 address</li>
</ul></dd>
</dl>
</td></tr></table>
</div>
<a name="ip2long_v4"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">ip2long_v4</span>(<span class="sig-arg">ip</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="pygeoip.util-pysrc.html#ip2long_v4">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>Convert a IPv4 address into a 32-bit integer.</p> <p>Convert a IPv4 address into a 32-bit integer.</p>
<dl class="fields"> <dl class="fields">
<dt>Parameters:</dt> <dt>Parameters:</dt>
...@@ -184,6 +241,31 @@ ...@@ -184,6 +241,31 @@
</dl> </dl>
</td></tr></table> </td></tr></table>
</div> </div>
<a name="ip2long_v6"></a>
<div>
<table class="details" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td>
<h3 class="epydoc"><span class="sig"><span class="sig-name">ip2long_v6</span>(<span class="sig-arg">ip</span>)</span>
</h3>
</td><td align="right" valign="top"
><span class="codelink"><a href="pygeoip.util-pysrc.html#ip2long_v6">source&nbsp;code</a></span>&nbsp;
</td>
</tr></table>
<p>Convert a IPv6 address into long.</p>
<dl class="fields">
<dt>Parameters:</dt>
<dd><ul class="nomargin-top">
<li><strong class="pname"><code>ip</code></strong> (str) - IPv6 address</li>
</ul></dd>
<dt>Returns: long</dt>
<dd>network byte order long</dd>
</dl>
</td></tr></table>
</div>
<br /> <br />
<!-- ==================== NAVIGATION BAR ==================== --> <!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0" <table class="navbar" border="0" width="100%" cellpadding="0"
...@@ -216,7 +298,7 @@ ...@@ -216,7 +298,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%"> <table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr> <tr>
<td align="left" class="footer"> <td align="left" class="footer">
Generated by Epydoc 3.0.1 on Thu Sep 20 17:58:04 2012 Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td> </td>
<td align="right" class="footer"> <td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net" <a target="mainFrame" href="http://epydoc.sourceforge.net"
......
...@@ -20,14 +20,18 @@ ...@@ -20,14 +20,18 @@
>pygeoip.GeoIPMetaclass</a><br /> <h2 class="toc">All Functions</h2> >pygeoip.GeoIPMetaclass</a><br /> <h2 class="toc">All Functions</h2>
<a target="mainFrame" href="pygeoip.timezone-module.html#time_zone_by_country_and_region" <a target="mainFrame" href="pygeoip.timezone-module.html#time_zone_by_country_and_region"
>pygeoip.timezone.time_zone_by_country_and_region</a><br /> <a target="mainFrame" href="pygeoip.util-module.html#ip2long" >pygeoip.timezone.time_zone_by_country_and_region</a><br /> <a target="mainFrame" href="pygeoip.util-module.html#ip2long"
>pygeoip.util.ip2long</a><br /> <h2 class="toc">All Variables</h2> >pygeoip.util.ip2long</a><br /> <a target="mainFrame" href="pygeoip.util-module.html#ip2long_v4"
<a target="mainFrame" href="pygeoip-module.html#MEMORY_CACHE" >pygeoip.util.ip2long_v4</a><br /> <a target="mainFrame" href="pygeoip.util-module.html#ip2long_v6"
>pygeoip.util.ip2long_v6</a><br /> <h2 class="toc">All Variables</h2>
<a target="mainFrame" href="pygeoip-module.html#ENCODING"
>pygeoip.ENCODING</a><br /> <a target="mainFrame" href="pygeoip-module.html#MEMORY_CACHE"
>pygeoip.MEMORY_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#MMAP_CACHE" >pygeoip.MEMORY_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#MMAP_CACHE"
>pygeoip.MMAP_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#STANDARD" >pygeoip.MMAP_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#STANDARD"
>pygeoip.STANDARD</a><br /> <a target="mainFrame" href="pygeoip-module.html#__package__" >pygeoip.STANDARD</a><br /> <a target="mainFrame" href="pygeoip-module.html#__package__"
>pygeoip.__package__</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ASNUM_EDITION" >pygeoip.__package__</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ASNUM_EDITION"
>pygeoip.const.ASNUM_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CANADA_OFFSET" >pygeoip.const.ASNUM_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CANADA_OFFSET"
>pygeoip.const.CANADA_OFFSET</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITION_REV0" >pygeoip.const.CANADA_OFFSET</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITIONS"
>pygeoip.const.CITY_EDITIONS</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITION_REV0"
>pygeoip.const.CITY_EDITION_REV0</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITION_REV1" >pygeoip.const.CITY_EDITION_REV0</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITION_REV1"
>pygeoip.const.CITY_EDITION_REV1</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_BEGIN" >pygeoip.const.CITY_EDITION_REV1</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_BEGIN"
>pygeoip.const.COUNTRY_BEGIN</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_CODES" >pygeoip.const.COUNTRY_BEGIN</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_CODES"
...@@ -37,11 +41,13 @@ ...@@ -37,11 +41,13 @@
>pygeoip.const.COUNTRY_EDITION_V6</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_NAMES" >pygeoip.const.COUNTRY_EDITION_V6</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_NAMES"
>pygeoip.const.COUNTRY_NAMES</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#DATABASE_INFO_MAX_SIZE" >pygeoip.const.COUNTRY_NAMES</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#DATABASE_INFO_MAX_SIZE"
>pygeoip.const.DATABASE_INFO_MAX_SIZE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#DMA_MAP" >pygeoip.const.DATABASE_INFO_MAX_SIZE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#DMA_MAP"
>pygeoip.const.DMA_MAP</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#FIPS_RANGE" >pygeoip.const.DMA_MAP</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ENCODING"
>pygeoip.const.ENCODING</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#FIPS_RANGE"
>pygeoip.const.FIPS_RANGE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#FULL_RECORD_LENGTH" >pygeoip.const.FIPS_RANGE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#FULL_RECORD_LENGTH"
>pygeoip.const.FULL_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#GEOIP_MEMORY_CACHE" >pygeoip.const.FULL_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#GEOIP_MEMORY_CACHE"
>pygeoip.const.GEOIP_MEMORY_CACHE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#GEOIP_STANDARD" >pygeoip.const.GEOIP_MEMORY_CACHE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#GEOIP_STANDARD"
>pygeoip.const.GEOIP_STANDARD</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ISP_EDITION" >pygeoip.const.GEOIP_STANDARD</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#IPV6_EDITIONS"
>pygeoip.const.IPV6_EDITIONS</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ISP_EDITION"
>pygeoip.const.ISP_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MAX_ORG_RECORD_LENGTH" >pygeoip.const.ISP_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MAX_ORG_RECORD_LENGTH"
>pygeoip.const.MAX_ORG_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MAX_RECORD_LENGTH" >pygeoip.const.MAX_ORG_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MAX_RECORD_LENGTH"
>pygeoip.const.MAX_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MEMORY_CACHE" >pygeoip.const.MAX_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MEMORY_CACHE"
...@@ -50,7 +56,11 @@ ...@@ -50,7 +56,11 @@
>pygeoip.const.NETSPEED_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ORG_EDITION" >pygeoip.const.NETSPEED_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ORG_EDITION"
>pygeoip.const.ORG_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ORG_RECORD_LENGTH" >pygeoip.const.ORG_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ORG_RECORD_LENGTH"
>pygeoip.const.ORG_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#PROXY_EDITION" >pygeoip.const.ORG_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#PROXY_EDITION"
>pygeoip.const.PROXY_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITION_REV0" >pygeoip.const.PROXY_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#PY2"
>pygeoip.const.PY2</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#PY3"
>pygeoip.const.PY3</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_CITY_EDITIONS"
>pygeoip.const.REGION_CITY_EDITIONS</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITIONS"
>pygeoip.const.REGION_EDITIONS</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITION_REV0"
>pygeoip.const.REGION_EDITION_REV0</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITION_REV1" >pygeoip.const.REGION_EDITION_REV0</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITION_REV1"
>pygeoip.const.REGION_EDITION_REV1</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#SEGMENT_RECORD_LENGTH" >pygeoip.const.REGION_EDITION_REV1</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#SEGMENT_RECORD_LENGTH"
>pygeoip.const.SEGMENT_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#STANDARD" >pygeoip.const.SEGMENT_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#STANDARD"
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
>GeoIPBase</a><br /> <a target="mainFrame" href="pygeoip.GeoIPError-class.html" >GeoIPBase</a><br /> <a target="mainFrame" href="pygeoip.GeoIPError-class.html"
>GeoIPError</a><br /> <a target="mainFrame" href="pygeoip.GeoIPMetaclass-class.html" >GeoIPError</a><br /> <a target="mainFrame" href="pygeoip.GeoIPMetaclass-class.html"
>GeoIPMetaclass</a><br /> <h2 class="toc">Variables</h2> >GeoIPMetaclass</a><br /> <h2 class="toc">Variables</h2>
<a target="mainFrame" href="pygeoip-module.html#MEMORY_CACHE" <a target="mainFrame" href="pygeoip-module.html#ENCODING"
>ENCODING</a><br /> <a target="mainFrame" href="pygeoip-module.html#MEMORY_CACHE"
>MEMORY_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#MMAP_CACHE" >MEMORY_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#MMAP_CACHE"
>MMAP_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#STANDARD" >MMAP_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#STANDARD"
>STANDARD</a><br /> <a target="mainFrame" href="pygeoip-module.html#__package__" >STANDARD</a><br /> <a target="mainFrame" href="pygeoip-module.html#__package__"
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
<h2 class="toc">Variables</h2> <h2 class="toc">Variables</h2>
<a target="mainFrame" href="pygeoip.const-module.html#ASNUM_EDITION" <a target="mainFrame" href="pygeoip.const-module.html#ASNUM_EDITION"
>ASNUM_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CANADA_OFFSET" >ASNUM_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CANADA_OFFSET"
>CANADA_OFFSET</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITION_REV0" >CANADA_OFFSET</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITIONS"
>CITY_EDITIONS</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITION_REV0"
>CITY_EDITION_REV0</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITION_REV1" >CITY_EDITION_REV0</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#CITY_EDITION_REV1"
>CITY_EDITION_REV1</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_BEGIN" >CITY_EDITION_REV1</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_BEGIN"
>COUNTRY_BEGIN</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_CODES" >COUNTRY_BEGIN</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_CODES"
...@@ -25,11 +26,13 @@ ...@@ -25,11 +26,13 @@
>COUNTRY_EDITION_V6</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_NAMES" >COUNTRY_EDITION_V6</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#COUNTRY_NAMES"
>COUNTRY_NAMES</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#DATABASE_INFO_MAX_SIZE" >COUNTRY_NAMES</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#DATABASE_INFO_MAX_SIZE"
>DATABASE_INFO_MAX_SIZE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#DMA_MAP" >DATABASE_INFO_MAX_SIZE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#DMA_MAP"
>DMA_MAP</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#FIPS_RANGE" >DMA_MAP</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ENCODING"
>ENCODING</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#FIPS_RANGE"
>FIPS_RANGE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#FULL_RECORD_LENGTH" >FIPS_RANGE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#FULL_RECORD_LENGTH"
>FULL_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#GEOIP_MEMORY_CACHE" >FULL_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#GEOIP_MEMORY_CACHE"
>GEOIP_MEMORY_CACHE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#GEOIP_STANDARD" >GEOIP_MEMORY_CACHE</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#GEOIP_STANDARD"
>GEOIP_STANDARD</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ISP_EDITION" >GEOIP_STANDARD</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#IPV6_EDITIONS"
>IPV6_EDITIONS</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ISP_EDITION"
>ISP_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MAX_ORG_RECORD_LENGTH" >ISP_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MAX_ORG_RECORD_LENGTH"
>MAX_ORG_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MAX_RECORD_LENGTH" >MAX_ORG_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MAX_RECORD_LENGTH"
>MAX_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MEMORY_CACHE" >MAX_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#MEMORY_CACHE"
...@@ -38,7 +41,11 @@ ...@@ -38,7 +41,11 @@
>NETSPEED_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ORG_EDITION" >NETSPEED_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ORG_EDITION"
>ORG_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ORG_RECORD_LENGTH" >ORG_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#ORG_RECORD_LENGTH"
>ORG_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#PROXY_EDITION" >ORG_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#PROXY_EDITION"
>PROXY_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITION_REV0" >PROXY_EDITION</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#PY2"
>PY2</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#PY3"
>PY3</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_CITY_EDITIONS"
>REGION_CITY_EDITIONS</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITIONS"
>REGION_EDITIONS</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITION_REV0"
>REGION_EDITION_REV0</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITION_REV1" >REGION_EDITION_REV0</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#REGION_EDITION_REV1"
>REGION_EDITION_REV1</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#SEGMENT_RECORD_LENGTH" >REGION_EDITION_REV1</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#SEGMENT_RECORD_LENGTH"
>SEGMENT_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#STANDARD" >SEGMENT_RECORD_LENGTH</a><br /> <a target="mainFrame" href="pygeoip.const-module.html#STANDARD"
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
<hr /> <hr />
<h2 class="toc">Functions</h2> <h2 class="toc">Functions</h2>
<a target="mainFrame" href="pygeoip.util-module.html#ip2long" <a target="mainFrame" href="pygeoip.util-module.html#ip2long"
>ip2long</a><br /> <h2 class="toc">Variables</h2> >ip2long</a><br /> <a target="mainFrame" href="pygeoip.util-module.html#ip2long_v4"
>ip2long_v4</a><br /> <a target="mainFrame" href="pygeoip.util-module.html#ip2long_v6"
>ip2long_v6</a><br /> <h2 class="toc">Variables</h2>
<a target="mainFrame" href="pygeoip.util-module.html#__package__" <a target="mainFrame" href="pygeoip.util-module.html#__package__"
>__package__</a><br /><hr /> >__package__</a><br /><hr />
<span class="options">[<a href="javascript:void(0);" class="privatelink" <span class="options">[<a href="javascript:void(0);" class="privatelink"
......
""" # -*- coding: utf-8 -*-
Misc. utility functions. It is part of the pygeoip package. """
Utility functions. Part of the pygeoip package.
@author: Jennifer Ennis <zaylea at gmail dot com>
@author: Jennifer Ennis <zaylea@gmail.com>
@license:
Copyright(C) 2004 MaxMind LLC @license: Copyright(C) 2004 MaxMind LLC
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License 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>.
""" """
import six import socket
import binascii
def ip2long(ip):
"""
Convert a IPv4 address into a 32-bit integer. def ip2long(ip):
"""
@param ip: quad-dotted IPv4 address Wrapper function for IPv4 and IPv6 converters
@type ip: str @param ip: IPv4 or IPv6 address
@return: network byte order 32-bit integer @type ip: str
@rtype: int """
""" try:
ip_array = ip.split('.') return int(binascii.hexlify(socket.inet_aton(ip)), 16)
except socket.error:
if six.PY3: return int(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16)
# int and long are unified in py3
ip_long = int(ip_array[0]) * 16777216 + int(ip_array[1]) * 65536 + int(ip_array[2]) * 256 + int(ip_array[3])
else:
ip_long = long(ip_array[0]) * 16777216 + long(ip_array[1]) * 65536 + long(ip_array[2]) * 256 + long(ip_array[3])
return ip_long
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*-
""" """
Setup file for pygeoip package. Setup file for pygeoip package.
...@@ -33,15 +33,17 @@ setup(name='pygeoip', ...@@ -33,15 +33,17 @@ setup(name='pygeoip',
description='Pure Python GeoIP API', description='Pure Python GeoIP API',
author='Jennifer Ennis', author='Jennifer Ennis',
author_email='zaylea@gmail.com', author_email='zaylea@gmail.com',
url='http://code.google.com/p/pygeoip/', maintainer='William Tisäter',
maintainer_email='william@defunct.cc',
url='https://github.com/appliedsec/pygeoip',
classifiers=['Programming Language :: Python', classifiers=['Programming Language :: Python',
'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.1', 'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2'], 'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3'],
packages=['pygeoip'], packages=['pygeoip'],
install_requires=['six'], license='LGPLv3+',
license='LGPL',
keywords='geoip') keywords='geoip')
...@@ -3,6 +3,9 @@ import os.path as path ...@@ -3,6 +3,9 @@ import os.path as path
DATA_DIR = path.join(path.dirname(path.realpath(__file__)), 'data') DATA_DIR = path.join(path.dirname(path.realpath(__file__)), 'data')
COUNTRY_DB_PATH = path.join(DATA_DIR, 'GeoIP.dat') COUNTRY_DB_PATH = path.join(DATA_DIR, 'GeoIP.dat')
COUNTRY_V6_DB_PATH = path.join(DATA_DIR, 'GeoIPv6.dat')
REGION_DB_PATH = path.join(DATA_DIR, 'GeoIPRegion.dat') REGION_DB_PATH = path.join(DATA_DIR, 'GeoIPRegion.dat')
CITY_DB_PATH = path.join(DATA_DIR, 'GeoLiteCity.dat') CITY_DB_PATH = path.join(DATA_DIR, 'GeoLiteCity.dat')
ORG_DB_PATH = path.join(DATA_DIR, 'GeoIPOrg.dat') ORG_DB_PATH = path.join(DATA_DIR, 'GeoIPOrg.dat')
ASNUM_DB_PATH = path.join(DATA_DIR, 'GeoIPASNum.dat')
ISP_DB_PATH = path.join(DATA_DIR, 'GeoIPISP.dat')
# -*- coding: utf-8 -*-
import unittest
import pygeoip
from tests.config import ASNUM_DB_PATH
class TestGeoIPASNumFunctions(unittest.TestCase):
def setUp(self):
self.us_as = 'AS15169 Google Inc.'
self.us_ip = '64.233.161.99'
self.us_hostname = 'google.com'
self.gb_as = 'AS2818 BBC Internet Services, UK'
self.gb_ip = '212.58.253.68'
self.gb_hostname = 'bbc.com'
self.gia = pygeoip.GeoIP(ASNUM_DB_PATH)
def testOrgByAddr(self):
gb_as = self.gia.org_by_addr(self.gb_ip)
us_as = self.gia.org_by_addr(self.us_ip)
self.assertEqual(gb_as, self.gb_as)
self.assertEqual(us_as, self.us_as)
def testOrgByName(self):
gb_as = self.gia.org_by_name(self.gb_hostname)
us_as = self.gia.org_by_name(self.us_hostname)
self.assertEqual(gb_as, self.gb_as)
self.assertEqual(us_as, self.us_as)
# -*- coding: utf-8 -*-
import unittest
import pygeoip
from pygeoip import MEMORY_CACHE, MMAP_CACHE, STANDARD
from tests.config import COUNTRY_DB_PATH
class TestGeoIPCacheMethods(unittest.TestCase):
def setUp(self):
self.us_ip = '64.233.161.99'
self.us_code = 'US'
self.gi_mmap = pygeoip.GeoIP(COUNTRY_DB_PATH, MMAP_CACHE)
self.gi_memory = pygeoip.GeoIP(COUNTRY_DB_PATH, MEMORY_CACHE)
self.gi_standard = pygeoip.GeoIP(COUNTRY_DB_PATH, STANDARD)
def testCountryCodeByAddr(self):
code_mmap = self.gi_mmap.country_code_by_addr(self.us_ip)
code_memory = self.gi_memory.country_code_by_addr(self.us_ip)
code_standard = self.gi_standard.country_code_by_addr(self.us_ip)
self.assertEqual(code_mmap, self.us_code)
self.assertEqual(code_memory, self.us_code)
self.assertEqual(code_standard, self.us_code)
...@@ -40,7 +40,8 @@ class TestGeoIPCityFunctions(unittest.TestCase): ...@@ -40,7 +40,8 @@ class TestGeoIPCityFunctions(unittest.TestCase):
'longitude': -0.23339999999998895, 'longitude': -0.23339999999998895,
'country_code3': 'GBR', 'country_code3': 'GBR',
'latitude': 51.283299999999997, 'latitude': 51.283299999999997,
'postal_code': None, 'dma_code': 0, 'postal_code': '',
'dma_code': 0,
'country_code': 'GB', 'country_code': 'GB',
'country_name': 'United Kingdom', 'country_name': 'United Kingdom',
'time_zone': 'Europe/London' 'time_zone': 'Europe/London'
...@@ -50,6 +51,8 @@ class TestGeoIPCityFunctions(unittest.TestCase): ...@@ -50,6 +51,8 @@ class TestGeoIPCityFunctions(unittest.TestCase):
self.gb_region_data = {'region_name': 'N7', 'country_code': 'GB'} self.gb_region_data = {'region_name': 'N7', 'country_code': 'GB'}
self.gic = pygeoip.GeoIP(CITY_DB_PATH) self.gic = pygeoip.GeoIP(CITY_DB_PATH)
self.gic_mem = pygeoip.GeoIP(CITY_DB_PATH, pygeoip.MEMORY_CACHE)
self.gic_mmap = pygeoip.GeoIP(CITY_DB_PATH, pygeoip.MMAP_CACHE)
def testCountryCodeByName(self): def testCountryCodeByName(self):
us_code = self.gic.country_code_by_name(self.us_hostname) us_code = self.gic.country_code_by_name(self.us_hostname)
...@@ -93,19 +96,12 @@ class TestGeoIPCityFunctions(unittest.TestCase): ...@@ -93,19 +96,12 @@ class TestGeoIPCityFunctions(unittest.TestCase):
self.assertEqual(us_region, self.us_region_data) self.assertEqual(us_region, self.us_region_data)
self.assertEqual(gb_region, self.gb_region_data) self.assertEqual(gb_region, self.gb_region_data)
def testTimeZoneByAddr(self): def testCacheMethods(self):
us_time_zone = self.gic.time_zone_by_addr(self.us_ip) mem_record = self.gic_mem.record_by_addr(self.us_ip)
gb_time_zone = self.gic.time_zone_by_addr(self.gb_ip) mmap_record = self.gic_mmap.record_by_addr(self.us_ip)
self.assertEquals(us_time_zone, 'America/Los_Angeles') self.assertEqual(mem_record['city'], self.us_record_data['city'])
self.assertEquals(gb_time_zone, 'Europe/London') self.assertEqual(mmap_record['city'], self.us_record_data['city'])
def testTimeZoneByName(self):
us_time_zone = self.gic.time_zone_by_name(self.us_hostname)
gb_time_zone = self.gic.time_zone_by_name(self.gb_hostname)
self.assertEquals(us_time_zone, 'America/Los_Angeles')
self.assertEquals(gb_time_zone, 'Europe/London')
def testRecordByAddr(self): def testRecordByAddr(self):
equal_keys = ('city', 'region_name', 'area_code', 'country_code3', equal_keys = ('city', 'region_name', 'area_code', 'country_code3',
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import unittest import unittest
import pygeoip import pygeoip
from tests.config import COUNTRY_DB_PATH from tests.config import COUNTRY_DB_PATH, COUNTRY_V6_DB_PATH
class TestGeoIPCountryFunctions(unittest.TestCase): class TestGeoIPCountryFunctions(unittest.TestCase):
...@@ -13,38 +13,52 @@ class TestGeoIPCountryFunctions(unittest.TestCase): ...@@ -13,38 +13,52 @@ class TestGeoIPCountryFunctions(unittest.TestCase):
self.us_ip = '64.233.161.99' self.us_ip = '64.233.161.99'
self.gb_ip = '212.58.253.68' self.gb_ip = '212.58.253.68'
self.ie6_hostname = 'google.com'
self.ie6_ip = '2a00:1450:400f:800::1002'
self.ie_code = 'IE'
self.us_code = 'US' self.us_code = 'US'
self.gb_code = 'GB' self.gb_code = 'GB'
self.ie_name = 'Ireland'
self.us_name = 'United States' self.us_name = 'United States'
self.gb_name = 'United Kingdom' self.gb_name = 'United Kingdom'
self.gi = pygeoip.GeoIP(COUNTRY_DB_PATH) self.gi = pygeoip.GeoIP(COUNTRY_DB_PATH)
self.gi6 = pygeoip.GeoIP(COUNTRY_V6_DB_PATH)
def testCountryCodeByName(self): def testCountryCodeByName(self):
us_code = self.gi.country_code_by_name(self.us_hostname) us_code = self.gi.country_code_by_name(self.us_hostname)
gb_code = self.gi.country_code_by_name(self.gb_hostname) gb_code = self.gi.country_code_by_name(self.gb_hostname)
ie6_code = self.gi6.country_code_by_name(self.ie6_hostname)
self.assertEqual(us_code, self.us_code) self.assertEqual(us_code, self.us_code)
self.assertEqual(gb_code, self.gb_code) self.assertEqual(gb_code, self.gb_code)
self.assertEqual(ie6_code, self.ie_code)
def testCountryCodeByAddr(self): def testCountryCodeByAddr(self):
us_code = self.gi.country_code_by_name(self.us_ip) us_code = self.gi.country_code_by_addr(self.us_ip)
gb_code = self.gi.country_code_by_name(self.gb_ip) gb_code = self.gi.country_code_by_addr(self.gb_ip)
ie6_code = self.gi6.country_code_by_addr(self.ie6_ip)
self.assertEqual(us_code, self.us_code) self.assertEqual(us_code, self.us_code)
self.assertEqual(gb_code, self.gb_code) self.assertEqual(gb_code, self.gb_code)
self.assertEqual(ie6_code, self.ie_code)
def testCountryNameByName(self): def testCountryNameByName(self):
us_name = self.gi.country_name_by_name(self.us_hostname) us_name = self.gi.country_name_by_name(self.us_hostname)
gb_name = self.gi.country_name_by_name(self.gb_hostname) gb_name = self.gi.country_name_by_name(self.gb_hostname)
ie6_name = self.gi6.country_name_by_name(self.ie6_hostname)
self.assertEqual(us_name, self.us_name) self.assertEqual(us_name, self.us_name)
self.assertEqual(gb_name, self.gb_name) self.assertEqual(gb_name, self.gb_name)
self.assertEqual(ie6_name, self.ie_name)
def testCountryNameByAddr(self): def testCountryNameByAddr(self):
us_name = self.gi.country_name_by_addr(self.us_ip) us_name = self.gi.country_name_by_addr(self.us_ip)
gb_name = self.gi.country_name_by_addr(self.gb_ip) gb_name = self.gi.country_name_by_addr(self.gb_ip)
ie6_name = self.gi6.country_name_by_addr(self.ie6_ip)
self.assertEqual(us_name, self.us_name) self.assertEqual(us_name, self.us_name)
self.assertEqual(gb_name, self.gb_name) self.assertEqual(gb_name, self.gb_name)
self.assertEqual(ie6_name, self.ie_name)
# -*- coding: utf-8 -*-
import unittest
import pygeoip
from tests.config import ISP_DB_PATH
class TestGeOIPISPFunctions(unittest.TestCase):
def setUp(self):
self.us_isp = 'Turner Broadcasting System'
self.us_ip = '157.166.255.18'
self.us_hostname = 'cnn.com'
self.se_isp = 'IP-Only Tele Communication AB'
self.se_ip = '213.132.112.97'
self.se_hostname = 'blocket.se'
self.gi = pygeoip.GeoIP(ISP_DB_PATH)
def testISPByAddr(self):
se_isp = self.gi.org_by_addr(self.se_ip)
us_isp = self.gi.org_by_addr(self.us_ip)
self.assertEqual(se_isp, self.se_isp)
self.assertEqual(us_isp, self.us_isp)
def testISPByName(self):
se_isp = self.gi.org_by_name(self.se_hostname)
us_isp = self.gi.org_by_name(self.us_hostname)
self.assertEqual(se_isp, self.se_isp)
self.assertEqual(us_isp, self.us_isp)
...@@ -7,9 +7,9 @@ from tests.config import ORG_DB_PATH ...@@ -7,9 +7,9 @@ from tests.config import ORG_DB_PATH
class TestGeoIPOrgFunctions(unittest.TestCase): class TestGeoIPOrgFunctions(unittest.TestCase):
def setUp(self): def setUp(self):
self.us_org = 'Google' self.us_org = 'APPLE COMPUTER'
self.us_ip = '64.233.161.99' self.us_ip = '17.172.224.47'
self.us_hostname = 'google.com' self.us_hostname = 'apple.com'
self.gb_org = 'BBC' self.gb_org = 'BBC'
self.gb_ip = '212.58.253.68' self.gb_ip = '212.58.253.68'
...@@ -30,6 +30,3 @@ class TestGeoIPOrgFunctions(unittest.TestCase): ...@@ -30,6 +30,3 @@ class TestGeoIPOrgFunctions(unittest.TestCase):
self.assertEqual(gb_org, self.gb_org) self.assertEqual(gb_org, self.gb_org)
self.assertEqual(us_org, self.us_org) self.assertEqual(us_org, self.us_org)
...@@ -8,10 +8,9 @@ from tests.config import REGION_DB_PATH ...@@ -8,10 +8,9 @@ from tests.config import REGION_DB_PATH
class TestGeoIPRegionFunctions(unittest.TestCase): class TestGeoIPRegionFunctions(unittest.TestCase):
def setUp(self): def setUp(self):
self.us_code = 'US' self.us_code = 'US'
self.us_hostname = 'apple.com'
self.yahoo_hostname = 'yahoo.com' self.us_ip = '17.172.224.47'
self.yahoo_ip = '209.131.36.159' self.us_region_data = {
self.yahoo_region_data = {
'region_name': 'CA', 'region_name': 'CA',
'country_code': 'US' 'country_code': 'US'
} }
...@@ -19,17 +18,17 @@ class TestGeoIPRegionFunctions(unittest.TestCase): ...@@ -19,17 +18,17 @@ class TestGeoIPRegionFunctions(unittest.TestCase):
self.gir = pygeoip.GeoIP(REGION_DB_PATH) self.gir = pygeoip.GeoIP(REGION_DB_PATH)
def testRegionByName(self): def testRegionByName(self):
region_name = self.gir.region_by_name(self.yahoo_hostname) region_name = self.gir.region_by_name(self.us_hostname)
self.assertEqual(region_name, self.yahoo_region_data) self.assertEqual(region_name, self.us_region_data)
def testRegionByAddr(self): def testRegionByAddr(self):
region_name = self.gir.region_by_addr(self.yahoo_ip) region_name = self.gir.region_by_addr(self.us_ip)
self.assertEqual(region_name, self.yahoo_region_data) self.assertEqual(region_name, self.us_region_data)
def testCountryCodeByName(self): def testCountryCodeByName(self):
us_code = self.gir.country_code_by_name(self.yahoo_hostname) us_code = self.gir.country_code_by_name(self.us_hostname)
self.assertEqual(us_code, self.us_code) self.assertEqual(us_code, self.us_code)
def testCountryCodeByAddr(self): def testCountryCodeByAddr(self):
us_code = self.gir.country_code_by_addr(self.yahoo_ip) us_code = self.gir.country_code_by_addr(self.us_ip)
self.assertEqual(us_code, self.us_code) self.assertEqual(us_code, self.us_code)
# -*- coding: utf-8 -*-
import unittest
import threading
import pygeoip
from tests.config import COUNTRY_DB_PATH
class TestGeoIPThreading(unittest.TestCase):
def setUp(self):
self.us_ip = '64.233.161.99'
self.gb_ip = '212.58.253.68'
self.us_code = 'US'
self.gb_code = 'GB'
self.gi = pygeoip.GeoIP(COUNTRY_DB_PATH)
def testCountryDatabase(self):
us_thread = TestThread('us', self.gi, self.us_ip, self.us_code, self.assertEqual)
gb_thread = TestThread('gb', self.gi, self.us_ip, self.us_code, self.assertEqual)
us_thread.start()
gb_thread.start()
us_thread.join()
gb_thread.join()
class TestThread(threading.Thread):
def __init__(self, name, gi, ip, code, assertEqual):
threading.Thread.__init__(self, name=name)
self.ip = ip
self.gi = gi
self.code = code
self.assertEqual = assertEqual
def run(self):
for i in range(1000):
code = self.gi.country_code_by_addr(self.ip)
self.assertEqual(code, self.code)
...@@ -17,14 +17,14 @@ class TestGeoIPTimeZoneFunctions(unittest.TestCase): ...@@ -17,14 +17,14 @@ class TestGeoIPTimeZoneFunctions(unittest.TestCase):
def testTimeZoneByAddr(self): def testTimeZoneByAddr(self):
us_time_zone = self.gic.time_zone_by_addr(self.us_ip) us_time_zone = self.gic.time_zone_by_addr(self.us_ip)
self.assertEquals(us_time_zone, 'America/Los_Angeles')
gb_time_zone = self.gic.time_zone_by_addr(self.gb_ip) gb_time_zone = self.gic.time_zone_by_addr(self.gb_ip)
self.assertEquals(us_time_zone, 'America/Los_Angeles')
self.assertEquals(gb_time_zone, 'Europe/London') self.assertEquals(gb_time_zone, 'Europe/London')
def testTimeZoneByName(self): def testTimeZoneByName(self):
us_time_zone = self.gic.time_zone_by_name(self.us_hostname) us_time_zone = self.gic.time_zone_by_name(self.us_hostname)
self.assertEquals(us_time_zone, 'America/Los_Angeles')
gb_time_zone = self.gic.time_zone_by_name(self.gb_hostname) gb_time_zone = self.gic.time_zone_by_name(self.gb_hostname)
self.assertEquals(us_time_zone, 'America/Los_Angeles')
self.assertEquals(gb_time_zone, 'Europe/London') self.assertEquals(gb_time_zone, 'Europe/London')
# -*- coding: utf-8 -*-
import unittest
import pygeoip
from pygeoip.const import PY2, PY3
from tests.config import CITY_DB_PATH
class TestGeoIPCacheMethods(unittest.TestCase):
def setUp(self):
self.de_hostname = 'www.osnabrueck.de'
self.de_city = 'Osnabr\xfcck'.decode('latin1') if PY2 else 'Osnabrück'
self.gic = pygeoip.GeoIP(CITY_DB_PATH)
def testUnicodeCity(self):
record = self.gic.record_by_name(self.de_hostname)
self.assertEqual(type(record['city']), unicode if PY2 else str)
self.assertEqual(record['city'], self.de_city)
[tox] [tox]
envlist = py25,py26,py27,py31,py32 envlist = py25,py26,py27,py31,py32,py33
[testenv] [testenv]
deps = nose deps = nose
......
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