From: German Service Network Date: Sun, 21 Dec 2025 06:26:02 +0000 (+0100) Subject: Merge github d0d3f9a (use urllib not urllib3 to download file:// urls) X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=raspbmirror.git Merge github d0d3f9a (use urllib not urllib3 to download file:// urls) --- diff --git a/raspbmirror.py b/raspbmirror.py index 0e5551d..e7f61ca 100644 --- a/raspbmirror.py +++ b/raspbmirror.py @@ -47,7 +47,7 @@ parser.add_argument("--repair", help="during mirroring, verify that all on-disk parser.add_argument("--urllib", help="force usage of the builtin urllib module, even if urllib3 is present", action="store_true") -parser.add_argument("--urllib3", help="force usage of the urllib3 module, panics if the dependency is missing", action="store_true") +parser.add_argument("--urllib3", help="force usage of the urllib3 module, panics if the dependency is missing, note that urllib is always used for file:// urls as urllib3 does not seem to support them", action="store_true") parser.add_argument("--ipv4", help="force usage of IPv4 addresses. Requires urllib3", action="store_true") @@ -67,8 +67,8 @@ if args.urllib and args.urllib3: logging.error('error: flags --urllib and --urllib3 are in conflict') exit(1) +import urllib.request if args.urllib: - import urllib.request use_urllib3 = False elif args.urllib3: import urllib3 @@ -79,7 +79,6 @@ else: import urllib3 use_urllib3 = True except: - import urllib.request use_urllib3 = False if args.ipv4 and args.ipv6: @@ -171,11 +170,13 @@ def ensuresafepath(path): sys.exit(1) def geturl(fileurl): - if use_urllib3: + if use_urllib3 and (b'file://' not in fileurl): + #print('downloading using urllib3') response = dlmanager.request("GET", fileurl.decode('ascii')) ts = getts(fileurl, response) return (response.data, ts) else: + #print('downloading using urllib') with urllib.request.urlopen(fileurl.decode('ascii')) as response: data = response.read() ts = getts(fileurl, response) @@ -357,7 +358,7 @@ def getandcheckfile(fileurl, sha256, size, path, outputpath, errorfromstr, error 'ascii') + ' to ' + outputpath.decode( 'ascii') + viamsg) f = open(writepath, 'wb') - if use_urllib3: + if use_urllib3 and (b'file://' not in fileurl): response = dlmanager.request("GET", fileurl.decode('ascii'), preload_content=False) ts = getts(fileurl, response) tl = 0