aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-03-22 17:18:53 +1300
committerAldo Cortesi <aldo@nullcube.com>2015-03-22 17:18:53 +1300
commit08bb07653306ed0f84932391732391227ee07ba2 (patch)
treef9b01df3489284f37f3df0c033f324f7e1d58c11 /libmproxy
parent120c8db8a413018bde60d156f480ade001b492ef (diff)
downloadmitmproxy-08bb07653306ed0f84932391732391227ee07ba2.tar.gz
mitmproxy-08bb07653306ed0f84932391732391227ee07ba2.tar.bz2
mitmproxy-08bb07653306ed0f84932391732391227ee07ba2.zip
console: signal-based view stack, unifying mechanisms for help, flow views, etc.
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/console/__init__.py36
-rw-r--r--libmproxy/console/common.py3
-rw-r--r--libmproxy/console/flowdetailview.py8
-rw-r--r--libmproxy/console/flowview.py12
-rw-r--r--libmproxy/console/grideditor.py2
-rw-r--r--libmproxy/console/help.py7
-rw-r--r--libmproxy/console/signals.py5
7 files changed, 35 insertions, 38 deletions
diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py
index f6f8e721..90c8bd89 100644
--- a/libmproxy/console/__init__.py
+++ b/libmproxy/console/__init__.py
@@ -28,7 +28,6 @@ class ConsoleState(flow.State):
self.follow_focus = None
self.default_body_view = contentview.get("Auto")
- self.view_mode = common.VIEW_LIST
self.view_flow_mode = common.VIEW_FLOW_REQUEST
self.flowsettings = weakref.WeakKeyDictionary()
@@ -210,9 +209,13 @@ class ConsoleMaster(flow.FlowMaster):
print >> sys.stderr, "Stream file error:", err
sys.exit(1)
+ self.view_stack = []
+
if options.app:
self.start_app(self.options.app_host, self.options.app_port)
signals.call_in.connect(self.sig_call_in)
+ signals.pop_view_state.connect(self.sig_pop_view_state)
+ signals.push_view_state.connect(self.sig_push_view_state)
def __setattr__(self, name, value):
self.__dict__[name] = value
@@ -223,6 +226,13 @@ class ConsoleMaster(flow.FlowMaster):
return callback(*args)
self.loop.set_alarm_in(seconds, cb)
+ def sig_pop_view_state(self, sender):
+ if self.view_stack:
+ self.loop.widget = self.view_stack.pop()
+
+ def sig_push_view_state(self, sender):
+ self.view_stack.append(self.loop.widget)
+
def start_stream_to_path(self, path, mode="wb"):
path = os.path.expanduser(path)
try:
@@ -433,30 +443,25 @@ class ConsoleMaster(flow.FlowMaster):
self.shutdown()
def view_help(self):
+ signals.push_view_state.send(self)
self.loop.widget = window.Window(
self,
- help.HelpView(
- self,
- self.help_context,
- self.loop.widget,
- ),
+ help.HelpView(self.help_context),
None,
statusbar.StatusBar(self, help.footer)
)
def view_flowdetails(self, flow):
+ signals.push_view_state.send(self)
self.loop.widget = window.Window(
self,
- flowdetailview.FlowDetailsView(
- self,
- flow,
- self.loop.widget
- ),
+ flowdetailview.FlowDetailsView(low),
None,
statusbar.StatusBar(self, flowdetailview.footer)
)
def view_grideditor(self, ge):
+ signals.push_view_state.send(self)
self.help_context = ge.make_help()
self.loop.widget = window.Window(
self,
@@ -475,7 +480,6 @@ class ConsoleMaster(flow.FlowMaster):
body = flowlist.BodyPile(self)
else:
body = flowlist.FlowListBox(self)
- self.state.view_mode = common.VIEW_LIST
self.help_context = flowlist.help_context
self.loop.widget = window.Window(
@@ -487,8 +491,8 @@ class ConsoleMaster(flow.FlowMaster):
self.loop.draw_screen()
def view_flow(self, flow):
+ signals.push_view_state.send(self)
self.state.set_focus_flow(flow)
- self.state.view_mode = common.VIEW_FLOW
self.help_context = flowview.help_context
self.loop.widget = window.Window(
self,
@@ -548,12 +552,6 @@ class ConsoleMaster(flow.FlowMaster):
self.state.default_body_view = v
self.refresh_focus()
- def pop_view(self):
- if self.state.view_mode == common.VIEW_FLOW:
- self.view_flow(self.state.view[self.state.focus])
- else:
- self.view_flowlist()
-
def edit_scripts(self, scripts):
commands = [x[0] for x in scripts] # remove outer array
if commands == [s.command for s in self.scripts]:
diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py
index c0593af4..a0590bb1 100644
--- a/libmproxy/console/common.py
+++ b/libmproxy/console/common.py
@@ -13,9 +13,6 @@ try:
except:
pyperclip = False
-VIEW_LIST = 0
-VIEW_FLOW = 1
-
VIEW_FLOW_REQUEST = 0
VIEW_FLOW_RESPONSE = 1
diff --git a/libmproxy/console/flowdetailview.py b/libmproxy/console/flowdetailview.py
index 15350ea1..8bfdae4a 100644
--- a/libmproxy/console/flowdetailview.py
+++ b/libmproxy/console/flowdetailview.py
@@ -1,6 +1,6 @@
from __future__ import absolute_import
import urwid
-from . import common
+from . import common, signals
from .. import utils
footer = [
@@ -8,8 +8,8 @@ footer = [
]
class FlowDetailsView(urwid.ListBox):
- def __init__(self, master, flow, state):
- self.master, self.flow, self.state = master, flow, state
+ def __init__(self, flow):
+ self.flow = flow
urwid.ListBox.__init__(
self,
self.flowtext()
@@ -18,7 +18,7 @@ class FlowDetailsView(urwid.ListBox):
def keypress(self, size, key):
key = common.shortcuts(key)
if key == "q":
- self.master.loop.widget = self.state
+ signals.pop_view_state.send(self)
return None
elif key == "?":
key = None
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py
index 2dd2cb82..fcb967cc 100644
--- a/libmproxy/console/flowview.py
+++ b/libmproxy/console/flowview.py
@@ -114,9 +114,6 @@ cache = CallbackCache()
class FlowView(urwid.WidgetWrap):
- REQ = 0
- RESP = 1
-
highlight_color = "focusfield"
def __init__(self, master, state, flow):
@@ -633,8 +630,9 @@ class FlowView(urwid.WidgetWrap):
new_flow, new_idx = self.state.get_prev(idx)
if new_flow is None:
signals.status_message.send(message="No more flows!")
- return
- self.master.view_flow(new_flow)
+ else:
+ signals.pop_view_state.send(self)
+ self.master.view_flow(new_flow)
def view_next_flow(self, flow):
return self._view_nextprev_flow("next", flow)
@@ -673,8 +671,8 @@ class FlowView(urwid.WidgetWrap):
conn = self.flow.response
if key == "q":
- self.master.view_flowlist()
- key = None
+ signals.pop_view_state.send(self)
+ return None
elif key == "tab":
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
self.view_response()
diff --git a/libmproxy/console/grideditor.py b/libmproxy/console/grideditor.py
index a1d662c8..4bcc0171 100644
--- a/libmproxy/console/grideditor.py
+++ b/libmproxy/console/grideditor.py
@@ -323,7 +323,7 @@ class GridEditor(urwid.WidgetWrap):
if not i[1] and any([x.strip() for x in i[0]]):
res.append(i[0])
self.callback(res, *self.cb_args, **self.cb_kwargs)
- self.master.pop_view()
+ signals.pop_view_state.send(self)
elif key in ["h", "left"]:
self.walker.left()
elif key in ["l", "right"]:
diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py
index 109a9792..73cd8a50 100644
--- a/libmproxy/console/help.py
+++ b/libmproxy/console/help.py
@@ -2,7 +2,7 @@ from __future__ import absolute_import
import urwid
-from . import common
+from . import common, signals
from .. import filt, version
footer = [
@@ -12,8 +12,7 @@ footer = [
class HelpView(urwid.ListBox):
- def __init__(self, master, help_context, state):
- self.master, self.state = master, state
+ def __init__(self, help_context):
self.help_context = help_context or []
urwid.ListBox.__init__(
self,
@@ -180,7 +179,7 @@ class HelpView(urwid.ListBox):
def keypress(self, size, key):
key = common.shortcuts(key)
if key == "q":
- self.master.loop.widget = self.state
+ signals.pop_view_state.send(self)
return None
elif key == "?":
key = None
diff --git a/libmproxy/console/signals.py b/libmproxy/console/signals.py
index 9afde6f4..e4c11f5a 100644
--- a/libmproxy/console/signals.py
+++ b/libmproxy/console/signals.py
@@ -23,3 +23,8 @@ update_settings = blinker.Signal()
# Fired when a flow changes
flow_change = blinker.Signal()
+
+
+# Pop and push view state onto a stack
+pop_view_state = blinker.Signal()
+push_view_state = blinker.Signal()