mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 15:55:28 +00:00
base.PathodSpec -> http.PathodResponse
This commit is contained in:
parent
a46e17459d
commit
bf71a9a2a0
@ -259,39 +259,6 @@ class KeyValue(_Component):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class PathodSpec(Token):
|
|
||||||
def __init__(self, value):
|
|
||||||
self.value = value
|
|
||||||
try:
|
|
||||||
import http
|
|
||||||
self.parsed = http.Response(
|
|
||||||
http.Response.expr().parseString(
|
|
||||||
value.val,
|
|
||||||
parseAll=True
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except pp.ParseException, v:
|
|
||||||
raise exceptions.ParseException(v.msg, v.line, v.col)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def expr(klass):
|
|
||||||
e = pp.Literal("s").suppress()
|
|
||||||
e = e + ValueLiteral.expr()
|
|
||||||
return e.setParseAction(lambda x: klass(*x))
|
|
||||||
|
|
||||||
def values(self, settings):
|
|
||||||
return [
|
|
||||||
self.value.get_generator(settings),
|
|
||||||
]
|
|
||||||
|
|
||||||
def spec(self):
|
|
||||||
return "s%s"%(self.value.spec())
|
|
||||||
|
|
||||||
def freeze(self, settings):
|
|
||||||
f = self.parsed.freeze(settings).spec()
|
|
||||||
return PathodSpec(ValueLiteral(f.encode("string_escape")))
|
|
||||||
|
|
||||||
|
|
||||||
class CaselessLiteral(_Component):
|
class CaselessLiteral(_Component):
|
||||||
"""
|
"""
|
||||||
A caseless token that can take only one value.
|
A caseless token that can take only one value.
|
||||||
|
@ -88,6 +88,38 @@ class ShortcutUserAgent(_HeaderMixin, base.OptionsOrValue):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PathodResponse(base.Token):
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
try:
|
||||||
|
self.parsed = Response(
|
||||||
|
Response.expr().parseString(
|
||||||
|
value.val,
|
||||||
|
parseAll=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except pp.ParseException, v:
|
||||||
|
raise exceptions.ParseException(v.msg, v.line, v.col)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def expr(klass):
|
||||||
|
e = pp.Literal("s").suppress()
|
||||||
|
e = e + base.ValueLiteral.expr()
|
||||||
|
return e.setParseAction(lambda x: klass(*x))
|
||||||
|
|
||||||
|
def values(self, settings):
|
||||||
|
return [
|
||||||
|
self.value.get_generator(settings),
|
||||||
|
]
|
||||||
|
|
||||||
|
def spec(self):
|
||||||
|
return "s%s"%(self.value.spec())
|
||||||
|
|
||||||
|
def freeze(self, settings):
|
||||||
|
f = self.parsed.freeze(settings).spec()
|
||||||
|
return PathodResponse(base.ValueLiteral(f.encode("string_escape")))
|
||||||
|
|
||||||
|
|
||||||
def get_header(val, headers):
|
def get_header(val, headers):
|
||||||
"""
|
"""
|
||||||
Header keys may be Values, so we have to "generate" them as we try the
|
Header keys may be Values, so we have to "generate" them as we try the
|
||||||
@ -248,7 +280,7 @@ class Request(_HTTPMessage):
|
|||||||
ShortcutContentType,
|
ShortcutContentType,
|
||||||
ShortcutUserAgent,
|
ShortcutUserAgent,
|
||||||
Raw,
|
Raw,
|
||||||
base.PathodSpec,
|
PathodResponse,
|
||||||
|
|
||||||
actions.PauseAt,
|
actions.PauseAt,
|
||||||
actions.DisconnectAt,
|
actions.DisconnectAt,
|
||||||
@ -270,7 +302,7 @@ class Request(_HTTPMessage):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def pathodspec(self):
|
def pathodspec(self):
|
||||||
return self.tok(base.PathodSpec)
|
return self.tok(PathodResponse)
|
||||||
|
|
||||||
def preamble(self, settings):
|
def preamble(self, settings):
|
||||||
v = self.method.values(settings)
|
v = self.method.values(settings)
|
||||||
|
@ -182,32 +182,6 @@ class TestMisc:
|
|||||||
s = v.spec()
|
s = v.spec()
|
||||||
assert s == v.expr().parseString(s)[0].spec()
|
assert s == v.expr().parseString(s)[0].spec()
|
||||||
|
|
||||||
def test_pathodspec(self):
|
|
||||||
e = base.PathodSpec.expr()
|
|
||||||
v = e.parseString("s'200'")[0]
|
|
||||||
assert v.value.val == "200"
|
|
||||||
tutils.raises(
|
|
||||||
language.ParseException,
|
|
||||||
e.parseString,
|
|
||||||
"s'foo'"
|
|
||||||
)
|
|
||||||
|
|
||||||
v = e.parseString('s"200:b@1"')[0]
|
|
||||||
assert "@1" in v.spec()
|
|
||||||
f = v.freeze({})
|
|
||||||
assert "@1" not in f.spec()
|
|
||||||
|
|
||||||
def test_pathodspec_freeze(self):
|
|
||||||
e = base.PathodSpec(
|
|
||||||
base.ValueLiteral(
|
|
||||||
"200:b'foo':i10,'\\''".encode(
|
|
||||||
"string_escape"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert e.freeze({})
|
|
||||||
assert e.values({})
|
|
||||||
|
|
||||||
def test_prevalue(self):
|
def test_prevalue(self):
|
||||||
class TT(base.PreValue):
|
class TT(base.PreValue):
|
||||||
preamble = "m"
|
preamble = "m"
|
||||||
|
@ -77,7 +77,7 @@ class TestRequest:
|
|||||||
r = language.parse_requests(l)
|
r = language.parse_requests(l)
|
||||||
assert len(r) == 1
|
assert len(r) == 1
|
||||||
assert len(r[0].tokens) == 3
|
assert len(r[0].tokens) == 3
|
||||||
assert isinstance(r[0].tokens[2], base.PathodSpec)
|
assert isinstance(r[0].tokens[2], http.PathodResponse)
|
||||||
assert r[0].values({})
|
assert r[0].values({})
|
||||||
|
|
||||||
def test_render(self):
|
def test_render(self):
|
||||||
@ -320,3 +320,31 @@ def test_user_agent():
|
|||||||
v2 = v.freeze({})
|
v2 = v.freeze({})
|
||||||
v3 = v2.freeze({})
|
v3 = v2.freeze({})
|
||||||
assert v2.value.val == v3.value.val
|
assert v2.value.val == v3.value.val
|
||||||
|
|
||||||
|
|
||||||
|
def test_pathodspec():
|
||||||
|
e = http.PathodResponse.expr()
|
||||||
|
v = e.parseString("s'200'")[0]
|
||||||
|
assert v.value.val == "200"
|
||||||
|
tutils.raises(
|
||||||
|
language.ParseException,
|
||||||
|
e.parseString,
|
||||||
|
"s'foo'"
|
||||||
|
)
|
||||||
|
|
||||||
|
v = e.parseString('s"200:b@1"')[0]
|
||||||
|
assert "@1" in v.spec()
|
||||||
|
f = v.freeze({})
|
||||||
|
assert "@1" not in f.spec()
|
||||||
|
|
||||||
|
|
||||||
|
def test_pathodspec_freeze():
|
||||||
|
e = http.PathodResponse(
|
||||||
|
base.ValueLiteral(
|
||||||
|
"200:b'foo':i10,'\\''".encode(
|
||||||
|
"string_escape"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert e.freeze({})
|
||||||
|
assert e.values({})
|
||||||
|
Loading…
Reference in New Issue
Block a user