def fetch(self): p = self.check_cache() if p is not None: return p release_list = yarg.get(self.name).release(self.version) preferred_release = self.pick_best_wheel(release_list) if preferred_release is None: raise NoWheelError( 'No compatible wheels found for {0.name} {0.version}'.format( self)) download_to = get_cache_dir() / 'pypi' / self.name / self.version try: download_to.mkdir(parents=True) except OSError as e: # Py2 compatible equivalent of FileExistsError if e.errno != errno.EEXIST: raise target = download_to / preferred_release.filename from . import __version__ hasher = HashTracker(hashlib.md5()) headers = {'user-agent': 'pynsist/' + __version__} logger.info('Downloading wheel: %s', preferred_release.url) download(preferred_release.url, str(target), headers=headers, trackers=(hasher, )) if hasher.hashobj.hexdigest() != preferred_release.md5_digest: target.unlink() raise ValueError('Downloaded wheel corrupted: {}'.format( preferred_release.url)) return target
def get_from_pypi(self): """Download a compatible wheel from PyPI. Downloads to the cache directory and returns the destination as a Path. Raises NoWheelError if no compatible wheel is found. """ try: pypi_pkg = yarg.get(self.name) except yarg.HTTPError as e: if e.status_code == 404: raise NoWheelError("No package named {} found on PyPI".format( self.name)) raise release_list = pypi_pkg.release(self.version) if release_list is None: raise NoWheelError( "No release {0.version} for package {0.name}".format(self)) preferred_release = self.pick_best_wheel(release_list) if preferred_release is None: raise NoWheelError( 'No compatible wheels found for {0.name} {0.version}'.format( self)) download_to = get_cache_dir() / 'pypi' / self.name / self.version try: download_to.mkdir(parents=True) except OSError: # Ignore OSError only if the directory exists if not download_to.is_dir(): raise target = download_to / preferred_release.filename from . import __version__ hasher = HashTracker(hashlib.md5()) headers = {'user-agent': 'pynsist/' + __version__} logger.info('Downloading wheel: %s', preferred_release.url) download(preferred_release.url, str(target), headers=headers, trackers=(hasher, )) if hasher.hashobj.hexdigest() != preferred_release.md5_digest: target.unlink() raise ValueError('Downloaded wheel corrupted: {}'.format( preferred_release.url)) return target
import urllib3.request import certifi import hashlib # progressbar is provided by progressbar2 on PYPI. from progressbar import DataTransferBar from requests_download import download, HashTracker, ProgressTracker user_agent = { 'user-agent': 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0' } http = urllib3.PoolManager(cert_reqs="CERT_REQUIRED", ca_certs=certifi.where(), headers=user_agent) hasher = HashTracker(hashlib.sha256()) progress = ProgressTracker(DataTransferBar()) def downloadEp(ep): src = BeautifulSoup( http.request("GET", "http://anime.megamanonline.org" + ep.p.a["href"]).data, "html.parser") vimeourl = src.find("iframe")["src"] index = vimeourl.rindex("/") + 1 idvid = vimeourl[index:index + 8] vimeourl = "https://player.vimeo.com/video/" + idvid res = ""