old_contents: from __future__ import absolute_import
  from __future__ import print_function
  
  import tarfile
  import os
  from six.moves.urllib.request import FancyURLopener
  
  from ..utils.generic_utils import Progbar
  
  
  class ParanoidURLopener(FancyURLopener):
      def http_error_default(self, url, fp, errcode, errmsg, headers):
          raise Exception('URL fetch failure on {}: {} -- {}'.format(url, errcode, errmsg))
  
  
  def get_file(fname, origin, untar=False):
      datadir_base = os.path.expanduser(os.path.join('~', '.keras'))
      if not os.access(datadir_base, os.W_OK):
          datadir_base = os.path.join('/tmp', '.keras')
      datadir = os.path.join(datadir_base, 'datasets')
      if not os.path.exists(datadir):
          os.makedirs(datadir)
  
      if untar:
          untar_fpath = os.path.join(datadir, fname)
          fpath = untar_fpath + '.tar.gz'
      else:
          fpath = os.path.join(datadir, fname)
  
      if not os.path.exists(fpath):
          print('Downloading data from',  origin)
          global progbar
          progbar = None
  
          def dl_progress(count, block_size, total_size):
              global progbar
              if progbar is None:
                  progbar = Progbar(total_size)
              else:
                  progbar.update(count*block_size)
  
          ParanoidURLopener().retrieve(origin, fpath, dl_progress)
          progbar = None
  
      if untar:
          if not os.path.exists(untar_fpath):
              print('Untaring file...')
              tfile = tarfile.open(fpath, 'r:gz')
              tfile.extractall(path=datadir)
              tfile.close()
          return untar_fpath
  
      return fpath
  
new_contents: from __future__ import absolute_import
  from __future__ import print_function
  
  import tarfile
  import os
  import sys
  from six.moves.urllib.request import urlopen, build_opener, install_opener
  from six.moves.urllib.error import URLError, HTTPError
  
  from ..utils.generic_utils import Progbar
  
  
  # Under Python 2, 'urlretrieve' relies on FancyURLopener from legacy
  # urllib module, known to have issues with proxy management
  if sys.version_info[0] == 2:
      def urlretrieve(url, filename, reporthook=None, data=None):
          def chunk_read(response, chunk_size=8192, reporthook=None):
              total_size = response.info().get('Content-Length').strip()
              total_size = int(total_size)
              bytes_so_far = 0
              count = 0
              while 1:
                  chunk = response.read(chunk_size)
                  if not chunk:
                      break
                  count += 1
                  if reporthook:
                      reporthook(count, chunk_size, total_size)
                  yield chunk
  
          response = urlopen(url, data)
          with open(filename, 'wb') as fd:
              for chunk in chunk_read(response, reporthook=reporthook):
                  fd.write(chunk)
  else:
      from six.moves.urllib.request import urlretrieve
  
  
  def get_file(fname, origin, untar=False):
      datadir_base = os.path.expanduser(os.path.join('~', '.keras'))
      if not os.access(datadir_base, os.W_OK):
          datadir_base = os.path.join('/tmp', '.keras')
      datadir = os.path.join(datadir_base, 'datasets')
      if not os.path.exists(datadir):
          os.makedirs(datadir)
  
      if untar:
          untar_fpath = os.path.join(datadir, fname)
          fpath = untar_fpath + '.tar.gz'
      else:
          fpath = os.path.join(datadir, fname)
  
      if not os.path.exists(fpath):
          print('Downloading data from',  origin)
          global progbar
          progbar = None
  
          def dl_progress(count, block_size, total_size):
              global progbar
              if progbar is None:
                  progbar = Progbar(total_size)
              else:
                  progbar.update(count*block_size)
  
          error_msg = 'URL fetch failure on {}: {} -- {}'
          try:
              urlretrieve(origin, fpath, dl_progress)
          except URLError as e:
              raise Exception(error_msg.format(url, e.errno, e.reason))
          except HTTPError as e:
              raise Exception(error_msg.format(url, e.code, e.msg))
          progbar = None
  
      if untar:
          if not os.path.exists(untar_fpath):
              print('Untaring file...')
              tfile = tarfile.open(fpath, 'r:gz')
              tfile.extractall(path=datadir)
              tfile.close()
          return untar_fpath
  
      return fpath
  
subject: Add http/https proxy management for dataset downloading