Make beeping more general.

- The "B" key now sets a filter pattern. Whenever the filter matches, the
  terminal beeps.
- The beep specification is now stored in the State object, where I want to
  keep all mutable state.
- I've removed the startup flags for beeping for now. We probably want to let
  users specify a number of options on startup, including interception patterns
  and limits. When we do this, we should also separate out the dumping and
  curses programs, because many of these options will only make sense in one of
  the two.
- This isn't an exact replacement for the beep functionality I ripped out,
  because specifying beeping on intercept is slightly cumbersome (you need to
  re-specify the intercept pattern using B). Sorry - we'll add a better way
  soon.
This commit is contained in:
Aldo Cortesi 2010-03-01 13:55:32 +13:00
parent a40775b846
commit a7cea1749b
2 changed files with 18 additions and 27 deletions

View File

@ -586,6 +586,7 @@ class State:
# These are compiled filt expressions: # These are compiled filt expressions:
self.limit = None self.limit = None
self.intercept = None self.intercept = None
self.beep = None
def add_browserconnect(self, f): def add_browserconnect(self, f):
self.flow_list.insert(0, f) self.flow_list.insert(0, f)
@ -734,12 +735,6 @@ class State:
#begin nocover #begin nocover
class ConsoleMaster(controller.Master): class ConsoleMaster(controller.Master):
beep = {
'intercepting_request':False,
'request':False,
'intercepting_response':False,
'response':False
}
palette = [] palette = []
footer_text_default = [ footer_text_default = [
('key', "?"), ":help ", ('key', "?"), ":help ",
@ -752,9 +747,6 @@ class ConsoleMaster(controller.Master):
] ]
def __init__(self, server, options): def __init__(self, server, options):
self.set_palette(options.terminal_background) self.set_palette(options.terminal_background)
self.beep = {
'intercepting_request':options.beep_intercepted_request,
'intercepting_response':options.beep_intercepted_response}
controller.Master.__init__(self, server) controller.Master.__init__(self, server)
self.config = options.verbose self.config = options.verbose
self.state = State() self.state = State()
@ -762,10 +754,6 @@ class ConsoleMaster(controller.Master):
self.stickycookie = None self.stickycookie = None
self.stickyhosts = {} self.stickyhosts = {}
def check_beep(self, source):
if self.beep.get(source, False):
urwid.curses_display.curses.beep()
def set_palette(self, terminal_background): def set_palette(self, terminal_background):
if terminal_background: if terminal_background:
background_color = 'default' background_color = 'default'
@ -842,6 +830,7 @@ class ConsoleMaster(controller.Master):
text.extend([("head", "Global keys:\n")]) text.extend([("head", "Global keys:\n")])
keys = [ keys = [
("a", "accept intercepted request or response"), ("a", "accept intercepted request or response"),
("B", "set beep filter pattern"),
("i", "set interception pattern"), ("i", "set interception pattern"),
("j, k", "up, down"), ("j, k", "up, down"),
("l", "set limit filter pattern"), ("l", "set limit filter pattern"),
@ -989,6 +978,14 @@ class ConsoleMaster(controller.Master):
self.state.intercept = None self.state.intercept = None
self.sync_list_view() self.sync_list_view()
def set_beep(self, txt):
if txt:
self.state.beep = filt.parse(txt)
if not self.state.beep:
return "Invalid filter expression."
else:
self.state.beep = None
def set_stickycookie(self, txt): def set_stickycookie(self, txt):
if txt: if txt:
self.stickycookie = filt.parse(txt) self.stickycookie = filt.parse(txt)
@ -1040,6 +1037,9 @@ class ConsoleMaster(controller.Master):
elif k == "i": elif k == "i":
self.prompt("Intercept: ", self.set_intercept) self.prompt("Intercept: ", self.set_intercept)
k = None k = None
elif k == "B":
self.prompt("Beep: ", self.set_beep)
k = None
elif k == "C": elif k == "C":
self.clear_connections() self.clear_connections()
elif k == "j": elif k == "j":
@ -1115,12 +1115,11 @@ class ConsoleMaster(controller.Master):
self.stickyhosts[hid] = f.request.headers["cookie"] self.stickyhosts[hid] = f.request.headers["cookie"]
elif hid in self.stickyhosts: elif hid in self.stickyhosts:
f.request.headers["cookie"] = self.stickyhosts[hid] f.request.headers["cookie"] = self.stickyhosts[hid]
if f.match(self.state.beep):
urwid.curses_display.curses.beep()
if f.match(self.state.intercept): if f.match(self.state.intercept):
self.check_beep('intercepting_request')
f.intercept() f.intercept()
else: else:
self.check_beep('request')
r.ack() r.ack()
self.sync_list_view() self.sync_list_view()
self.refresh_connection(f) self.refresh_connection(f)
@ -1135,11 +1134,11 @@ class ConsoleMaster(controller.Master):
if f.response.headers.has_key("set-cookie"): if f.response.headers.has_key("set-cookie"):
self.stickyhosts[hid] = f.response.headers["set-cookie"] self.stickyhosts[hid] = f.response.headers["set-cookie"]
if f.match(self.state.beep):
urwid.curses_display.curses.beep()
if f.match(self.state.intercept): if f.match(self.state.intercept):
self.check_beep('intercepting_response')
f.intercept() f.intercept()
else: else:
self.check_beep('response')
r.ack() r.ack()
self.sync_list_view() self.sync_list_view()
self.refresh_connection(f) self.refresh_connection(f)

View File

@ -25,14 +25,6 @@ if __name__ == '__main__':
usage = "%prog [options] output", usage = "%prog [options] output",
version="%prog 0.1", version="%prog 0.1",
) )
parser.add_option(
"", "--bireq", action="store_true",
dest="beep_intercepted_request", default=False,
help = "Beep on intercepted request")
parser.add_option(
"", "--bires", action="store_true",
dest="beep_intercepted_response", default=False,
help = "Beep on intercepted response")
parser.add_option( parser.add_option(
"-d", "--dump", action="store_true", "-d", "--dump", action="store_true",
dest="dump", default=False, dest="dump", default=False,
@ -53,7 +45,7 @@ if __name__ == '__main__':
help="Quiet.") help="Quiet.")
parser.add_option( parser.add_option(
"-t", "--terminal-backround", action="store_true", dest="terminal_background", "-t", "--terminal-backround", action="store_true", dest="terminal_background",
default=False, help="Uses the standard terminal background instead of setting an own. (Useful for transparent terminals etc.)") default=False, help="Uses the standard terminal background instead of setting an own. Useful for transparent terminals.")
parser.add_option("-v", "--verbose", parser.add_option("-v", "--verbose",
action="count", dest="verbose", default=1, action="count", dest="verbose", default=1,