diff --git a/mitmproxy/script/script.py b/mitmproxy/script/script.py index 48efcde54..9d149f4d8 100644 --- a/mitmproxy/script/script.py +++ b/mitmproxy/script/script.py @@ -6,10 +6,12 @@ by the mitmproxy-specific ScriptContext. # Do not import __future__ here, this would apply transitively to the inline scripts. from __future__ import absolute_import, print_function, division +import inspect import os import shlex import sys import contextlib +import warnings import six @@ -20,8 +22,10 @@ from mitmproxy import exceptions def setargs(args): oldargs = sys.argv sys.argv = args - yield - sys.argv = oldargs + try: + yield + finally: + sys.argv = oldargs class Script(object): @@ -98,7 +102,15 @@ class Script(object): finally: sys.path.pop() sys.path.pop() - return self.run("start", self.args) + + start_fn = self.ns.get("start") + if len(inspect.getargspec(start_fn).args) == 2: + warnings.warn( + "The 'args' argument of the start() script hook is deprecated. " + "Please use sys.argv instead." + ) + return self.run("start", self.args) + return self.run("start") def unload(self): try: