Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #27 from NoRedInk/add-urlretrieve-timeouts
Browse files Browse the repository at this point in the history
Enable timeouts when retreiving content via url.
  • Loading branch information
omnibs authored Mar 8, 2018
2 parents 097bfc7 + bb25a9c commit f5bd06c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions native_package_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
import os
import sys
import tarfile
try:
# For Python 3.0 and later
from urllib.request import urlretrieve
except ImportError:
# Fall back to Python 2's urllib2
from urllib import urlretrieve
import requests

import elm_package
import exact_dependencies
Expand Down Expand Up @@ -87,6 +82,13 @@ def vendor_package_dir(vendor_dir, package):
)


def urlretrieve(url, filename, timeout = 60):
response = requests.get(url, timeout=timeout, stream=True)
response.raise_for_status()
with open(filename, "wb") as output:
for chunk in response.iter_content(4096):
output.write(chunk)

def fetch_packages(vendor_dir, packages):
"""
Fetches all packages from github.
Expand Down

0 comments on commit f5bd06c

Please sign in to comment.