-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Console/Python 3] Remove pyreadline/gnureadline #703
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
Conversation
b5a6d9e
to
8789142
Compare
Codecov Report
@@ Coverage Diff @@
## master #703 +/- ##
==========================================
+ Coverage 80.14% 81.19% +1.05%
==========================================
Files 140 141 +1
Lines 34207 35139 +932
==========================================
+ Hits 27416 28532 +1116
+ Misses 6791 6607 -184
|
0b4897b
to
4694529
Compare
4694529
to
3dcf0da
Compare
@ThomasFaivre Could you have a look at this please ? Thanks! |
scapy/utils.py
Outdated
@@ -37,6 +37,9 @@ def get_temp_file(keep=False, autoext=""): | |||
conf.temp_files.append(f+autoext) | |||
return f | |||
|
|||
class Bunch: | |||
__init__ = lambda self, **kw: setattr(self, '__dict__', kw) |
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.
This may be used in tests, to create fake objects:
>>> Bunch(a=1).a
1
That looks promising! Can you rebase against master? |
9445ff5
to
4483401
Compare
Rebased. |
I have a question for you and @guedou: is it still useful, now, to have this rather than using dedicated shells, like iPython for example. What do you think? |
I guess IPython could handle it... We simply need to have an easy backup when it's not available... This would mean that ASCII color codes and auto completion are features only provided through IPython. The current implementation (or the one from this PR) allowed people who don't like IPython to have those two features... |
I don't have a strong opinion on this topic. As long as the module is easy to install and use on our side, I am fine with any choice.
If most of the same features can be achieved with iPython without any modifications in Scapy, that might be the best option.
|
If people don't like iPython, they have at least bpython as an alternative. I don't think we really need to maintain this interface when great tools exist that do the job (and can run under Linux, *BSD, MacOS & Windows). @gpotter2 are you one of the people who "don't like iPython"? I'd like to hear what you don't like if that's the case. Thanks! |
@p-l- I don't like the input system "In[..]" "Out...". I saw there is an option to change this to the "classic legacy" prompt, so i'm ok to use IPython instead. |
@gpotter2 maybe we could have |
@p-l- Sounds good. Will work onto this. |
4483401
to
baf1bf0
Compare
900f2f5
to
5b7594c
Compare
Fixed the bug "No warning messages were shown", added indirectedly by @p-l- in https://github.com/secdev/scapy/pull/764/files. |
5b7594c
to
4a29b0b
Compare
There are some changes to the current behavior:
I think that they should be fixed. |
4a29b0b
to
5475c7d
Compare
@guedou Fixed all of your comments ! |
Great job! One problem I have with this code for now: when I type: |
Well I don't know how to fix this :/ |
This patch will add the fields as a completion on packet objects. The clean way to do that is normally to create a diff --git a/scapy/main.py b/scapy/main.py
index 38d37ac..23c0d83 100644
--- a/scapy/main.py
+++ b/scapy/main.py
@@ -314,9 +314,15 @@ def interact(mydict=None,argv=None,mybanner=None,loglevel=20):
IPYTHON=False
if IPYTHON:
+ from IPython.terminal.embed import InteractiveShellEmbed
from IPython.terminal.prompts import Prompts, Token
+ from IPython.utils.generics import complete_object
from traitlets.config.loader import Config
- from IPython.terminal.embed import InteractiveShellEmbed
+ from scapy.packet import Packet
+
+ @complete_object.when_type(Packet)
+ def complete_packet(obj, prev_completions):
+ return prev_completions + [fld.name for fld in obj.fields_desc]
banner = the_banner % (conf.version) + " using IPython %s" % IPython.__version__
cfg = Config() |
002467c
to
98fb01a
Compare
@p-l- @guedou Updated according to the new logo PR ! I won't be able to fix IPython autocompletion for now (i will try to submit a patch on their side i guess), so this PR may be merged as so. Please review it :-) |
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.
Cool PR. I have some small comments.
scapy/autorun.py
Outdated
@@ -58,7 +58,7 @@ def autorun_commands(cmds, my_globals=None, ignore_globals=None, verb=0): | |||
if cmd: | |||
sys.stderr.write(sys.__dict__.get("ps2","... ")) | |||
else: | |||
sys.stderr.write(str(sys.__dict__.get("ps1",ColorPrompt()))) | |||
sys.stderr.write(str(sys.__dict__.get("ps1",sys.ps1))) |
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.
Please put a space after the comma.
|
||
def _prompt_changer(attr,val): | ||
prompt = conf.prompt | ||
def _prompt_changer(attr, val): |
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.
Could you add the following docstring:
""Change the current prompt theme"""
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.
Done
scapy/data.py
Outdated
@@ -188,7 +188,7 @@ def load_manuf(filename): | |||
IP_PROTOS=load_protocols(os.environ["SystemRoot"]+"\system32\drivers\etc\protocol") | |||
TCP_SERVICES,UDP_SERVICES=load_services(os.environ["SystemRoot"] + "\system32\drivers\etc\services") | |||
# Default value, will be updated by arch.windows | |||
MANUFDB = load_manuf(os.environ["ProgramFiles"] + "\\wireshark\\manuf") | |||
MANUFDB = None |
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.
Why are you modifying this line ? This should be in a dedicated PR if really needed.
scapy/main.py
Outdated
|
||
from scapy.config import conf | ||
# Do not add any imports here that would trigger a warning messsage |
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 mean: 'never ever add imports' or 'never add imports before this line' ? I think that you should make this textt more explicit.
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.
# Never add any global import, in main.py, that would trigger a warning messsage
# before the console handlers gets added in interact()
@@ -58,13 +54,17 @@ def _probe_config_file(cf): | |||
else: | |||
return cf_path | |||
|
|||
def _read_config_file(cf): | |||
def _read_config_file(cf, _globals=globals(), _locals=locals(), interactive=True): |
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.
Could you add a docstring and explain what the kw args do ?
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.
Done
@@ -182,25 +182,29 @@ def list_contrib(name=None): | |||
|
|||
|
|||
def save_session(fname=None, session=None, pickleProto=-1): |
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.
Could you add a docstring ?
For example, """save current Scapy session to the file specified in the fname arg"""
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.
Done
scapy/main.py
Outdated
conf.color_theme = DefaultTheme() | ||
conf.interactive = True | ||
if loglevel is not None: | ||
conf.logLevel=loglevel |
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.
Add space around =
return ct.prompt(config.conf.prompt) | ||
except: | ||
return self.__prompt | ||
def apply_ipython_color(shell): |
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.
Docstring ? =)
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.
Done
scapy/utils.py
Outdated
@@ -35,7 +35,7 @@ def get_temp_file(keep=False, autoext=""): | |||
f = os.tempnam("","scapy") | |||
if not keep: | |||
conf.temp_files.append(f+autoext) | |||
return f | |||
return f+autoext |
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.
Add spaces around +
@@ -264,6 +264,8 @@ os.unlink("t2.pcap") | |||
= Test InjectSink and Inject3Sink | |||
~ needs_root | |||
|
|||
import mock |
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.
Is this needed in this PR ?
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.
This PR fixes some useless imports to be shared. This was a forgotten import, and crashed because of that.
98fb01a
to
1376c8c
Compare
1376c8c
to
a7e76d3
Compare
@p-l- It would be great if this could be merged in a near future, as it needs to replace Pyreadline/GnuReadline on the Python 3 port. |
5dc2189
to
2b04e2f
Compare
2b04e2f
to
333bd2b
Compare
@@ -1413,10 +1413,11 @@ a=Ether(str(Ether()/IPv6()/TCP())) | |||
a.type == 0x86dd | |||
|
|||
= IPv6 Class binding with GRE - build | |||
str(IP()/GRE()/Ether()/IP()/GRE()/IPv6()) == b'E\x00\x00f\x00\x01\x00\x00@/|f\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x00eX\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00E\x00\x00@\x00\x01\x00\x00@/|\x8c\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x00\x86\xdd`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01' | |||
s = str(IP(src="127.0.0.1")/GRE()/Ether(dst="ff:ff:ff:ff:ff:ff", src="00:00:00:00:00:00")/IP()/GRE()/IPv6(src="::1")) |
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.
In some cases, IPv6 resolution could get called through this function, which is not available on travis/appveyor. This is revealed because the fix-net6
pr was combined with 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.
OK for me @guedou
I am fine with @gpotter2 changes. This PR can be merged as soon as the OS X tests stop. |
This PR is an attempt of removing pyreadline/gnureadline, which have not been updated since (at least) 2015, and are mostly broken under python 3...
IPython
to handle the shell.