aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/dump.py
blob: 83238da4c4d88e994bb975138450e33be4ad44a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sys
import controller

class DumpMaster(controller.Master):
    """
        A simple master that just dumps to screen.
    """
    def __init__(self, server, verbosity):
        self.verbosity = verbosity
        controller.Master.__init__(self, server)

    def run(self):
        try:
            return controller.Master.run(self)
        except KeyboardInterrupt:
            self.shutdown()

    def handle_response(self, msg):
        if 0 < self.verbosity < 3:
            print >> sys.stderr, ">>",
            print >> sys.stderr, msg.request.short()
        if self.verbosity == 1:
            print >> sys.stderr, "<<",
            print >> sys.stderr, msg.short()
        elif self.verbosity == 2:
            print >> sys.stderr, "<<"
            for i in msg.assemble().splitlines():
                print >> sys.stderr, "\t", i
            print >> sys.stderr, "<<"
        elif self.verbosity == 3:
            print >> sys.stderr, ">>"
            for i in msg.request.assemble().splitlines():
                print >> sys.stderr, "\t", i
            print >> sys.stderr, ">>"
            print >> sys.stderr, "<<"
            for i in msg.assemble().splitlines():
                print >> sys.stderr, "\t", i
            print >> sys.stderr, "<<"
        msg.ack()