示例#1
0
    def _set_maxmind_geolocation(self, ip_address, country, city):
        geo_record = maxmind.GeoRecord()
        address_family = None

        if _is_valid_ipv6(ip_address):
            address_family = message.ADDRESS_FAMILY_IPv6
        elif _is_valid_ipv4(ip_address):
            address_family = message.ADDRESS_FAMILY_IPv4

        if ip_address is not None:
            logging.debug('Getting maxmind info for ip %s in family %s',
                          ip_address, address_family)
            geo_record = maxmind.get_ip_geolocation(ip_address)
        elif city is not None and country is not None:
            geo_record = maxmind.get_city_geolocation(city, country)
        elif country is not None:
            geo_record = maxmind.get_country_geolocation(country)

        self._maxmind_city = geo_record.city
        self._maxmind_country = geo_record.country
        self._maxmind_latitude = geo_record.latitude
        self._maxmind_longitude = geo_record.longitude

        return (geo_record.latitude is not None
                and geo_record.longitude is not None)
示例#2
0
 def _set_maxmind_geolocation(self, ip_address, country, city):
     geo_record = maxmind.GeoRecord()
     if ip_address is not None:
         geo_record = maxmind.get_ip_geolocation(ip_address)
     elif city is not None and country is not None:
         geo_record = maxmind.get_city_geolocation(city, country)
     elif country is not None:
         geo_record = maxmind.get_country_geolocation(country)
     self._maxmind_city = geo_record.city
     self._maxmind_country = geo_record.country
     self._maxmind_latitude = geo_record.latitude
     self._maxmind_longitude = geo_record.longitude
示例#3
0
 def _set_maxmind_geolocation(self, ip_address, country, city):
     geo_record = maxmind.GeoRecord()
     if ip_address is not None:
         geo_record = maxmind.get_ip_geolocation(ip_address)
     elif city is not None and country is not None:
         geo_record = maxmind.get_city_geolocation(city, country)
     elif country is not None:
         geo_record = maxmind.get_country_geolocation(country)
     self._maxmind_city = geo_record.city
     self._maxmind_country = geo_record.country
     self._maxmind_latitude = geo_record.latitude
     self._maxmind_longitude = geo_record.longitude
示例#4
0
    def testGetCountryGeolocationYesCountry(self):
        class Location:
            def __init__(self):
                self.alpha2_code = 'country'
                self.latitude = 'latitude'
                self.longitude = 'longitude'
        location = Location()
        expected_geo_record = maxmind.GeoRecord()
        expected_geo_record.city = constants.UNKNOWN_CITY
        expected_geo_record.country = location.alpha2_code
        expected_geo_record.latitude = location.latitude
        expected_geo_record.longitude = location.longitude

        self.assertGeoRecordEqual(
            expected_geo_record,
            maxmind.get_country_geolocation(
                'unused_country',
                 country_table=MaxmindTestClass.ModelMockup(location=location)))
示例#5
0
    def testGetCountryGeolocationYesCountry(self):
        class Location:
            def __init__(self):
                self.alpha2_code = 'country'
                self.latitude = 'latitude'
                self.longitude = 'longitude'

        location = Location()
        expected_geo_record = maxmind.GeoRecord()
        expected_geo_record.city = constants.UNKNOWN_CITY
        expected_geo_record.country = location.alpha2_code
        expected_geo_record.latitude = location.latitude
        expected_geo_record.longitude = location.longitude

        self.assertEqual(
            expected_geo_record,
            maxmind.get_country_geolocation(
                'unused_country',
                country_table=MaxmindTestClass.ModelMockup(location=location)))
示例#6
0
    def _set_maxmind_geolocation(self, ip_address, country, city):
        geo_record = maxmind.GeoRecord()
        address_family = None

        if _is_valid_ipv6(ip_address):
            address_family = message.ADDRESS_FAMILY_IPv6
        elif _is_valid_ipv4(ip_address):
            address_family = message.ADDRESS_FAMILY_IPv4

        if ip_address is not None:
            logging.debug('Getting maxmind info for ip %s in family %s',
                          ip_address, address_family)
            geo_record = maxmind.get_ip_geolocation(ip_address)
        elif city is not None and country is not None:
            geo_record = maxmind.get_city_geolocation(city, country)
        elif country is not None:
            geo_record = maxmind.get_country_geolocation(country)
        self._maxmind_city = geo_record.city
        self._maxmind_country = geo_record.country
        self._maxmind_latitude = geo_record.latitude
        self._maxmind_longitude = geo_record.longitude
示例#7
0
 def testGetCountryGeolocationNoCountry(self):
     self.assertNoneGeoRecord(
         maxmind.get_country_geolocation("unused_country", country_table=MaxmindTestClass.ModelMockup())
     )
示例#8
0
 def testGetCountryGeolocationNoCountry(self):
     self.assertNoneGeoRecord(
         maxmind.get_country_geolocation(
             'unused_country',
             country_table=MaxmindTestClass.ModelMockup()))