From 804efe9d38449d484a37430459d1af45c7fcf0cf Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 13 Jun 2016 18:08:57 -0700 Subject: [PATCH] fix contextmanager, remove args argument to start() --- mitmproxy/script/script.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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: