mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 11:03:13 +00:00
Deprecate Flow.unload_script in favor of Flow.unload_scripts
In the presence of arguments, unloading a single script is clumsy and less useful.
This commit is contained in:
parent
4f69eef8f3
commit
069aca1df4
@ -1394,9 +1394,10 @@ class FlowMaster(controller.Master):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def unload_script(self, script):
|
def unload_scripts(self):
|
||||||
script.unload()
|
for script in self.scripts[:]:
|
||||||
self.scripts.remove(script)
|
script.unload()
|
||||||
|
self.scripts.remove(script)
|
||||||
|
|
||||||
def load_script(self, command):
|
def load_script(self, command):
|
||||||
"""
|
"""
|
||||||
@ -1627,8 +1628,7 @@ class FlowMaster(controller.Master):
|
|||||||
return f
|
return f
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
for script in self.scripts:
|
self.unload_scripts()
|
||||||
self.unload_script(script)
|
|
||||||
controller.Master.shutdown(self)
|
controller.Master.shutdown(self)
|
||||||
if self.stream:
|
if self.stream:
|
||||||
for i in self.state._flow_list:
|
for i in self.state._flow_list:
|
||||||
|
@ -565,8 +565,7 @@ class TestFlowMaster:
|
|||||||
fm = flow.FlowMaster(None, s)
|
fm = flow.FlowMaster(None, s)
|
||||||
assert not fm.load_script(tutils.test_data.path("scripts/a.py"))
|
assert not fm.load_script(tutils.test_data.path("scripts/a.py"))
|
||||||
assert not fm.load_script(tutils.test_data.path("scripts/a.py"))
|
assert not fm.load_script(tutils.test_data.path("scripts/a.py"))
|
||||||
assert not fm.unload_script(fm.scripts[0])
|
assert not fm.unload_scripts()
|
||||||
assert not fm.unload_script(fm.scripts[0])
|
|
||||||
assert fm.load_script("nonexistent")
|
assert fm.load_script("nonexistent")
|
||||||
assert "ValueError" in fm.load_script(tutils.test_data.path("scripts/starterr.py"))
|
assert "ValueError" in fm.load_script(tutils.test_data.path("scripts/starterr.py"))
|
||||||
assert len(fm.scripts) == 0
|
assert len(fm.scripts) == 0
|
||||||
@ -613,9 +612,13 @@ class TestFlowMaster:
|
|||||||
fm.handle_clientdisconnect(dc)
|
fm.handle_clientdisconnect(dc)
|
||||||
assert fm.scripts[0].ns["log"][-1] == "clientdisconnect"
|
assert fm.scripts[0].ns["log"][-1] == "clientdisconnect"
|
||||||
assert fm.scripts[1].ns["log"][-1] == "clientdisconnect"
|
assert fm.scripts[1].ns["log"][-1] == "clientdisconnect"
|
||||||
|
|
||||||
|
|
||||||
#unload first script
|
#unload first script
|
||||||
fm.unload_script(fm.scripts[0])
|
fm.unload_scripts()
|
||||||
assert len(fm.scripts) == 1
|
assert len(fm.scripts) == 0
|
||||||
|
|
||||||
|
assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
|
||||||
err = flow.Error(f.request, "msg")
|
err = flow.Error(f.request, "msg")
|
||||||
err.reply = controller.DummyReply()
|
err.reply = controller.DummyReply()
|
||||||
fm.handle_error(err)
|
fm.handle_error(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user