bitbake-devel.lists.openembedded.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fetch2/wget: clean up netrc usage
@ 2023-02-14 16:07 Ross Burton
  2023-02-16  9:58 ` [bitbake-devel] " Paulo Neves
  0 siblings, 1 reply; 3+ messages in thread
From: Ross Burton @ 2023-02-14 16:07 UTC (permalink / raw)
  To: bitbake-devel; +Cc: nd

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 <ross.burton@arm.com>
---
 bitbake/lib/bb/fetch2/wget.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py
index 696e9180303..6d365729e0c 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:
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [bitbake-devel] [PATCH] fetch2/wget: clean up netrc usage
  2023-02-14 16:07 [PATCH] fetch2/wget: clean up netrc usage Ross Burton
@ 2023-02-16  9:58 ` Paulo Neves
  2023-02-16 11:11   ` Ross Burton
  0 siblings, 1 reply; 3+ messages in thread
From: Paulo Neves @ 2023-02-16  9:58 UTC (permalink / raw)
  To: Ross Burton, bitbake-devel; +Cc: nd

Your commit mentions TypeError but you also removed ImportError and
IOError. Why were they there and why are they removed?

Paulo Neves
On 2/14/23 17:07, Ross Burton wrote:
> 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 <ross.burton@arm.com>
> ---
>   bitbake/lib/bb/fetch2/wget.py | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py
> index 696e9180303..6d365729e0c 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:
> --
> 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: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [paulo@myneves.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [bitbake-devel] [PATCH] fetch2/wget: clean up netrc usage
  2023-02-16  9:58 ` [bitbake-devel] " Paulo Neves
@ 2023-02-16 11:11   ` Ross Burton
  0 siblings, 0 replies; 3+ messages in thread
From: Ross Burton @ 2023-02-16 11:11 UTC (permalink / raw)
  To: Paulo Neves; +Cc: bitbake-devel

On 16 Feb 2023, at 09:58, Paulo Neves <paulo@myneves.com> wrote:
> 
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-16 11:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 16:07 [PATCH] fetch2/wget: clean up netrc usage Ross Burton
2023-02-16  9:58 ` [bitbake-devel] " Paulo Neves
2023-02-16 11:11   ` Ross Burton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).