From d115b5ae707d00dd09bebc7f5e63d4e25cdb1a04 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 14 Sep 2012 09:41:01 +1200 Subject: Expand Flow.match to accept either a string or a compiled filter expression. --- libmproxy/flow.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libmproxy') 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 -- cgit v1.2.3