From 11b30b91df1f0e03b53da970ec2588e85817bacc Mon Sep 17 00:00:00 2001 From: Matt Story Date: Tue, 26 Oct 2021 10:56:13 -0400 Subject: [PATCH] Support more url schemes for getting standalone manifest urllib.requests.urlopen also supports file, so call it unless the scheme is 'gs'. This adds http, https, and ftp support. Change-Id: I3f215c3ebd8e6dee29ba14c7e79ed99d37287109 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/322095 Reviewed-by: Michael Kelly Reviewed-by: Mike Frysinger Tested-by: Matt Story --- fetch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fetch.py b/fetch.py index d79f9479..c954a9c2 100644 --- a/fetch.py +++ b/fetch.py @@ -17,6 +17,8 @@ import subprocess import sys from urllib.parse import urlparse +from urllib.request import urlopen + def fetch_file(url, verbose=False): """Fetch a file from the specified source using the appropriate protocol. @@ -39,7 +41,5 @@ def fetch_file(url, verbose=False): print('fatal: error running "gsutil": %s' % e.stderr, file=sys.stderr) sys.exit(1) - if scheme == 'file': - with open(url[len('file://'):], 'rb') as f: - return f.read() - raise ValueError('unsupported url %s' % url) + with urlopen(url) as f: + return f.read()