Skip to content

Commit

Permalink
Merge pull request appliedsec#69 from Ironholds/patch-2
Browse files Browse the repository at this point in the history
Improve exception handling
  • Loading branch information
tiwilliam committed Oct 8, 2014
2 parents c1259b4 + f298b4f commit e813632
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pygeoip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,13 @@ def id_by_addr(self, addr):
:arg addr: IPv4 or IPv6 address (eg. 203.0.113.30)
"""
if self._databaseType in (const.PROXY_EDITION, const.NETSPEED_EDITION_REV1, const.NETSPEED_EDITION_REV1_V6):
raise GeoIPError('Invalid database type; this database is not supported')
ipv = 6 if addr.find(':') >= 0 else 4
if ipv == 4 and self._databaseType not in (const.COUNTRY_EDITION, const.NETSPEED_EDITION):
raise GeoIPError('Invalid database type; expected IPv6 address')
raise GeoIPError('Invalid database type; this database supports IPv6 addresses, not IPv4')
if ipv == 6 and self._databaseType != const.COUNTRY_EDITION_V6:
raise GeoIPError('Invalid database type; expected IPv4 address')
raise GeoIPError('Invalid database type; this database supports IPv4 addresses, not IPv6')

ipnum = util.ip2long(addr)
return self._seek_country(ipnum) - const.COUNTRY_BEGIN
Expand Down

0 comments on commit e813632

Please sign in to comment.