Commit ca3743d7 by William Tisäter

Catch all db parsing errors and complain

parent 448d8cc8
...@@ -199,6 +199,7 @@ class GeoIP(GeoIPBase): ...@@ -199,6 +199,7 @@ class GeoIP(GeoIPBase):
@return: offset of start of record @return: offset of start of record
@rtype: int @rtype: int
""" """
try:
offset = 0 offset = 0
seek_depth = 127 if len(str(ipnum)) > 10 else 31 seek_depth = 127 if len(str(ipnum)) > 10 else 31
...@@ -231,6 +232,8 @@ class GeoIP(GeoIPBase): ...@@ -231,6 +232,8 @@ class GeoIP(GeoIPBase):
if x[0] >= self._databaseSegments: if x[0] >= self._databaseSegments:
return x[0] return x[0]
offset = x[0] offset = x[0]
except:
pass
raise GeoIPError('Corrupt database') raise GeoIPError('Corrupt database')
...@@ -449,7 +452,6 @@ class GeoIP(GeoIPBase): ...@@ -449,7 +452,6 @@ class GeoIP(GeoIPBase):
raise ValueError(message) raise ValueError(message)
country_id = self.id_by_addr(addr) country_id = self.id_by_addr(addr)
return const.COUNTRY_CODES[country_id] return const.COUNTRY_CODES[country_id]
elif self._databaseType in const.REGION_CITY_EDITIONS: elif self._databaseType in const.REGION_CITY_EDITIONS:
return self.region_by_addr(addr).get('country_code') return self.region_by_addr(addr).get('country_code')
...@@ -485,7 +487,8 @@ class GeoIP(GeoIPBase): ...@@ -485,7 +487,8 @@ class GeoIP(GeoIPBase):
try: try:
VALID_EDITIONS = (const.COUNTRY_EDITION, const.COUNTRY_EDITION_V6) VALID_EDITIONS = (const.COUNTRY_EDITION, const.COUNTRY_EDITION_V6)
if self._databaseType in VALID_EDITIONS: if self._databaseType in VALID_EDITIONS:
return const.COUNTRY_NAMES[self.id_by_addr(addr)] country_id = self.id_by_addr(addr)
return const.COUNTRY_NAMES[country_id]
elif self._databaseType in const.CITY_EDITIONS: elif self._databaseType in const.CITY_EDITIONS:
return self.record_by_addr(addr).get('country_name') return self.record_by_addr(addr).get('country_name')
else: else:
......
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