Beispiel #1
0
    def route(self, target):
        if not target:
            return abort(404)
        ip_address = self._get_ip_address(request)
        geoip = EntropyGeoIP(self._geoip_path)
        data = geoip.get_geoip_record_from_ip(ip_address)
        country = geoip.get_geoip_country_code_from_ip(ip_address)
        continent = geoip.COUNTRY_CONTINENT.get(country)
        fallback_continent = "EU"

        if continent is None:
            continent = fallback_continent  # fallback continent

        mrs = None
        try:
            mrs = Mirrors()
            mirrors = mrs.continent_mirrors(continent)
            if not mirrors and continent != fallback_continent:
                mirrors = mrs.continent_mirrors(fallback_continent)
            if not mirrors:
                return abort(404)
        except ServiceConnectionError:
            return abort(404)
        finally:
            if mrs is not None:
                mrs.disconnect()

        # pick one random mirror
        mirror = random.choice(mirrors)
        url = os.path.join(mirror, target)
        return redirect(url)
Beispiel #2
0
    def route(self, target):
        if not target:
            return abort(404)
        ip_address = self._get_ip_address(request)
        geoip = EntropyGeoIP(self._geoip_path)
        data = geoip.get_geoip_record_from_ip(ip_address)
        country = geoip.get_geoip_country_code_from_ip(ip_address)
        continent = geoip.COUNTRY_CONTINENT.get(country)
        fallback_continent = "EU"

        if continent is None:
            continent = fallback_continent # fallback continent

        mrs = None
        try:
            mrs = Mirrors()
            mirrors = mrs.continent_mirrors(continent)
            if not mirrors and continent != fallback_continent:
                mirrors = mrs.continent_mirrors(fallback_continent)
            if not mirrors:
                return abort(404)
        except ServiceConnectionError:
            return abort(404)
        finally:
            if mrs is not None:
                mrs.disconnect()

        # pick one random mirror
        mirror = random.choice(mirrors)
        url = os.path.join(mirror, target)
        return redirect(url)
Beispiel #3
0
 def _get_geoip_data_from_ip_address(self, ip_address):
     if os.path.isfile(config.GEOIP_DB_PATH) and \
             os.access(config.GEOIP_DB_PATH, os.R_OK):
         try:
             geo = EntropyGeoIP(config.GEOIP_DB_PATH)
             return geo.get_geoip_record_from_ip(ip_address)
         except:  # lame, but I don't know what exceptions are thrown
             pass
Beispiel #4
0
 def _get_geoip_data_from_ip_address(self, ip_address):
     if os.path.isfile(config.GEOIP_DB_PATH) and \
             os.access(config.GEOIP_DB_PATH, os.R_OK):
         try:
             geo = EntropyGeoIP(config.GEOIP_DB_PATH)
             return geo.get_geoip_record_from_ip(ip_address)
         except: # lame, but I don't know what exceptions are thrown
             pass