def load_geodb(path, log=None):
    def geoip(reader, ip):
        try:
            record = reader.city(ip)
        except (AddressNotFoundError, __HOLE__):
            return {}

        if record is None:
            return {}

        result = {}
        geoip_cc = record.country.iso_code
        if geoip_cc:
            result["geoip cc"] = [geoip_cc]

        latitude = record.location.latitude
        longitude = record.location.longitude
        if latitude and longitude:
            result["latitude"] = [unicode(latitude)]
            result["longitude"] = [unicode(longitude)]

        return result

    def legacy_geoip(reader, ip):
        if not is_ipv4(ip):
            return {}

        try:
            record = reader.record_by_addr(ip)
        except GeoIPError:
            return {}

        if record is None:
            return {}

        result = {}
        geoip_cc = record.get("country_code", None)
        if geoip_cc:
            result["geoip cc"] = [geoip_cc]

        latitude = record.get("latitude", None)
        longitude = record.get("longitude", None)
        if latitude and longitude:
            result["latitude"] = [unicode(latitude)]
            result["longitude"] = [unicode(longitude)]

        return result

    try:
        from geoip2.database import Reader
        from maxminddb.errors import InvalidDatabaseError
        from geoip2.errors import AddressNotFoundError

        try:
            reader = Reader(path)
            fun = geoip
        except InvalidDatabaseError:
            raise ImportError

        if log:
            log.info("GeoIP2 initiated")

    except ImportError:
        from pygeoip import GeoIP, GeoIPError

        reader = GeoIP(path)
        fun = legacy_geoip

        if log:
            log.info("Legacy GeoIP initiated")

    def geoip_reader(ip):
        return fun(reader, ip)

    return geoip_reader
dataset/ETHPy150Open abusesa/abusehelper/abusehelper/bots/experts/geoipexpert.py/load_geodb