diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-12-19 10:09:14 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2017-12-19 10:19:08 +1300 |
commit | 6563feaf059f9c829ba6b57d312a0f1dbfb84e33 (patch) | |
tree | 6baebf45d24369be51964d6a628902e582a325c2 /mitmproxy/utils/typecheck.py | |
parent | cda14830d349f4c1c60af2d1ec563e4894b836c3 (diff) | |
download | mitmproxy-6563feaf059f9c829ba6b57d312a0f1dbfb84e33.tar.gz mitmproxy-6563feaf059f9c829ba6b57d312a0f1dbfb84e33.tar.bz2 mitmproxy-6563feaf059f9c829ba6b57d312a0f1dbfb84e33.zip |
types: use new type validation mechanism in commands
Diffstat (limited to 'mitmproxy/utils/typecheck.py')
-rw-r--r-- | mitmproxy/utils/typecheck.py | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/mitmproxy/utils/typecheck.py b/mitmproxy/utils/typecheck.py index 87a0e804..1070fad0 100644 --- a/mitmproxy/utils/typecheck.py +++ b/mitmproxy/utils/typecheck.py @@ -1,41 +1,6 @@ import typing -def check_command_type(value: typing.Any, typeinfo: typing.Any) -> bool: - """ - Check if the provided value is an instance of typeinfo. Returns True if the - types match, False otherwise. This function supports only those types - required for command return values. - """ - typename = str(typeinfo) - if typename.startswith("typing.Sequence"): - try: - T = typeinfo.__args__[0] # type: ignore - except AttributeError: - # Python 3.5.0 - T = typeinfo.__parameters__[0] # type: ignore - if not isinstance(value, (tuple, list)): - return False - for v in value: - if not check_command_type(v, T): - return False - elif typename.startswith("typing.Union"): - try: - types = typeinfo.__args__ # type: ignore - except AttributeError: - # Python 3.5.x - types = typeinfo.__union_params__ # type: ignore - for T in types: - checks = [check_command_type(value, T) for T in types] - if not any(checks): - return False - elif value is None and typeinfo is None: - return True - elif not isinstance(value, typeinfo): - return False - return True - - def check_option_type(name: str, value: typing.Any, typeinfo: typing.Any) -> None: """ Check if the provided value is an instance of typeinfo and raises a |