move flow.match to flowfilter.match

This commit is contained in:
Thomas Kriechbaumer 2016-10-01 12:32:56 +02:00
parent ba84248910
commit 5f8b8bf35e
2 changed files with 8 additions and 19 deletions

View File

@ -36,6 +36,7 @@ from __future__ import absolute_import, print_function, division
import re
import sys
import functools
import six
from mitmproxy.models.http import HTTPFlow
from mitmproxy.models.tcp import TCPFlow
@ -501,16 +502,15 @@ def parse(s):
return None
def match(self, flow, flt):
def match(flow, flt):
"""
Match a flow against a compiled filter expression.
Matches a flow against a compiled filter expression.
Returns True if matched, False if not.
If flt is a string, it will be compiled as a filter expression.
If the expression is invalid, ValueError is raised.
"""
if isinstance(flt, six.string_types):
flt = parse(flt)
if not flt:
raise ValueError("Invalid filter expression.")

View File

@ -189,20 +189,9 @@ class Flow(stateobject.StateObject):
self.reply.commit()
master.handle_accept_intercept(self)
def match(self, flt):
"""
Matches a flow against a compiled filter expression.
Returns True if matched, False if not.
def match(self, f):
import warnings
warnings.warn(".match() is deprecated, please use flowfilter.match(some_flow, some_filter) instead.", DeprecationWarning)
If flt is a string, it will be compiled as a filter expression.
If the expression is invalid, ValueError is raised.
"""
if isinstance(flt, six.string_types):
from ..flowfilter import parse
flt = parse(flt)
if not flt:
raise ValueError("Invalid filter expression.")
if flt:
return flt(self)
return True
from mitmproxy import flowfilter
return flowfilter.match(self, f)