From eb5f37a7d19d74c88eed25d4b90f98bec1afa4be Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 26 May 2017 16:14:20 +0200 Subject: fix mypy annotations --- pathod/language/actions.py | 2 +- pathod/language/base.py | 8 +++++--- pathod/language/http.py | 4 +++- pathod/language/http2.py | 8 +++++--- pathod/language/websockets.py | 24 ++++++++---------------- 5 files changed, 22 insertions(+), 24 deletions(-) (limited to 'pathod') diff --git a/pathod/language/actions.py b/pathod/language/actions.py index fc57a18b..3e48f40d 100644 --- a/pathod/language/actions.py +++ b/pathod/language/actions.py @@ -50,7 +50,7 @@ class _Action(base.Token): class PauseAt(_Action): - unique_name = None # type: ignore + unique_name = None def __init__(self, offset, seconds): _Action.__init__(self, offset) diff --git a/pathod/language/base.py b/pathod/language/base.py index c8892748..3b33c5ed 100644 --- a/pathod/language/base.py +++ b/pathod/language/base.py @@ -6,7 +6,9 @@ import pyparsing as pp from mitmproxy.utils import strutils from mitmproxy.utils import human import typing # noqa -from . import generators, exceptions +from . import generators +from . import exceptions +from . import message # noqa class Settings: @@ -375,7 +377,7 @@ class OptionsOrValue(_Component): class Integer(_Component): - bounds = (None, None) # type: typing.Tuple[typing.Union[int, None], typing.Union[int , None]] + bounds = (None, None) # type: typing.Tuple[typing.Optional[int], typing.Optional[int]] preamble = "" def __init__(self, value): @@ -545,7 +547,7 @@ class NestedMessage(Token): A nested message, as an escaped string with a preamble. """ preamble = "" - nest_type = None # type: ignore + nest_type = None # type: typing.Optional[typing.Type[message.Message]] def __init__(self, value): Token.__init__(self) diff --git a/pathod/language/http.py b/pathod/language/http.py index 5cd717a9..1ea55d75 100644 --- a/pathod/language/http.py +++ b/pathod/language/http.py @@ -54,7 +54,9 @@ class Method(base.OptionsOrValue): class _HeaderMixin: - unique_name = None # type: ignore + @property + def unique_name(self): + return None def format_header(self, key, value): return [key, b": ", value, b"\r\n"] diff --git a/pathod/language/http2.py b/pathod/language/http2.py index 47d6e370..dc842e59 100644 --- a/pathod/language/http2.py +++ b/pathod/language/http2.py @@ -1,9 +1,9 @@ import pyparsing as pp + from mitmproxy.net import http from mitmproxy.net.http import user_agents, Headers from . import base, message - """ Normal HTTP requests: ::
: @@ -41,7 +41,9 @@ def get_header(val, headers): class _HeaderMixin: - unique_name = None # type: ignore + @property + def unique_name(self): + return None def values(self, settings): return ( @@ -146,7 +148,7 @@ class Times(base.Integer): class Response(_HTTP2Message): - unique_name = None # type: ignore + unique_name = None comps = ( Header, Body, diff --git a/pathod/language/websockets.py b/pathod/language/websockets.py index b4faf59b..68167964 100644 --- a/pathod/language/websockets.py +++ b/pathod/language/websockets.py @@ -1,10 +1,12 @@ import random import string +import typing # noqa + +import pyparsing as pp + import mitmproxy.net.websockets from mitmproxy.utils import strutils -import pyparsing as pp from . import base, generators, actions, message -import typing # noqa NESTED_LEADER = b"pathod!" @@ -74,7 +76,7 @@ class Times(base.Integer): preamble = "x" -COMPONENTS = ( +COMPONENTS = [ OpCode, Length, # Bit flags @@ -89,14 +91,13 @@ COMPONENTS = ( KeyNone, Key, Times, - Body, RawBody, -) +] class WebsocketFrame(message.Message): - components = COMPONENTS + components = COMPONENTS # type: typing.List[typing.Type[base._Component]] logattrs = ["body"] # Used for nested frames unique_name = "body" @@ -240,14 +241,5 @@ class NestedFrame(base.NestedMessage): nest_type = WebsocketFrame -COMP = typing.Tuple[ - typing.Type[OpCode], typing.Type[Length], typing.Type[Fin], typing.Type[RSV1], typing.Type[RSV2], typing.Type[RSV3], typing.Type[Mask], - typing.Type[actions.PauseAt], typing.Type[actions.DisconnectAt], typing.Type[actions.InjectAt], typing.Type[KeyNone], typing.Type[Key], - typing.Type[Times], typing.Type[Body], typing.Type[RawBody] -] - - class WebsocketClientFrame(WebsocketFrame): - components = typing.cast(COMP, COMPONENTS + ( - NestedFrame, - )) + components = COMPONENTS + [NestedFrame] -- cgit v1.2.3