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

Field objects (solving multiple fields of same name issue) #46

Merged
merged 4 commits into from
Dec 26, 2014

Conversation

KimiNewt
Copy link
Owner

@KimiNewt KimiNewt commented Nov 1, 2014

This pull-request solves the issue of multiple fields under the same name by introducing a new class: FieldsContainer, which is a class which acts as a string but in fact holds the values of multiple fields.

As such, it is completely backwards compatible with earlier code, but can be used to access alternate fields in a fairly easy way:

>>> p.ip.addr
10.0.0.1
>>> isinstance(p.ip.addr, str)
True
>>> p.ip.addr.alternate_fields
[<LayerField ip.addr: 10.0.0.138>] # Shows the other fields with the same name

It also allows easier access of previously harder-to-access fields, such as:

>>> p.ip.addr.showname
Source or Destination Address: 10.0.0.10 (10.0.0.10)
# And some new attributes as well:
>>> p.ip.addr.int_value
167772170
>>> p.ip.addr.binary_value
'\n\x00\x00\n'

This solves long-standing issues #15 & #23 and replaces pull-requests #16 & #17 .

Before merging, I wanted to know from the issuers and any others of any opinion as for this solution's implementation. It also requires documentation, testing and possibly modifications for python3 (not tested thoroughly, but it seems the current tests pass).

Now using it instead of fields directly, in order to be able to keep
multiple fields under one name.
@lowdef
Copy link

lowdef commented Nov 1, 2014

Would it be a good idea to have an accesor method that always returns all fields for a name as a list, i.e. not only the alternate fields. That way code dealing with multiple instanced name fields would be more generic.

>>> p.ip.addr.all_fields
[<LayerField ip.addr: 10.0.0.1>, <LayerField ip.addr: 10.0.0.138>] # Shows all fields with the same name

KimiNewt added a commit that referenced this pull request Dec 26, 2014
Field objects (solving multiple fields of same name issue)
@KimiNewt KimiNewt merged commit 26f21f5 into master Dec 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants