-
Notifications
You must be signed in to change notification settings - Fork 183
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
Miscellaneous usability improvements #225
Conversation
Since chains are normally accessed using names, a dict is more useful than a list here. This change breaks API compatibility.
Add __repr__ for Table, Chain, Rule, Matcher and Target. This greatly eases debugging and interactive usage. This change requires at least Python version 3.3 for the ipaddress module.
I'm not sure what's up with the Travis tests here. All unit tests pass on my machine, and the error it throws looks like it might be unrelated to my changes? |
I think the tests fail due to the new dependency. Can you try applying this diff:
|
This is necessary for python versions <3.3
That was it. I have added a version check, since ipaddress is a built-in module starting in python 3.3. I think it is better to not have that dependency on these versions. |
Looks good, thanks! Can you add a few test cases for testing the new |
Here you go. Two observations:
|
Turns out, ipaddress is actually behaving to its spec, that spec is just very dumb. I'll just rip out that part of the repr code. |
* Use @Property and its .setter decorator. * Add fancy netmask formatting for src/dst: You can now get 127.0.0.1/24 instead of 127.0.0.1/255.255.255.0 by using .src_numeric_mask instead of just .src. * Simplify code of .src and dst a bit
@jaseg thanks, please let me know once it's ready for review. 👍 |
There. In my enthusiasm I changed quite a lot, have a look whether that works for you. |
LGTM, and the tests are passing. The only thing remaining is to update |
Is this going to be merged? I've been waiting for a while :) |
@Troyhy if you (or someone else) can add a few lines of documentation to |
Ok, I'm using your library in one project. I will try to resolve it as part of the project. |
Looks stale, closing. Feel free to reopen if this is still relevant. |
Here's three small changes I found useful. Tell me what you think.
First, using
@functools.wraps
, docstrings and function signatures can be preserved when using@autocommit
. This is useful in interactive usage. This change should be backwards-compatible to at least python 2.7.Second, I found
Table.chains
not very useful as a plain list, since I'd only iterate over it to get a particular chain anyway. A dict makes more sense to me here. This is obviously breaking the API, so I don't expect you to merge this right away.Third, I wrote some nice
__repr__
s for the most common ip4tables classes. This also is really useful in interactive usage, or even when just printing debug output. Be aware that as-is the formatting code pretty-prints IP adresses using theipaddress
module found in python 3.3 upwards.Thank you for the nice module, jaseg