Skip to content
Snippets Groups Projects
Commit b3ef12b7 authored by gpotter2's avatar gpotter2
Browse files

Add main.py tests

parent aa951f80
No related branches found
No related tags found
No related merge requests found
...@@ -166,6 +166,55 @@ def update_session(fname=None): ...@@ -166,6 +166,55 @@ def update_session(fname=None):
scapy_session = __builtin__.__dict__["scapy_session"] scapy_session = __builtin__.__dict__["scapy_session"]
scapy_session.update(s) scapy_session.update(s)
def init_session(mydict=None, session_name="", STARTUP_FILE=DEFAULT_STARTUP_FILE):
global session
scapy_builtins = __import__("all",globals(),locals(),".").__dict__
for name, sym in scapy_builtins.iteritems():
if name [0] != '_':
__builtin__.__dict__[name] = sym
globkeys = scapy_builtins.keys()
globkeys.append("scapy_session")
scapy_builtins=None # XXX replace with "with" statement
if mydict is not None:
__builtin__.__dict__.update(mydict)
globkeys += mydict.keys()
conf.color_theme = DefaultTheme()
if STARTUP_FILE:
_read_config_file(STARTUP_FILE)
if session_name:
try:
os.stat(session_name)
except OSError:
log_loading.info("New session [%s]" % session_name)
else:
try:
try:
session = cPickle.load(gzip.open(session_name,"rb"))
except IOError:
session = cPickle.load(open(session_name,"rb"))
log_loading.info("Using session [%s]" % session_name)
except EOFError:
log_loading.error("Error opening session [%s]" % session_name)
except AttributeError:
log_loading.error("Error opening session [%s]. Attribute missing" % session_name)
if session:
if "conf" in session:
conf.configure(session["conf"])
session["conf"] = conf
else:
conf.session = session_name
session={"conf":conf}
else:
session={"conf": conf}
__builtin__.__dict__["scapy_session"] = session
return globkeys
################ ################
##### Main ##### ##### Main #####
...@@ -299,52 +348,7 @@ def interact(mydict=None,argv=None,mybanner=None,loglevel=20): ...@@ -299,52 +348,7 @@ def interact(mydict=None,argv=None,mybanner=None,loglevel=20):
if PRESTART_FILE: if PRESTART_FILE:
_read_config_file(PRESTART_FILE) _read_config_file(PRESTART_FILE)
scapy_builtins = __import__("all",globals(),locals(),".").__dict__ globkeys = init_session(mydict, session_name, STARTUP_FILE)
for name, sym in scapy_builtins.iteritems():
if name [0] != '_':
__builtin__.__dict__[name] = sym
globkeys = scapy_builtins.keys()
globkeys.append("scapy_session")
scapy_builtins=None # XXX replace with "with" statement
if mydict is not None:
__builtin__.__dict__.update(mydict)
globkeys += mydict.keys()
conf.color_theme = DefaultTheme()
if STARTUP_FILE:
_read_config_file(STARTUP_FILE)
if session_name:
try:
os.stat(session_name)
except OSError:
log_loading.info("New session [%s]" % session_name)
else:
try:
try:
session = cPickle.load(gzip.open(session_name,"rb"))
except IOError:
session = cPickle.load(open(session_name,"rb"))
log_loading.info("Using session [%s]" % session_name)
except EOFError:
log_loading.error("Error opening session [%s]" % session_name)
except AttributeError:
log_loading.error("Error opening session [%s]. Attribute missing" % session_name)
if session:
if "conf" in session:
conf.configure(session["conf"])
session["conf"] = conf
else:
conf.session = session_name
session={"conf":conf}
else:
session={"conf": conf}
__builtin__.__dict__["scapy_session"] = session
if READLINE: if READLINE:
if conf.histfile: if conf.histfile:
......
...@@ -75,6 +75,19 @@ else: ...@@ -75,6 +75,19 @@ else:
conf.route6.ifchange(LOOPBACK_NAME, "::1/128") conf.route6.ifchange(LOOPBACK_NAME, "::1/128")
True True
############
############
+ Main.py tests
= Test save_session
init_session()
# TODO: Remove the comments once the pickling bug has been fixed
#test_value = IP(dst="192.168.0.10")
#test_value
save_session(fname="scapySession1")
= Test load_session
load_session(fname="scapySession1")
############ ############
############ ############
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment