Merge pull request #1020 from gpotter2/ipython-old

Support old IPython versions
This commit is contained in:
Pierre Lalet 2018-01-10 14:26:08 +01:00 committed by GitHub
commit 8857f01511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 9 deletions

View File

@ -502,10 +502,13 @@ def interact(mydict=None,argv=None,mybanner=None,loglevel=20):
"traitlets not available. Some Scapy shell features won't be " "traitlets not available. Some Scapy shell features won't be "
"available." "available."
) )
try:
ipshell = InteractiveShellEmbed( ipshell = InteractiveShellEmbed(
banner1=banner, banner1=banner,
user_ns=SESSION, user_ns=SESSION,
) )
except:
code.interact(banner = the_banner, local=SESSION)
else: else:
cfg = Config() cfg = Config()
try: try:
@ -518,10 +521,20 @@ def interact(mydict=None,argv=None,mybanner=None,loglevel=20):
cfg.TerminalInteractiveShell.separate_in = u'' cfg.TerminalInteractiveShell.separate_in = u''
cfg.TerminalInteractiveShell.hist_file = conf.histfile cfg.TerminalInteractiveShell.hist_file = conf.histfile
# configuration can thus be specified here. # configuration can thus be specified here.
try:
ipshell = InteractiveShellEmbed(config=cfg, ipshell = InteractiveShellEmbed(config=cfg,
banner1=banner, banner1=banner,
hist_file=conf.histfile if conf.histfile else None, hist_file=conf.histfile if conf.histfile else None,
user_ns=SESSION) user_ns=SESSION)
except (AttributeError, TypeError):
log_loading.warning("IPython too old. Won't support history and color style.")
try:
ipshell = InteractiveShellEmbed(
banner1=banner,
user_ns=SESSION,
)
except:
code.interact(banner = the_banner, local=SESSION)
ipshell(local_ns=SESSION) ipshell(local_ns=SESSION)
else: else:
code.interact(banner = the_banner, local=SESSION) code.interact(banner = the_banner, local=SESSION)

View File

@ -296,7 +296,7 @@ def apply_ipython_style(shell):
except: except:
from scapy.error import log_loading from scapy.error import log_loading
log_loading.warning( log_loading.warning(
"IPython too old. Some Scapy shell features won't be available." "IPython too old. Shell color won't be handled."
) )
return return
from scapy.config import conf from scapy.config import conf