fetch2/wget: clean up netrc usage
PATCH 1/1 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/lib/bb/fetch2/wget.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
bitbake/lib/bb/fetch2/wget.py +5 -4
@@ -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:
Signature · 1 line
2.34.1
Your commit mentions TypeError but you also removed ImportError and IOError. Why were they there and why are they removed?
Paulo Neves
Quoted 41 lines · Ross Burton
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.
Signed-off-by Ross Burton <[email protected]>--- bitbake/lib/bb/fetch2/wget.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)bitbake/lib/bb/fetch2/wget.py +5
-5@@ -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: --2.34.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#14419): https://lists.openembedded.org/g/bitbake-devel/message/14419
Mute This Topic: https://lists.openembedded.org/mt/96962989/4454782
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Quoted 3 lines · Paulo Neves
Your commit mentions TypeError but you also removed ImportError and IOError. Why were they there and why are they removed?
ImportError makes no sense as netrc is a standard module.
IOError was used to catch FileNotFoundError, but the netrc class documents that it throws FileNotFound if there isn’t a netrc, so that’s expected behaviour that we should silently handle. Any other disk IO errors are a problem that should be raised.
Ross