def Download(url):
 FilenameFromUrl = (lambda url: urlparse.urlparse(url)[2].split('/')[(-1)])
 FilenameFromHandler = None
 for handler in _realurl_handlers:
  url4dnld = handler(url)
  if (not url4dnld):
   continue
  if isinstance(url4dnld, tuple):
   (FilenameFromHandler, url) = url4dnld
  else:
   url = url4dnld
  break
 dl = FileDownload()
 resp = dl.open(url)
 if FilenameFromHandler:
  filename = FilenameFromHandler
 elif dl.filename:
  filename = dl.filename
 else:
  filename = FilenameFromUrl(dl.realurl)
  if (not filename):
   filename = 'NoName'
 if (resp.status_code == 413):
  return ('too large', filename, '')
 elif (resp.status_code not in (200, 206)):
  return ('download failed', filename, '')
 elif (not resp.content):
  return ('not resuming', filename, '')
 else:
  return ('', filename, resp.content)

def Download ( url ) : FilenameFromUrl = ( lambda url : urlparse . urlparse ( url ) [ 2 ] . split ( '/' ) [ ( - 1 ) ] ) FilenameFromHandler = None for handler in _realurl_handlers : url4dnld = handler ( url ) if ( not url4dnld ) : continue if isinstance ( url4dnld , tuple ) : ( FilenameFromHandler , url ) = url4dnld else : url = url4dnld break dl = FileDownload ( ) resp = dl . open ( url ) if FilenameFromHandler : filename = FilenameFromHandler elif dl . filename : filename = dl . filename else : filename = FilenameFromUrl ( dl . realurl ) if ( not filename ) : filename = 'NoName' if ( resp . status_code == 413 ) : return ( 'too large' , filename , '' ) elif ( resp . status_code not in ( 200 , 206 ) ) : return ( 'download failed' , filename , '' ) elif ( not resp . content ) : return ( 'not resuming' , filename , '' ) else : return ( '' , filename , resp . content )
filedownload工具函数，简化文件下载工作 返回一个元组 .