mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
A tiny wrapper to make script invocations nicer
This commit is contained in:
parent
ccf4723505
commit
e7b61995ad
@ -9,12 +9,21 @@ from __future__ import absolute_import, print_function, division
|
||||
import os
|
||||
import shlex
|
||||
import sys
|
||||
import contextlib
|
||||
|
||||
import six
|
||||
|
||||
from mitmproxy import exceptions
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def setargs(args):
|
||||
oldargs = sys.argv
|
||||
sys.argv = args
|
||||
yield
|
||||
sys.argv = oldargs
|
||||
|
||||
|
||||
class Script(object):
|
||||
|
||||
"""
|
||||
@ -113,7 +122,8 @@ class Script(object):
|
||||
f = self.ns.get(name)
|
||||
if f:
|
||||
try:
|
||||
return f(self.ctx, *args, **kwargs)
|
||||
with setargs(self.args):
|
||||
return f(self.ctx, *args, **kwargs)
|
||||
except Exception:
|
||||
six.reraise(
|
||||
exceptions.ScriptException,
|
||||
|
Loading…
Reference in New Issue
Block a user