lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKH8qBtaWOOdcfZ2s1Nym6oB1=rC4cxxO6Q5z39yvAyQMgNyAg@mail.gmail.com>
Date:   Mon, 20 Mar 2023 11:03:24 -0700
From:   Stanislav Fomichev <sdf@...gle.com>
To:     Jakub Kicinski <kuba@...nel.org>
Cc:     netdev@...r.kernel.org, davem@...emloft.net, edumazet@...gle.com,
        pabeni@...hat.com
Subject: Re: [PATCH net-next 3/4] ynl: replace print with NlError

On Fri, Mar 17, 2023 at 9:21 PM Jakub Kicinski <kuba@...nel.org> wrote:
>
> On Fri, 17 Mar 2023 17:23:39 -0700 Stanislav Fomichev wrote:
> > Instead of dumping the error on the stdout, make the callee and
> > opportunity to decide what to do with it. This is mostly for the
> > ethtool testing.
>
> > diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
> > index 21c015911803..6c1a59cef957 100644
> > --- a/tools/net/ynl/lib/ynl.py
> > +++ b/tools/net/ynl/lib/ynl.py
> > @@ -67,6 +67,13 @@ from .nlspec import SpecFamily
> >      NLMSGERR_ATTR_MISS_NEST = 6
> >
> >
> > +class NlError(Exception):
> > +  def __init__(self, nl_msg):
> > +    self.nl_msg = nl_msg
> > +
> > +  def __str__(self):
>
> Why not __repr__ ?

The following:
class A(Exception):
  def __repr__(self):
    return "{{{A}}}"
  def __str__(self):
    return "{{{B}}}"

raise A

Gets me this:
$ python3 tmp.py
Traceback (most recent call last):
  File "/usr/local/google/home/sdf/tmp/tmp.py", line 9, in <module>
    raise A
__main__.A: {{{B}}}


And for this:
class A(Exception):
  def __repr__(self):
    return "{{{A}}}"

raise A

I see:
$ python3 tmp.py
Traceback (most recent call last):
  File "/usr/local/google/home/sdf/tmp/tmp.py", line 7, in <module>
    raise A
__main__.A

It seems that __repr__ is mostly for repr()? And the rest is using
__str__? My pythonic powers are weak, can convert to __repr__ if you
prefer (or understand the difference).



> > +    return f"Netlink error: {os.strerror(-self.nl_msg.error)}\n{self.nl_msg}"
> > +
>
> nit: double new line here
>
> >  class NlAttr:
> >      def __init__(self, raw, offset):
> >          self._len, self._type = struct.unpack("HH", raw[offset:offset + 4])
> > @@ -495,9 +502,7 @@ genl_family_name_to_id = None
> >                      self._decode_extack(msg, op.attr_set, nl_msg.extack)
> >
> >                  if nl_msg.error:
> > -                    print("Netlink error:", os.strerror(-nl_msg.error))
> > -                    print(nl_msg)
> > -                    return
> > +                    raise NlError(nl_msg)
> >                  if nl_msg.done:
> >                      if nl_msg.extack:
> >                          print("Netlink warning:")
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ