From 375d1ee6386b70b13b7d4574b245b9916b8d911d Mon Sep 17 00:00:00 2001 From: Paul Fuqua Date: Wed, 22 Jun 2022 21:36:43 -0500 Subject: [PATCH 1/3] Replace CGetURLOpener with urlretrieve. --- cget/util.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cget/util.py b/cget/util.py index b41ac1a..d6686fc 100644 --- a/cget/util.py +++ b/cget/util.py @@ -16,7 +16,7 @@ else: import subprocess -from six.moves.urllib import request +from six.moves.urllib import request, error def to_bool(value): x = str(value).lower() @@ -209,12 +209,6 @@ def symlink_to(src, dst_dir): os.symlink(src, target) return target -class CGetURLOpener(request.FancyURLopener): - def http_error_default(self, url, fp, errcode, errmsg, headers): - if errcode >= 400: - raise BuildError("Download failed with error {0} for: {1}".format(errcode, url)) - return request.FancyURLopener.http_error_default(self, url, fp, errcode, errmsg, headers) - def download_to(url, download_dir, insecure=False): name = url.split('/')[-1] file = os.path.join(download_dir, name) @@ -229,7 +223,12 @@ def hook(count, block_size, total_size): bar.update(0) context = None if insecure: context = ssl._create_unverified_context() - CGetURLOpener(context=context).retrieve(url, filename=file, reporthook=hook, data=None) + try: + request.urlretrieve(url, filename=file, reporthook=hook, data=None) + except error.HTTPError as e: + if e.status >= 400: + raise BuildError("Download failed with error {0} for: {1}".format(e.status, url)) + raise bar.update(bar_len) if not os.path.exists(file): raise BuildError("Download failed for: {0}".format(url)) From 3d5f4d6c9d66ebcae8542d16436c39bbc34a97e8 Mon Sep 17 00:00:00 2001 From: Paul Fuqua Date: Thu, 23 Jun 2022 10:45:53 -0500 Subject: [PATCH 2/3] Remove unused context variable. --- cget/util.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cget/util.py b/cget/util.py index d6686fc..31f1c71 100644 --- a/cget/util.py +++ b/cget/util.py @@ -221,8 +221,6 @@ def hook(count, block_size, total_size): # Hack because we can't set the position bar.pos = percent bar.update(0) - context = None - if insecure: context = ssl._create_unverified_context() try: request.urlretrieve(url, filename=file, reporthook=hook, data=None) except error.HTTPError as e: From 5ab9f18db1af878642b54723e851f562d13c1f26 Mon Sep 17 00:00:00 2001 From: Paul Fuqua Date: Thu, 23 Jun 2022 11:34:46 -0500 Subject: [PATCH 3/3] Remove unused ssl import. --- cget/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cget/util.py b/cget/util.py index 31f1c71..34a4d56 100644 --- a/cget/util.py +++ b/cget/util.py @@ -1,4 +1,4 @@ -import click, os, sys, shutil, json, six, hashlib, ssl +import click, os, sys, shutil, json, six, hashlib if sys.version_info[0] < 3: try: