mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 07:49:10 +00:00
Multiline specifications for pathod and pathoc.
This commit is contained in:
parent
30a6988392
commit
817e550aa1
@ -40,7 +40,7 @@ class Pathoc(tcp.TCPClient):
|
|||||||
r = rparse.parse_request({}, i)
|
r = rparse.parse_request({}, i)
|
||||||
req = r.serve(self.wfile)
|
req = r.serve(self.wfile)
|
||||||
if reqdump:
|
if reqdump:
|
||||||
print >> fp, "\n>>", req["method"], req["path"]
|
print >> fp, "\n>>", req["method"], repr(req["path"])
|
||||||
for a in req["actions"]:
|
for a in req["actions"]:
|
||||||
print >> fp, "\t",
|
print >> fp, "\t",
|
||||||
for x in a:
|
for x in a:
|
||||||
|
@ -17,7 +17,7 @@ class ParseException(Exception):
|
|||||||
return "%s\n%s"%(self.s, " "*(self.col-1) + "^")
|
return "%s\n%s"%(self.s, " "*(self.col-1) + "^")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.msg
|
return "%s at offset %s of %s"%(self.msg, self.col, repr(self.s))
|
||||||
|
|
||||||
|
|
||||||
class ServerError(Exception): pass
|
class ServerError(Exception): pass
|
||||||
@ -101,15 +101,15 @@ v_integer = pp.Regex(r"[+-]?\d+")\
|
|||||||
|
|
||||||
v_literal = pp.MatchFirst(
|
v_literal = pp.MatchFirst(
|
||||||
[
|
[
|
||||||
pp.QuotedString("\"", escChar="\\", unquoteResults=True),
|
pp.QuotedString("\"", escChar="\\", unquoteResults=True, multiline=True),
|
||||||
pp.QuotedString("'", escChar="\\", unquoteResults=True),
|
pp.QuotedString("'", escChar="\\", unquoteResults=True, multiline=True),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
v_naked_literal = pp.MatchFirst(
|
v_naked_literal = pp.MatchFirst(
|
||||||
[
|
[
|
||||||
v_literal,
|
v_literal,
|
||||||
pp.Word("".join(i for i in pp.printables if i not in ",:"))
|
pp.Word("".join(i for i in pp.printables if i not in ",:\n"))
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -543,6 +543,8 @@ class Message:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
Sep = pp.Optional(pp.Literal(":")).suppress()
|
||||||
|
|
||||||
class Response(Message):
|
class Response(Message):
|
||||||
comps = (
|
comps = (
|
||||||
Body,
|
Body,
|
||||||
@ -571,7 +573,7 @@ class Response(Message):
|
|||||||
resp = pp.And(
|
resp = pp.And(
|
||||||
[
|
[
|
||||||
Code.expr(),
|
Code.expr(),
|
||||||
pp.ZeroOrMore(pp.Literal(":").suppress() + atom)
|
pp.ZeroOrMore(Sep + atom)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return resp
|
return resp
|
||||||
@ -610,9 +612,9 @@ class Request(Message):
|
|||||||
resp = pp.And(
|
resp = pp.And(
|
||||||
[
|
[
|
||||||
Method.expr(),
|
Method.expr(),
|
||||||
pp.Literal(":").suppress(),
|
Sep,
|
||||||
Path.expr(),
|
Path.expr(),
|
||||||
pp.ZeroOrMore(pp.Literal(":").suppress() + atom)
|
pp.ZeroOrMore(Sep + atom)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return resp
|
return resp
|
||||||
|
@ -250,6 +250,34 @@ class TestParseRequest:
|
|||||||
r = rparse.parse_request({}, 'GET:"/foo"')
|
r = rparse.parse_request({}, 'GET:"/foo"')
|
||||||
assert str(r)
|
assert str(r)
|
||||||
|
|
||||||
|
def test_multiline(self):
|
||||||
|
l = """
|
||||||
|
GET
|
||||||
|
"/foo"
|
||||||
|
ir,@1
|
||||||
|
"""
|
||||||
|
r = rparse.parse_request({}, l)
|
||||||
|
assert r.method == "GET"
|
||||||
|
assert r.path == "/foo"
|
||||||
|
assert r.actions
|
||||||
|
|
||||||
|
|
||||||
|
l = """
|
||||||
|
GET
|
||||||
|
|
||||||
|
"/foo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bar"
|
||||||
|
|
||||||
|
ir,@1
|
||||||
|
"""
|
||||||
|
r = rparse.parse_request({}, l)
|
||||||
|
assert r.method == "GET"
|
||||||
|
assert r.path.s.endswith("bar")
|
||||||
|
assert r.actions
|
||||||
|
|
||||||
|
|
||||||
class TestParseResponse:
|
class TestParseResponse:
|
||||||
def test_parse_err(self):
|
def test_parse_err(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user