Merge pull request #1982 from ujjwal96/preserve-marked-flows

Closes #1960 'Z' removes unmarked flows
This commit is contained in:
Maximilian Hils 2017-02-03 11:43:57 +01:00 committed by GitHub
commit 3f26a0b5a5
3 changed files with 21 additions and 0 deletions

View File

@ -230,6 +230,17 @@ class View(collections.Sequence):
self.sig_view_refresh.send(self)
self.sig_store_refresh.send(self)
def clear_not_marked(self):
"""
Clears only the unmarked flows.
"""
for flow in self._store.copy().values():
if not flow.marked:
self._store.pop(flow.id)
self._refilter()
self.sig_store_refresh.send(self)
def add(self, f: mitmproxy.flow.Flow) -> bool:
"""
Adds a flow to the state. If the flow already exists, it is

View File

@ -35,6 +35,7 @@ def _mkhelp():
("W", "stream flows to file"),
("X", "kill and delete flow, even if it's mid-intercept"),
("z", "clear flow list or eventlog"),
("Z", "clear unmarked flows"),
("tab", "tab between eventlog and flow list"),
("enter", "view flow"),
("|", "run script on this flow"),
@ -354,6 +355,8 @@ class FlowListBox(urwid.ListBox):
self.master.view.update(f)
elif key == "z":
self.master.view.clear()
elif key == "Z":
self.master.view.clear_not_marked()
elif key == "e":
self.master.toggle_eventlog()
elif key == "g":

View File

@ -108,6 +108,13 @@ def test_simple():
assert list(v) == [f, f3, f2]
assert len(v._store) == 3
f.marked = not f.marked
f2.marked = not f2.marked
v.clear_not_marked()
assert list(v) == [f, f2]
assert len(v) == 2
assert len(v._store) == 2
v.clear()
assert len(v) == 0
assert len(v._store) == 0