Console options cleanup
Use setters, use togglers, move more things out of master
This commit is contained in:
parent
ff80c7b618
commit
e9865800a8
|
@ -151,7 +151,7 @@ class ConnectionItem(urwid.WidgetWrap):
|
|||
if k == "a":
|
||||
self.master.start_server_playback(
|
||||
[i.copy() for i in self.master.state.view],
|
||||
self.master.killextra, self.master.rheaders,
|
||||
self.master.options.kill, self.master.rheaders,
|
||||
False, self.master.nopop,
|
||||
self.master.options.replay_ignore_params,
|
||||
self.master.options.replay_ignore_content,
|
||||
|
@ -161,7 +161,7 @@ class ConnectionItem(urwid.WidgetWrap):
|
|||
elif k == "t":
|
||||
self.master.start_server_playback(
|
||||
[self.flow.copy()],
|
||||
self.master.killextra, self.master.rheaders,
|
||||
self.master.options.kill, self.master.rheaders,
|
||||
False, self.master.nopop,
|
||||
self.master.options.replay_ignore_params,
|
||||
self.master.options.replay_ignore_content,
|
||||
|
|
|
@ -220,9 +220,6 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
|
||||
self.set_stream_large_bodies(options.stream_large_bodies)
|
||||
|
||||
self.refresh_server_playback = options.refresh_server_playback
|
||||
self.anticache = options.anticache
|
||||
self.killextra = options.kill
|
||||
self.rheaders = options.rheaders
|
||||
self.nopop = options.nopop
|
||||
self.palette = options.palette
|
||||
|
@ -372,7 +369,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
if flows:
|
||||
self.start_server_playback(
|
||||
flows,
|
||||
self.killextra, self.rheaders,
|
||||
self.options.kill, self.rheaders,
|
||||
False, self.nopop,
|
||||
self.options.replay_ignore_params,
|
||||
self.options.replay_ignore_content,
|
||||
|
|
|
@ -97,25 +97,25 @@ class Options(urwid.WidgetWrap):
|
|||
"Anti-Cache",
|
||||
"a",
|
||||
lambda: master.options.anticache,
|
||||
self.toggle_anticache
|
||||
master.options.toggler("anticache")
|
||||
),
|
||||
select.Option(
|
||||
"Anti-Compression",
|
||||
"o",
|
||||
lambda: master.options.anticomp,
|
||||
self.toggle_anticomp
|
||||
master.options.toggler("anticomp")
|
||||
),
|
||||
select.Option(
|
||||
"Kill Extra",
|
||||
"x",
|
||||
lambda: master.killextra,
|
||||
self.toggle_killextra
|
||||
lambda: master.options.kill,
|
||||
master.options.toggler("kill")
|
||||
),
|
||||
select.Option(
|
||||
"No Refresh",
|
||||
"f",
|
||||
lambda: not master.refresh_server_playback,
|
||||
self.toggle_refresh_server_playback
|
||||
lambda: not master.options.refresh_server_playback,
|
||||
master.options.toggler("refresh_server_playback")
|
||||
),
|
||||
select.Option(
|
||||
"Sticky Auth",
|
||||
|
@ -152,8 +152,6 @@ class Options(urwid.WidgetWrap):
|
|||
return super(self.__class__, self).keypress(size, key)
|
||||
|
||||
def clearall(self):
|
||||
self.master.killextra = False
|
||||
self.master.refresh_server_playback = True
|
||||
self.master.server.config.no_upstream_cert = False
|
||||
self.master.set_ignore_filter([])
|
||||
self.master.set_tcp_filter([])
|
||||
|
@ -161,6 +159,8 @@ class Options(urwid.WidgetWrap):
|
|||
self.master.options.update(
|
||||
anticache = False,
|
||||
anticomp = False,
|
||||
kill = False,
|
||||
refresh_server_playback = True,
|
||||
replacements = [],
|
||||
scripts = [],
|
||||
setheaders = [],
|
||||
|
@ -177,30 +177,16 @@ class Options(urwid.WidgetWrap):
|
|||
expire = 1
|
||||
)
|
||||
|
||||
def toggle_anticache(self):
|
||||
self.master.options.anticache = not self.master.options.anticache
|
||||
|
||||
def toggle_anticomp(self):
|
||||
self.master.options.anticomp = not self.master.options.anticomp
|
||||
|
||||
def toggle_killextra(self):
|
||||
self.master.killextra = not self.master.killextra
|
||||
|
||||
def toggle_refresh_server_playback(self):
|
||||
self.master.refresh_server_playback = not self.master.refresh_server_playback
|
||||
|
||||
def toggle_upstream_cert(self):
|
||||
self.master.server.config.no_upstream_cert = not self.master.server.config.no_upstream_cert
|
||||
signals.update_settings.send(self)
|
||||
|
||||
def setheaders(self):
|
||||
def _set(shdrs):
|
||||
self.master.options.setheaders = shdrs
|
||||
self.master.view_grideditor(
|
||||
grideditor.SetHeadersEditor(
|
||||
self.master,
|
||||
self.master.options.setheaders,
|
||||
_set
|
||||
self.master.options.setter("setheaders")
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -216,14 +202,11 @@ class Options(urwid.WidgetWrap):
|
|||
)
|
||||
|
||||
def replacepatterns(self):
|
||||
def _set(replacements):
|
||||
self.master.options.replacements = replacements
|
||||
signals.update_settings.send(self)
|
||||
self.master.view_grideditor(
|
||||
grideditor.ReplaceEditor(
|
||||
self.master,
|
||||
self.master.options.replacements,
|
||||
_set
|
||||
self.master.options.setter("replacements")
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -196,9 +196,9 @@ class StatusBar(urwid.WidgetWrap):
|
|||
opts.append("anticomp")
|
||||
if self.master.options.showhost:
|
||||
opts.append("showhost")
|
||||
if not self.master.refresh_server_playback:
|
||||
if not self.master.options.refresh_server_playback:
|
||||
opts.append("norefresh")
|
||||
if self.master.killextra:
|
||||
if self.master.options.kill:
|
||||
opts.append("killextra")
|
||||
if self.master.server.config.no_upstream_cert:
|
||||
opts.append("no-upstream-cert")
|
||||
|
|
|
@ -35,7 +35,6 @@ class FlowMaster(controller.Master):
|
|||
self.kill_nonreplay = False
|
||||
|
||||
self.stream_large_bodies = None # type: Optional[modules.StreamLargeBodies]
|
||||
self.refresh_server_playback = False
|
||||
self.replay_ignore_params = False
|
||||
self.replay_ignore_content = None
|
||||
self.replay_ignore_host = False
|
||||
|
@ -120,7 +119,7 @@ class FlowMaster(controller.Master):
|
|||
return None
|
||||
response = rflow.response.copy()
|
||||
response.is_replay = True
|
||||
if self.refresh_server_playback:
|
||||
if self.options.refresh_server_playback:
|
||||
response.refresh()
|
||||
flow.response = response
|
||||
return True
|
||||
|
|
|
@ -751,7 +751,11 @@ class TestFlowMaster:
|
|||
|
||||
f = tutils.tflow(resp=True)
|
||||
pb = [tutils.tflow(resp=True), f]
|
||||
fm = flow.FlowMaster(None, DummyServer(ProxyConfig()), s)
|
||||
fm = flow.FlowMaster(
|
||||
flow.options.Options(),
|
||||
DummyServer(ProxyConfig()),
|
||||
s
|
||||
)
|
||||
assert not fm.start_server_playback(
|
||||
pb,
|
||||
False,
|
||||
|
@ -779,7 +783,7 @@ class TestFlowMaster:
|
|||
f.response = HTTPResponse.wrap(netlib.tutils.tresp(content=f.request))
|
||||
pb = [f]
|
||||
|
||||
fm = flow.FlowMaster(None, None, s)
|
||||
fm = flow.FlowMaster(flow.options.Options(), None, s)
|
||||
fm.refresh_server_playback = True
|
||||
assert not fm.do_server_playback(tutils.tflow())
|
||||
|
||||
|
|
Loading…
Reference in New Issue