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/base.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'pathod/language/base.py') 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) -- cgit v1.2.3 From e7990e0983344179e49a46f160e1482a0a0f6aa7 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 26 May 2017 16:22:13 +0200 Subject: fix recursive import --- pathod/language/base.py | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'pathod/language/base.py') diff --git a/pathod/language/base.py b/pathod/language/base.py index 3b33c5ed..97871e7e 100644 --- a/pathod/language/base.py +++ b/pathod/language/base.py @@ -8,7 +8,6 @@ from mitmproxy.utils import human import typing # noqa from . import generators from . import exceptions -from . import message # noqa class Settings: @@ -539,43 +538,3 @@ class IntField(_Component): def spec(self): return "%s%s" % (self.preamble, self.origvalue) - - -class NestedMessage(Token): - - """ - A nested message, as an escaped string with a preamble. - """ - preamble = "" - nest_type = None # type: typing.Optional[typing.Type[message.Message]] - - def __init__(self, value): - Token.__init__(self) - self.value = value - try: - self.parsed = self.nest_type( - self.nest_type.expr().parseString( - value.val.decode(), - parseAll=True - ) - ) - except pp.ParseException as v: - raise exceptions.ParseException(v.msg, v.line, v.col) - - @classmethod - def expr(cls): - e = pp.Literal(cls.preamble).suppress() - e = e + TokValueLiteral.expr() - return e.setParseAction(lambda x: cls(*x)) - - def values(self, settings): - return [ - self.value.get_generator(settings), - ] - - def spec(self): - return "%s%s" % (self.preamble, self.value.spec()) - - def freeze(self, settings): - f = self.parsed.freeze(settings).spec() - return self.__class__(TokValueLiteral(strutils.bytes_to_escaped_str(f.encode(), escape_single_quotes=True))) -- cgit v1.2.3