def read_head_info(cls, url): try: req = HEADRequest(url) res = urlopen(req) except IOError: raise DownloadError('Failed to fetch %s' % url) else: if res.code != 200: raise DownloadError('Failed to fetch %s' % url) return res.info()
def read(cls, url): try: r = urlopen(url) except IOError: raise DownloadError('Failed to fetch %s' % url) else: return r.read()
def urlretrieve(url, filename, reporthook, sha256sum): try: _urlretrieve(url, filename, reporthook) if not validate_sha256(filename, sha256sum): raise DownloadError( "Corrupted download, the sha256 doesn't match") except BaseException: os.unlink(filename) raise
def fetch(cls, url, filename, expected_sha256=None): b = ProgressBar() try: urlretrieve(url, filename, b.reporthook, sha256sum=expected_sha256) sys.stdout.write('\n') except DownloadError: if os.path.exists(filename): os.unlink(filename) raise except IOError: sys.stdout.write('\n') raise DownloadError('Failed to fetch %s from %s' % (filename, url))