From 77f91746dc86656dd960d910698c51a0559d1837 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Tue, 14 Feb 2023 16:07:51 +0000 Subject: bitbake: fetch2/wget: clean up netrc usage Assigning a return value which is potentially None to a tuple and catching TypeError is pretty ugly. Rewrite the code to explicitly check the value for clarity. (Bitbake rev: f4ebb27616ac2df27c29a6052b1526a4c48db607) Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- bitbake/lib/bb/fetch2/wget.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bitbake/lib/bb/fetch2/wget.py') diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py index 696e918030..6d365729e0 100644 --- a/bitbake/lib/bb/fetch2/wget.py +++ b/bitbake/lib/bb/fetch2/wget.py @@ -361,10 +361,11 @@ class Wget(FetchMethod): try: import netrc - n = netrc.netrc() - login, unused, password = n.authenticators(urllib.parse.urlparse(uri).hostname) - add_basic_auth("%s:%s" % (login, password), r) - except (TypeError, ImportError, IOError, netrc.NetrcParseError): + auth_data = netrc.netrc().authenticators(urllib.parse.urlparse(uri).hostname) + if auth_data: + login, _, password = auth_data + add_basic_auth("%s:%s" % (login, password), r) + except (FileNotFoundError, netrc.NetrcParseError): pass with opener.open(r, timeout=30) as response: -- cgit v1.2.3-54-g00ecf