aboutsummaryrefslogtreecommitdiff
path: root/cgi/geoip.py
diff options
context:
space:
mode:
authorLibravatar Renard 2020-03-29 18:43:36 -0300
committerLibravatar Renard 2020-03-29 18:43:36 -0300
commit56c690b9efdb009ab44f3112b6c301d7d393f07e (patch)
treeb2a28666888df9b60b46b6d1c59dd3818437b405 /cgi/geoip.py
parent775ef3e6291c5ad6bff68a12f6ca81c8663da3dc (diff)
downloadweabot-56c690b9efdb009ab44f3112b6c301d7d393f07e.tar.gz
weabot-56c690b9efdb009ab44f3112b6c301d7d393f07e.tar.xz
weabot-56c690b9efdb009ab44f3112b6c301d7d393f07e.zip
Formateo de python con pep8
Diffstat (limited to 'cgi/geoip.py')
-rw-r--r--cgi/geoip.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/cgi/geoip.py b/cgi/geoip.py
index 0bcb3d8..36c25d1 100644
--- a/cgi/geoip.py
+++ b/cgi/geoip.py
@@ -41,6 +41,7 @@ countries = (
'VU', 'WF', 'WS', 'YE', 'YT', 'RS', 'ZA', 'ZM', 'ME', 'ZW', 'A1', 'A2', 'O1',
'AX', 'GG', 'IM', 'JE', 'BL', 'MF')
+
def iptonum(ip):
"""Convert IP address string to 32-bit integer, or return None if IP is bad.
@@ -70,9 +71,11 @@ def iptonum(ip):
num = num << 8 | segment
return num
+
class DatabaseError(Exception):
pass
+
class GeoIP(object):
"""Wraps GeoIP country database lookup into a class."""
@@ -119,10 +122,12 @@ class GeoIP(object):
offset = x[i]
raise DatabaseError('GeoIP database corrupt: offset=%s' % offset)
+
def country(ip, dbname='GeoIP.dat'):
"""Helper function that creates a GeoIP instance and calls country()."""
return GeoIP(dbname).country(ip)
+
if __name__ == '__main__':
import doctest
doctest.testmod()