2010-03-01 01:58:04 +00:00
|
|
|
import sys
|
2011-02-16 09:10:24 +00:00
|
|
|
import flow
|
2010-03-01 01:58:04 +00:00
|
|
|
|
2011-02-16 10:03:46 +00:00
|
|
|
class Options(object):
|
|
|
|
__slots__ = [
|
|
|
|
"verbosity",
|
|
|
|
"wfile",
|
|
|
|
]
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
for k, v in kwargs.items():
|
|
|
|
setattr(self, k, v)
|
|
|
|
|
|
|
|
|
2011-02-16 09:10:24 +00:00
|
|
|
class DumpMaster(flow.FlowMaster):
|
2011-02-16 10:03:46 +00:00
|
|
|
def __init__(self, server, options, outfile=sys.stdout):
|
2011-02-16 09:10:24 +00:00
|
|
|
flow.FlowMaster.__init__(self, server, flow.State())
|
2011-02-16 10:03:46 +00:00
|
|
|
self.outfile = outfile
|
|
|
|
self.o = options
|
2010-03-01 01:58:04 +00:00
|
|
|
|
2011-02-16 09:10:24 +00:00
|
|
|
def handle_clientconnection(self, r):
|
|
|
|
flow.FlowMaster.handle_clientconnection(self, r)
|
|
|
|
r.ack()
|
|
|
|
|
|
|
|
def handle_error(self, r):
|
|
|
|
flow.FlowMaster.handle_error(self, r)
|
|
|
|
r.ack()
|
|
|
|
|
|
|
|
def handle_request(self, r):
|
|
|
|
flow.FlowMaster.handle_request(self, r)
|
|
|
|
r.ack()
|
2010-03-01 01:58:04 +00:00
|
|
|
|
|
|
|
def handle_response(self, msg):
|
2011-02-16 09:10:24 +00:00
|
|
|
f = flow.FlowMaster.handle_response(self, msg)
|
2011-02-16 10:03:46 +00:00
|
|
|
if f:
|
|
|
|
if 0 < self.o.verbosity < 3:
|
|
|
|
print >> self.outfile, ">>",
|
|
|
|
print >> self.outfile, msg.request.short()
|
|
|
|
if self.o.verbosity == 1:
|
|
|
|
print >> self.outfile, "<<",
|
|
|
|
print >> self.outfile, msg.short()
|
|
|
|
elif self.o.verbosity == 2:
|
|
|
|
print >> self.outfile, "<<"
|
|
|
|
for i in msg.assemble().splitlines():
|
|
|
|
print >> self.outfile, "\t", i
|
|
|
|
print >> self.outfile, "<<"
|
|
|
|
elif self.o.verbosity == 3:
|
|
|
|
print >> self.outfile, ">>"
|
|
|
|
for i in msg.request.assemble().splitlines():
|
|
|
|
print >> self.outfile, "\t", i
|
|
|
|
print >> self.outfile, ">>"
|
|
|
|
print >> self.outfile, "<<"
|
|
|
|
for i in msg.assemble().splitlines():
|
|
|
|
print >> self.outfile, "\t", i
|
|
|
|
print >> self.outfile, "<<"
|
|
|
|
|
|
|
|
msg.ack()
|
|
|
|
self.state.delete_flow(f)
|
2011-02-16 09:10:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
# begin nocover
|
|
|
|
def run(self):
|
|
|
|
try:
|
|
|
|
return flow.FlowMaster.run(self)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
self.shutdown()
|
|
|
|
|