aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2014-10-25 17:27:08 +1300
committerAldo Cortesi <aldo@nullcube.com>2014-10-25 17:27:08 +1300
commit609d6eab30aac0601106993eb8c5d9a953ba402b (patch)
tree6cf640d10acb13495d4b339965f470f3dd80f878
parentac4e9f8cb5a9541dcff0a86efdb04357b9bc027f (diff)
downloadmitmproxy-609d6eab30aac0601106993eb8c5d9a953ba402b.tar.gz
mitmproxy-609d6eab30aac0601106993eb8c5d9a953ba402b.tar.bz2
mitmproxy-609d6eab30aac0601106993eb8c5d9a953ba402b.zip
Make grammar less ambiguous for multi-pattern files
-rw-r--r--libpathod/language.py4
-rw-r--r--test/test_language.py11
2 files changed, 12 insertions, 3 deletions
diff --git a/libpathod/language.py b/libpathod/language.py
index f40499f6..d8f201db 100644
--- a/libpathod/language.py
+++ b/libpathod/language.py
@@ -137,7 +137,7 @@ DATATYPES = dict(
)
-v_integer = pp.Regex(r"\d+")\
+v_integer = pp.Word(pp.nums)\
.setName("integer")\
.setParseAction(lambda toks: int(toks[0]))
@@ -308,7 +308,7 @@ class ValueGenerate(_Token):
u = reduce(
operator.or_,
[pp.Literal(i) for i in utils.SIZE_UNITS.keys()]
- )
+ ).leaveWhitespace()
e = e + pp.Optional(u, default=None)
s = pp.Literal(",").suppress()
diff --git a/test/test_language.py b/test/test_language.py
index 007eb5b7..b2add149 100644
--- a/test/test_language.py
+++ b/test/test_language.py
@@ -464,7 +464,7 @@ class TestRequest:
r = parse_request('GET:@1k')
assert len(r.path.string()) == 1024
- def test_multi(self):
+ def test_multiple(self):
r = language.parse_requests("GET:/ PUT:/")
assert r[0].method.string() == "GET"
assert r[1].method.string() == "PUT"
@@ -490,6 +490,15 @@ class TestRequest:
assert r[0].method.string() == "GET"
assert r[1].method.string() == "PUT"
+ l = """
+ get:"http://localhost:9999/p/200":ir,@1
+ get:"http://localhost:9999/p/200":ir,@2
+ """
+ r = language.parse_requests(l)
+ assert len(r) == 2
+ assert r[0].method.string() == "GET"
+ assert r[1].method.string() == "GET"
+
def test_render(self):
s = cStringIO.StringIO()
r = parse_request("GET:'/foo'")