From ae8ceead45cdeff841f059648226c98e6e3a93c8 Mon Sep 17 00:00:00 2001 From: "J. Patrick Avery, Jr" Date: Sun, 10 Feb 2013 00:30:19 -0600 Subject: [PATCH 1/2] add DumbSession and DropSession add a magic method to instantiate Sessions --- netarch/ip.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/netarch/ip.py b/netarch/ip.py index 309e025..a938ace 100644 --- a/netarch/ip.py +++ b/netarch/ip.py @@ -691,6 +691,11 @@ class Session(object): self.setup() + @classmethod + def session(*args, **kwargs): + cls, args = args[0], args[1:] + return cls(*args, **kwargs) + def setup(self): """Set things up.""" @@ -772,6 +777,18 @@ class Session(object): self.done() +class DumbSession(Session): + ''' Just a dumb Session ''' + pass + + +class DropSession(Session): + ''' a Session that drops all data passed to it ''' + + def process(self, packet): + pass + + class HtmlSession(Session): def __init__(self, frame, packetClass=Packet, debug=True): Session.__init__(self, frame, packetClass) From 89ae0c868b7285e0d0d3ab5e5556d1c867f91517 Mon Sep 17 00:00:00 2001 From: "J. Patrick Avery, Jr" Date: Sun, 10 Feb 2013 00:31:17 -0600 Subject: [PATCH 2/2] add an import harness to start-here.py --- extra/start-here.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extra/start-here.py b/extra/start-here.py index dbda74a..d057962 100644 --- a/extra/start-here.py +++ b/extra/start-here.py @@ -85,8 +85,8 @@ class StinkyPinkySession(ip.HtmlSession): self.log(packet.firstframe, packet.text, True) -# execution harness if __name__ == '__main__': + ''' an execution harness ''' if len(sys.argv) > 1: sessions = {} dp = ip.Dispatch(*sys.argv[1:]) @@ -99,3 +99,6 @@ if __name__ == '__main__': sessions[fhash].handle(is_srv, frame, gs, dp.last) for sess in sessions.itervalues(): sess.done() +else: + ''' an import harness ''' + session = StinkyPinkySession