Skip to content
Snippets Groups Projects
Commit a5d79997 authored by Jan Mach's avatar Jan Mach
Browse files

Code style improvements with pylint tool.

Fixed all pylint issues in mentat.geoip module. (Redmine issue: #3443)
parent 4725772f
No related branches found
No related tags found
No related merge requests found
......@@ -297,7 +297,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=rrdtool
ignored-modules=rrdtool,geoip2.records
# Show a hint with possible names when a member name was not found. The aspect
# of finding the hint is based on edit distance.
......
......@@ -51,15 +51,19 @@ class GeoipService:
"""
def __init__(self, asndb = None, citydb = None, countrydb = None):
"""
Initialize geolocation service with paths to desired database files.
"""
self.fn_asndb = asndb
self.fn_citydb = citydb
self.fn_countrydb = countrydb
self.asndb = None
self.citydb = None
self.countrydb = None
def __del__(self):
"""
Close internal geolocation database readers.
"""
if self.fn_asndb:
self.asndb.close()
......@@ -70,16 +74,18 @@ class GeoipService:
def setup(self):
"""
Setup internal geolocation database readers.
"""
if self.fn_asndb:
self.asndb = geoip2.database.Reader(self.fn_asndb)
else:
self.asndb = None
if self.fn_citydb:
self.citydb = geoip2.database.Reader(self.fn_citydb)
else:
self.citydb = None
if self.fn_countrydb:
self.countrydb = geoip2.database.Reader(self.fn_countrydb)
else:
......@@ -87,7 +93,7 @@ class GeoipService:
def status(self):
"""
Display status of internal geolocation readers.
"""
return {
'asn': self.fn_asndb,
......@@ -97,7 +103,7 @@ class GeoipService:
def lookup(self, ipaddr):
"""
Lookup given IP address in all databases.
"""
result = {}
if self.fn_asndb:
......@@ -110,7 +116,7 @@ class GeoipService:
def lookup_asn(self, ipaddr):
"""
Lookup given IP address in ASN database.
"""
try:
......@@ -126,7 +132,7 @@ class GeoipService:
def lookup_city(self, ipaddr):
"""
Lookup given IP address in city database.
"""
try:
......@@ -148,7 +154,7 @@ class GeoipService:
def lookup_country(self, ipaddr):
"""
Lookup given IP address in Country database.
"""
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment