diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-12-12 08:03:09 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-12 08:03:09 +1300 |
commit | 4912920573c71a49670928b19893b965d199f836 (patch) | |
tree | 170034aac0b28e93dfa7e6735b873593d5a5a30a | |
parent | 7654ad2d31d294d227e9ed305309c927a2ec0b94 (diff) | |
parent | b09c28d8a6fcd2af4a43b968b800d44c5a8c836e (diff) | |
download | mitmproxy-4912920573c71a49670928b19893b965d199f836.tar.gz mitmproxy-4912920573c71a49670928b19893b965d199f836.tar.bz2 mitmproxy-4912920573c71a49670928b19893b965d199f836.zip |
Merge branch 'master' into browser-win
-rw-r--r-- | mitmproxy/command.py | 9 | ||||
-rw-r--r-- | setup.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/test_command.py | 7 |
3 files changed, 18 insertions, 2 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py index c9776bc3..eae3d80c 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -190,10 +190,19 @@ def parsearg(manager: CommandManager, spec: str, argtype: type) -> typing.Any: raise exceptions.CommandError("Unsupported argument type: %s" % argtype) +def verify_arg_signature(f: typing.Callable, args: list, kwargs: dict) -> None: + sig = inspect.signature(f) + try: + sig.bind(*args, **kwargs) + except TypeError as v: + raise exceptions.CommandError("Argument mismatch: %s" % v.args[0]) + + def command(path): def decorator(function): @functools.wraps(function) def wrapper(*args, **kwargs): + verify_arg_signature(function, args, kwargs) return function(*args, **kwargs) wrapper.__dict__["command_path"] = path return wrapper @@ -70,8 +70,8 @@ setup( "kaitaistruct>=0.7, <0.8", "ldap3>=2.4,<2.5", "passlib>=1.6.5, <1.8", - "pyasn1>=0.3.1, <0.4", - "pyOpenSSL>=17.2,<17.4", + "pyasn1>=0.3.1,<0.5", + "pyOpenSSL>=17.2,<17.6", "pyparsing>=2.1.3, <2.3", "pyperclip>=1.5.22, <1.7", "requests>=2.9.1, <3", diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 87432163..43b97742 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -163,3 +163,10 @@ def test_decorator(): with taddons.context() as tctx: tctx.master.addons.add(a) assert tctx.master.commands.call("cmd1 bar") == "ret bar" + + +def test_verify_arg_signature(): + with pytest.raises(exceptions.CommandError): + command.verify_arg_signature(lambda: None, [1, 2], {}) + print('hello there') + command.verify_arg_signature(lambda a, b: None, [1, 2], {})
\ No newline at end of file |