The Wayback Machine - https://web.archive.org/web/20201107153307/https://github.com/secdev/scapy/issues/2746
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Use namedtuples in SndRcvList() #2746

Open
guedou opened this issue Aug 3, 2020 · 1 comment · May be fixed by #2846
Open

[Proposal] Use namedtuples in SndRcvList() #2746

guedou opened this issue Aug 3, 2020 · 1 comment · May be fixed by #2846

Comments

@guedou
Copy link
Member

@guedou guedou commented Aug 3, 2020

While teaching Scapy, I realized that it is difficult to understand which indices to use to iterate a response of type SndRcvList().

For example, to display the first answer, a user must do:

>>> r, u = sr(IP(dst="8.8.8.8") / ICMP())
>>> r[0][1]

Beginners might do the following, which is more complex to understand:

>>> r = sr(IP(dst="8.8.8.8") / ICMP())
>>> r[0][0][1]

Using a namedtuple instead of a tuple in SndRcvList(), it is possible to simplify the access to the answer with .answer while maintaining [1] for backward compatibility:

>>> r, u = sr(IP(dst="8.8.8.8") / ICMP()
>>> r[0].answer == r[0][1]

Do you think that this feature is interesting?

@guedou guedou added the discussion label Aug 3, 2020
@guedou guedou self-assigned this Aug 3, 2020
@guedou guedou added this to To do in Release 2.5.0 via automation Aug 3, 2020
@gpotter2
Copy link
Member

@gpotter2 gpotter2 commented Aug 8, 2020

This sounds super reasonable, LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.