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
[Deprecated PR] Python 3- Step 2: Auto-code migration #574
Conversation
Codecov Report
@@ Coverage Diff @@
## master #574 +/- ##
==========================================
- Coverage 77.48% 77.33% -0.16%
==========================================
Files 125 127 +2
Lines 30980 31633 +653
==========================================
+ Hits 24005 24462 +457
- Misses 6975 7171 +196
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not reviewed in entirely yet, but that's a good start!
scapy/arch/linux.py
Outdated
@@ -145,7 +147,7 @@ def attach_filter(s, bpf_filter, iface): | |||
nb = int(lines[0]) | |||
bpf = "" | |||
for l in lines[1:]: | |||
bpf += struct.pack("HBBI",*map(long,l.split())) | |||
bpf += struct.pack("HBBI",*list(map(int,l.split()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need list()
here, this should be enough: bpf += struct.pack("HBBI",*map(int, l.split()))
scapy/as_resolvers.py
Outdated
@@ -88,7 +90,7 @@ def resolve(self, *ips): | |||
for l in r.splitlines()[1:]: | |||
if "|" not in l: | |||
continue | |||
asn,ip,desc = map(str.strip, l.split("|")) | |||
asn,ip,desc = list(map(str.strip, l.split("|"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, list()
is not needed here.
import gtp_v2 | ||
return gtp_v2.GTPHeader | ||
return GTPHeader | ||
@classmethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this windows EOL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ideas how to do it ? I cannot see it using vim/windows and want to avoid having the entire file changed....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dos2unix
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot do it without chaning the hole file... Will do this in a next PR :/ (5 files in total are badly encoded)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files that have wrong line endings: gtp.py, ppi.py, ppi_cace.py, ppi_geotag.py, rsvp.py
Editing those files often creates messy eol like this one :(
Oh yeah 👍 @gpotter2 what about adding: from __future__ import unicode_literals in all files? This would require using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not have time to read all of this but it looks good.
Do you think this would be possible to split this commit a70a803 into several ones?
Maybe at least a separate commit for the print()
function.
scapy/base_classes.py
Outdated
import re,random,socket | ||
import types | ||
from six.moves import map | ||
from six.moves import range | ||
from six.moves import zip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe merge the 3 import lines like this?
from six.moves import map, range, zip
scapy/contrib/bgp.py
Outdated
@@ -27,6 +28,9 @@ | |||
from scapy.layers.inet6 import IP6Field | |||
from scapy.config import conf, ConfClass | |||
from scapy.error import log_runtime | |||
from six.moves import map | |||
import six | |||
from six.moves import range |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here:
from six.moves import map, range
scapy/layers/inet.py
Outdated
import six | ||
from six.moves import map | ||
from six.moves import range | ||
from six.moves import zip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from six.moves import map, range, zip
scapy/layers/inet.py
Outdated
r.sprintf("%-15s,IP.src% {TCP:%TCP.flags%}{ICMP:%ir,ICMP.type%}"))) | ||
return self.make_table(lambda s_r: (s_r[0].sprintf("%IP.dst%:{TCP:tcp%ir,TCP.dport%}{UDP:udp%ir,UDP.dport%}{ICMP:ICMP}"), | ||
s_r[0].ttl, | ||
s_r[1].sprintf("%-15s,IP.src% {TCP:%TCP.flags%}{ICMP:%ir,ICMP.type%}"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation here.
scapy/layers/inet6.py
Outdated
r.sprintf("%-42s,IPv6.src% {TCP:%TCP.flags%}"+ | ||
return self.make_table(lambda s_r: (s_r[0].sprintf("%-42s,IPv6.dst%:{TCP:tcp%TCP.dport%}{UDP:udp%UDP.dport%}{ICMPv6EchoRequest:IER}"), # TODO: ICMPv6 ! | ||
s_r[0].hlim, | ||
s_r[1].sprintf("%-42s,IPv6.src% {TCP:%TCP.flags%}"+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation here also :)
scapy/layers/netbios.py
Outdated
@@ -89,7 +90,7 @@ class NBNSRequest(Packet): | |||
IntField("TTL", 0), | |||
ShortField("RDLENGTH", 6), | |||
BitEnumField("G",0,1,{0:"Unique name",1:"Group name"}), | |||
BitEnumField("OWNER_NODE_TYPE",00,2,{00:"B node",01:"P node",02:"M node",03:"H node"}), | |||
BitEnumField("OWNER_NODE_TYPE",00,2,{00:"B node",0o1:"P node",0o2:"M node",0o3:"H node"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this. Are you sure this is octal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well no. But written like 01, it's interpreted as an octal...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gpotter2 that's an error, can you use decimal values here?
scapy/layers/netbios.py
Outdated
@@ -131,7 +132,7 @@ class NBNSQueryResponseNegative(Packet): | |||
IntField("TTL",0), | |||
ShortField("RDLENGTH",6), | |||
BitEnumField("G",0,1,{0:"Unique name",1:"Group name"}), | |||
BitEnumField("OWNER_NODE_TYPE",00,2,{00:"B node",01:"P node",02:"M node",03:"H node"}), | |||
BitEnumField("OWNER_NODE_TYPE",00,2,{00:"B node",0o1:"P node",0o2:"M node",0o3:"H node"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@robin-jarry I know the commit is massive. As I said, it partially result from an auto tool, so I won't be able to split it :/ |
@p-l- @robin-jarry
|
@gpotter2, I had not seen @guedou comment on another PR which you closed: #567 I completely agree on the "divide and conquer" strategy. This is always better than large patches. It is easier to check for details in small patches, limiting the risks. On the whole from __future__ import print_function everywhere, even if this is quite cumbersome. It has the benefit of completely preventing the use of the old @guedou, what do you think? To all, what do you think about also adding: from __future__ import unicode_literals |
I got a patch for the failing travis test... @robin-jarry
Why not... I don't really understand how useful it is ? |
This makes python 2 behave like python 3 regarding string literals. I found this article inspiring on that matter: |
Thanks @robin-jarry |
I think that it is too soon to add restrictions with __future__ imports. It might take some until the compatibility is achieved, and I would like that contributors keep writing code without restrictions.
I am not convinced that the print one should be enforced on every file.
|
99a3365
to
768557f
Compare
That's right. We can always add it later, once the compatibility will be really working. |
f434855
to
7be0ac1
Compare
To all:
I'll won't add more fixes to this PR. Waiting for it to be reviewed. Every thing will be in parts 3+ I'm stopping there for now, waiting for all this to be approved + modified. |
@@ -16,6 +17,7 @@ | |||
import scapy.config | |||
from scapy.pton_ntop import inet_pton | |||
from scapy.data import * | |||
from scapy.modules.six.moves import map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it will be nice to rewrite the map calls using list comprehensions. I can do that in another PR if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that would be great. I don't want to make overweight this one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still working on it =/
I agree with @robin-jarry regarding the use of |
@p-l- regarding |
Here is a nice and clean rebased state. (removed all merge commits + fixed conflicts). |
@guedou, I don’t see why it would bother anyone to put parentheses arround print arguments. And this is the new official python syntax, I think everyone should get used to it. Also, using |
As Scapy does not use print a lot, I think that there is no point in adding the print import on top of all files. Moreover, it's quite inconvenient for regular Python 2 users/contributors.
That's something that we can discuss again when the "compatibility mode" will work fine.
Who knows, we might end up supporting 2.7 as long as we did with 2.5 =)
|
5bd1e8f
to
d8c4ee8
Compare
To all, @p-l- @guedou A last question: what do we do about Apart from that, it's quite painful to maintain this PR up to date with the rest of scapy, so it would be great if it could be merged or included quite soon :) Thanks ! |
As already suggested, it makes more sense to submit PR targeting single changes (for example, exceptions, range, ...) and update CONTRIBUTING as well for future reference.
Such PR are easier to review and merge. Moreover, they tend to provide a cleaner commits history.
|
@guedou You are right, but It's hard to split a PR like this one:
I know it's a hard work for you guys, and i'm sorry of that... |
Apply python-modernize + applied small fix from secdev#571 to fix stderr not being logged
Also force git to correctly manage EOL in the future
@gpotter2 python-modernize has a nice -l and -f options, so it's not so hard to split this pull request |
Please don't make me do every thing again :( |
@gpotter2 I really understand your frustration, but we need to find a way to merge your patches easily. Unfortunately, you would need to submit smaller PRs to do so, as we previously discussed. I can assure you that I will be able to review and merge the smaller ones quickly. I consider that this one is a proof of concept that needs to be split for easier review and maintenance. We won't have a time to proof read all of the subsequent changes to make sure that everything is fine. This current PR as already some issues: for example Could you submit the following small PRs?
I am still working on rewriting the map() with list comprehension and I am planning to submit a PRs next week. |
OK.
|
@gpotter2 can we close this PR ? |
EDIT: That PR was splitted in smaller ones. This will stay open for legacy until all have been merged
Next part of supporting Python 3. This increases the compatibility between python 2 and 3, by using common methods + six.py module. It does not provide a suitable python 3 compatibility yet.
The PR:
six.py
in modules