Commit 5ab11d2a by William Tisäter

Add ASN lookup to readme

parent 504b0f4d
......@@ -23,6 +23,7 @@ You can easily install pygeoip with setuptools:
* City
* Organization
* ISP
* ASN
## Quick Documentation ##
......@@ -77,4 +78,10 @@ Create your GeoIP instance with appropriate access flag. `STANDARD` reads data f
>>> 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.ENCODING pygeoip-module.html#ENCODING
pygeoip.time_zone_by_country_and_region pygeoip.timezone-module.html#time_zone_by_country_and_region
pygeoip.__package__ pygeoip-module.html#__package__
pygeoip.STANDARD pygeoip-module.html#STANDARD
......@@ -6,6 +7,7 @@ pygeoip.MMAP_CACHE pygeoip-module.html#MMAP_CACHE
pygeoip.MEMORY_CACHE pygeoip-module.html#MEMORY_CACHE
pygeoip.const pygeoip.const-module.html
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.PY3 pygeoip.const-module.html#PY3
pygeoip.const.IPV6_EDITIONS pygeoip.const-module.html#IPV6_EDITIONS
......
......@@ -123,7 +123,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -256,7 +256,7 @@ page was last updated. </p>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -63,7 +63,7 @@
B
<a href="#C">C</a>
<a href="#D">D</a>
E
<a href="#E">E</a>
<a href="#F">F</a>
<a href="#G">G</a>
H
......@@ -159,6 +159,19 @@
<tr><td class="link-index">&nbsp;</td><td class="link-index">&nbsp;</td><td class="link-index">&nbsp;</td></tr>
</table>
</td></tr>
<tr valign="top"><td valign="top" width="1%"><h2 class="epydoc"><a name="E">E</a></h2></td>
<td valign="top">
<table class="link-index" width="100%" border="1">
<tr>
<td width="33%" class="link-index"><a href="pygeoip-module.html#ENCODING">ENCODING</a><br />
<span class="index-where">(in&nbsp;<a href="pygeoip-module.html">pygeoip</a>)</span></td>
<td width="33%" class="link-index"><a href="pygeoip.const-module.html#ENCODING">ENCODING</a><br />
<span class="index-where">(in&nbsp;<a href="pygeoip.const-module.html">pygeoip.const</a>)</span></td>
<td width="33%" class="link-index">&nbsp;</td>
</tr>
<tr><td class="link-index">&nbsp;</td><td class="link-index">&nbsp;</td><td class="link-index">&nbsp;</td></tr>
</table>
</td></tr>
<tr valign="top"><td valign="top" width="1%"><h2 class="epydoc"><a name="F">F</a></h2></td>
<td valign="top">
<table class="link-index" width="100%" border="1">
......@@ -459,7 +472,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -62,9 +62,9 @@
<ul class="nomargin-top">
<li> <strong class="uidlink"><a href="pygeoip-module.html">pygeoip</a></strong>: <em class="summary">Pure Python GeoIP API</em>
<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.timezone-module.html">pygeoip.timezone</a></strong> </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.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>: <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">Utility functions.</em> </li>
</ul>
</li>
</ul>
......@@ -99,7 +99,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -61,24 +61,14 @@
<!-- ==================== 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>
<p>Pure Python GeoIP API</p>
<p>The API is based on <a href="http://www.maxmind.com/app/python"
target="_top">MaxMind's C-based Python API</a>, but the code itself is
based on the <a href="http://pear.php.net/package/Net_GeoIP/"
target="_top">pure PHP5 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>
<p>The API is based on MaxMind's C-based Python API, but the code itself
is ported from the Pure PHP GeoIP API by Jim Winstead and Hans
Lellelid.</p>
<hr />
<div class="fields"> <dl><dt>Authors:</dt>
<dd>
Jennifer Ennis &lt;zaylea at gmail dot com&gt;,
William Tis&#228;ter &lt;william@defunct.cc&gt;
</dd>
</dl>
<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
......@@ -112,9 +102,9 @@
</tr>
<tr><td class="summary">
<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.timezone-module.html">pygeoip.timezone</a></strong> </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.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>: <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">Utility functions.</em> </li>
</ul></td></tr>
</table>
......@@ -186,6 +176,13 @@
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</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>
</td>
</tr>
......@@ -200,7 +197,7 @@
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</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>
</tr>
<tr>
......@@ -242,7 +239,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<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.
......@@ -563,9 +563,9 @@ object --+
used and setup segment sizes and start points that will be used by the
seek*() methods later.</p>
<p>Supported databases:</p>
<p>* COUNTRY_EDITION * REGION_EDITION_REV0 * REGION_EDITION_REV1 *
CITY_EDITION_REV0 * CITY_EDITION_REV1 * ORG_EDITION * ISP_EDITION *
ASNUM_EDITION</p>
<p>* COUNTRY_EDITION * COUNTRY_EDITION_V6 * REGION_EDITION_REV0 *
REGION_EDITION_REV1 * CITY_EDITION_REV0 * CITY_EDITION_REV1 * ORG_EDITION
* ISP_EDITION * ASNUM_EDITION</p>
<dl class="fields">
</dl>
</td></tr></table>
......@@ -1065,7 +1065,7 @@ object --+
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -167,7 +167,7 @@ object --+
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -177,7 +177,7 @@ exceptions.BaseException --+
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -337,7 +337,7 @@ object --+
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -61,12 +61,12 @@
</table>
<!-- ==================== 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>
<p>Constants needed for parsing binary GeoIP databases. It is part of the
pygeoip package.</p>
<p>Constants needed for the binary parser. Part of the pygeoip
package.</p>
<hr />
<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><strong>License:</strong>
Copyright(C) 2004 MaxMind LLC
......@@ -422,6 +422,13 @@
<td width="15%" align="right" valign="top" class="summary">
<span class="summary-type">&nbsp;</span>
</td><td class="summary">
<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>
</tr>
......@@ -580,7 +587,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<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 @@
</table>
<!-- ==================== 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>
<!-- ==================== 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>
<table class="summary" border="1" cellpadding="3"
cellspacing="0" width="100%" bgcolor="white">
......@@ -212,7 +232,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<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 @@
</table>
<!-- ==================== 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>
<p>Misc. utility functions. It is part of the pygeoip package.</p>
<p>Utility functions. Part of the pygeoip package.</p>
<hr />
<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><strong>License:</strong>
Copyright(C) 2004 MaxMind LLC
......@@ -298,7 +298,7 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -63,79 +63,78 @@
<pre class="py-src">
<a name="L1"></a><tt class="py-lineno"> 1</tt> <tt class="py-line"><tt class="py-comment"># -*- coding: utf-8 -*-</tt> </tt>
<a name="L2"></a><tt class="py-lineno"> 2</tt> <tt class="py-line"><tt class="py-docstring">"""</tt> </tt>
<a name="L3"></a><tt class="py-lineno"> 3</tt> <tt class="py-line"><tt class="py-docstring">Misc. utility functions. It is part of the pygeoip package.</tt> </tt>
<a name="L3"></a><tt class="py-lineno"> 3</tt> <tt class="py-line"><tt class="py-docstring">Utility functions. Part of the pygeoip package.</tt> </tt>
<a name="L4"></a><tt class="py-lineno"> 4</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L5"></a><tt class="py-lineno"> 5</tt> <tt class="py-line"><tt class="py-docstring">@author: Jennifer Ennis &lt;zaylea at gmail dot com&gt;</tt> </tt>
<a name="L5"></a><tt class="py-lineno"> 5</tt> <tt class="py-line"><tt class="py-docstring">@author: Jennifer Ennis &lt;zaylea@gmail.com&gt;</tt> </tt>
<a name="L6"></a><tt class="py-lineno"> 6</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L7"></a><tt class="py-lineno"> 7</tt> <tt class="py-line"><tt class="py-docstring">@license:</tt> </tt>
<a name="L8"></a><tt class="py-lineno"> 8</tt> <tt class="py-line"><tt class="py-docstring">Copyright(C) 2004 MaxMind LLC</tt> </tt>
<a name="L9"></a><tt class="py-lineno"> 9</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L10"></a><tt class="py-lineno">10</tt> <tt class="py-line"><tt class="py-docstring">This program is free software: you can redistribute it and/or modify</tt> </tt>
<a name="L11"></a><tt class="py-lineno">11</tt> <tt class="py-line"><tt class="py-docstring">it under the terms of the GNU Lesser General Public License as published by</tt> </tt>
<a name="L12"></a><tt class="py-lineno">12</tt> <tt class="py-line"><tt class="py-docstring">the Free Software Foundation, either version 3 of the License, or</tt> </tt>
<a name="L13"></a><tt class="py-lineno">13</tt> <tt class="py-line"><tt class="py-docstring">(at your option) any later version.</tt> </tt>
<a name="L14"></a><tt class="py-lineno">14</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L15"></a><tt class="py-lineno">15</tt> <tt class="py-line"><tt class="py-docstring">This program is distributed in the hope that it will be useful,</tt> </tt>
<a name="L16"></a><tt class="py-lineno">16</tt> <tt class="py-line"><tt class="py-docstring">but WITHOUT ANY WARRANTY; without even the implied warranty of</tt> </tt>
<a name="L17"></a><tt class="py-lineno">17</tt> <tt class="py-line"><tt class="py-docstring">MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</tt> </tt>
<a name="L18"></a><tt class="py-lineno">18</tt> <tt class="py-line"><tt class="py-docstring">GNU General Public License for more details.</tt> </tt>
<a name="L19"></a><tt class="py-lineno">19</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L20"></a><tt class="py-lineno">20</tt> <tt class="py-line"><tt class="py-docstring">You should have received a copy of the GNU Lesser General Public License</tt> </tt>
<a name="L21"></a><tt class="py-lineno">21</tt> <tt class="py-line"><tt class="py-docstring">along with this program. If not, see &lt;http://www.gnu.org/licenses/lgpl.txt&gt;.</tt> </tt>
<a name="L22"></a><tt class="py-lineno">22</tt> <tt class="py-line"><tt class="py-docstring">"""</tt> </tt>
<a name="L23"></a><tt class="py-lineno">23</tt> <tt class="py-line"> </tt>
<a name="L24"></a><tt class="py-lineno">24</tt> <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">struct</tt> </tt>
<a name="L25"></a><tt class="py-lineno">25</tt> <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">socket</tt> </tt>
<a name="L26"></a><tt class="py-lineno">26</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">array</tt> <tt class="py-keyword">import</tt> <tt class="py-name">array</tt> </tt>
<a name="L27"></a><tt class="py-lineno">27</tt> <tt class="py-line"> </tt>
<a name="L28"></a><tt class="py-lineno">28</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-0" class="py-name" targets="Package pygeoip=pygeoip-module.html"><a title="pygeoip" class="py-name" href="#" onclick="return doclink('link-0', 'pygeoip', 'link-0');">pygeoip</a></tt><tt class="py-op">.</tt><tt id="link-1" class="py-name" targets="Module pygeoip.const=pygeoip.const-module.html"><a title="pygeoip.const" class="py-name" href="#" onclick="return doclink('link-1', 'const', 'link-1');">const</a></tt> <tt class="py-keyword">import</tt> <tt id="link-2" class="py-name" targets="Variable pygeoip.const.PY3=pygeoip.const-module.html#PY3"><a title="pygeoip.const.PY3" class="py-name" href="#" onclick="return doclink('link-2', 'PY3', 'link-2');">PY3</a></tt> </tt>
<a name="L7"></a><tt class="py-lineno"> 7</tt> <tt class="py-line"><tt class="py-docstring">@license: Copyright(C) 2004 MaxMind LLC</tt> </tt>
<a name="L8"></a><tt class="py-lineno"> 8</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L9"></a><tt class="py-lineno"> 9</tt> <tt class="py-line"><tt class="py-docstring">This program is free software: you can redistribute it and/or modify</tt> </tt>
<a name="L10"></a><tt class="py-lineno">10</tt> <tt class="py-line"><tt class="py-docstring">it under the terms of the GNU Lesser General Public License as published by</tt> </tt>
<a name="L11"></a><tt class="py-lineno">11</tt> <tt class="py-line"><tt class="py-docstring">the Free Software Foundation, either version 3 of the License, or</tt> </tt>
<a name="L12"></a><tt class="py-lineno">12</tt> <tt class="py-line"><tt class="py-docstring">(at your option) any later version.</tt> </tt>
<a name="L13"></a><tt class="py-lineno">13</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L14"></a><tt class="py-lineno">14</tt> <tt class="py-line"><tt class="py-docstring">This program is distributed in the hope that it will be useful,</tt> </tt>
<a name="L15"></a><tt class="py-lineno">15</tt> <tt class="py-line"><tt class="py-docstring">but WITHOUT ANY WARRANTY; without even the implied warranty of</tt> </tt>
<a name="L16"></a><tt class="py-lineno">16</tt> <tt class="py-line"><tt class="py-docstring">MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</tt> </tt>
<a name="L17"></a><tt class="py-lineno">17</tt> <tt class="py-line"><tt class="py-docstring">GNU General Public License for more details.</tt> </tt>
<a name="L18"></a><tt class="py-lineno">18</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L19"></a><tt class="py-lineno">19</tt> <tt class="py-line"><tt class="py-docstring">You should have received a copy of the GNU Lesser General Public License</tt> </tt>
<a name="L20"></a><tt class="py-lineno">20</tt> <tt class="py-line"><tt class="py-docstring">along with this program. If not, see &lt;http://www.gnu.org/licenses/lgpl.txt&gt;.</tt> </tt>
<a name="L21"></a><tt class="py-lineno">21</tt> <tt class="py-line"><tt class="py-docstring">"""</tt> </tt>
<a name="L22"></a><tt class="py-lineno">22</tt> <tt class="py-line"> </tt>
<a name="L23"></a><tt class="py-lineno">23</tt> <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">struct</tt> </tt>
<a name="L24"></a><tt class="py-lineno">24</tt> <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">socket</tt> </tt>
<a name="L25"></a><tt class="py-lineno">25</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">array</tt> <tt class="py-keyword">import</tt> <tt class="py-name">array</tt> </tt>
<a name="L26"></a><tt class="py-lineno">26</tt> <tt class="py-line"> </tt>
<a name="L27"></a><tt class="py-lineno">27</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-0" class="py-name" targets="Package pygeoip=pygeoip-module.html"><a title="pygeoip" class="py-name" href="#" onclick="return doclink('link-0', 'pygeoip', 'link-0');">pygeoip</a></tt><tt class="py-op">.</tt><tt id="link-1" class="py-name" targets="Module pygeoip.const=pygeoip.const-module.html"><a title="pygeoip.const" class="py-name" href="#" onclick="return doclink('link-1', 'const', 'link-1');">const</a></tt> <tt class="py-keyword">import</tt> <tt id="link-2" class="py-name" targets="Variable pygeoip.const.PY3=pygeoip.const-module.html#PY3"><a title="pygeoip.const.PY3" class="py-name" href="#" onclick="return doclink('link-2', 'PY3', 'link-2');">PY3</a></tt> </tt>
<a name="L28"></a><tt class="py-lineno">28</tt> <tt class="py-line"> </tt>
<a name="L29"></a><tt class="py-lineno">29</tt> <tt class="py-line"> </tt>
<a name="L30"></a><tt class="py-lineno">30</tt> <tt class="py-line"> </tt>
<a name="ip2long"></a><div id="ip2long-def"><a name="L31"></a><tt class="py-lineno">31</tt> <a class="py-toggle" href="#" id="ip2long-toggle" onclick="return toggle('ip2long');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="pygeoip.util-module.html#ip2long">ip2long</a><tt class="py-op">(</tt><tt class="py-param">ip</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="ip2long-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="ip2long-expanded"><a name="L32"></a><tt class="py-lineno">32</tt> <tt class="py-line"> <tt class="py-docstring">"""</tt> </tt>
<a name="L33"></a><tt class="py-lineno">33</tt> <tt class="py-line"><tt class="py-docstring"> Wrapper function for IPv4 and IPv6 converters</tt> </tt>
<a name="L34"></a><tt class="py-lineno">34</tt> <tt class="py-line"><tt class="py-docstring"> @param ip: IPv4 or IPv6 address</tt> </tt>
<a name="L35"></a><tt class="py-lineno">35</tt> <tt class="py-line"><tt class="py-docstring"> @type ip: str</tt> </tt>
<a name="L36"></a><tt class="py-lineno">36</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
<a name="L37"></a><tt class="py-lineno">37</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">ip</tt><tt class="py-op">.</tt><tt class="py-name">find</tt><tt class="py-op">(</tt><tt class="py-string">':'</tt><tt class="py-op">)</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">0</tt><tt class="py-op">:</tt> </tt>
<a name="L38"></a><tt class="py-lineno">38</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-3" class="py-name" targets="Function pygeoip.util.ip2long_v6()=pygeoip.util-module.html#ip2long_v6"><a title="pygeoip.util.ip2long_v6" class="py-name" href="#" onclick="return doclink('link-3', 'ip2long_v6', 'link-3');">ip2long_v6</a></tt><tt class="py-op">(</tt><tt class="py-name">ip</tt><tt class="py-op">)</tt> </tt>
<a name="L39"></a><tt class="py-lineno">39</tt> <tt class="py-line"> <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L40"></a><tt class="py-lineno">40</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-4" class="py-name" targets="Function pygeoip.util.ip2long_v4()=pygeoip.util-module.html#ip2long_v4"><a title="pygeoip.util.ip2long_v4" class="py-name" href="#" onclick="return doclink('link-4', 'ip2long_v4', 'link-4');">ip2long_v4</a></tt><tt class="py-op">(</tt><tt class="py-name">ip</tt><tt class="py-op">)</tt> </tt>
</div><a name="L41"></a><tt class="py-lineno">41</tt> <tt class="py-line"> </tt>
<a name="L42"></a><tt class="py-lineno">42</tt> <tt class="py-line"> </tt>
<a name="ip2long_v4"></a><div id="ip2long_v4-def"><a name="L43"></a><tt class="py-lineno">43</tt> <a class="py-toggle" href="#" id="ip2long_v4-toggle" onclick="return toggle('ip2long_v4');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="pygeoip.util-module.html#ip2long_v4">ip2long_v4</a><tt class="py-op">(</tt><tt class="py-param">ip</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="ip2long_v4-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="ip2long_v4-expanded"><a name="L44"></a><tt class="py-lineno">44</tt> <tt class="py-line"> <tt class="py-docstring">"""</tt> </tt>
<a name="L45"></a><tt class="py-lineno">45</tt> <tt class="py-line"><tt class="py-docstring"> Convert a IPv4 address into a 32-bit integer.</tt> </tt>
<a name="L46"></a><tt class="py-lineno">46</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L47"></a><tt class="py-lineno">47</tt> <tt class="py-line"><tt class="py-docstring"> @param ip: quad-dotted IPv4 address</tt> </tt>
<a name="L48"></a><tt class="py-lineno">48</tt> <tt class="py-line"><tt class="py-docstring"> @type ip: str</tt> </tt>
<a name="L49"></a><tt class="py-lineno">49</tt> <tt class="py-line"><tt class="py-docstring"> @return: network byte order 32-bit integer</tt> </tt>
<a name="L50"></a><tt class="py-lineno">50</tt> <tt class="py-line"><tt class="py-docstring"> @rtype: int</tt> </tt>
<a name="L51"></a><tt class="py-lineno">51</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
<a name="L52"></a><tt class="py-lineno">52</tt> <tt class="py-line"> <tt class="py-name">ip_array</tt> <tt class="py-op">=</tt> <tt class="py-name">ip</tt><tt class="py-op">.</tt><tt class="py-name">split</tt><tt class="py-op">(</tt><tt class="py-string">'.'</tt><tt class="py-op">)</tt> </tt>
<a name="L53"></a><tt class="py-lineno">53</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt id="link-5" class="py-name"><a title="pygeoip.const.PY3" class="py-name" href="#" onclick="return doclink('link-5', 'PY3', 'link-2');">PY3</a></tt><tt class="py-op">:</tt> </tt>
<a name="L54"></a><tt class="py-lineno">54</tt> <tt class="py-line"> <tt class="py-comment"># int and long are unified in py3</tt> </tt>
<a name="L55"></a><tt class="py-lineno">55</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">16777216</tt> <tt class="py-op">+</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">65536</tt> <tt class="py-op">+</tt> \ </tt>
<a name="L56"></a><tt class="py-lineno">56</tt> <tt class="py-line"> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">2</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">256</tt> <tt class="py-op">+</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">3</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L57"></a><tt class="py-lineno">57</tt> <tt class="py-line"> <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L58"></a><tt class="py-lineno">58</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">long</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">16777216</tt> <tt class="py-op">+</tt> <tt class="py-name">long</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">65536</tt> <tt class="py-op">+</tt> \ </tt>
<a name="L59"></a><tt class="py-lineno">59</tt> <tt class="py-line"> <tt class="py-name">long</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">2</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">256</tt> <tt class="py-op">+</tt> <tt class="py-name">long</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">3</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
</div><a name="L60"></a><tt class="py-lineno">60</tt> <tt class="py-line"> </tt>
<a name="L61"></a><tt class="py-lineno">61</tt> <tt class="py-line"> </tt>
<a name="ip2long_v6"></a><div id="ip2long_v6-def"><a name="L62"></a><tt class="py-lineno">62</tt> <a class="py-toggle" href="#" id="ip2long_v6-toggle" onclick="return toggle('ip2long_v6');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="pygeoip.util-module.html#ip2long_v6">ip2long_v6</a><tt class="py-op">(</tt><tt class="py-param">ip</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="ip2long_v6-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="ip2long_v6-expanded"><a name="L63"></a><tt class="py-lineno">63</tt> <tt class="py-line"> <tt class="py-docstring">"""</tt> </tt>
<a name="L64"></a><tt class="py-lineno">64</tt> <tt class="py-line"><tt class="py-docstring"> Convert a IPv6 address into long.</tt> </tt>
<a name="L65"></a><tt class="py-lineno">65</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L66"></a><tt class="py-lineno">66</tt> <tt class="py-line"><tt class="py-docstring"> @param ip: IPv6 address</tt> </tt>
<a name="L67"></a><tt class="py-lineno">67</tt> <tt class="py-line"><tt class="py-docstring"> @type ip: str</tt> </tt>
<a name="L68"></a><tt class="py-lineno">68</tt> <tt class="py-line"><tt class="py-docstring"> @return: network byte order long</tt> </tt>
<a name="L69"></a><tt class="py-lineno">69</tt> <tt class="py-line"><tt class="py-docstring"> @rtype: long</tt> </tt>
<a name="L70"></a><tt class="py-lineno">70</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
<a name="L71"></a><tt class="py-lineno">71</tt> <tt class="py-line"> <tt class="py-name">ipbyte</tt> <tt class="py-op">=</tt> <tt class="py-name">socket</tt><tt class="py-op">.</tt><tt class="py-name">inet_pton</tt><tt class="py-op">(</tt><tt class="py-name">socket</tt><tt class="py-op">.</tt><tt class="py-name">AF_INET6</tt><tt class="py-op">,</tt> <tt class="py-name">ip</tt><tt class="py-op">)</tt> </tt>
<a name="L72"></a><tt class="py-lineno">72</tt> <tt class="py-line"> <tt class="py-name">ipnum</tt> <tt class="py-op">=</tt> <tt class="py-name">array</tt><tt class="py-op">(</tt><tt class="py-string">'L'</tt><tt class="py-op">,</tt> <tt class="py-name">struct</tt><tt class="py-op">.</tt><tt class="py-name">unpack</tt><tt class="py-op">(</tt><tt class="py-string">'!4L'</tt><tt class="py-op">,</tt> <tt class="py-name">ipbyte</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L73"></a><tt class="py-lineno">73</tt> <tt class="py-line"> <tt class="py-name">max_index</tt> <tt class="py-op">=</tt> <tt class="py-name">len</tt><tt class="py-op">(</tt><tt class="py-name">ipnum</tt><tt class="py-op">)</tt> <tt class="py-op">-</tt> <tt class="py-number">1</tt> </tt>
<a name="L74"></a><tt class="py-lineno">74</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">sum</tt><tt class="py-op">(</tt><tt class="py-name">ipnum</tt><tt class="py-op">[</tt><tt class="py-name">max_index</tt> <tt class="py-op">-</tt> <tt class="py-name">i</tt><tt class="py-op">]</tt> <tt class="py-op">&lt;&lt;</tt> <tt class="py-op">(</tt><tt class="py-name">i</tt> <tt class="py-op">*</tt> <tt class="py-number">32</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-name">len</tt><tt class="py-op">(</tt><tt class="py-name">ipnum</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
</div><a name="L75"></a><tt class="py-lineno">75</tt> <tt class="py-line"> </tt><script type="text/javascript">
<a name="ip2long"></a><div id="ip2long-def"><a name="L30"></a><tt class="py-lineno">30</tt> <a class="py-toggle" href="#" id="ip2long-toggle" onclick="return toggle('ip2long');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="pygeoip.util-module.html#ip2long">ip2long</a><tt class="py-op">(</tt><tt class="py-param">ip</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="ip2long-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="ip2long-expanded"><a name="L31"></a><tt class="py-lineno">31</tt> <tt class="py-line"> <tt class="py-docstring">"""</tt> </tt>
<a name="L32"></a><tt class="py-lineno">32</tt> <tt class="py-line"><tt class="py-docstring"> Wrapper function for IPv4 and IPv6 converters</tt> </tt>
<a name="L33"></a><tt class="py-lineno">33</tt> <tt class="py-line"><tt class="py-docstring"> @param ip: IPv4 or IPv6 address</tt> </tt>
<a name="L34"></a><tt class="py-lineno">34</tt> <tt class="py-line"><tt class="py-docstring"> @type ip: str</tt> </tt>
<a name="L35"></a><tt class="py-lineno">35</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
<a name="L36"></a><tt class="py-lineno">36</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">ip</tt><tt class="py-op">.</tt><tt class="py-name">find</tt><tt class="py-op">(</tt><tt class="py-string">':'</tt><tt class="py-op">)</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">0</tt><tt class="py-op">:</tt> </tt>
<a name="L37"></a><tt class="py-lineno">37</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-3" class="py-name" targets="Function pygeoip.util.ip2long_v6()=pygeoip.util-module.html#ip2long_v6"><a title="pygeoip.util.ip2long_v6" class="py-name" href="#" onclick="return doclink('link-3', 'ip2long_v6', 'link-3');">ip2long_v6</a></tt><tt class="py-op">(</tt><tt class="py-name">ip</tt><tt class="py-op">)</tt> </tt>
<a name="L38"></a><tt class="py-lineno">38</tt> <tt class="py-line"> <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L39"></a><tt class="py-lineno">39</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt id="link-4" class="py-name" targets="Function pygeoip.util.ip2long_v4()=pygeoip.util-module.html#ip2long_v4"><a title="pygeoip.util.ip2long_v4" class="py-name" href="#" onclick="return doclink('link-4', 'ip2long_v4', 'link-4');">ip2long_v4</a></tt><tt class="py-op">(</tt><tt class="py-name">ip</tt><tt class="py-op">)</tt> </tt>
</div><a name="L40"></a><tt class="py-lineno">40</tt> <tt class="py-line"> </tt>
<a name="L41"></a><tt class="py-lineno">41</tt> <tt class="py-line"> </tt>
<a name="ip2long_v4"></a><div id="ip2long_v4-def"><a name="L42"></a><tt class="py-lineno">42</tt> <a class="py-toggle" href="#" id="ip2long_v4-toggle" onclick="return toggle('ip2long_v4');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="pygeoip.util-module.html#ip2long_v4">ip2long_v4</a><tt class="py-op">(</tt><tt class="py-param">ip</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="ip2long_v4-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="ip2long_v4-expanded"><a name="L43"></a><tt class="py-lineno">43</tt> <tt class="py-line"> <tt class="py-docstring">"""</tt> </tt>
<a name="L44"></a><tt class="py-lineno">44</tt> <tt class="py-line"><tt class="py-docstring"> Convert a IPv4 address into a 32-bit integer.</tt> </tt>
<a name="L45"></a><tt class="py-lineno">45</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L46"></a><tt class="py-lineno">46</tt> <tt class="py-line"><tt class="py-docstring"> @param ip: quad-dotted IPv4 address</tt> </tt>
<a name="L47"></a><tt class="py-lineno">47</tt> <tt class="py-line"><tt class="py-docstring"> @type ip: str</tt> </tt>
<a name="L48"></a><tt class="py-lineno">48</tt> <tt class="py-line"><tt class="py-docstring"> @return: network byte order 32-bit integer</tt> </tt>
<a name="L49"></a><tt class="py-lineno">49</tt> <tt class="py-line"><tt class="py-docstring"> @rtype: int</tt> </tt>
<a name="L50"></a><tt class="py-lineno">50</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
<a name="L51"></a><tt class="py-lineno">51</tt> <tt class="py-line"> <tt class="py-name">ip_array</tt> <tt class="py-op">=</tt> <tt class="py-name">ip</tt><tt class="py-op">.</tt><tt class="py-name">split</tt><tt class="py-op">(</tt><tt class="py-string">'.'</tt><tt class="py-op">)</tt> </tt>
<a name="L52"></a><tt class="py-lineno">52</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt id="link-5" class="py-name"><a title="pygeoip.const.PY3" class="py-name" href="#" onclick="return doclink('link-5', 'PY3', 'link-2');">PY3</a></tt><tt class="py-op">:</tt> </tt>
<a name="L53"></a><tt class="py-lineno">53</tt> <tt class="py-line"> <tt class="py-comment"># int and long are unified in py3</tt> </tt>
<a name="L54"></a><tt class="py-lineno">54</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">16777216</tt> <tt class="py-op">+</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">65536</tt> <tt class="py-op">+</tt> \ </tt>
<a name="L55"></a><tt class="py-lineno">55</tt> <tt class="py-line"> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">2</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">256</tt> <tt class="py-op">+</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">3</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L56"></a><tt class="py-lineno">56</tt> <tt class="py-line"> <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L57"></a><tt class="py-lineno">57</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">long</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">16777216</tt> <tt class="py-op">+</tt> <tt class="py-name">long</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">65536</tt> <tt class="py-op">+</tt> \ </tt>
<a name="L58"></a><tt class="py-lineno">58</tt> <tt class="py-line"> <tt class="py-name">long</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">2</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">256</tt> <tt class="py-op">+</tt> <tt class="py-name">long</tt><tt class="py-op">(</tt><tt class="py-name">ip_array</tt><tt class="py-op">[</tt><tt class="py-number">3</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
</div><a name="L59"></a><tt class="py-lineno">59</tt> <tt class="py-line"> </tt>
<a name="L60"></a><tt class="py-lineno">60</tt> <tt class="py-line"> </tt>
<a name="ip2long_v6"></a><div id="ip2long_v6-def"><a name="L61"></a><tt class="py-lineno">61</tt> <a class="py-toggle" href="#" id="ip2long_v6-toggle" onclick="return toggle('ip2long_v6');">-</a><tt class="py-line"><tt class="py-keyword">def</tt> <a class="py-def-name" href="pygeoip.util-module.html#ip2long_v6">ip2long_v6</a><tt class="py-op">(</tt><tt class="py-param">ip</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="ip2long_v6-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="ip2long_v6-expanded"><a name="L62"></a><tt class="py-lineno">62</tt> <tt class="py-line"> <tt class="py-docstring">"""</tt> </tt>
<a name="L63"></a><tt class="py-lineno">63</tt> <tt class="py-line"><tt class="py-docstring"> Convert a IPv6 address into long.</tt> </tt>
<a name="L64"></a><tt class="py-lineno">64</tt> <tt class="py-line"><tt class="py-docstring"></tt> </tt>
<a name="L65"></a><tt class="py-lineno">65</tt> <tt class="py-line"><tt class="py-docstring"> @param ip: IPv6 address</tt> </tt>
<a name="L66"></a><tt class="py-lineno">66</tt> <tt class="py-line"><tt class="py-docstring"> @type ip: str</tt> </tt>
<a name="L67"></a><tt class="py-lineno">67</tt> <tt class="py-line"><tt class="py-docstring"> @return: network byte order long</tt> </tt>
<a name="L68"></a><tt class="py-lineno">68</tt> <tt class="py-line"><tt class="py-docstring"> @rtype: long</tt> </tt>
<a name="L69"></a><tt class="py-lineno">69</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
<a name="L70"></a><tt class="py-lineno">70</tt> <tt class="py-line"> <tt class="py-name">ipbyte</tt> <tt class="py-op">=</tt> <tt class="py-name">socket</tt><tt class="py-op">.</tt><tt class="py-name">inet_pton</tt><tt class="py-op">(</tt><tt class="py-name">socket</tt><tt class="py-op">.</tt><tt class="py-name">AF_INET6</tt><tt class="py-op">,</tt> <tt class="py-name">ip</tt><tt class="py-op">)</tt> </tt>
<a name="L71"></a><tt class="py-lineno">71</tt> <tt class="py-line"> <tt class="py-name">ipnum</tt> <tt class="py-op">=</tt> <tt class="py-name">array</tt><tt class="py-op">(</tt><tt class="py-string">'L'</tt><tt class="py-op">,</tt> <tt class="py-name">struct</tt><tt class="py-op">.</tt><tt class="py-name">unpack</tt><tt class="py-op">(</tt><tt class="py-string">'!4L'</tt><tt class="py-op">,</tt> <tt class="py-name">ipbyte</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L72"></a><tt class="py-lineno">72</tt> <tt class="py-line"> <tt class="py-name">max_index</tt> <tt class="py-op">=</tt> <tt class="py-name">len</tt><tt class="py-op">(</tt><tt class="py-name">ipnum</tt><tt class="py-op">)</tt> <tt class="py-op">-</tt> <tt class="py-number">1</tt> </tt>
<a name="L73"></a><tt class="py-lineno">73</tt> <tt class="py-line"> <tt class="py-keyword">return</tt> <tt class="py-name">sum</tt><tt class="py-op">(</tt><tt class="py-name">ipnum</tt><tt class="py-op">[</tt><tt class="py-name">max_index</tt> <tt class="py-op">-</tt> <tt class="py-name">i</tt><tt class="py-op">]</tt> <tt class="py-op">&lt;&lt;</tt> <tt class="py-op">(</tt><tt class="py-name">i</tt> <tt class="py-op">*</tt> <tt class="py-number">32</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-name">len</tt><tt class="py-op">(</tt><tt class="py-name">ipnum</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
</div><a name="L74"></a><tt class="py-lineno">74</tt> <tt class="py-line"> </tt><script type="text/javascript">
<!--
expandto(location.href);
// -->
......@@ -173,7 +172,7 @@ expandto(location.href);
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Sat Sep 29 02:57:38 2012
Generated by Epydoc 3.0.1 on Sun Sep 30 13:48:03 2012
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
......
......@@ -23,7 +23,8 @@
>pygeoip.util.ip2long</a><br /> <a target="mainFrame" href="pygeoip.util-module.html#ip2long_v4"
>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#MEMORY_CACHE"
<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.MMAP_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#STANDARD"
>pygeoip.STANDARD</a><br /> <a target="mainFrame" href="pygeoip-module.html#__package__"
......@@ -40,7 +41,8 @@
>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.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.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"
......
......@@ -18,7 +18,8 @@
>GeoIPBase</a><br /> <a target="mainFrame" href="pygeoip.GeoIPError-class.html"
>GeoIPError</a><br /> <a target="mainFrame" href="pygeoip.GeoIPMetaclass-class.html"
>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"
>MMAP_CACHE</a><br /> <a target="mainFrame" href="pygeoip-module.html#STANDARD"
>STANDARD</a><br /> <a target="mainFrame" href="pygeoip-module.html#__package__"
......
......@@ -26,7 +26,8 @@
>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"
>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"
>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"
......
......@@ -7,10 +7,8 @@ from tests.config import COUNTRY_DB_PATH
class TestGeoIPCacheMethods(unittest.TestCase):
def setUp(self):
self.us_hostname = 'google.com'
self.us_ip = '64.233.161.99'
self.us_code = 'US'
self.us_name = 'United States'
self.gi_mmap = pygeoip.GeoIP(COUNTRY_DB_PATH, MMAP_CACHE)
self.gi_memory = pygeoip.GeoIP(COUNTRY_DB_PATH, MEMORY_CACHE)
......
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