From a7bb0f5d02e0cdba628887846523a2ca48b2d0a9 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Wed, 13 Jul 2016 17:24:33 +0530 Subject: Add TCPFlow.match --- mitmproxy/models/tcp.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mitmproxy/models/tcp.py b/mitmproxy/models/tcp.py index e33475c2..6650141d 100644 --- a/mitmproxy/models/tcp.py +++ b/mitmproxy/models/tcp.py @@ -7,6 +7,8 @@ from typing import List import netlib.basetypes from mitmproxy.models.flow import Flow +import six + class TCPMessage(netlib.basetypes.Serializable): @@ -53,3 +55,22 @@ class TCPFlow(Flow): def __repr__(self): return "".format(len(self.messages)) + + def match(self, f): + """ + 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, six.string_types): + from .. import filt + + f = filt.parse(f) + if not f: + raise ValueError("Invalid filter expression.") + if f: + return f(self) + + return True -- cgit v1.2.3