aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-09-14 09:41:01 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-09-14 09:41:01 +1200
commitd115b5ae707d00dd09bebc7f5e63d4e25cdb1a04 (patch)
tree460a078d12be2af9dd36fe4f76cbf41cfe7fff8a
parent54cee9db7f6a03bca3058a4b4722073bb55896d8 (diff)
downloadmitmproxy-d115b5ae707d00dd09bebc7f5e63d4e25cdb1a04.tar.gz
mitmproxy-d115b5ae707d00dd09bebc7f5e63d4e25cdb1a04.tar.bz2
mitmproxy-d115b5ae707d00dd09bebc7f5e63d4e25cdb1a04.zip
Expand Flow.match to accept either a string or a compiled filter expression.
-rw-r--r--libmproxy/flow.py7
-rw-r--r--test/test_flow.py9
2 files changed, 13 insertions, 3 deletions
diff --git a/libmproxy/flow.py b/libmproxy/flow.py
index 44bb1018..8e4c2117 100644
--- a/libmproxy/flow.py
+++ b/libmproxy/flow.py
@@ -1092,7 +1092,14 @@ class Flow:
"""
Match this flow against a compiled filter expression. Returns True
if matched, False if not.
+
+ If f is a string, it will be compiled as a filter expression. If
+ the expression is invalid, ValueError is raised.
"""
+ if isinstance(f, basestring):
+ f = filt.parse(f)
+ if not f:
+ raise ValueError("Invalid filter expression.")
if f:
return f(self)
return True
diff --git a/test/test_flow.py b/test/test_flow.py
index 53d92f25..277d2407 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -171,12 +171,15 @@ class TestFlow:
f = tutils.tflow()
f.response = tutils.tresp()
f.request = f.response.request
- assert not f.match(filt.parse("~b test"))
+ assert not f.match("~b test")
assert f.match(None)
- assert not f.match(filt.parse("~b test"))
+ assert not f.match("~b test")
f = tutils.tflow_err()
- assert f.match(filt.parse("~e"))
+ assert f.match("~e")
+
+ tutils.raises(ValueError, f.match, "~")
+
def test_backup(self):
f = tutils.tflow()