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

View File

@ -25,14 +25,6 @@ if __name__ == '__main__':
usage = "%prog [options] output",
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(
"-d", "--dump", action="store_true",
dest="dump", default=False,
@ -53,7 +45,7 @@ if __name__ == '__main__':
help="Quiet.")
parser.add_option(
"-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",
action="count", dest="verbose", default=1,