def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay=15):
 import urllib2, shutil
 egg_name = ('setuptools-%s-py%s.egg' % (version, sys.version[:3]))
 url = (download_base + egg_name)
 saveto = os.path.join(to_dir, egg_name)
 src = dst = None
 if (not os.path.exists(saveto)):
  try:
   from distutils import log
   if delay:
    log.warn('\n---------------------------------------------------------------------------\nThis script requires setuptools version %s to run (even to display\nhelp).  I will attempt to download it for you (from\n%s), but\nyou may need to enable firewall access for this script first.\nI will start the download in %d seconds.\n\n(Note: if this machine does not have network access, please obtain the file\n\n   %s\n\nand place it in this directory before rerunning this script.)\n---------------------------------------------------------------------------', version, download_base, delay, url)
    from time import sleep
    sleep(delay)
   log.warn('Downloading %s', url)
   src = urllib2.urlopen(url)
   data = _validate_md5(egg_name, src.read())
   dst = open(saveto, 'wb')
   dst.write(data)
  finally:
   if src:
    src.close()
   if dst:
    dst.close()
 return os.path.realpath(saveto)

def download_setuptools ( version = DEFAULT_VERSION , download_base = DEFAULT_URL , to_dir = os . curdir , delay = 15 ) : import urllib2 , shutil egg_name = ( 'setuptools-%s-py%s.egg' % ( version , sys . version [ : 3 ] ) ) url = ( download_base + egg_name ) saveto = os . path . join ( to_dir , egg_name ) src = dst = None if ( not os . path . exists ( saveto ) ) : try : from distutils import log if delay : log . warn ( '\n---------------------------------------------------------------------------\nThis script requires setuptools version %s to run (even to display\nhelp).  I will attempt to download it for you (from\n%s), but\nyou may need to enable firewall access for this script first.\nI will start the download in %d seconds.\n\n(Note: if this machine does not have network access, please obtain the file\n\n   %s\n\nand place it in this directory before rerunning this script.)\n---------------------------------------------------------------------------' , version , download_base , delay , url ) from time import sleep sleep ( delay ) log . warn ( 'Downloading %s' , url ) src = urllib2 . urlopen ( url ) data = _validate_md5 ( egg_name , src . read ( ) ) dst = open ( saveto , 'wb' ) dst . write ( data ) finally : if src : src . close ( ) if dst : dst . close ( ) return os . path . realpath ( saveto )
download setuptools from a specified location and return its filename version should be a valid setuptools version number that is available as an egg for download under the download_base url .