PKK˰]c c requests_download.py"""Download files using requests and save them to a target path Usage example:: import hashlib # progressbar is provided by progressbar2 on PYPI. from progressbar import DataTransferBar from requests_download import download, HashTracker, ProgressTracker hasher = HashTracker(hashlib.sha256()) progress = ProgressTracker(DataTransferBar()) download('https://github.com/takluyver/requests_download/archive/master.zip', 'requests_download.zip', trackers=(hasher, progress)) assert hasher.hashobj.hexdigest() == '...' """ import requests __version__ = '0.1.2' class TrackerBase(object): def on_start(self, response): pass def on_chunk(self, chunk): pass def on_finish(self): pass class ProgressTracker(TrackerBase): def __init__(self, progressbar): self.progressbar = progressbar self.recvd = 0 def on_start(self, response): max_value = None if 'content-length' in response.headers: max_value = int(response.headers['content-length']) self.progressbar.start(max_value=max_value) self.recvd = 0 def on_chunk(self, chunk): self.recvd += len(chunk) try: self.progressbar.update(self.recvd) except ValueError: # Probably the HTTP headers lied. pass def on_finish(self): self.progressbar.finish() class HashTracker(TrackerBase): def __init__(self, hashobj): self.hashobj = hashobj def on_chunk(self, chunk): self.hashobj.update(chunk) def download(url, target, headers=None, trackers=()): """Download a file using requests. This is like urllib.request.urlretrieve, but: - requests validates SSL certificates by default - you can pass tracker objects to e.g. display a progress bar or calculate a file hash. """ if headers is None: headers = {} headers.setdefault('user-agent', 'requests_download/'+__version__) r = requests.get(url, headers=headers, stream=True) r.raise_for_status() for t in trackers: t.on_start(r) with open(target, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): if chunk: f.write(chunk) for t in trackers: t.on_chunk(chunk) for t in trackers: t.on_finish() PKt%Hm 599)requests_download-0.1.2.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2016 Thomas Kluyver Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!Hf$Wd'requests_download-0.1.2.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,Q0343 /, (-JLR()*M ILR(4KM̫#DPK!H{)*requests_download-0.1.2.dist-info/METADATAUMs6WI j=8UN|'Ivz@rE 0 ~ȴ\7)۷oWwE&X)Sd,]13M{>E!l`{ATA8qD xasP /ٍ)pU2J+M\yY'<5ڋ#KHKGݿ=464pWXcB.y}`pN>|Yxݎ#QZ9cWþ.SOG=38coS)NbeJIj }S[ }gkaS& Zxna<स|#K8̾؉$ޚIV7hq(*2#x9(".UTgwLJLcmH%|ޚgzJԔnO/7zLh=.jxObLO2؜Za χeouO_'oYE'#0sC(v"yq3S6smi~,P1|NҰ a vk<ý*vK:ӛڱ e|bC(L*<КP6|R;EaQg!~cPRYJUE U.q%'Xg1EKM= H,:v!K%4<PK!H O(requests_download-0.1.2.dist-info/RECORDͻv0oha#- (PHC߷K'ޡ8Rv][ZSzƆ[1$,MN)PSnc6TAMh-F+/|ڡǀܶ1S+TT~4"s3-* ⚶4!>d Bs0tr*cmI&-ė6]]NOKcpp>H¬r){ofo|q.6P/PKK˰]c c requests_download.pyPKt%Hm 599) requests_download-0.1.2.dist-info/LICENSEPK!Hf$Wd'requests_download-0.1.2.dist-info/WHEELPK!H{)*requests_download-0.1.2.dist-info/METADATAPK!H O(requests_download-0.1.2.dist-info/RECORDPK