Commit f6235b23 authored by PJ Eby's avatar PJ Eby

Randomly select a SourceForge mirror IP for each download, to work

around too-aggressive DNS caches on some platforms, that could otherwise
result in a stuck bad IP.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4042156
parent a16d5ce9
"""PyPI and direct package downloading""" """PyPI and direct package downloading"""
import sys, os.path, re, urlparse, urllib2, shutil import sys, os.path, re, urlparse, urllib2, shutil, random, socket
from pkg_resources import * from pkg_resources import *
from distutils import log from distutils import log
from distutils.errors import DistutilsError from distutils.errors import DistutilsError
...@@ -562,18 +562,28 @@ class PackageIndex(Environment): ...@@ -562,18 +562,28 @@ class PackageIndex(Environment):
log.warn(msg, *args) log.warn(msg, *args)
def fix_sf_url(url): def fix_sf_url(url):
scheme, server, path, param, query, frag = urlparse.urlparse(url) scheme, server, path, param, query, frag = urlparse.urlparse(url)
if server!='prdownloads.sourceforge.net': if server!='prdownloads.sourceforge.net':
return url return url
return urlparse.urlunparse( return urlparse.urlunparse(
(scheme, 'dl.sourceforge.net', 'sourceforge'+path, param, '', frag) (scheme, get_sf_ip(), 'sourceforge'+path, param, '', frag)
) )
def get_sf_ip(_mirrors=[]):
if not _mirrors:
_mirrors[:] = socket.gethostbyname_ex('dl.sourceforge.net')[-1]
return random.choice(_mirrors)
......
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