aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-22 15:26:05 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-22 15:26:05 +1200
commit817e550aa1da0eab8b9116f46f8d65a80fcb46e2 (patch)
tree0a961b2610fa2a213ef8def8d0317ea0f372ea5d
parent30a69883925a4ee01b6eb0586e8295fa72458b16 (diff)
downloadmitmproxy-817e550aa1da0eab8b9116f46f8d65a80fcb46e2.tar.gz
mitmproxy-817e550aa1da0eab8b9116f46f8d65a80fcb46e2.tar.bz2
mitmproxy-817e550aa1da0eab8b9116f46f8d65a80fcb46e2.zip
Multiline specifications for pathod and pathoc.
-rw-r--r--libpathod/pathoc.py2
-rw-r--r--libpathod/rparse.py16
-rw-r--r--test/test_rparse.py28
3 files changed, 38 insertions, 8 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py
index 793135e7..9970ffd9 100644
--- a/libpathod/pathoc.py
+++ b/libpathod/pathoc.py
@@ -40,7 +40,7 @@ class Pathoc(tcp.TCPClient):
r = rparse.parse_request({}, i)
req = r.serve(self.wfile)
if reqdump:
- print >> fp, "\n>>", req["method"], req["path"]
+ print >> fp, "\n>>", req["method"], repr(req["path"])
for a in req["actions"]:
print >> fp, "\t",
for x in a:
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index 6eb7d5a4..17e1ebd4 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -17,7 +17,7 @@ class ParseException(Exception):
return "%s\n%s"%(self.s, " "*(self.col-1) + "^")
def __str__(self):
- return self.msg
+ return "%s at offset %s of %s"%(self.msg, self.col, repr(self.s))
class ServerError(Exception): pass
@@ -101,15 +101,15 @@ v_integer = pp.Regex(r"[+-]?\d+")\
v_literal = pp.MatchFirst(
[
- pp.QuotedString("\"", escChar="\\", unquoteResults=True),
- pp.QuotedString("'", escChar="\\", unquoteResults=True),
+ pp.QuotedString("\"", escChar="\\", unquoteResults=True, multiline=True),
+ pp.QuotedString("'", escChar="\\", unquoteResults=True, multiline=True),
]
)
v_naked_literal = pp.MatchFirst(
[
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
+Sep = pp.Optional(pp.Literal(":")).suppress()
+
class Response(Message):
comps = (
Body,
@@ -571,7 +573,7 @@ class Response(Message):
resp = pp.And(
[
Code.expr(),
- pp.ZeroOrMore(pp.Literal(":").suppress() + atom)
+ pp.ZeroOrMore(Sep + atom)
]
)
return resp
@@ -610,9 +612,9 @@ class Request(Message):
resp = pp.And(
[
Method.expr(),
- pp.Literal(":").suppress(),
+ Sep,
Path.expr(),
- pp.ZeroOrMore(pp.Literal(":").suppress() + atom)
+ pp.ZeroOrMore(Sep + atom)
]
)
return resp
diff --git a/test/test_rparse.py b/test/test_rparse.py
index 1527bddf..8d157a10 100644
--- a/test/test_rparse.py
+++ b/test/test_rparse.py
@@ -250,6 +250,34 @@ class TestParseRequest:
r = rparse.parse_request({}, 'GET:"/foo"')
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:
def test_parse_err(self):