fix contextmanager, remove args argument to start()

This commit is contained in:
Maximilian Hils 2016-06-13 18:08:57 -07:00
parent e7b61995ad
commit 804efe9d38

View File

@ -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: