From f6235b239c8327962c0025ec607541a6648d53a8 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 23 Jan 2006 16:29:16 +0000 Subject: 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 --- setuptools/package_index.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index c48968f1..2813631e 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -1,6 +1,6 @@ """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 distutils import log from distutils.errors import DistutilsError @@ -562,18 +562,28 @@ class PackageIndex(Environment): log.warn(msg, *args) + + + + + + + + + + def fix_sf_url(url): scheme, server, path, param, query, frag = urlparse.urlparse(url) if server!='prdownloads.sourceforge.net': return url 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) -- cgit v1.2.3