mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
fix recursive import
This commit is contained in:
parent
eb5f37a7d1
commit
e7990e0983
@ -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)))
|
||||
|
@ -253,7 +253,7 @@ class Response(_HTTPMessage):
|
||||
return ":".join([i.spec() for i in self.tokens])
|
||||
|
||||
|
||||
class NestedResponse(base.NestedMessage):
|
||||
class NestedResponse(message.NestedMessage):
|
||||
preamble = "s"
|
||||
nest_type = Response
|
||||
|
||||
|
@ -205,7 +205,7 @@ class Response(_HTTP2Message):
|
||||
return ":".join([i.spec() for i in self.tokens])
|
||||
|
||||
|
||||
class NestedResponse(base.NestedMessage):
|
||||
class NestedResponse(message.NestedMessage):
|
||||
preamble = "s"
|
||||
nest_type = Response
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
import abc
|
||||
from . import actions, exceptions
|
||||
from mitmproxy.utils import strutils
|
||||
import typing # noqa
|
||||
|
||||
import pyparsing as pp
|
||||
|
||||
from mitmproxy.utils import strutils
|
||||
from . import actions, exceptions, base
|
||||
|
||||
LOG_TRUNCATE = 1024
|
||||
|
||||
|
||||
@ -96,3 +99,46 @@ class Message:
|
||||
|
||||
def __repr__(self):
|
||||
return self.spec()
|
||||
|
||||
|
||||
class NestedMessage(base.Token):
|
||||
"""
|
||||
A nested message, as an escaped string with a preamble.
|
||||
"""
|
||||
preamble = ""
|
||||
nest_type = None # type: typing.Optional[typing.Type[Message]]
|
||||
|
||||
def __init__(self, value):
|
||||
super().__init__()
|
||||
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 + base.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__(
|
||||
base.TokValueLiteral(
|
||||
strutils.bytes_to_escaped_str(f.encode(), escape_single_quotes=True)
|
||||
)
|
||||
)
|
||||
|
@ -236,7 +236,7 @@ class WebsocketFrame(message.Message):
|
||||
return ":".join([i.spec() for i in self.tokens])
|
||||
|
||||
|
||||
class NestedFrame(base.NestedMessage):
|
||||
class NestedFrame(message.NestedMessage):
|
||||
preamble = "f"
|
||||
nest_type = WebsocketFrame
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user