aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/console
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2016-09-11 13:43:20 +1200
committerGitHub <noreply@github.com>2016-09-11 13:43:20 +1200
commit734d1770078832bf079bc7493c3633d5c51663d6 (patch)
treeb01c182cc7effe5ae651390039ae55a0147a751c /mitmproxy/console
parent387e91f9a6deaad72231a91a0735638f52f06fca (diff)
parent6b9221ffeb48ea2935ca96f0b3c885fef5f00f52 (diff)
downloadmitmproxy-734d1770078832bf079bc7493c3633d5c51663d6.tar.gz
mitmproxy-734d1770078832bf079bc7493c3633d5c51663d6.tar.bz2
mitmproxy-734d1770078832bf079bc7493c3633d5c51663d6.zip
Merge pull request #1550 from cortesi/script
Add "run_once" support to the script addon, use it in mitmproxy
Diffstat (limited to 'mitmproxy/console')
-rw-r--r--mitmproxy/console/master.py37
1 files changed, 5 insertions, 32 deletions
diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py
index 1cb3a32b..b63507a3 100644
--- a/mitmproxy/console/master.py
+++ b/mitmproxy/console/master.py
@@ -22,7 +22,6 @@ from mitmproxy import contentviews
from mitmproxy import controller
from mitmproxy import exceptions
from mitmproxy import flow
-from mitmproxy import script
from mitmproxy import utils
import mitmproxy.options
from mitmproxy.console import flowlist
@@ -329,39 +328,13 @@ class ConsoleMaster(flow.FlowMaster):
self.loop.widget = window
self.loop.draw_screen()
- def _run_script_method(self, method, s, f):
- status, val = s.run(method, f)
- if val:
- if status:
- signals.add_log("Method %s return: %s" % (method, val), "debug")
- else:
- signals.add_log(
- "Method %s error: %s" %
- (method, val[1]), "error")
-
def run_script_once(self, command, f):
- if not command:
- return
- signals.add_log("Running script on flow: %s" % command, "debug")
-
+ sc = self.addons.get("scriptloader")
try:
- s = script.Script(command)
- s.load()
- except script.ScriptException as e:
- signals.status_message.send(
- message='Error loading "{}".'.format(command)
- )
- signals.add_log('Error loading "{}":\n{}'.format(command, e), "error")
- return
-
- if f.request:
- self._run_script_method("request", s, f)
- if f.response:
- self._run_script_method("response", s, f)
- if f.error:
- self._run_script_method("error", s, f)
- s.unload()
- signals.flow_change.send(self, flow = f)
+ with self.handlecontext():
+ sc.run_once(command, [f])
+ except mitmproxy.exceptions.AddonError as e:
+ signals.add_log("Script error: %s" % e, "warn")
def toggle_eventlog(self):
self.options.eventlog = not self.options.eventlog